From 249534c041971db5e9f89cb11b6d38d311e91f57 Mon Sep 17 00:00:00 2001 From: Breno Leitao Date: Tue, 3 Nov 2009 13:38:32 -0200 Subject: [PATCH] Fix for bug 10866 (exit with rc != 0 on script ERRORs). This patch just make the RC=1 when any output line starts with ERROR:. Also some minors error that was returning 0 instead of 1 were fixed. --- runtime/staprun/mainloop.c | 24 ++++++++++++++---------- runtime/staprun/staprun.h | 2 +- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/runtime/staprun/mainloop.c b/runtime/staprun/mainloop.c index cf8bef9aa..67fbfad6c 100644 --- a/runtime/staprun/mainloop.c +++ b/runtime/staprun/mainloop.c @@ -38,7 +38,7 @@ static void *signal_thread(void *arg) } dbug(2, "sigproc %d (%s)\n", signum, strsignal(signum)); if (signum == SIGQUIT) - cleanup_and_exit(1); + cleanup_and_exit(1, 0); else if (signum == SIGINT || signum == SIGHUP || signum == SIGTERM) { // send STP_EXIT rc = write(control_channel, &btype, sizeof(btype)); @@ -383,7 +383,7 @@ int init_stapio(void) /* cleanup_and_exit() closed channels, frees memory, * removes the module (if necessary) and exits. */ -void cleanup_and_exit(int detach) +void cleanup_and_exit(int detach, int rc) { static int exiting = 0; const char *staprun; @@ -467,7 +467,7 @@ void cleanup_and_exit(int detach) } if (WIFEXITED(rstatus)) { - _exit(WEXITSTATUS(rstatus)); /* only possibility for rc=0 exit */ + _exit(rc ?: WEXITSTATUS(rstatus)); } _exit(-1); } @@ -484,6 +484,7 @@ int stp_main_loop(void) uint32_t type; FILE *ofp = stdout; char recvbuf[8196]; + int error_detected = 0; setvbuf(ofp, (char *)NULL, _IOLBF, 0); setup_main_signals(); @@ -511,18 +512,21 @@ int stp_main_loop(void) case STP_REALTIME_DATA: if (write_realtime_data(data, nb)) { _perr("write error (nb=%ld)", (long)nb); - cleanup_and_exit(0); + cleanup_and_exit(0, 1); } break; #endif case STP_OOB_DATA: eprintf("%s", (char *)data); + if (strncmp(data, "ERROR:", 5) == 0){ + error_detected = 1; + } break; case STP_EXIT: { /* module asks us to unload it and exit */ dbug(2, "got STP_EXIT\n"); - cleanup_and_exit(0); + cleanup_and_exit(0, error_detected); break; } case STP_REQUEST_EXIT: @@ -540,7 +544,7 @@ int stp_main_loop(void) if (t->res < 0) { if (target_cmd) kill(target_pid, SIGKILL); - cleanup_and_exit(0); + cleanup_and_exit(0, 1); } else if (target_cmd) { dbug(1, "detaching pid %d\n", target_pid); #if WORKAROUND_BZ467568 @@ -555,7 +559,7 @@ int stp_main_loop(void) perror ("ptrace detach"); if (target_cmd) kill(target_pid, SIGKILL); - cleanup_and_exit(0); + cleanup_and_exit(0, 1); } #endif } @@ -573,15 +577,15 @@ int stp_main_loop(void) struct _stp_msg_start ts; if (use_old_transport) { if (init_oldrelayfs() < 0) - cleanup_and_exit(0); + cleanup_and_exit(0, 1); } else { if (init_relayfs() < 0) - cleanup_and_exit(0); + cleanup_and_exit(0, 1); } ts.target = target_pid; send_request(STP_START, &ts, sizeof(ts)); if (load_only) - cleanup_and_exit(1); + cleanup_and_exit(1, 0); break; } default: diff --git a/runtime/staprun/staprun.h b/runtime/staprun/staprun.h index f9f01003f..9cdbc861e 100644 --- a/runtime/staprun/staprun.h +++ b/runtime/staprun/staprun.h @@ -114,7 +114,7 @@ int init_staprun(void); int init_stapio(void); int stp_main_loop(void); int send_request(int type, void *data, int len); -void cleanup_and_exit (int); +void cleanup_and_exit (int, int); int init_ctl_channel(const char *name, int verb); void close_ctl_channel(void); int init_relayfs(void); -- 2.43.5