OpenCoverage

timeout.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/timeout.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9static int timed_out;-
10static int term_signal = -
11 15-
12 ;-
13static pid_t monitored_pid;-
14static double kill_after;-
15static -
16 _Bool -
17 foreground;-
18static -
19 _Bool -
20 preserve_status;-
21static -
22 _Bool -
23 verbose;-
24static char const* command;-
25-
26-
27enum-
28{-
29 FOREGROUND_OPTION = 0x7f + 1,-
30 PRESERVE_STATUS_OPTION-
31};-
32-
33static struct option const long_options[] =-
34{-
35 {"kill-after", -
36 1-
37 , -
38 ((void *)0)-
39 , 'k'},-
40 {"signal", -
41 1-
42 , -
43 ((void *)0)-
44 , 's'},-
45 {"verbose", -
46 0-
47 , -
48 ((void *)0)-
49 , 'v'},-
50 {"foreground", -
51 0-
52 , -
53 ((void *)0)-
54 , FOREGROUND_OPTION},-
55 {"preserve-status", -
56 0-
57 , -
58 ((void *)0)-
59 , PRESERVE_STATUS_OPTION},-
60 {"help", -
61 0-
62 , -
63 ((void *)0)-
64 , GETOPT_HELP_CHAR},-
65 {"version", -
66 0-
67 , -
68 ((void *)0)-
69 , GETOPT_VERSION_CHAR},-
70 {-
71 ((void *)0)-
72 , 0, -
73 ((void *)0)-
74 , 0}-
75};-
76-
77-
78-
79-
80-
81-
82static void-
83settimeout (double duration, -
84 _Bool -
85 warn)-
86{-
87 struct timespec ts = dtotimespec (duration);-
88 struct itimerspec its = { {0, 0}, ts };-
89 timer_t timerid;-
90 if (timer_create (
timer_create (...&timerid) == 0Description
TRUEevaluated 143 times by 1 test
Evaluated by:
  • timeout
FALSEnever evaluated
0-143
91 0
timer_create (...&timerid) == 0Description
TRUEevaluated 143 times by 1 test
Evaluated by:
  • timeout
FALSEnever evaluated
0-143
92 ,
timer_create (...&timerid) == 0Description
TRUEevaluated 143 times by 1 test
Evaluated by:
  • timeout
FALSEnever evaluated
0-143
93 ((void *)0)
timer_create (...&timerid) == 0Description
TRUEevaluated 143 times by 1 test
Evaluated by:
  • timeout
FALSEnever evaluated
0-143
94 , &timerid) == 0
timer_create (...&timerid) == 0Description
TRUEevaluated 143 times by 1 test
Evaluated by:
  • timeout
FALSEnever evaluated
)
0-143
95 {-
96 if (timer_settime (timerid, 0, &its,
timer_settime ...id *)0) ) == 0Description
TRUEevaluated 143 times by 1 test
Evaluated by:
  • timeout
FALSEnever evaluated
0-143
97 ((void *)0)
timer_settime ...id *)0) ) == 0Description
TRUEevaluated 143 times by 1 test
Evaluated by:
  • timeout
FALSEnever evaluated
0-143
98 ) == 0
timer_settime ...id *)0) ) == 0Description
TRUEevaluated 143 times by 1 test
Evaluated by:
  • timeout
FALSEnever evaluated
)
0-143
99 return;
executed 143 times by 1 test: return;
Executed by:
  • timeout
