aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-05-20 00:00:40 +0200
committerChristian Grothoff <christian@grothoff.org>2019-05-20 00:00:40 +0200
commit426317707f34282830e5595193fcf2546c7d5b49 (patch)
tree3a18da0e6268dac4dabe9517d3a66e1644fc0423 /src/util
parent6e2ca97fb0d3d85c1ef127bc0b9bd3e1e72aa9e8 (diff)
downloadgnunet-426317707f34282830e5595193fcf2546c7d5b49.tar.gz
gnunet-426317707f34282830e5595193fcf2546c7d5b49.zip
use _exit in signal handlers
Diffstat (limited to 'src/util')
-rw-r--r--src/util/gnunet-timeout.c33
1 files changed, 11 insertions, 22 deletions
diff --git a/src/util/gnunet-timeout.c b/src/util/gnunet-timeout.c
index 18721ba03..d71b66af4 100644
--- a/src/util/gnunet-timeout.c
+++ b/src/util/gnunet-timeout.c
@@ -41,42 +41,33 @@ sigchld_handler (int val)
41 int ret = 0; 41 int ret = 0;
42 42
43 (void) val; 43 (void) val;
44 waitpid (child, 44 waitpid (child, &status, 0);
45 &status,
46 0);
47 if (WIFEXITED (status) != 0) 45 if (WIFEXITED (status) != 0)
48 { 46 {
49 ret = WEXITSTATUS (status); 47 ret = WEXITSTATUS (status);
50 fprintf (stderr, 48 fprintf (stderr, "Process exited with result %u\n", ret);
51 "Process exited with result %u\n", 49 _exit (ret); /* return same status code */
52 ret);
53 exit (ret); /* return same status code */
54 } 50 }
55 if (WIFSIGNALED (status) != 0) 51 if (WIFSIGNALED (status) != 0)
56 { 52 {
57 ret = WTERMSIG (status); 53 ret = WTERMSIG (status);
58 fprintf (stderr, 54 fprintf (stderr, "Process received signal %u\n", ret);
59 "Process received signal %u\n", 55 kill (getpid (), ret); /* kill self with the same signal */
60 ret);
61 kill (getpid (),
62 ret); /* kill self with the same signal */
63 } 56 }
64 exit (-1); 57 _exit (-1);
65} 58}
66 59
67 60
68static void 61static void
69sigint_handler (int val) 62sigint_handler (int val)
70{ 63{
71 kill (0, 64 kill (0, val);
72 val); 65 _exit (val);
73 exit (val);
74} 66}
75 67
76 68
77int 69int
78main (int argc, 70main (int argc, char *argv[])
79 char *argv[])
80{ 71{
81 int timeout = 0; 72 int timeout = 0;
82 pid_t gpid = 0; 73 pid_t gpid = 0;
@@ -111,8 +102,7 @@ main (int argc,
111 //setpgrp (0, pid_t gpid); 102 //setpgrp (0, pid_t gpid);
112 if (-1 != gpid) 103 if (-1 != gpid)
113 setpgid (0, gpid); 104 setpgid (0, gpid);
114 execvp (argv[2], 105 execvp (argv[2], &argv[2]);
115 &argv[2]);
116 exit (-1); 106 exit (-1);
117 } 107 }
118 if (child > 0) 108 if (child > 0)
@@ -120,8 +110,7 @@ main (int argc,
120 sleep (timeout); 110 sleep (timeout);
121 printf ("Child processes were killed after timeout of %u seconds\n", 111 printf ("Child processes were killed after timeout of %u seconds\n",
122 timeout); 112 timeout);
123 kill (0, 113 kill (0, SIGTERM);
124 SIGTERM);
125 exit (3); 114 exit (3);
126 } 115 }
127 exit (-1); 116 exit (-1);