diff options
author | Stefan Metzmacher <metze@samba.org> | 2006-03-21 21:25:29 +0000 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2006-03-21 21:25:29 +0000 |
commit | 6a444acd9dec1ebae9557b1c5f970a2353f9322b (patch) | |
tree | 89888929a932f48800a960ac7e2e3f5a32ec15c2 /source/script | |
parent | 7d140b603c1b4b8944591770e007690cfd4582f5 (diff) | |
download | samba-6a444acd9dec1ebae9557b1c5f970a2353f9322b.tar.gz samba-6a444acd9dec1ebae9557b1c5f970a2353f9322b.tar.xz samba-6a444acd9dec1ebae9557b1c5f970a2353f9322b.zip |
r14628: sync timelimit.c with the version from the build-farm repository
metze
Diffstat (limited to 'source/script')
-rw-r--r-- | source/script/tests/timelimit.c | 59 |
1 files changed, 39 insertions, 20 deletions
diff --git a/source/script/tests/timelimit.c b/source/script/tests/timelimit.c index 93d7f6497e3..af8ff274545 100644 --- a/source/script/tests/timelimit.c +++ b/source/script/tests/timelimit.c @@ -12,57 +12,74 @@ #include <sys/types.h> #include <sys/wait.h> +static pid_t child_pid; + static void usage(void) { printf("usage: timelimit <time> <command>\n"); + printf(" SIGALRM - passes SIGKILL to command's process group and exit(1)\n"); + printf(" SIGUSR1 - passes SIGTERM to command's process group\n"); + printf(" SIGTERM - passes SIGTERM to command's process group and exit(0)\n"); } static void sig_alrm(int sig) { - kill(0, SIGKILL); + fprintf(stderr, "\nMaximum time expired in timelimit - killing\n"); + kill(-child_pid, SIGKILL); exit(1); } -static void sig_term_kill(int sig) +static void sig_term(int sig) { - static int c = 0; - - if (c > 2) { - kill(0, SIGKILL); - exit(0); - } + kill(-child_pid, SIGTERM); + exit(0); +} - c++; +static void sig_usr1(int sig) +{ + kill(-child_pid, SIGTERM); } -static void sig_term(int sig) +static void new_process_group(void) { - kill(0, SIGTERM); - signal(SIGTERM, sig_term_kill); +#ifdef BSD_SETPGRP + if (setpgrp(0,0) == -1) { + perror("setpgrp"); + exit(1); + } +#else + if (setpgrp() == -1) { + perror("setpgrp"); + exit(1); + } +#endif } + int main(int argc, char *argv[]) { int maxtime, ret=1; + pid_t pgid; if (argc < 3) { usage(); exit(1); } - if (setpgrp() == -1) { - perror("setpgrp"); + maxtime = atoi(argv[1]); + + child_pid = fork(); + if (child_pid == 0) { + new_process_group(); + execvp(argv[2], argv+2); + perror(argv[2]); exit(1); } - maxtime = atoi(argv[1]); + signal(SIGTERM, sig_term); + signal(SIGUSR1, sig_usr1); signal(SIGALRM, sig_alrm); alarm(maxtime); - signal(SIGTERM, sig_term); - - if (fork() == 0) { - execvp(argv[2], argv+2); - } do { int status; @@ -74,5 +91,7 @@ int main(int argc, char *argv[]) } } while (1); + kill(-child_pid, SIGKILL); + exit(ret); } |