143
100 else-
101 {-
102 if (warn
warnDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
103 error (0,
never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "warning: timer_settime" , 5) );
0
104 (*__errno_location ())
never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "warning: timer_settime" , 5) );
0
105 ,
never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "warning: timer_settime" , 5) );
0
106 dcgettext (((void *)0),
never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "warning: timer_settime" , 5) );
0
107 "warning: timer_settime"
never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "warning: timer_settime" , 5) );
0
108 , 5)
never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "warning: timer_settime" , 5) );
0
109 );
never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "warning: timer_settime" , 5) );
0
110 timer_delete (timerid);-
111 }
never executed: end of block
0
112 }-
113 else if (warn
warnDescription
TRUEnever evaluated
FALSEnever evaluated
&&
0
114 (*
(*__errno_location ()) != 38Description
TRUEnever evaluated
FALSEnever evaluated
__errno_location ())
(*__errno_location ()) != 38Description
TRUEnever evaluated
FALSEnever evaluated
0
115 !=
(*__errno_location ()) != 38Description
TRUEnever evaluated
FALSEnever evaluated
0
116 38
(*__errno_location ()) != 38Description
TRUEnever evaluated
FALSEnever evaluated
0
117 )-
118 error (0,
never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "warning: timer_create" , 5) );
0
119 (*__errno_location ())
never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "warning: timer_create" , 5) );
0
120 ,
never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "warning: timer_create" , 5) );
0
121 dcgettext (((void *)0),
never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "warning: timer_create" , 5) );
0
122 "warning: timer_create"
never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "warning: timer_create" , 5) );
0
123 , 5)
never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "warning: timer_create" , 5) );
0
124 );
never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "warning: timer_create" , 5) );
0
125-
126-
127 unsigned int timeint;-
128 if (-
129 (
(0x7fffffff * ...U) <= durationDescription
TRUEnever evaluated
FALSEnever evaluated
0x7fffffff * 2U + 1U)
(0x7fffffff * ...U) <= durationDescription
TRUEnever evaluated
FALSEnever evaluated
0
130 <= duration
(0x7fffffff * ...U) <= durationDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
131 timeint =
never executed: timeint = (0x7fffffff * 2U + 1U) ;
0
132 (0x7fffffff * 2U + 1U)
never executed: timeint = (0x7fffffff * 2U + 1U) ;
0
133 ;
never executed: timeint = (0x7fffffff * 2U + 1U) ;
0
134 else-
135 {-
136 unsigned int duration_floor = duration;-
137 timeint = duration_floor + (duration_floor < duration);-
138 }
never executed: end of block
0
139 alarm (timeint);-
140}
never executed: end of block
0
141-
142-
143-
144static int-
145send_sig (pid_t where, int sig)-
146{-
147-
148-
149-
150-
151-
152-
153-
154 if (where
where == 0Description
TRUEevaluated 48 times by 1 test
Evaluated by:
  • timeout
FALSEevaluated 49 times by 1 test
Evaluated by:
  • timeout
== 0
where == 0Description
TRUEevaluated 48 times by 1 test
Evaluated by:
  • timeout
FALSEevaluated 49 times by 1 test
Evaluated by:
  • timeout
)
48-49
155 signal (sig,
executed 48 times by 1 test: signal (sig, ((__sighandler_t) 1) );
Executed by:
  • timeout
48
156 ((__sighandler_t) 1)
executed 48 times by 1 test: signal (sig, ((__sighandler_t) 1) );
Executed by:
  • timeout
48
157 );
executed 48 times by 1 test: signal (sig, ((__sighandler_t) 1) );
Executed by:
  • timeout
48
158 return
executed 97 times by 1 test: return kill (where, sig);
Executed by:
  • timeout
kill (where, sig);
executed 97 times by 1 test: return kill (where, sig);
Executed by:
  • timeout
97
159}-
160-
161-
162-
163static void-
164chld (int sig)-
165{-
166}-
167-
168-
169static void-
170cleanup (int sig)-
171{-
172 if (sig ==
sig == 14Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • timeout
FALSEevaluated 1 time by 1 test
Evaluated by:
  • timeout
1-24
173 14
sig == 14Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • timeout
FALSEevaluated 1 time by 1 test
Evaluated by:
  • timeout
1-24
174 )-
175 {-
176 timed_out = 1;-
177 sig = term_signal;-
178 }
executed 24 times by 1 test: end of block
Executed by:
  • timeout
24
179 if (monitored_pid
monitored_pidDescription
TRUEevaluated 25 times by 1 test
Evaluated by:
  • timeout
FALSEnever evaluated
)
0-25
180 {-
181 if (kill_after
kill_afterDescription
TRUEnever evaluated
FALSEevaluated 25 times by 1 test
Evaluated by:
  • timeout
)
0-25
182 {-
183 int saved_errno = -
184 (*__errno_location ())-
185 ;-
186-
187 term_signal = -
188 9-
189 ;-
190 settimeout (kill_after, -
191 0-
192 );-
193 kill_after = 0;-
194 -
195 (*__errno_location ()) -
196 = saved_errno;-
197 }
never executed: end of block
0
198-
199-
200-
201-
202 if (verbose
verboseDescription
TRUEnever evaluated
FALSEevaluated 25 times by 1 test
Evaluated by:
  • timeout
)
0-25
203 {-
204 char signame[-
205 (((-
206 (sizeof "SIGRTMAX" + (((((sizeof (int) * 8) - (! ((__typeof__ (int)) 0 < (__typeof__ (int)) -1))) * 146 + 484) / 485) + (! ((__typeof__ (int)) 0 < (__typeof__ (int)) -1))) - 1)-
207 )>(-
208 ((((((sizeof (int) * 8) - (! ((__typeof__ (int)) 0 < (__typeof__ (int)) -1))) * 146 + 484) / 485) + (! ((__typeof__ (int)) 0 < (__typeof__ (int)) -1))) + 1)-
209 ))?(-
210 (sizeof "SIGRTMAX" + (((((sizeof (int) * 8) - (! ((__typeof__ (int)) 0 < (__typeof__ (int)) -1))) * 146 + 484) / 485) + (! ((__typeof__ (int)) 0 < (__typeof__ (int)) -1))) - 1)-
211 ):(-
212 ((((((sizeof (int) * 8) - (! ((__typeof__ (int)) 0 < (__typeof__ (int)) -1))) * 146 + 484) / 485) + (! ((__typeof__ (int)) 0 < (__typeof__ (int)) -1))) + 1)-
213 ))-
214 ];-
215 if (sig2str (sig, signame) != 0
sig2str (sig, signame) != 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
216 snprintf (signame, sizeof signame, "%d", sig);
never executed: snprintf (signame, sizeof signame, "%d", sig);
0
217 error (0, 0, -
218 dcgettext (((void *)0), -
219 "sending signal %s to command %s"-
220 , 5)-
221 ,-
222 signame, quote (command));-
223 }
never executed: end of block
0
224 send_sig (monitored_pid, sig);-
225-
226-
227-
228 if (!foreground
!foregroundDescription
TRUEevaluated 24 times by 1 test
Evaluated by:
  • timeout
FALSEevaluated 1 time by 1 test
Evaluated by:
  • timeout
)
1-24
229 {-
230 send_sig (0, sig);-
231 if (sig !=
sig != 9Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • timeout
FALSEnever evaluated
0-24
232 9
sig != 9Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • timeout
FALSEnever evaluated
0-24
233 && sig !=
sig != 18Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • timeout
FALSEnever evaluated
0-24
234 18
sig != 18Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • timeout
FALSEnever evaluated
0-24
235 )-
236 {-
237 send_sig (monitored_pid, -
238 18-
239 );-
240 send_sig (0, -
241 18-
242 );-
243 }
executed 24 times by 1 test: end of block
Executed by:
  • timeout
24
244 }
executed 24 times by 1 test: end of block
Executed by:
  • timeout
24
245 }
executed 25 times by 1 test: end of block
Executed by:
  • timeout
25
246 else-
247 _exit (128 + sig);
never executed: _exit (128 + sig);
0
248}-
249-
250void-
251usage (int status)-
252{-
253 if (status !=
status != 0Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • timeout
FALSEevaluated 7 times by 1 test
Evaluated by:
  • timeout
7-12
254 0
status != 0Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • timeout
FALSEevaluated 7 times by 1 test
Evaluated by:
  • timeout
7-12
255 )-
256 do { fprintf (-
257 stderr-
258 , -
259 dcgettext (((void *)0), -
260 "Try '%s --help' for more information.\n"-
261 , 5)-
262 , program_name); }
executed 12 times by 1 test: end of block
Executed by:
  • timeout
while (0);
12
263 else-
264 {-
265 printf (-
266 dcgettext (((void *)0), -
267 "Usage: %s [OPTION] DURATION COMMAND [ARG]...\n or: %s [OPTION]\n"-
268 , 5)-
269-
270 -
271 , program_name, program_name);-
272-
273 fputs_unlocked (-
274 dcgettext (((void *)0), -
275 "Start COMMAND, and kill it if still running after DURATION.\n"-
276 , 5)-
277 ,-
278 stdout-
279 )-
280-
281 ;-
282-
283 emit_mandatory_arg_note ();-
284-
285 fputs_unlocked (-
286 dcgettext (((void *)0), -
287 " --preserve-status\n exit with the same status as COMMAND, even when the\n command times out\n --foreground\n when not running timeout directly from a shell prompt,\n allow COMMAND to read from the TTY and get TTY signals;\n in this mode, children of COMMAND will not be timed out\n -k, --kill-after=DURATION\n also send a KILL signal if COMMAND is still running\n this long after the initial signal was sent\n -s, --signal=SIGNAL\n specify the signal to be sent on timeout;\n SIGNAL may be a name like 'HUP' or a number;\n see 'kill -l' for a list of signals\n"-
288 , 5)-
289 ,-
290 stdout-
291 )-
292 ;-
293 fputs_unlocked (-
294 dcgettext (((void *)0), -
295 " -v, --verbose diagnose to stderr any signal sent upon timeout\n"-
296 , 5)-
297 ,-
298 stdout-
299 )-
300 ;-
301-
302 fputs_unlocked (-
303 dcgettext (((void *)0), -
304 " --help display this help and exit\n"-
305 , 5)-
306 ,-
307 stdout-
308 );-
309 fputs_unlocked (-
310 dcgettext (((void *)0), -
311 " --version output version information and exit\n"-
312 , 5)-
313 ,-
314 stdout-
315 );-
316-
317 fputs_unlocked (-
318 dcgettext (((void *)0), -
319 "\nDURATION is a floating point number with an optional suffix:\n's' for seconds (the default), 'm' for minutes, 'h' for hours or 'd' for days.\n"-
320 , 5)-
321 ,-
322 stdout-
323 )-
324-
325-
326 ;-
327-
328 fputs_unlocked (-
329 dcgettext (((void *)0), -
330 "\nIf the command times out, and --preserve-status is not set, then exit with\nstatus 124. Otherwise, exit with the status of COMMAND. If no signal\nis specified, send the TERM signal upon timeout. The TERM signal kills\nany process that does not block or catch that signal. It may be necessary\nto use the KILL (9) signal, since this signal cannot be caught, in which\ncase the exit status is 128+9 rather than 124.\n"-
331 , 5)-
332 ,-
333 stdout-
334 )-
335-
336-
337-
338-
339-
340 ;-
341 emit_ancillary_info ("timeout");-
342 }
executed 7 times by 1 test: end of block
Executed by:
  • timeout
7
343 exit (status);
executed 19 times by 1 test: exit (status);
Executed by:
  • timeout
19
344}-
345-
346-
347-
348-
349-
350-
351-
352static -
353 _Bool-
354-
355apply_time_suffix (double *x, char suffix_char)-
356{-
357 int multiplier;-
358-
359 switch (suffix_char)-
360 {-
361 case
executed 131 times by 1 test: case 0:
Executed by:
  • timeout
0:
executed 131 times by 1 test: case 0:
Executed by:
  • timeout
131
362 case
executed 11 times by 1 test: case 's':
Executed by:
  • timeout
's':
executed 11 times by 1 test: case 's':
Executed by:
  • timeout
11
363 multiplier = 1;-
364 break;
executed 142 times by 1 test: break;
Executed by:
  • timeout
142
365 case
never executed: case 'm':
'm':
never executed: case 'm':
0
366 multiplier = 60;-
367 break;
never executed: break;
0
368 case
never executed: case 'h':
'h':
never executed: case 'h':
0
369 multiplier = 60 * 60;-
370 break;
never executed: break;
0
371 case
executed 3 times by 1 test: case 'd':
Executed by:
  • timeout
'd':
executed 3 times by 1 test: case 'd':
Executed by:
  • timeout
3
372 multiplier = 60 * 60 * 24;-
373 break;
executed 3 times by 1 test: break;
Executed by:
  • timeout
3
374 default
executed 1 time by 1 test: default:
Executed by:
  • timeout
:
executed 1 time by 1 test: default:
Executed by:
  • timeout
1
375 return
executed 1 time by 1 test: return 0 ;
Executed by:
  • timeout
executed 1 time by 1 test: return 0 ;
Executed by:
  • timeout
1
376 0
executed 1 time by 1 test: return 0 ;
Executed by:
  • timeout
1
377 ;
executed 1 time by 1 test: return 0 ;
Executed by:
  • timeout
1
378 }-
379-
380 *x *= multiplier;-
381-
382 return
executed 145 times by 1 test: return 1 ;
Executed by:
  • timeout
executed 145 times by 1 test: return 1 ;
Executed by:
  • timeout
145
383 1
executed 145 times by 1 test: return 1 ;
Executed by:
  • timeout
145
384 ;
executed 145 times by 1 test: return 1 ;
Executed by:
  • timeout
145
385}-
386-
387static double-
388parse_duration (const char* str)-
389{-
390 double duration;-
391 const char *ep;-
392-
393 if (! (xstrtod (str, &ep, &duration, c_strtod)
xstrtod (str, ...ion, c_strtod)Description
TRUEevaluated 145 times by 1 test
Evaluated by:
  • timeout
FALSEevaluated 6 times by 1 test
Evaluated by:
  • timeout
||
6-145
394 (*
(*__errno_location ()) == 34Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • timeout
FALSEevaluated 4 times by 1 test
Evaluated by:
  • timeout
__errno_location ())
(*__errno_location ()) == 34Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • timeout
FALSEevaluated 4 times by 1 test
Evaluated by:
  • timeout
2-4
395 ==
(*__errno_location ()) == 34Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • timeout
FALSEevaluated 4 times by 1 test
Evaluated by:
  • timeout
2-4
396 34
(*__errno_location ()) == 34Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • timeout
FALSEevaluated 4 times by 1 test
Evaluated by:
  • timeout
2-4
397 )-
398-
399 || ! (0 <= duration)
! (0 <= duration)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • timeout
FALSEevaluated 146 times by 1 test
Evaluated by:
  • timeout
1-146
400-
401 || (*
*epDescription
TRUEevaluated 15 times by 1 test
Evaluated by:
  • timeout
FALSEevaluated 131 times by 1 test
Evaluated by:
  • timeout
ep
*epDescription
TRUEevaluated 15 times by 1 test
Evaluated by:
  • timeout
FALSEevaluated 131 times by 1 test
Evaluated by:
  • timeout
&& *(
*(ep + 1)Description
TRUEnever evaluated
FALSEevaluated 15 times by 1 test
Evaluated by:
  • timeout
ep + 1)
*(ep + 1)Description
TRUEnever evaluated
FALSEevaluated 15 times by 1 test
Evaluated by:
  • timeout
)
0-131
402-
403 || !apply_time_suffix (&duration, *ep)
!apply_time_su...duration, *ep)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • timeout
FALSEevaluated 145 times by 1 test
Evaluated by:
  • timeout
)
1-145
404 {-
405 error (0, 0, -
406 dcgettext (((void *)0), -
407 "invalid time interval %s"-
408 , 5)-
409 , quote (str));-
410 usage (EXIT_CANCELED);-
411 }
never executed: end of block
0
412-
413 return
executed 145 times by 1 test: return duration;
Executed by:
  • timeout
duration;
executed 145 times by 1 test: return duration;
Executed by:
  • timeout
145
414}-
415-
416static void-
417unblock_signal (int sig)-
418{-
419 sigset_t unblock_set;-
420 sigemptyset (&unblock_set);-
421 sigaddset (&unblock_set, sig);-
422 if (sigprocmask (
sigprocmask ( ...id *)0) ) != 0Description
TRUEnever evaluated
FALSEevaluated 288 times by 1 test
Evaluated by:
  • timeout
0-288
423 1
sigprocmask ( ...id *)0) ) != 0Description
TRUEnever evaluated
FALSEevaluated 288 times by 1 test
Evaluated by:
  • timeout
