aboutsummaryrefslogtreecommitdiff
path: root/contrib/timeout_watchdog.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2010-06-28 10:52:25 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2010-06-28 10:52:25 +0000
commit1fbea1a160373147db6ef31f5d05d61e63296077 (patch)
tree923bb11180fe49d57b650c2dcd2d0189bf321467 /contrib/timeout_watchdog.c
parentb917264c966ab8a8fa8476ebc7d718dcea8f4143 (diff)
downloadgnunet-1fbea1a160373147db6ef31f5d05d61e63296077.tar.gz
gnunet-1fbea1a160373147db6ef31f5d05d61e63296077.zip
Diffstat (limited to 'contrib/timeout_watchdog.c')
-rw-r--r--contrib/timeout_watchdog.c53
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)
54void sigint_handler(int val) 55void 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)
80char ** arguments = &argv[3]; 81char ** arguments = &argv[3];
81 82
82pid_t gpid = getpgid(0); 83pid_t gpid = getpgid(0);
84signal(SIGCHLD, sigchld_handler);
85signal(SIGABRT, sigint_handler);
86signal(SIGKILL, sigint_handler);
87signal(SIGILL, sigint_handler);
88signal(SIGSEGV, sigint_handler);
89signal(SIGINT, sigint_handler);
90signal(SIGTERM, sigint_handler);
83 91
84child = fork(); 92child = fork();
85if (child > 0) 93if (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}
90for (;;) 101if (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 */