nats-top icon indicating copy to clipboard operation
nats-top copied to clipboard

Allow use of CTRL-Z

Open wallyqs opened this issue 9 years ago • 9 comments

It seems the framework is making it not possible to respond to some signals.

wallyqs avatar Sep 17 '15 01:09 wallyqs

Do you have a signal handler installed?

https://github.com/nats-io/gnatsd/blob/master/server/server.go#L146

derekcollison avatar Sep 17 '15 02:09 derekcollison

The issue seems to be that the termui+termbox dependency which I added uses raw terminal input mode and also handles the signals instead, that is why they are ended up being disabled: https://github.com/nsf/termbox-go/blob/9914d1c528437633580e9aeda764bfb8c1415a9a/api.go#L305

wallyqs avatar Sep 17 '15 04:09 wallyqs

Raw terminal mode just means no key bindings. From what I see, termbox is only handling SIGWINCH and SIGIO. You could still keybind CTRL-z as SIGTSTP, and install your own signal handler for SIGTSTP. (caveat: I only looked at the code you linked. If other signals are actively being blocked/ignored, I didn't see it.)

On Wed, Sep 16, 2015 at 10:56 PM, Waldemar Quevedo <[email protected]

wrote:

The issue seems to be that the termui+termbox dependency which I added uses raw terminal input mode and also handles the signals instead, that is why they are ended up being disabled: https://github.com/nsf/termbox-go/blob/9914d1c528437633580e9aeda764bfb8c1415a9a/api.go#L305

— Reply to this email directly or view it on GitHub https://github.com/nats-io/nats-top/issues/16#issuecomment-140970220.

Larry McQueary | Director, Messaging Technology [email protected] | @mcqueary | github.com/mcqueary

mcqueary avatar Sep 17 '15 18:09 mcqueary

If you do that, you might want to also handle SIGINT. I notice that top(1) handles both SIGTSTP (CTRL-Z) and SIGINT (CTRL-C) in the usual way.

On Thu, Sep 17, 2015 at 12:27 PM, Larry McQueary [email protected] wrote:

Raw terminal mode just means no key bindings. From what I see, termbox is only handling SIGWINCH and SIGIO. You could still keybind CTRL-z as SIGTSTP, and install your own signal handler for SIGTSTP. (caveat: I only looked at the code you linked. If other signals are actively being blocked/ignored, I didn't see it.)

On Wed, Sep 16, 2015 at 10:56 PM, Waldemar Quevedo < [email protected]> wrote:

The issue seems to be that the termui+termbox dependency which I added uses raw terminal input mode and also handles the signals instead, that is why they are ended up being disabled: https://github.com/nsf/termbox-go/blob/9914d1c528437633580e9aeda764bfb8c1415a9a/api.go#L305

— Reply to this email directly or view it on GitHub https://github.com/nats-io/nats-top/issues/16#issuecomment-140970220.

Larry McQueary | Director, Messaging Technology [email protected] | @mcqueary | github.com/mcqueary

Larry McQueary | Director, Messaging Technology [email protected] | @mcqueary | github.com/mcqueary

mcqueary avatar Sep 17 '15 18:09 mcqueary

Thanks @mcqueary . Yes the issue seems to be that termbox is disabling syscall_ISIG which is required by SIGTSTP to work as intended. https://github.com/nsf/termbox-go/blob/9914d1c528437633580e9aeda764bfb8c1415a9a/api.go#L62 Once removing the toggling of that flag in termbox, I was able to make, ctrl-z, fg work properly.

wallyqs avatar Sep 17 '15 19:09 wallyqs

Ah -- good thing I included that caveat ;) Nice work.

On Thu, Sep 17, 2015 at 1:40 PM, Waldemar Quevedo [email protected] wrote:

Thanks @mcqueary https://github.com/mcqueary . Yes the issue seems to be that termbox is disabling syscall_ISIG which is required by SIGTSTP to work as intended.

https://github.com/nsf/termbox-go/blob/9914d1c528437633580e9aeda764bfb8c1415a9a/api.go#L62 Once removing the toggling of that flag in termbox, I was able to make, ctrl-z, fg work properly.

— Reply to this email directly or view it on GitHub https://github.com/nats-io/nats-top/issues/16#issuecomment-141204111.

mcqueary avatar Sep 17 '15 19:09 mcqueary

Looked a bit into this one, and fix seems to be more involved than I thought. It is possible to allow suspending a process, but once the process resumes I should be handling SIGCONT to do so gracefully and currently Go 1.5.1 does not have a built-in way to handle it. There are alternatives for doing so by using cgo though: https://github.com/burke/go-sigcont

wallyqs avatar Sep 18 '15 18:09 wallyqs

@wallyqs did you ever implement this?

mcqueary avatar Mar 20 '16 00:03 mcqueary

Haven't, though maybe possible to do so now since looks like SIGCONT handling is supported in Go 1.6 https://github.com/golang/go/commit/81b35117d9e0b99a5894d65c8c419541a48c87dd

wallyqs avatar Mar 20 '16 00:03 wallyqs