0-288
424 , &unblock_set,
sigprocmask ( ...id *)0) ) != 0Description
TRUEnever evaluated
FALSEevaluated 288 times by 1 test
Evaluated by:
  • timeout
0-288
425 ((void *)0)
sigprocmask ( ...id *)0) ) != 0Description
TRUEnever evaluated
FALSEevaluated 288 times by 1 test
Evaluated by:
  • timeout
0-288
426 ) != 0
sigprocmask ( ...id *)0) ) != 0Description
TRUEnever evaluated
FALSEevaluated 288 times by 1 test
Evaluated by:
  • timeout
)
0-288
427 error (0,
never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "warning: sigprocmask" , 5) );
0
428 (*__errno_location ())
never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "warning: sigprocmask" , 5) );
0
429 ,
never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "warning: sigprocmask" , 5) );
0
430 dcgettext (((void *)0),
never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "warning: sigprocmask" , 5) );
0
431 "warning: sigprocmask"
never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "warning: sigprocmask" , 5) );
0
432 , 5)
never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "warning: sigprocmask" , 5) );
0
433 );
never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "warning: sigprocmask" , 5) );
0
434}
executed 288 times by 1 test: end of block
Executed by:
  • timeout
288
435-
436static void-
437install_sigchld (void)-
438{-
439 struct sigaction sa;-
440 sigemptyset (&sa.sa_mask);-
441 sa.-
442 __sigaction_handler.sa_handler -
443 = chld;-
444 sa.sa_flags = -
445 0x10000000-
446 ;-
447-
448-
449 sigaction (-
450 17-
451 , &sa, -
452 ((void *)0)-
453 );-
454-
455-
456-
457 unblock_signal (-
458 17-
459 );-
460}
executed 145 times by 1 test: end of block
Executed by:
  • timeout
