tenox7 / ttyplot

a realtime plotting utility for terminal/console with data input from stdin
Apache License 2.0
961 stars 43 forks source link

Fix signal handler #62

Closed elfring closed 6 months ago

elfring commented 1 year ago

The function “endwin” does not belong to the list of async-signal-safe functions. I guess that a different program design will be needed for your functions “finish” and “resize”.

tenox7 commented 1 year ago

ha, thats a tricky one, reason being that ttyplot does a blocking read from stdin and redraw when there is input; so KEY_RESIZE or flag + periodic redraw cannot be used without resorting to threads. I'm thinking that perhaps sigprocmask() could be used to block interrupting endwin() with another one. Because ttyplot doesn't use endwin is not used elsewhere and no other ncurses input functions are used it may be good enough.

I really don't want to go in to threads because I like to use ttyplot on older systems that may not have these.

elfring commented 1 year ago

Would you like to consider other software design options?

elfring commented 1 year ago

:crystal_ball: Will it matter for you if signal notifications would be handled only by a separate thread?

tenox7 commented 1 year ago

I really don't want to do threads in ttyplot. I mentioned it above. I sometimes use it on very old systems that do not have pthreads even. Also I don't like the complexity.

I will consider/accept anything else. I like sigwaitinfo() and sigprocmask(). Also the self pipe trick looks really cool. I was actually thinking about feeding ttyplot a sync clock via pipe mixed with data like over a sync serial line. This could be interlaced with refresh events. The chart would advance only if there is data coming in.

Are you willing to send a PR? Or do you want me to look at implementing these?

elfring commented 1 year ago

Also the self pipe trick looks really cool.

:crystal_ball: How far would you get with another event-driven application architecture?

Or do you want me to look at implementing these?

:thought_balloon: Probably, yes.

Further collateral evolution would be nice, wouldn't it?

tenox7 commented 1 year ago

Hahaha.

BTW I started looking at writing a more modern replacement for ttyplot. Most likely in Go, using something like termbox-go or maybe simpler termui. It will have colors, braille character charts, bar charts, etc. Ttyplot2 will be the new, modern, fancy, flashy thing. I want ttyplot1 to remain pure, plain and simple. Compatible with older Unix like AIX, HPUX, IRIX, Solaris, Unixware, SCO, Tru64, dont use threads, unicode, etc.

tenox7 commented 1 year ago

I added sigprocmask() for now. Feel free to submit a PR with something better.

elfring commented 1 year ago

:thought_balloon: I find your signal handler implementations still async-signal-unsafe.

tenox7 commented 1 year ago

Yes thats true. I'm not closing the ticket. However fixing this will require much bigger changes. This is just a quick patch for a most obvious issue.

tenox7 commented 1 year ago

how does this work with the default signal handler in curses?