aboutsummaryrefslogtreecommitdiff
path: root/contrib/timeout_watchdog.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/timeout_watchdog.c')
-rw-r--r--contrib/timeout_watchdog.c26
1 files changed, 13 insertions, 13 deletions
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
33static int child_died;
34static pid_t child; 34static pid_t child;
35 35
36static void sigchld_handler(int val) 36static void sigchld_handler(int val)
@@ -55,15 +55,13 @@ static void sigchld_handler(int val)
55static void sigint_handler(int val) 55static 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
62int main(int argc, char *argv[]) 61int main(int argc, char *argv[])
63{ 62{
64int timeout = 0; 63int timeout = 0;
65int remain = 0; 64pid_t gpid =0;
66int ret = 0;
67 65
68if (argc < 3) 66if (argc < 3)
69{ 67{
@@ -76,21 +74,22 @@ timeout = atoi(argv[1]);
76if (timeout == 0) 74if (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 */
78gpid = getpgrp();
79 79
80char ** arguments = &argv[3];
81
82pid_t gpid = getpgid(0);
83signal(SIGCHLD, sigchld_handler); 80signal(SIGCHLD, sigchld_handler);
84signal(SIGABRT, sigint_handler); 81signal(SIGABRT, sigint_handler);
85signal(SIGKILL, sigint_handler); 82signal(SIGFPE, sigint_handler);
86signal(SIGILL, sigint_handler); 83signal(SIGILL, sigint_handler);
87signal(SIGSEGV, sigint_handler);
88signal(SIGINT, sigint_handler); 84signal(SIGINT, sigint_handler);
85signal(SIGSEGV, sigint_handler);
89signal(SIGTERM, sigint_handler); 86signal(SIGTERM, sigint_handler);
90 87
91child = fork(); 88child = fork();
92if (child==0) 89if (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}
103exit(1);
104} 104}
105 105
106/* end of timeout_watchdog.c */ 106/* end of timeout_watchdog.c */