145
461-
462static void-
463install_cleanup (int sigterm)-
464{-
465 struct sigaction sa;-
466 sigemptyset (&sa.sa_mask);-
467 sa.-
468 __sigaction_handler.sa_handler -
469 = cleanup;-
470 sa.sa_flags = -
471 0x10000000-
472 ;-
473-
474-
475 sigaction (-
476 14-
477 , &sa, -
478 ((void *)0)-
479 );-
480 sigaction (-
481 2-
482 , &sa, -
483 ((void *)0)-
484 );-
485 sigaction (-
486 3-
487 , &sa, -
488 ((void *)0)-
489 );-
490 sigaction (-
491 1-
492 , &sa, -
493 ((void *)0)-
494 );-
495 sigaction (-
496 15-
497 , &sa, -
498 ((void *)0)-
499 );-
500 sigaction (sigterm, &sa, -
501 ((void *)0)-
502 );-
503}
executed 145 times by 1 test: end of block
Executed by:
  • timeout
145
504-
505-
506-
507-
508-
509-
510static void-
511block_cleanup_and_chld (int sigterm, sigset_t *old_set)-
512{-
513 sigset_t block_set;-
514 sigemptyset (&block_set);-
515-
516 sigaddset (&block_set, -
517 14-
518 );-
519 sigaddset (&block_set, -
520 2-
521 );-
522 sigaddset (&block_set, -
523 3-
524 );-
525 sigaddset (&block_set, -
526 1-
527 );-
528 sigaddset (&block_set, -
529 15-
530 );-
531 sigaddset (&block_set, sigterm);-
532-
533 sigaddset (&block_set, -
534 17-
535 );-
536-
537 if (sigprocmask (
sigprocmask ( ... old_set) != 0Description
TRUEnever evaluated
FALSEevaluated 143 times by 1 test
Evaluated by:
  • timeout
0-143
538 0
sigprocmask ( ... old_set) != 0Description
TRUEnever evaluated
FALSEevaluated 143 times by 1 test
Evaluated by:
  • timeout
0-143
539 , &block_set, old_set) != 0
sigprocmask ( ... old_set) != 0Description
TRUEnever evaluated
FALSEevaluated 143 times by 1 test
Evaluated by:
  • timeout
)
0-143
540 error (0,
never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "warning: sigprocmask" , 5) );
0
541 (*__errno_location ())
never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "warning: sigprocmask" , 5) );
0
542 ,
never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "warning: sigprocmask" , 5) );
0
543 dcgettext (((void *)0),
never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "warning: sigprocmask" , 5) );
0
544 "warning: sigprocmask"
never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "warning: sigprocmask" , 5) );
0
545 , 5)
never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "warning: sigprocmask" , 5) );
0
546 );
never executed: error (0, (*__errno_location ()) , dcgettext (((void *)0), "warning: sigprocmask" , 5) );
0
547}
executed 143 times by 1 test: end of block
Executed by:
  • timeout
