aboutsummaryrefslogtreecommitdiff
path: root/tests/to.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/to.c')
-rw-r--r--tests/to.c50
1 files changed, 41 insertions, 9 deletions
diff --git a/tests/to.c b/tests/to.c
index 6511a54..6874bfd 100644
--- a/tests/to.c
+++ b/tests/to.c
@@ -1 +1,2 @@
1#include <config.h>
1#include <stdlib.h> 2#include <stdlib.h>
@@ -6,2 +7,20 @@
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
@@ -15,3 +34,3 @@ main (int argc, char **argv)
15 int status; 34 int status;
16 35
17 if (argc < 3) 36 if (argc < 3)
@@ -32,2 +51,5 @@ main (int argc, char **argv)
32 51
52 signal (SIGALRM, sighan);
53 signal (SIGCHLD, sighan);
54
33 pid = fork (); 55 pid = fork ();
@@ -38,3 +60,3 @@ main (int argc, char **argv)
38 } 60 }
39 61
40 if (pid == 0) 62 if (pid == 0)
@@ -47,4 +69,19 @@ main (int argc, char **argv)
47 alarm (n); 69 alarm (n);
70 while (1)
71 {
72 pause ();
73 if (got_sigchld)
74 {
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
48 ret = wait (&status); 86 ret = wait (&status);
49 alarm (0);
50 87
@@ -58,3 +95,3 @@ main (int argc, char **argv)
58 return WEXITSTATUS (status); 95 return WEXITSTATUS (status);
59 96
60 if (WIFSIGNALED (status)) 97 if (WIFSIGNALED (status))
@@ -69,6 +106 @@ main (int argc, char **argv)
69} 106}
70
71
72
73
74

Return to:

Send suggestions and report system problems to the System administrator.