diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/util/gnunet-timeout.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/util/gnunet-timeout.c')
-rw-r--r-- | src/util/gnunet-timeout.c | 102 |
1 files changed, 51 insertions, 51 deletions
diff --git a/src/util/gnunet-timeout.c b/src/util/gnunet-timeout.c index 2b1754a5e..cd6707db8 100644 --- a/src/util/gnunet-timeout.c +++ b/src/util/gnunet-timeout.c | |||
@@ -35,85 +35,85 @@ static pid_t child; | |||
35 | 35 | ||
36 | 36 | ||
37 | static void | 37 | static void |
38 | sigchld_handler(int val) | 38 | sigchld_handler (int val) |
39 | { | 39 | { |
40 | int status = 0; | 40 | int status = 0; |
41 | int ret = 0; | 41 | int ret = 0; |
42 | 42 | ||
43 | (void)val; | 43 | (void) val; |
44 | waitpid(child, &status, 0); | 44 | waitpid (child, &status, 0); |
45 | if (WIFEXITED(status) != 0) | 45 | if (WIFEXITED (status) != 0) |
46 | { | 46 | { |
47 | ret = WEXITSTATUS(status); | 47 | ret = WEXITSTATUS (status); |
48 | fprintf(stderr, "Process exited with result %u\n", ret); | 48 | fprintf (stderr, "Process exited with result %u\n", ret); |
49 | _exit(ret); /* return same status code */ | 49 | _exit (ret); /* return same status code */ |
50 | } | 50 | } |
51 | if (WIFSIGNALED(status) != 0) | 51 | if (WIFSIGNALED (status) != 0) |
52 | { | 52 | { |
53 | ret = WTERMSIG(status); | 53 | ret = WTERMSIG (status); |
54 | fprintf(stderr, "Process received signal %u\n", ret); | 54 | fprintf (stderr, "Process received signal %u\n", ret); |
55 | kill(getpid(), ret); /* kill self with the same signal */ | 55 | kill (getpid (), ret); /* kill self with the same signal */ |
56 | } | 56 | } |
57 | _exit(-1); | 57 | _exit (-1); |
58 | } | 58 | } |
59 | 59 | ||
60 | 60 | ||
61 | static void | 61 | static void |
62 | sigint_handler(int val) | 62 | sigint_handler (int val) |
63 | { | 63 | { |
64 | kill(0, val); | 64 | kill (0, val); |
65 | _exit(val); | 65 | _exit (val); |
66 | } | 66 | } |
67 | 67 | ||
68 | 68 | ||
69 | int | 69 | int |
70 | main(int argc, char *argv[]) | 70 | main (int argc, char *argv[]) |
71 | { | 71 | { |
72 | int timeout = 0; | 72 | int timeout = 0; |
73 | pid_t gpid = 0; | 73 | pid_t gpid = 0; |
74 | 74 | ||
75 | if (argc < 3) | 75 | if (argc < 3) |
76 | { | 76 | { |
77 | fprintf(stderr, | 77 | fprintf (stderr, |
78 | "arg 1: timeout in sec., arg 2: executable, arg<n> arguments\n"); | 78 | "arg 1: timeout in sec., arg 2: executable, arg<n> arguments\n"); |
79 | exit(-1); | 79 | exit (-1); |
80 | } | 80 | } |
81 | 81 | ||
82 | timeout = atoi(argv[1]); | 82 | timeout = atoi (argv[1]); |
83 | 83 | ||
84 | if (timeout == 0) | 84 | if (timeout == 0) |
85 | timeout = 600; | 85 | timeout = 600; |
86 | 86 | ||
87 | /* with getpgid() it does not compile, but getpgrp is the BSD version and working */ | 87 | /* with getpgid() it does not compile, but getpgrp is the BSD version and working */ |
88 | gpid = getpgrp(); | 88 | gpid = getpgrp (); |
89 | 89 | ||
90 | signal(SIGCHLD, sigchld_handler); | 90 | signal (SIGCHLD, sigchld_handler); |
91 | signal(SIGABRT, sigint_handler); | 91 | signal (SIGABRT, sigint_handler); |
92 | signal(SIGFPE, sigint_handler); | 92 | signal (SIGFPE, sigint_handler); |
93 | signal(SIGILL, sigint_handler); | 93 | signal (SIGILL, sigint_handler); |
94 | signal(SIGINT, sigint_handler); | 94 | signal (SIGINT, sigint_handler); |
95 | signal(SIGSEGV, sigint_handler); | 95 | signal (SIGSEGV, sigint_handler); |
96 | signal(SIGTERM, sigint_handler); | 96 | signal (SIGTERM, sigint_handler); |
97 | 97 | ||
98 | child = fork(); | 98 | child = fork (); |
99 | if (child == 0) | 99 | if (child == 0) |
100 | { | 100 | { |
101 | /* int setpgrp(pid_t pid, pid_t pgid); is not working on this machine */ | 101 | /* int setpgrp(pid_t pid, pid_t pgid); is not working on this machine */ |
102 | //setpgrp (0, pid_t gpid); | 102 | // setpgrp (0, pid_t gpid); |
103 | if (-1 != gpid) | 103 | if (-1 != gpid) |
104 | setpgid(0, gpid); | 104 | setpgid (0, gpid); |
105 | execvp(argv[2], &argv[2]); | 105 | execvp (argv[2], &argv[2]); |
106 | exit(-1); | 106 | exit (-1); |
107 | } | 107 | } |
108 | if (child > 0) | 108 | if (child > 0) |
109 | { | 109 | { |
110 | sleep(timeout); | 110 | sleep (timeout); |
111 | printf("Child processes were killed after timeout of %u seconds\n", | 111 | printf ("Child processes were killed after timeout of %u seconds\n", |
112 | timeout); | 112 | timeout); |
113 | kill(0, SIGTERM); | 113 | kill (0, SIGTERM); |
114 | exit(3); | 114 | exit (3); |
115 | } | 115 | } |
116 | exit(-1); | 116 | exit (-1); |
117 | } | 117 | } |
118 | 118 | ||
119 | /* end of timeout_watchdog.c */ | 119 | /* end of timeout_watchdog.c */ |