diff options
-rw-r--r-- | contrib/Makefile.am | 6 | ||||
-rw-r--r-- | contrib/timeout_watchdog.c | 26 |
2 files changed, 19 insertions, 13 deletions
diff --git a/contrib/Makefile.am b/contrib/Makefile.am index f8e0d2f49..43348b309 100644 --- a/contrib/Makefile.am +++ b/contrib/Makefile.am | |||
@@ -1,3 +1,9 @@ | |||
1 | noinst_PROGRAMS = \ | ||
2 | timeout_watchdog | ||
3 | |||
4 | timeout_watchdog_SOURCES = \ | ||
5 | timeout_watchdog.c | ||
6 | |||
1 | dist_pkgdata_DATA = \ | 7 | dist_pkgdata_DATA = \ |
2 | gnunet-logo-color.png \ | 8 | gnunet-logo-color.png \ |
3 | defaults.conf | 9 | defaults.conf |
diff --git a/contrib/timeout_watchdog.c b/contrib/timeout_watchdog.c index 82bf11b0f..27b46f2b0 100644 --- a/contrib/timeout_watchdog.c +++ b/contrib/timeout_watchdog.c | |||
@@ -24,13 +24,13 @@ | |||
24 | * @author Matthias Wachs | 24 | * @author Matthias Wachs |
25 | */ | 25 | */ |
26 | 26 | ||
27 | #include "signal.h" | 27 | #include <sys/types.h> |
28 | #include "stdio.h" | 28 | #include <signal.h> |
29 | #include "stdlib.h" | 29 | #include <stdio.h> |
30 | #include <stdlib.h> | ||
30 | #include <unistd.h> | 31 | #include <unistd.h> |
31 | #include <wait.h> | 32 | #include <wait.h> |
32 | 33 | ||
33 | static int child_died; | ||
34 | static pid_t child; | 34 | static pid_t child; |
35 | 35 | ||
36 | static void sigchld_handler(int val) | 36 | static void sigchld_handler(int val) |
@@ -55,15 +55,13 @@ static void sigchld_handler(int val) | |||
55 | static void sigint_handler(int val) | 55 | static void sigint_handler(int val) |
56 | { | 56 | { |
57 | kill(0, val); | 57 | kill(0, val); |
58 | exit(1); | 58 | exit(val); |
59 | } | 59 | } |
60 | 60 | ||
61 | |||
62 | int main(int argc, char *argv[]) | 61 | int main(int argc, char *argv[]) |
63 | { | 62 | { |
64 | int timeout = 0; | 63 | int timeout = 0; |
65 | int remain = 0; | 64 | pid_t gpid =0; |
66 | int ret = 0; | ||
67 | 65 | ||
68 | if (argc < 3) | 66 | if (argc < 3) |
69 | { | 67 | { |
@@ -76,21 +74,22 @@ timeout = atoi(argv[1]); | |||
76 | if (timeout == 0) | 74 | if (timeout == 0) |
77 | timeout = 600; | 75 | timeout = 600; |
78 | 76 | ||
77 | /* with getpgid() it does not compile, but getpgrp is the BSD version and working */ | ||
78 | gpid = getpgrp(); | ||
79 | 79 | ||
80 | char ** arguments = &argv[3]; | ||
81 | |||
82 | pid_t gpid = getpgid(0); | ||
83 | signal(SIGCHLD, sigchld_handler); | 80 | signal(SIGCHLD, sigchld_handler); |
84 | signal(SIGABRT, sigint_handler); | 81 | signal(SIGABRT, sigint_handler); |
85 | signal(SIGKILL, sigint_handler); | 82 | signal(SIGFPE, sigint_handler); |
86 | signal(SIGILL, sigint_handler); | 83 | signal(SIGILL, sigint_handler); |
87 | signal(SIGSEGV, sigint_handler); | ||
88 | signal(SIGINT, sigint_handler); | 84 | signal(SIGINT, sigint_handler); |
85 | signal(SIGSEGV, sigint_handler); | ||
89 | signal(SIGTERM, sigint_handler); | 86 | signal(SIGTERM, sigint_handler); |
90 | 87 | ||
91 | child = fork(); | 88 | child = fork(); |
92 | if (child==0) | 89 | if (child==0) |
93 | { | 90 | { |
91 | /* int setpgrp(pid_t pid, pid_t pgid); is not working on this machine*/ | ||
92 | //setpgrp (0, pid_t gpid); | ||
94 | setpgid(0,gpid); | 93 | setpgid(0,gpid); |
95 | execvp(argv[2],&argv[2]); | 94 | execvp(argv[2],&argv[2]); |
96 | exit(1); | 95 | exit(1); |
@@ -101,6 +100,7 @@ if (child > 0) | |||
101 | kill(0,SIGABRT); | 100 | kill(0,SIGABRT); |
102 | exit(1); | 101 | exit(1); |
103 | } | 102 | } |
103 | exit(1); | ||
104 | } | 104 | } |
105 | 105 | ||
106 | /* end of timeout_watchdog.c */ | 106 | /* end of timeout_watchdog.c */ |