diff options
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/timeout_watchdog.c | 53 |
1 files changed, 24 insertions, 29 deletions
diff --git a/contrib/timeout_watchdog.c b/contrib/timeout_watchdog.c index 2fb4cd20b..dfeed6782 100644 --- a/contrib/timeout_watchdog.c +++ b/contrib/timeout_watchdog.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors) | 3 | (C) 2010 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -47,6 +47,7 @@ void sigchld_handler(int val) | |||
47 | if (WIFSIGNALED(status) == 1) | 47 | if (WIFSIGNALED(status) == 1) |
48 | { | 48 | { |
49 | printf("Test process was signaled %u\n", WTERMSIG(status)); | 49 | printf("Test process was signaled %u\n", WTERMSIG(status)); |
50 | ret = WTERMSIG(status); | ||
50 | } | 51 | } |
51 | exit(ret); | 52 | exit(ret); |
52 | } | 53 | } |
@@ -54,8 +55,8 @@ void sigchld_handler(int val) | |||
54 | void sigint_handler(int val) | 55 | void sigint_handler(int val) |
55 | { | 56 | { |
56 | printf("Killing test process\n"); | 57 | printf("Killing test process\n"); |
57 | kill(0, SIGINT); | 58 | kill(0, val); |
58 | exit(0); | 59 | exit(1); |
59 | } | 60 | } |
60 | 61 | ||
61 | 62 | ||
@@ -80,36 +81,30 @@ if (timeout == 0) | |||
80 | char ** arguments = &argv[3]; | 81 | char ** arguments = &argv[3]; |
81 | 82 | ||
82 | pid_t gpid = getpgid(0); | 83 | pid_t gpid = getpgid(0); |
84 | signal(SIGCHLD, sigchld_handler); | ||
85 | signal(SIGABRT, sigint_handler); | ||
86 | signal(SIGKILL, sigint_handler); | ||
87 | signal(SIGILL, sigint_handler); | ||
88 | signal(SIGSEGV, sigint_handler); | ||
89 | signal(SIGINT, sigint_handler); | ||
90 | signal(SIGTERM, sigint_handler); | ||
83 | 91 | ||
84 | child = fork(); | 92 | child = fork(); |
85 | if (child > 0) | 93 | if (child==0) |
86 | { | 94 | { |
87 | signal(SIGCHLD, sigchld_handler); | 95 | printf("Starting test process `%s'\n",argv[2],arguments); |
88 | signal(SIGINT, sigint_handler); | 96 | setpgid(0,gpid); |
97 | execvp(argv[2],&argv[2]); | ||
98 | printf("Test process `%s' could not be started\n",argv[2]); | ||
99 | exit(1); | ||
89 | } | 100 | } |
90 | for (;;) | 101 | if (child > 0) |
91 | { | 102 | { |
92 | if (child==0) | 103 | sleep(timeout); |
93 | { | 104 | printf("Timeout, killing all test processes\n"); |
94 | printf("Starting test process `%s'\n",argv[2],arguments); | 105 | kill(0,SIGABRT); |
95 | setpgid(0,gpid); | 106 | exit(1); |
96 | execvp(argv[2],&argv[2]); | ||
97 | printf("Test process `%s' could not be started\n",argv[1]); | ||
98 | exit(1); | ||
99 | } | ||
100 | if (child > 0) | ||
101 | { | ||
102 | sleep(1); | ||
103 | remain++; | ||
104 | if (timeout == remain) | ||
105 | { | ||
106 | printf("Timeout, killing all test processes\n"); | ||
107 | kill(0,SIGABRT); | ||
108 | exit(1); | ||
109 | } | ||
110 | } | ||
111 | } | 107 | } |
112 | |||
113 | } | 108 | } |
114 | 109 | ||
115 | /* end of timeout_watchdog.c */ \ No newline at end of file | 110 | /* end of timeout_watchdog.c */ |