From 16c6a28c4d17feda8acc4c52b010968a6719a66f Mon Sep 17 00:00:00 2001 From: hunt Date: Sat, 25 Feb 2006 09:41:53 +0000 Subject: [PATCH] 2006-02-25 Martin Hunt * librelay.c (init_stp): Better error handling and cleanup. --- runtime/stpd/ChangeLog | 4 ++++ runtime/stpd/librelay.c | 17 +++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/runtime/stpd/ChangeLog b/runtime/stpd/ChangeLog index 1695cf6ec..3875aecd8 100644 --- a/runtime/stpd/ChangeLog +++ b/runtime/stpd/ChangeLog @@ -1,3 +1,7 @@ +2006-02-25 Martin Hunt + + * librelay.c (init_stp): Better error handling and cleanup. + 2006-02-23 Frank Ch. Eigler PR 1304 diff --git a/runtime/stpd/librelay.c b/runtime/stpd/librelay.c index 719f026d1..0ef15acda 100644 --- a/runtime/stpd/librelay.c +++ b/runtime/stpd/librelay.c @@ -507,8 +507,13 @@ int init_stp(const char *relay_filebase, int print_summary) ti.subbuf_size = 0; ti.n_subbufs = 0; ti.target = target_pid; - send_request(STP_TRANSPORT_INFO, &ti, sizeof(ti)); - + if (send_request(STP_TRANSPORT_INFO, &ti, sizeof(ti)) < 0) { + fprintf(stderr, "stpd failed because TRANSPORT_INFO returned an error.\n"); + if (target_cmd) + kill (target_pid, SIGKILL); + close(control_channel); + return -1; + } return 0; } @@ -629,9 +634,7 @@ static void cleanup_and_exit (int closed) close(control_channel); if (!closed) { - /* FIXME. overflow check */ - strcpy (tmpbuf, "/sbin/rmmod "); - strcpy (tmpbuf + strlen(tmpbuf), modname); + snprintf(tmpbuf, sizeof(tmpbuf), "/sbin/rmmod %s", modname); if (system(tmpbuf)) { fprintf(stderr, "ERROR: couldn't rmmod probe module %s. No output will be written.\n", modname); @@ -728,6 +731,7 @@ int stp_main_loop(void) if (rc < 0) { close(control_channel); fprintf(stderr, "ERROR: couldn't init relayfs, exiting\n"); + /* FIXME. Need to cleanup properly */ exit(1); } } else if (outfile_name) { @@ -735,10 +739,11 @@ int stp_main_loop(void) if (!ofp) { fprintf (stderr, "ERROR: couldn't open output file %s: errcode = %s\n", outfile_name, strerror(errno)); + /* FIXME. Need to cleanup properly */ exit(1); } } - ts.pid = 0; // FIXME. not implemented yet + ts.pid = getpid(); send_request(STP_START, &ts, sizeof(ts)); break; } -- 2.43.5