aboutsummaryrefslogtreecommitdiff
path: root/tests/to.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/to.c')
-rw-r--r--tests/to.c44
1 files changed, 38 insertions, 6 deletions
diff --git a/tests/to.c b/tests/to.c
index 6511a54..6874bfd 100644
--- a/tests/to.c
+++ b/tests/to.c
@@ -1,9 +1,28 @@
1#include <config.h>
1#include <stdlib.h> 2#include <stdlib.h>
2#include <stdio.h> 3#include <stdio.h>
3#include <errno.h> 4#include <errno.h>
4#include <unistd.h> 5#include <unistd.h>
5#include <sys/types.h> 6#include <sys/types.h>
6#include <sys/wait.h> 7#include <sys/wait.h>
8#include <signal.h>
9
10int volatile got_sigchld, got_sigalrm;
11
12void
13sighan (int sig)
14{
15 switch (sig)
16 {
17 case SIGCHLD:
18 got_sigchld = 1;
19 break;
20
21 case SIGALRM:
22 got_sigalrm = 1;
23 break;
24 }
25}
7 26
8int 27int
9main (int argc, char **argv) 28main (int argc, char **argv)
@@ -30,6 +49,9 @@ main (int argc, char **argv)
30 argc -= 2; 49 argc -= 2;
31 argv += 2; 50 argv += 2;
32 51
52 signal (SIGALRM, sighan);
53 signal (SIGCHLD, sighan);
54
33 pid = fork (); 55 pid = fork ();
34 if (pid == -1) 56 if (pid == -1)
35 { 57 {
@@ -45,8 +67,23 @@ main (int argc, char **argv)
45 } 67 }
46 68
47 alarm (n); 69 alarm (n);
48 ret = wait (&status); 70 while (1)
71 {
72 pause ();
73 if (got_sigchld)
74 {
49 alarm (0); 75 alarm (0);
76 break;
77 }
78 if (got_sigalrm)
79 {
80 fprintf (stderr, "%s: timed out\n", progname);
81 kill (pid, SIGKILL);
82 exit (127);
83 }
84 }
85
86 ret = wait (&status);
50 87
51 if (ret != pid) 88 if (ret != pid)
52 { 89 {
@@ -67,8 +104,3 @@ main (int argc, char **argv)
67 progname, argv[0], status); 104 progname, argv[0], status);
68 return 127; 105 return 127;
69} 106}
70
71
72
73
74

Return to:

Send suggestions and report system problems to the System administrator.