diff options
author | Stefan Metzmacher <metze@samba.org> | 2006-03-21 15:33:14 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 11:15:39 -0500 |
commit | d9df1853b947c70f747ea30a353162f2985ef250 (patch) | |
tree | ab78246c4c27dc447514229f5ba551c4e4e8a319 /source/script | |
parent | c3a9f30e2a12cc852c9fa3a7d161f5c6ee0694ce (diff) | |
download | samba-d9df1853b947c70f747ea30a353162f2985ef250.tar.gz |
r14624: - add timelimit.c
- add configure tests --with-selftest-prefix=/tmp/samba-test
this is needed because the path name of unix socket can only be 108 chars long
- add configure test --with-smbtorture4-path=/home/foo/prefix/samba4/bin/smbtorture
this will be used to run samba4's smbtorture inside samba3's make test later
metze
Diffstat (limited to 'source/script')
-rw-r--r-- | source/script/tests/timelimit.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/source/script/tests/timelimit.c b/source/script/tests/timelimit.c new file mode 100644 index 00000000000..93d7f6497e3 --- /dev/null +++ b/source/script/tests/timelimit.c @@ -0,0 +1,78 @@ +/* run a command with a limited timeout + tridge@samba.org, June 2005 + + attempt to be as portable as possible (fighting posix all the way) +*/ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <unistd.h> +#include <signal.h> +#include <errno.h> +#include <sys/types.h> +#include <sys/wait.h> + +static void usage(void) +{ + printf("usage: timelimit <time> <command>\n"); +} + +static void sig_alrm(int sig) +{ + kill(0, SIGKILL); + exit(1); +} + +static void sig_term_kill(int sig) +{ + static int c = 0; + + if (c > 2) { + kill(0, SIGKILL); + exit(0); + } + + c++; +} + +static void sig_term(int sig) +{ + kill(0, SIGTERM); + signal(SIGTERM, sig_term_kill); +} + +int main(int argc, char *argv[]) +{ + int maxtime, ret=1; + + if (argc < 3) { + usage(); + exit(1); + } + + if (setpgrp() == -1) { + perror("setpgrp"); + exit(1); + } + + maxtime = atoi(argv[1]); + 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); + if (pid != -1) { + ret = WEXITSTATUS(status); + } else if (errno == ECHILD) { + break; + } + } while (1); + + exit(ret); +} |