143
548-
549-
550-
551static -
552 _Bool-
553-
554disable_core_dumps (void)-
555{-
556-
557 if (prctl (
prctl ( 4 , 0) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
558 4
prctl ( 4 , 0) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
559 , 0) == 0
prctl ( 4 , 0) == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
560 return
never executed: return 1 ;
never executed: return 1 ;
0
561 1
never executed: return 1 ;
0
562 ;
never executed: return 1 ;
0
563 error (0, -
564 (*__errno_location ())-
565 , -
566 dcgettext (((void *)0), -
567 "warning: disabling core dumps failed"-
568 , 5)-
569 );-
570 return
never executed: return 0 ;
never executed: return 0 ;
0
571 0
never executed: return 0 ;
0
572 ;
never executed: return 0 ;
0
573}-
574-
575int-
576main (int argc, char **argv)-
577{-
578 double timeout;-
579 char signame[(sizeof "SIGRTMAX" + (((((sizeof (int) * 8) - (! ((__typeof__ (int)) 0 < (__typeof__ (int)) -1))) * 146 + 484) / 485) + (! ((__typeof__ (int)) 0 < (__typeof__ (int)) -1))) - 1)];-
580 int c;-
581-
582 ;-
583 set_program_name (argv[0]);-
584 setlocale (-
585 6-
586 , "");-
587 bindtextdomain ("coreutils", "/usr/local/share/locale");-
588 textdomain ("coreutils");-
589-
590 initialize_exit_failure (EXIT_CANCELED);-
591 atexit (close_stdout);-
592-
593 while ((
(c = getopt_lo... *)0) )) != -1Description
TRUEevaluated 32 times by 1 test
Evaluated by:
  • timeout
FALSEevaluated 148 times by 1 test
Evaluated by:
  • timeout
c = getopt_long (argc, argv, "+k:s:v", long_options,
(c = getopt_lo... *)0) )) != -1Description
TRUEevaluated 32 times by 1 test
Evaluated by:
  • timeout
