aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'contrib')
-rw-r--r--contrib/timeout_watchdog.c115
1 files changed, 60 insertions, 55 deletions
diff --git a/contrib/timeout_watchdog.c b/contrib/timeout_watchdog.c
index 9a1fc006d..b28e8e833 100644
--- a/contrib/timeout_watchdog.c
+++ b/contrib/timeout_watchdog.c
@@ -33,75 +33,80 @@
33 33
34static pid_t child; 34static pid_t child;
35 35
36static void sigchld_handler(int val) 36static void
37sigchld_handler (int val)
37{ 38{
38 int status = 0; 39 int status = 0;
39 int ret = 0; 40 int ret = 0;
40 41
41 waitpid (child, &status, 0); 42 waitpid (child, &status, 0);
42 if (WIFEXITED(status) != 0) 43 if (WIFEXITED (status) != 0)
43 { 44 {
44 ret = WEXITSTATUS(status); 45 ret = WEXITSTATUS (status);
45 printf("Test process exited with result %u\n", ret); 46 printf ("Test process exited with result %u\n", ret);
46 } 47 }
47 if (WIFSIGNALED(status) != 0) 48 if (WIFSIGNALED (status) != 0)
48 { 49 {
49 ret = WTERMSIG(status); 50 ret = WTERMSIG (status);
50 printf("Test process was signaled %u\n", ret); 51 printf ("Test process was signaled %u\n", ret);
51 } 52 }
52 exit(ret); 53 exit (ret);
53} 54}
54 55
55static void sigint_handler(int val) 56static void
56{ 57sigint_handler (int val)
57 kill(0, val); 58{
58 exit(val); 59 kill (0, val);
60 exit (val);
59} 61}
60 62
61int main(int argc, char *argv[]) 63int
64main (int argc, char *argv[])
62{ 65{
63int timeout = 0; 66 int timeout = 0;
64pid_t gpid =0; 67 pid_t gpid = 0;
65 68
66if (argc < 3) 69 if (argc < 3)
67{ 70 {
68 printf("arg 1: timeout in sec., arg 2: executable, arg<n> arguments\n"); 71 printf
69 exit(1); 72 ("arg 1: timeout in sec., arg 2: executable, arg<n> arguments\n");
70} 73 exit (1);
74 }
71 75
72timeout = atoi(argv[1]); 76 timeout = atoi (argv[1]);
73 77
74if (timeout == 0) 78 if (timeout == 0)
75 timeout = 600; 79 timeout = 600;
76 80
77/* with getpgid() it does not compile, but getpgrp is the BSD version and working */ 81/* with getpgid() it does not compile, but getpgrp is the BSD version and working */
78gpid = getpgrp(); 82 gpid = getpgrp ();
79 83
80signal(SIGCHLD, sigchld_handler); 84 signal (SIGCHLD, sigchld_handler);
81signal(SIGABRT, sigint_handler); 85 signal (SIGABRT, sigint_handler);
82signal(SIGFPE, sigint_handler); 86 signal (SIGFPE, sigint_handler);
83signal(SIGILL, sigint_handler); 87 signal (SIGILL, sigint_handler);
84signal(SIGINT, sigint_handler); 88 signal (SIGINT, sigint_handler);
85signal(SIGSEGV, sigint_handler); 89 signal (SIGSEGV, sigint_handler);
86signal(SIGTERM, sigint_handler); 90 signal (SIGTERM, sigint_handler);
87 91
88child = fork(); 92 child = fork ();
89if (child==0) 93 if (child == 0)
90{ 94 {
91 /* int setpgrp(pid_t pid, pid_t pgid); is not working on this machine*/ 95 /* int setpgrp(pid_t pid, pid_t pgid); is not working on this machine */
92 //setpgrp (0, pid_t gpid); 96 //setpgrp (0, pid_t gpid);
93 setpgid(0,gpid); 97 setpgid (0, gpid);
94 execvp(argv[2],&argv[2]); 98 execvp (argv[2], &argv[2]);
95 exit(1); 99 exit (1);
96} 100 }
97if (child > 0) 101 if (child > 0)
98{ 102 {
99 sleep(timeout); 103 sleep (timeout);
100 printf("Child processes were killed after timeout of %u seconds\n",timeout); 104 printf ("Child processes were killed after timeout of %u seconds\n",
101 kill(0,SIGTERM); 105 timeout);
102 exit(1); 106 kill (0, SIGTERM);
103} 107 exit (1);
104exit(1); 108 }
109 exit (1);
105} 110}
106 111
107/* end of timeout_watchdog.c */ 112/* end of timeout_watchdog.c */