summaryrefslogtreecommitdiff
path: root/source3/script/tests
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2006-03-21 21:25:29 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 11:15:40 -0500
commit906c19faca757561e55d7d5470940535810779d5 (patch)
treea8cc11eff05625b687934b25c8eef9ebd7c6bf2b /source3/script/tests
parentbc87a5fbabf05c06bcca6b3cbc2d80d0a1f74330 (diff)
downloadsamba-906c19faca757561e55d7d5470940535810779d5.tar.gz
samba-906c19faca757561e55d7d5470940535810779d5.tar.bz2
samba-906c19faca757561e55d7d5470940535810779d5.zip
r14628: sync timelimit.c with the version from the build-farm repository
metze (This used to be commit 1b6a64378553008127a85131fa4139842de4128b)
Diffstat (limited to 'source3/script/tests')
-rw-r--r--source3/script/tests/timelimit.c59
1 files changed, 39 insertions, 20 deletions
diff --git a/source3/script/tests/timelimit.c b/source3/script/tests/timelimit.c
index 93d7f6497e..af8ff27454 100644
--- a/source3/script/tests/timelimit.c
+++ b/source3/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);
}