FALSEevaluated 148 times by 1 test
Evaluated by:
  • timeout
32-148
594 ((void *)0)
(c = getopt_lo... *)0) )) != -1Description
TRUEevaluated 32 times by 1 test
Evaluated by:
  • timeout
FALSEevaluated 148 times by 1 test
Evaluated by:
  • timeout
32-148
595 )) != -1
(c = getopt_lo... *)0) )) != -1Description
TRUEevaluated 32 times by 1 test
Evaluated by:
  • timeout
FALSEevaluated 148 times by 1 test
Evaluated by:
  • timeout
)
32-148
596 {-
597 switch (c)-
598 {-
599 case
executed 3 times by 1 test: case 'k':
Executed by:
  • timeout
'k':
executed 3 times by 1 test: case 'k':
Executed by:
  • timeout
3
600 kill_after = parse_duration (optarg);-
601 break;
never executed: break;
0
602-
603 case
executed 5 times by 1 test: case 's':
Executed by:
  • timeout
's':
executed 5 times by 1 test: case 's':
Executed by:
  • timeout
5
604 term_signal = operand2sig (optarg, signame);-
605 if (term_signal == -1
term_signal == -1Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • timeout
FALSEevaluated 2 times by 1 test
Evaluated by:
  • timeout
)
2-3
606 usage (EXIT_CANCELED);
executed 3 times by 1 test: usage (EXIT_CANCELED);
Executed by:
  • timeout
3
607 break;
executed 2 times by 1 test: break;
Executed by:
  • timeout
2
608-
609 case
executed 2 times by 1 test: case 'v':
Executed by:
  • timeout
'v':
executed 2 times by 1 test: case 'v':
Executed by:
  • timeout
2
610 verbose = -
611 1-
612 ;-
613 break;
executed 2 times by 1 test: break;
Executed by:
  • timeout
2
614-
615 case
executed 2 times by 1 test: case FOREGROUND_OPTION:
Executed by:
  • timeout
FOREGROUND_OPTION:
executed 2 times by 1 test: case FOREGROUND_OPTION:
Executed by:
  • timeout
2
616 foreground = -
617 1-
618 ;-
619 break;
executed 2 times by 1 test: break;
Executed by:
  • timeout
2
620-
621 case
executed 2 times by 1 test: case PRESERVE_STATUS_OPTION:
Executed by:
  • timeout
PRESERVE_STATUS_OPTION:
executed 2 times by 1 test: case PRESERVE_STATUS_OPTION:
Executed by:
  • timeout
2
622 preserve_status = -
623 1-
624 ;-
625 break;
executed 2 times by 1 test: break;
Executed by:
  • timeout
2
626-
627 case
executed 7 times by 1 test: case GETOPT_HELP_CHAR:
Executed by:
  • timeout
GETOPT_HELP_CHAR:
executed 7 times by 1 test: case GETOPT_HELP_CHAR:
Executed by:
  • timeout
usage (
7
628 0-
629 ); break;
never executed: break;
;
0
630-
631 case
executed 8 times by 1 test: case GETOPT_VERSION_CHAR:
Executed by:
  • timeout
GETOPT_VERSION_CHAR:
executed 8 times by 1 test: case GETOPT_VERSION_CHAR:
Executed by:
  • timeout
version_etc (
8
632 stdout-
633 , "timeout", "GNU coreutils", Version, ("Padraig Brady"), (char *) -
634 ((void *)0)-
635 ); exit (
executed 8 times by 1 test: exit ( 0 );
Executed by:
  • timeout
8
636 0
executed 8 times by 1 test: exit ( 0 );
Executed by:
  • timeout
8
637 );
executed 8 times by 1 test: exit ( 0 );
Executed by:
  • timeout
break;
never executed: break;
;
0-8
638-
639 default
executed 3 times by 1 test: default:
Executed by:
  • timeout
:
executed 3 times by 1 test: default:
Executed by:
  • timeout
3
640 usage (EXIT_CANCELED);-
641 break;
never executed: break;
0
642 }-
643 }-
644-
645 if (argc - optind < 2
argc - optind < 2Description
TRUEnever evaluated
FALSEevaluated 148 times by 1 test
Evaluated by:
  • timeout
)
0-148
646 usage (EXIT_CANCELED);
never executed: usage (EXIT_CANCELED);
0
647-
648 timeout = parse_duration (argv[optind++]);-
649-
650 argv += optind;-
651 command = argv[0];-
652-
653-
654-
655-
656-
657 if (!foreground
!foregroundDescription
TRUEevaluated 144 times by 1 test
Evaluated by:
  • timeout
FALSEevaluated 1 time by 1 test
Evaluated by:
  • timeout
)
1-144
658 setpgid (0, 0);
executed 144 times by 1 test: setpgid (0, 0);
Executed by:
  • timeout
