diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | buildrun.cxx | 32 | ||||
-rw-r--r-- | runtime/stpd/ChangeLog | 9 | ||||
-rw-r--r-- | runtime/stpd/librelay.c | 23 | ||||
-rw-r--r-- | runtime/stpd/stpd.c | 7 |
5 files changed, 61 insertions, 16 deletions
@@ -1,3 +1,9 @@ +2005-12-08 Frank Ch. Eigler <fche@elastic.org> + + PR 1937 + * buildrun.cxx (run_pass): Pass new "-d PID" option to stpd. + Set SIGHUP to SIG_IGN too. + 2005-12-07 Graydon Hoare <graydon@redhat.com> * staptree.cxx (traversing_visitor::visit_foreach_loop): Visit diff --git a/buildrun.cxx b/buildrun.cxx index ade972be..05d903d5 100644 --- a/buildrun.cxx +++ b/buildrun.cxx @@ -14,6 +14,7 @@ extern "C" { #include "signal.h" +#include <sys/wait.h> } @@ -41,6 +42,17 @@ lex_cast_qstring(IN const & in) } +template <typename T> +static string +stringify(T t) +{ + ostringstream s; + s << t; + return s.str (); +} + + + int compile_pass (systemtap_session& s) { @@ -117,16 +129,6 @@ compile_pass (systemtap_session& s) } -template <typename T> -static string -stringify(T t) -{ - ostringstream s; - s << t; - return s.str (); -} - - int run_pass (systemtap_session& s) { @@ -141,9 +143,6 @@ run_pass (systemtap_session& s) } else // real run { - // leave parent process alone - sighandler_t oldsig = signal (SIGINT, SIG_IGN); - // for now, just spawn stpd string stpd_cmd = string("sudo ") + string(PKGLIBDIR) + "/stpd " @@ -151,6 +150,8 @@ run_pass (systemtap_session& s) + (s.verbose ? "" : "-q ") + (s.output_file.empty() ? "" : "-o " + s.output_file + " "); + stpd_cmd += "-d " + stringify(getpid()) + " "; + if (s.cmd != "") stpd_cmd += "-c \"" + s.cmd + "\" "; @@ -163,9 +164,10 @@ run_pass (systemtap_session& s) stpd_cmd += s.tmpdir + "/" + s.module_name + ".ko"; if (s.verbose) clog << "Running " << stpd_cmd << endl; + + signal (SIGHUP, SIG_IGN); + signal (SIGINT, SIG_IGN); rc = system (stpd_cmd.c_str ()); - - signal (SIGINT, oldsig); } return rc; diff --git a/runtime/stpd/ChangeLog b/runtime/stpd/ChangeLog index 2fd03259..e72ec4d0 100644 --- a/runtime/stpd/ChangeLog +++ b/runtime/stpd/ChangeLog @@ -1,3 +1,12 @@ +2005-12-08 Frank Ch. Eigler <fche@elastic.org> + + PR 1937 + * stpd.c (main): Support new "-d" option. + (usage): Document it. + * librelay.c (driver_poll): New function to react to death of + driver process. + (stp_main_loop): Call it if "-d PID" given. Treat SIGHUP like others. + 2005-10-19 Tom Zanussi <zanussi@us.ibm.com> * librelay.c: Move output_file var to stpd.c. diff --git a/runtime/stpd/librelay.c b/runtime/stpd/librelay.c index 9ed408d9..e2beece2 100644 --- a/runtime/stpd/librelay.c +++ b/runtime/stpd/librelay.c @@ -84,6 +84,7 @@ extern unsigned int buffer_size; extern char *modname; extern char *modpath; extern int target_pid; +extern int driver_pid; extern char *target_cmd; /* per-cpu buffer info */ @@ -641,6 +642,23 @@ static void sigproc(int signum __attribute__((unused))) send_request(STP_EXIT, NULL, 0); } +static void driver_poll (int signum __attribute__((unused))) +{ + /* See if the driver process is still alive. If not, time to exit. */ + if (kill (driver_pid, 0) < 0) + { + send_request(STP_EXIT, NULL, 0); + return; + } + else + { + /* Check again later. */ + signal (SIGALRM, driver_poll); + alarm (10); // any reasonable poll interval + } +} + + /** * stp_main_loop - loop forever reading data */ @@ -659,6 +677,11 @@ int stp_main_loop(void) signal(SIGINT, sigproc); signal(SIGTERM, sigproc); signal(SIGCHLD, sigproc); + signal(SIGHUP, sigproc); + + if (driver_pid) + driver_poll(0); // And by the way, I'm also the signal handler. + dbug("in main loop\n"); while (1) { /* handle messages from control channel */ diff --git a/runtime/stpd/stpd.c b/runtime/stpd/stpd.c index 9587d29f..c12ca096 100644 --- a/runtime/stpd/stpd.c +++ b/runtime/stpd/stpd.c @@ -37,6 +37,7 @@ int merge = 1; int verbose = 0; int enable_relayfs = 1; int target_pid = 0; +int driver_pid = 0; unsigned int buffer_size = 0; char *modname = NULL; char *modpath = NULL; @@ -66,6 +67,7 @@ static void usage(char *prog) fprintf(stderr, "-c cmd. Command \'cmd\' will be run and stpd will exit when it does.\n"); fprintf(stderr, " _stp_target will contain the pid for the command.\n"); fprintf(stderr, "-t pid. Sets _stp_target to pid.\n"); + fprintf(stderr, "-d pid. Pass the systemtap driver's pid.\n"); fprintf(stderr, "-b buffer size. The systemtap module will specify a buffer size.\n"); fprintf(stderr, "-o FILE. Send output to FILE.\n"); fprintf(stderr, " Setting one here will override that value. The value should be\n"); @@ -79,7 +81,7 @@ int main(int argc, char **argv) int c, status; pid_t pid; - while ((c = getopt(argc, argv, "mpqrb:n:t:c:vo:")) != EOF) + while ((c = getopt(argc, argv, "mpqrb:n:t:d:c:vo:")) != EOF) { switch (c) { case 'm': @@ -112,6 +114,9 @@ int main(int argc, char **argv) case 't': target_pid = atoi(optarg); break; + case 'd': + driver_pid = atoi(optarg); + break; case 'c': target_cmd = optarg; break; |