]> sourceware.org Git - systemtap.git/commitdiff
stapsh: Remove the signal command, just call it quit
authorJosh Stone <jistone@redhat.com>
Fri, 11 Mar 2011 23:54:43 +0000 (15:54 -0800)
committerJosh Stone <jistone@redhat.com>
Sat, 12 Mar 2011 01:19:29 +0000 (17:19 -0800)
As Przemysław pointed out, signal numbers are not 100% portable across
different architectures, and we should allow for the possibility of
cross-compilation in --remote execution.  Since the only point of the
signal command was to trigger an exit, let's just replace it with a
"quit" command.

* runtime/staprun/stapsh.c (do_signal -> do_quit): Forget about parsing
  signal numbers -- just call cleanup (which sends SIGHUP anyway).
  (cleanup): Mask signals, so if called from non-signal context, we
  won't get a reentry (especially for SIGCHLD).
* remote.cxx (stapsh::handle_poll): Send a quit instead of signal.

remote.cxx
runtime/staprun/stapsh.c

index bf41b92801a8bfc82e532ee15a618e9d0d7e8ae5..7736ed76c5cd75dd8ce7d948351c742a63577c33 100644 (file)
@@ -149,9 +149,7 @@ class stapsh : public remote {
                 {
                   if (fds[i].revents & POLLOUT)
                     {
-                      ostringstream cmd;
-                      cmd << "signal " << SIGINT << "\n";
-                      if (send_command(cmd.str()) == 0)
+                      if (send_command("quit\n") == 0)
                         {
                           ++interrupts_sent;
                           continue;
index 8b51927b631d5e6f9c3c5846754c864c3e2672c6..2d5292e37eceb801dd46e8536cd240b6f97be3d9 100644 (file)
@@ -34,9 +34,9 @@
 //            in the arguments.  Any embedded NIL (=00) will truncate the
 //            argument in the actual command invocation.
 //
-//   command: signal NUM
+//   command: quit
 //     reply: (none)
-//      desc: Send signal NUM to the child process.
+//      desc: Signal the child process to quit, then cleanup and exit.
 //
 // If stapsh reaches EOF on its standard input, it will send SIGHUP to the
 // child process, wait for completion, then cleanup and exit normally.
@@ -73,14 +73,17 @@ struct stapsh_handler {
 static int do_hello(void);
 static int do_file(void);
 static int do_run(void);
-static int do_signal(void);
+static int do_quit(void);
 
+static const int signals[] = {
+    SIGHUP, SIGPIPE, SIGINT, SIGTERM, SIGCHLD
+};
 
 static const struct stapsh_handler commands[] = {
       { "stap", do_hello },
       { "file", do_file },
       { "run", do_run },
-      { "signal", do_signal },
+      { "quit", do_quit },
 };
 
 static char tmpdir[FILENAME_MAX] = "";
@@ -91,6 +94,15 @@ static pid_t staprun_pid = -1;
 static void __attribute__ ((noreturn))
 cleanup(int status)
 {
+  // Mask signals, so if called from non-signal context, we
+  // won't get a reentry (especially for SIGCHLD).
+  unsigned i;
+  sigset_t mask;
+  sigemptyset (&mask);
+  for (i = 0; i < sizeof(signals) / sizeof(*signals); ++i)
+    sigaddset (&mask, signals[i]);
+  sigprocmask(SIG_BLOCK, &mask, 0);
+
   if (staprun_pid > 0)
     {
       int rc, ret;
@@ -127,7 +139,6 @@ handle_signal(int sig __attribute__ ((unused)))
 static void
 setup_signals (void)
 {
-  static int signals[] = { SIGHUP, SIGPIPE, SIGINT, SIGTERM, SIGCHLD };
   unsigned i;
   struct sigaction sa;
   sa.sa_handler = handle_signal;
@@ -309,20 +320,9 @@ do_run()
 }
 
 static int
-do_signal()
+do_quit()
 {
-  if (staprun_pid <= 0)
-    return 1;
-
-  char* arg = strtok(NULL, STAPSH_TOK_DELIM);
-  if (!arg)
-    {
-      fprintf(stderr, "missing signal number\n");
-      return 1;
-    }
-
-  int sig = atoi(arg);
-  return kill(staprun_pid, sig);
+  cleanup(0);
 }
 
 int
This page took 0.03002 seconds and 5 git commands to generate.