nats-io / nats-top

A top-like tool for monitoring NATS servers.
https://nats.io
MIT License
351 stars 30 forks source link

Allow use of CTRL-Z #16

Open wallyqs opened 9 years ago

wallyqs commented 9 years ago

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

derekcollison commented 9 years ago

Do you have a signal handler installed?

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

wallyqs commented 9 years ago

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

mcqueary commented 9 years ago

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 <notifications@github.com

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 larry@apcera.com | @mcqueary | github.com/mcqueary

mcqueary commented 9 years ago

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 larry@apcera.com 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 < notifications@github.com> 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 larry@apcera.com | @mcqueary | github.com/mcqueary

Larry McQueary | Director, Messaging Technology larry@apcera.com | @mcqueary | github.com/mcqueary

wallyqs commented 9 years ago

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.

mcqueary commented 9 years ago

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

On Thu, Sep 17, 2015 at 1:40 PM, Waldemar Quevedo notifications@github.com 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.

wallyqs commented 9 years ago

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

mcqueary commented 8 years ago

@wallyqs did you ever implement this?

wallyqs commented 8 years ago

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