From: Josh Stone Date: Fri, 11 Mar 2011 23:54:43 +0000 (-0800) Subject: stapsh: Remove the signal command, just call it quit X-Git-Tag: release-1.5~179 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=7185074b5c2f159b00f903bead9118e4a897ae8f;p=systemtap.git stapsh: Remove the signal command, just call it quit 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. --- diff --git a/remote.cxx b/remote.cxx index bf41b9280..7736ed76c 100644 --- a/remote.cxx +++ b/remote.cxx @@ -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; diff --git a/runtime/staprun/stapsh.c b/runtime/staprun/stapsh.c index 8b51927b6..2d5292e37 100644 --- a/runtime/staprun/stapsh.c +++ b/runtime/staprun/stapsh.c @@ -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