Author: metze Date: 2006-03-21 21:25:29 +0000 (Tue, 21 Mar 2006) New Revision: 14628
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=14628 Log: sync timelimit.c with the version from the build-farm repository metze Modified: branches/SAMBA_3_0/source/script/tests/timelimit.c Changeset: Modified: branches/SAMBA_3_0/source/script/tests/timelimit.c =================================================================== --- branches/SAMBA_3_0/source/script/tests/timelimit.c 2006-03-21 19:50:28 UTC (rev 14627) +++ branches/SAMBA_3_0/source/script/tests/timelimit.c 2006-03-21 21:25:29 UTC (rev 14628) @@ -12,58 +12,75 @@ #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; + kill(-child_pid, SIGTERM); + exit(0); +} - if (c > 2) { - kill(0, SIGKILL); - 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; pid_t pid = wait(&status); @@ -74,5 +91,7 @@ } } while (1); + kill(-child_pid, SIGKILL); + exit(ret); }
