How to wait for Ctrl+C (session.Signals does not work as expected)
- Dominant language
- Go
- Stars
- 4.2k
- Forks
- 509
- PR merge metrics
- No merged PRs in 30d
Description
I'm trying to block the handler whenever a reverse port forwarding was requested. The tunnel should exist as long as the user stops the SSH session by entering the Ctrl+C sequence. There is a Signals function that I would expect to do this, but nothing arrives at the channel in my testing code:
```go
func handler(s ssh.Session) {
// ...
if requestedRevPortForwarding { // set in the reversePortForwardingHandler using ctx.SetValue()
io.WriteString(s, "[*] Forwarding initialized!\n")
io.WriteString(s, "[*] Stop with Ctrl+C")
signals := make(chan ssh.Signal, 10)
s.Signals(signals)
go func() {
for {
fmt.Println(<-signals)
}
}()
}
<-s.Context().Done() // block
// ...
}
```
With this example the user can only exit the session by closing the terminal he's in. There must be a way to handle this with signals. I know that I can use terminals to get like a "quit" command, but I want to use the Ctrl+C approach here.
Any idea why this is not working or an alternative to solve this?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.