From 6d04c012a2a9699c99e56e8a54c5d60c93c91af5 Mon Sep 17 00:00:00 2001 From: "Frank Ch. Eigler" Date: Wed, 23 Mar 2016 18:02:15 -0400 Subject: [PATCH] stapio main loop: always time out on pselect() The main thread's pselect() call must now get a timeout setting too, because it is responsible for orderly shutdown of the stap module in case of interrupts. Without a polling timeout, the pselect() can just sit there, with other reader threads happily continuing their work, as though the ^C never took effect. --- staprun/mainloop.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/staprun/mainloop.c b/staprun/mainloop.c index 9df06c506..65321d57a 100644 --- a/staprun/mainloop.c +++ b/staprun/mainloop.c @@ -649,15 +649,15 @@ int stp_main_loop(void) pthread_sigmask(SIG_BLOCK, &blockset, &mainset); } - /* In monitor mode, we must timeout pselect to poll the monitor - * interface. */ if (monitor) - { monitor_setup(); - ts.tv_sec = 0; - ts.tv_nsec = 500*1000*1000; - timeout = &ts; - } + + /* In monitor mode, we must timeout pselect to poll the monitor + interface. In non-monitor mode, we must timeout pselect so that + we can handle pending_interrupts. */ + ts.tv_sec = 0; + ts.tv_nsec = 500*1000*1000; + timeout = &ts; /* handle messages from control channel */ while (1) { @@ -671,7 +671,10 @@ int stp_main_loop(void) int btype = STP_EXIT; int rc = write(control_channel, &btype, sizeof(btype)); dbug(2, "signal-triggered %d exit rc %d\n", pending_interrupts, rc); - cleanup_and_exit (load_only /* = detach */, 0); + if (monitor || (pending_interrupts > 2)) /* user mashing on ^C multiple times */ + cleanup_and_exit (load_only /* = detach */, 0); + else + {} /* await STP_EXIT reply message to kill staprun */ } /* If the runtime does not implement select() on the command -- 2.43.5