144
659-
660-
661-
662 install_cleanup (term_signal);-
663 signal (-
664 21-
665 , -
666 ((__sighandler_t) 1)-
667 );-
668 signal (-
669 22-
670 , -
671 ((__sighandler_t) 1)-
672 );-
673 install_sigchld ();-
674-
675 monitored_pid = fork ();-
676 if (monitored_pid == -1
monitored_pid == -1Description
TRUEnever evaluated
FALSEevaluated 145 times by 1 test
Evaluated by:
  • timeout
)
0-145
677 {-
678 error (0, -
679 (*__errno_location ())-
680 , -
681 dcgettext (((void *)0), -
682 "fork system call failed"-
683 , 5)-
684 );-
685 return
never executed: return EXIT_CANCELED;
EXIT_CANCELED;
never executed: return EXIT_CANCELED;
0
686 }-
687 else if (monitored_pid == 0
monitored_pid == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • timeout
FALSEevaluated 143 times by 1 test
Evaluated by:
  • timeout
)
2-143
688 {-
689-
690 signal (-
691 21-
692 , -
693 ((__sighandler_t) 0)-
694 );-
695 signal (-
696 22-
697 , -
698 ((__sighandler_t) 0)-
699 );-
700-
701 execvp (argv[0], argv);-
702-
703-
704 int exit_status = -
705 (*
(*__errno_location ()) == 2Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • timeout
FALSEevaluated 1 time by 1 test
Evaluated by:
  • timeout
__errno_location ())
(*__errno_location ()) == 2Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • timeout
FALSEevaluated 1 time by 1 test
Evaluated by:
  • timeout
1
706 ==
(*__errno_location ()) == 2Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • timeout
FALSEevaluated 1 time by 1 test
Evaluated by:
  • timeout
1
707 2
(*__errno_location ()) == 2Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • timeout
FALSEevaluated 1 time by 1 test
Evaluated by:
  • timeout
1
708 ? EXIT_ENOENT : EXIT_CANNOT_INVOKE;-
709 error (0, -
710 (*__errno_location ())-
711 , -
712 dcgettext (((void *)0), -
713 "failed to run command %s"-
714 , 5)-
715 , quote (command));-
716 return
executed 2 times by 1 test: return exit_status;
Executed by:
  • timeout
exit_status;
executed 2 times by 1 test: return exit_status;
Executed by:
  • timeout
2
717 }-
718 else-
719 {-
720 pid_t wait_result;-
721 int status;-
722-
723-
724-
725 unblock_signal (-
726 14-
727 );-
728-
729 settimeout (timeout, -
730 1-
731 );-
732-
733-
734-
735 sigset_t cleanup_set;-
736 block_cleanup_and_chld (term_signal, &cleanup_set);-
737-
738 while ((
(wait_result =...tus, 1 )) == 0Description
TRUEevaluated 169 times by 1 test
Evaluated by:
  • timeout
FALSEevaluated 143 times by 1 test
Evaluated by:
  • timeout
wait_result = waitpid (monitored_pid, &status,
(wait_result =...tus, 1 )) == 0Description
TRUEevaluated 169 times by 1 test
Evaluated by:
  • timeout
FALSEevaluated 143 times by 1 test
Evaluated by:
  • timeout
143-169
739 1
(wait_result =...tus, 1 )) == 0Description
TRUEevaluated 169 times by 1 test
Evaluated by:
  • timeout
FALSEevaluated 143 times by 1 test
Evaluated by:
  • timeout
143-169
740 )) == 0
(wait_result =...tus, 1 )) == 0Description
TRUEevaluated 169 times by 1 test
Evaluated by:
  • timeout
FALSEevaluated 143 times by 1 test
Evaluated by:
  • timeout
)
143-169
741 sigsuspend (&cleanup_set);
executed 169 times by 1 test: sigsuspend (&cleanup_set);
Executed by:
  • timeout
