X-Git-Url: http://git.tuebingen.mpg.de/?p=dss.git;a=blobdiff_plain;f=dss.c;h=491b8aa791fdafc29589ec08eae878e9e67039be;hp=d60f00b1cc08f44ac29ae383c71b376f9e9ef49d;hb=324d1364004376fa0b018afcb57cfe14aca7fcdb;hpb=ffce5ac0f8d17dad30fa0c2fee32aef9eadecf27;ds=sidebyside diff --git a/dss.c b/dss.c index d60f00b..491b8aa 100644 --- a/dss.c +++ b/dss.c @@ -287,11 +287,13 @@ static char *get_config_file_name(void) return config_file; } -static int send_signal(int sig) +static int send_signal(int sig, bool wait) { pid_t pid; char *config_file = get_config_file_name(); int ret = get_dss_pid(config_file, &pid); + unsigned ms = 32; + struct timespec ts; free(config_file); if (ret < 0) @@ -304,7 +306,23 @@ static int send_signal(int sig) ret = kill(pid, sig); if (ret < 0) return -ERRNO_TO_DSS_ERROR(errno); - return 1; + if (!wait) + return 1; + while (ms < 5000) { + ts.tv_sec = ms / 1000; + ts.tv_nsec = (ms % 1000) * 1000 * 1000; + ret = nanosleep(&ts, NULL); + if (ret < 0) + return -ERRNO_TO_DSS_ERROR(errno); + ret = kill(pid, 0); + if (ret < 0) { + if (errno != ESRCH) + return -ERRNO_TO_DSS_ERROR(errno); + return 1; + } + ms *= 2; + } + return -E_KILL_TIMEOUT; } struct signal_info { @@ -363,6 +381,7 @@ static const struct signal_info signal_table[] = { static int com_kill(void) { + bool w_given = OPT_GIVEN(KILL, WAIT); const char *arg = OPT_STRING_VAL(KILL, SIGNAL); int ret, i; @@ -373,17 +392,17 @@ static int com_kill(void) return ret; if (val < 0 || val > SIGRTMAX) return -ERRNO_TO_DSS_ERROR(EINVAL); - return send_signal(val); + return send_signal(val, w_given); } if (strncasecmp(arg, "sig", 3) == 0) arg += 3; if (strcasecmp(arg, "CLD") == 0) - return send_signal(SIGCHLD); + return send_signal(SIGCHLD, w_given); if (strcasecmp(arg, "IOT") == 0) - return send_signal(SIGABRT); + return send_signal(SIGABRT, w_given); for (i = 0; i < SIGNAL_TABLE_SIZE; i++) if (strcasecmp(arg, signal_table[i].name) == 0) - return send_signal(signal_table[i].num); + return send_signal(signal_table[i].num, w_given); DSS_ERROR_LOG(("invalid sigspec: %s\n", arg)); return -ERRNO_TO_DSS_ERROR(EINVAL); } @@ -1594,6 +1613,8 @@ static int com_run(void) ret = -E_BUG; kill_children(); exit_hook(ret); + while (wait(NULL) >= 0 || errno != ECHILD) + ; /* still have children to wait for */ return ret; } EXPORT_CMD_HANDLER(run);