Message ID | c79ad8475f0d30c81f45660db98dea237e187e26.1587958237.git.geoff@infradead.org |
---|---|
State | New |
Headers | show |
Series | [v1,1/5] ncurses/nc-menu: Remove stray declaration | expand |
Hi Geoff, > -static int running; > +static volatile sig_atomic_t running; OK, looks good. > -static void sigint_handler(int __attribute__((unused)) signum) > +static void sigint_handler(int signum) > { > running = 0; > + signal(signum, sigint_handler); But this shouldn't be needed; invoking the signal shouldn't change the handler - at least on Linux. Do you have a specific OS implementation that requires the signal to be re-registered? Cheers, Jeremy
Hi Jeremy, On 5/2/20 11:00 PM, Jeremy Kerr wrote: >> -static void sigint_handler(int __attribute__((unused)) signum) >> +static void sigint_handler(int signum) >> { >> running = 0; >> + signal(signum, sigint_handler); > > But this shouldn't be needed; invoking the signal shouldn't change the > handler - at least on Linux. Do you have a specific OS implementation > that requires the signal to be re-registered? I've never experienced needing to do this, but I though to add it in to be more compatible. I don't think it matters that much to have it or not. Can you think of some problem having it could cause? -Geoff
diff --git a/discover/pb-discover.c b/discover/pb-discover.c index e2b36dd..f67eea5 100644 --- a/discover/pb-discover.c +++ b/discover/pb-discover.c @@ -113,11 +113,12 @@ static int opts_parse(struct opts *opts, int argc, char *argv[]) return optind != argc; } -static int running; +static volatile sig_atomic_t running; -static void sigint_handler(int __attribute__((unused)) signum) +static void sigint_handler(int signum) { running = 0; + signal(signum, sigint_handler); } int main(int argc, char *argv[])
Variables shared between signal handlers and the main program need to be of type 'volatile sig_atomic_t'. Also, after a signal is serviced it should be re-enabled, so add a call to signal() in the handler. Signed-off-by: Geoff Levand <geoff@infradead.org> --- discover/pb-discover.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)