]> sourceware.org Git - systemtap.git/commitdiff
stapio main loop: always time out on pselect()
authorFrank Ch. Eigler <fche@redhat.com>
Wed, 23 Mar 2016 22:02:15 +0000 (18:02 -0400)
committerFrank Ch. Eigler <fche@redhat.com>
Thu, 24 Mar 2016 00:42:50 +0000 (20:42 -0400)
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

index 9df06c506b0458062b19c2ccee892f8676a1fa67..65321d57a4008ab7f759be5d7385f1242d9cdc2f 100644 (file)
@@ -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
This page took 0.031546 seconds and 5 git commands to generate.