169
742-
743 if (wait_result < 0
wait_result < 0Description
TRUEnever evaluated
FALSEevaluated 143 times by 1 test
Evaluated by:
  • timeout
)
0-143
744 {-
745-
746 error (0, -
747 (*__errno_location ())-
748 , -
749 dcgettext (((void *)0), -
750 "error waiting for command"-
751 , 5)-
752 );-
753 status = EXIT_CANCELED;-
754 }
never executed: end of block
0
755 else-
756 {-
757 if (-
758 (((
((( status ) & 0x7f) == 0)Description
TRUEevaluated 121 times by 1 test
Evaluated by:
  • timeout
FALSEevaluated 22 times by 1 test
Evaluated by:
  • timeout
22-121
759 status
((( status ) & 0x7f) == 0)Description
TRUEevaluated 121 times by 1 test
Evaluated by:
  • timeout
FALSEevaluated 22 times by 1 test
Evaluated by:
  • timeout
22-121
760 ) & 0x7f) == 0)
((( status ) & 0x7f) == 0)Description
TRUEevaluated 121 times by 1 test
Evaluated by:
  • timeout
FALSEevaluated 22 times by 1 test
Evaluated by:
  • timeout
22-121
761 )-
762 status =
executed 121 times by 1 test: status = ((( status ) & 0xff00) >> 8) ;
Executed by:
  • timeout
121
763 (((
executed 121 times by 1 test: status = ((( status ) & 0xff00) >> 8) ;
Executed by:
  • timeout
121
764 status
executed 121 times by 1 test: status = ((( status ) & 0xff00) >> 8) ;
Executed by:
  • timeout
121
765 ) & 0xff00) >> 8)
executed 121 times by 1 test: status = ((( status ) & 0xff00) >> 8) ;
Executed by:
  • timeout
121
766 ;
executed 121 times by 1 test: status = ((( status ) & 0xff00) >> 8) ;
Executed by:
  • timeout
121
767 else if (-
768 (((
(((signed char... 1) >> 1) > 0)Description
TRUEevaluated 22 times by 1 test
Evaluated by:
  • timeout
FALSEnever evaluated
signed char) (((
(((signed char... 1) >> 1) > 0)Description
TRUEevaluated 22 times by 1 test
Evaluated by:
  • timeout
FALSEnever evaluated
0-22
769 status
(((signed char... 1) >> 1) > 0)Description
TRUEevaluated 22 times by 1 test
Evaluated by:
  • timeout
FALSEnever evaluated
0-22
770 ) & 0x7f) + 1) >> 1) > 0)
(((signed char... 1) >> 1) > 0)Description
TRUEevaluated 22 times by 1 test
Evaluated by:
  • timeout
FALSEnever evaluated
0-22
771 )-
772 {-
773 int sig = -
774 ((-
775 status-
776 ) & 0x7f)-
777 ;-
778 if (-
779 ((
(( status ) & 0x80)Description
TRUEnever evaluated
FALSEevaluated 22 times by 1 test
Evaluated by:
  • timeout
0-22
780 status
(( status ) & 0x80)Description
TRUEnever evaluated
FALSEevaluated 22 times by 1 test
Evaluated by:
  • timeout
0-22
781 ) & 0x80)
(( status ) & 0x80)Description
TRUEnever evaluated
FALSEevaluated 22 times by 1 test
Evaluated by:
  • timeout
0-22
782 )-
783 error (0, 0,
never executed: error (0, 0, dcgettext (((void *)0), "the monitored command dumped core" , 5) );
0
784 dcgettext (((void *)0),
never executed: error (0, 0, dcgettext (((void *)0), "the monitored command dumped core" , 5) );
0
785 "the monitored command dumped core"
never executed: error (0, 0, dcgettext (((void *)0), "the monitored command dumped core" , 5) );
0
786 , 5)
never executed: error (0, 0, dcgettext (((void *)0), "the monitored command dumped core" , 5) );
0
787 );
never executed: error (0, 0, dcgettext (((void *)0), "the monitored command dumped core" , 5) );
0
788 if (!timed_out
!timed_outDescription
TRUEnever evaluated
FALSEevaluated 22 times by 1 test
Evaluated by:
  • timeout
&& disable_core_dumps ()
disable_core_dumps ()Description
TRUEnever evaluated
FALSEnever evaluated
)
0-22
789 {-
790-
791 signal (sig, -
792 ((__sighandler_t) 0)-
793 );-
794 unblock_signal (sig);-
795 raise (sig);-
796 }
never executed: end of block
0
797 status = sig + 128;-
798 }
executed 22 times by 1 test: end of block
Executed by:
  • timeout
22
799 else-
800 {-
801-
802 error (0, 0, -
803 dcgettext (((void *)0), -
804 "unknown status from command (%d)"-
805 , 5)-
806 , status);-
807 status = -
808 1-
809 ;-
810 }
never executed: end of block
0
811 }-
812-
813 if (timed_out
timed_outDescription
TRUEevaluated 24 times by 1 test
Evaluated by:
  • timeout
FALSEevaluated 119 times by 1 test
Evaluated by:
  • timeout
&& !preserve_status
!preserve_statusDescription
TRUEevaluated 23 times by 1 test
Evaluated by:
  • timeout
FALSEevaluated 1 time by 1 test
Evaluated by:
  • timeout
)
1-119
814 status = EXIT_TIMEDOUT;
executed 23 times by 1 test: status = EXIT_TIMEDOUT;
Executed by:
  • timeout
23
815 return
executed 143 times by 1 test: return status;
Executed by:
  • timeout
status;
executed 143 times by 1 test: return status;
Executed by:
  • timeout
143
816 }-
817}-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.1.2