OpenCoverage

execute_cmd.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/execute_cmd.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* execute_cmd.c -- Execute a COMMAND structure. */-
2-
3/* Copyright (C) 1987-2018 Free Software Foundation, Inc.-
4-
5 This file is part of GNU Bash, the Bourne Again SHell.-
6-
7 Bash is free software: you can redistribute it and/or modify-
8 it under the terms of the GNU General Public License as published by-
9 the Free Software Foundation, either version 3 of the License, or-
10 (at your option) any later version.-
11-
12 Bash is distributed in the hope that it will be useful,-
13 but WITHOUT ANY WARRANTY; without even the implied warranty of-
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
15 GNU General Public License for more details.-
16-
17 You should have received a copy of the GNU General Public License-
18 along with Bash. If not, see <http://www.gnu.org/licenses/>.-
19*/-
20-
21#include "config.h"-
22-
23#if !defined (__GNUC__) && !defined (HAVE_ALLOCA_H) && defined (_AIX)-
24 #pragma alloca-
25#endif /* _AIX && RISC6000 && !__GNUC__ */-
26-
27#include <stdio.h>-
28#include "chartypes.h"-
29#include "bashtypes.h"-
30#if !defined (_MINIX) && defined (HAVE_SYS_FILE_H)-
31# include <sys/file.h>-
32#endif-
33#include "filecntl.h"-
34#include "posixstat.h"-
35#include <signal.h>-
36#if defined (HAVE_SYS_PARAM_H)-
37# include <sys/param.h>-
38#endif-
39-
40#if defined (HAVE_UNISTD_H)-
41# include <unistd.h>-
42#endif-
43-
44#include "posixtime.h"-
45-
46#if defined (HAVE_SYS_RESOURCE_H) && !defined (RLIMTYPE)-
47# include <sys/resource.h>-
48#endif-
49-
50#if defined (HAVE_SYS_TIMES_H) && defined (HAVE_TIMES)-
51# include <sys/times.h>-
52#endif-
53-
54#include <errno.h>-
55-
56#if !defined (errno)-
57extern int errno;-
58#endif-
59-
60#define NEED_FPURGE_DECL-
61#define NEED_SH_SETLINEBUF_DECL-
62-
63#include "bashansi.h"-
64#include "bashintl.h"-
65-
66#include "memalloc.h"-
67#include "shell.h"-
68#include <y.tab.h> /* use <...> so we pick it up from the build directory */-
69#include "parser.h"-
70#include "flags.h"-
71#include "builtins.h"-
72#include "hashlib.h"-
73#include "jobs.h"-
74#include "execute_cmd.h"-
75#include "findcmd.h"-
76#include "redir.h"-
77#include "trap.h"-
78#include "pathexp.h"-
79#include "hashcmd.h"-
80-
81#if defined (COND_COMMAND)-
82# include "test.h"-
83#endif-
84-
85#include "builtins/common.h"-
86#include "builtins/builtext.h" /* list of builtins */-
87-
88#include "builtins/getopt.h"-
89-
90#include <glob/strmatch.h>-
91#include <tilde/tilde.h>-
92-
93#if defined (BUFFERED_INPUT)-
94# include "input.h"-
95#endif-
96-
97#if defined (ALIAS)-
98# include "alias.h"-
99#endif-
100-
101#if defined (HISTORY)-
102# include "bashhist.h"-
103#endif-
104-
105#if defined (HAVE_MBSTR_H) && defined (HAVE_MBSCHR)-
106# include <mbstr.h> /* mbschr */-
107#endif-
108-
109extern int command_string_index;-
110extern char *the_printed_command;-
111extern time_t shell_start_time;-
112#if 0-
113extern char *glob_argv_flags;-
114#endif-
115-
116extern int close __P((int));-
117-
118/* Static functions defined and used in this file. */-
119static void close_pipes __P((int, int));-
120static void do_piping __P((int, int));-
121static void bind_lastarg __P((char *));-
122static int shell_control_structure __P((enum command_type));-
123static void cleanup_redirects __P((REDIRECT *));-
124-
125#if defined (JOB_CONTROL)-
126static int restore_signal_mask __P((sigset_t *));-
127#endif-
128-
129static void async_redirect_stdin __P((void));-
130-
131static int builtin_status __P((int));-
132-
133static int execute_for_command __P((FOR_COM *));-
134#if defined (SELECT_COMMAND)-
135static int displen __P((const char *));-
136static int print_index_and_element __P((int, int, WORD_LIST *));-
137static void indent __P((int, int));-
138static void print_select_list __P((WORD_LIST *, int, int, int));-
139static char *select_query __P((WORD_LIST *, int, char *, int));-
140static int execute_select_command __P((SELECT_COM *));-
141#endif-
142#if defined (DPAREN_ARITHMETIC)-
143static int execute_arith_command __P((ARITH_COM *));-
144#endif-
145#if defined (COND_COMMAND)-
146static int execute_cond_node __P((COND_COM *));-
147static int execute_cond_command __P((COND_COM *));-
148#endif-
149#if defined (COMMAND_TIMING)-
150static int mkfmt __P((char *, int, int, time_t, int));-
151static void print_formatted_time __P((FILE *, char *,-
152 time_t, int, time_t, int,-
153 time_t, int, int));-
154static int time_command __P((COMMAND *, int, int, int, struct fd_bitmap *));-
155#endif-
156#if defined (ARITH_FOR_COMMAND)-
157static intmax_t eval_arith_for_expr __P((WORD_LIST *, int *));-
158static int execute_arith_for_command __P((ARITH_FOR_COM *));-
159#endif-
160static int execute_case_command __P((CASE_COM *));-
161static int execute_while_command __P((WHILE_COM *));-
162static int execute_until_command __P((WHILE_COM *));-
163static int execute_while_or_until __P((WHILE_COM *, int));-
164static int execute_if_command __P((IF_COM *));-
165static int execute_null_command __P((REDIRECT *, int, int, int));-
166static void fix_assignment_words __P((WORD_LIST *));-
167static int execute_simple_command __P((SIMPLE_COM *, int, int, int, struct fd_bitmap *));-
168static int execute_builtin __P((sh_builtin_func_t *, WORD_LIST *, int, int));-
169static int execute_function __P((SHELL_VAR *, WORD_LIST *, int, struct fd_bitmap *, int, int));-
170static int execute_builtin_or_function __P((WORD_LIST *, sh_builtin_func_t *,-
171 SHELL_VAR *,-
172 REDIRECT *, struct fd_bitmap *, int));-
173static void execute_subshell_builtin_or_function __P((WORD_LIST *, REDIRECT *,-
174 sh_builtin_func_t *,-
175 SHELL_VAR *,-
176 int, int, int,-
177 struct fd_bitmap *,-
178 int));-
179static int execute_disk_command __P((WORD_LIST *, REDIRECT *, char *,-
180 int, int, int, struct fd_bitmap *, int));-
181-
182static char *getinterp __P((char *, int, int *));-
183static void initialize_subshell __P((void));-
184static int execute_in_subshell __P((COMMAND *, int, int, int, struct fd_bitmap *));-
185#if defined (COPROCESS_SUPPORT)-
186static void coproc_setstatus __P((struct coproc *, int));-
187static int execute_coproc __P((COMMAND *, int, int, struct fd_bitmap *));-
188#endif-
189-
190static int execute_pipeline __P((COMMAND *, int, int, int, struct fd_bitmap *));-
191-
192static int execute_connection __P((COMMAND *, int, int, int, struct fd_bitmap *));-
193-
194static int execute_intern_function __P((WORD_DESC *, FUNCTION_DEF *));-
195-
196/* Set to 1 if fd 0 was the subject of redirection to a subshell. Global-
197 so that reader_loop can set it to zero before executing a command. */-
198int stdin_redir;-
199-
200/* The name of the command that is currently being executed.-
201 `test' needs this, for example. */-
202char *this_command_name;-
203-
204/* The printed representation of the currently-executing command (same as-
205 the_printed_command), except when a trap is being executed. Useful for-
206 a debugger to know where exactly the program is currently executing. */-
207char *the_printed_command_except_trap;-
208-
209/* For catching RETURN in a function. */-
210int return_catch_flag;-
211int return_catch_value;-
212procenv_t return_catch;-
213-
214/* The value returned by the last synchronous command. */-
215volatile int last_command_exit_value;-
216-
217/* Whether or not the last command (corresponding to last_command_exit_value)-
218 was terminated by a signal, and, if so, which one. */-
219int last_command_exit_signal;-
220-
221/* Are we currently ignoring the -e option for the duration of a builtin's-
222 execution? */-
223int builtin_ignoring_errexit = 0;-
224-
225/* The list of redirections to perform which will undo the redirections-
226 that I made in the shell. */-
227REDIRECT *redirection_undo_list = (REDIRECT *)NULL;-
228-
229/* The list of redirections to perform which will undo the internal-
230 redirections performed by the `exec' builtin. These are redirections-
231 that must be undone even when exec discards redirection_undo_list. */-
232REDIRECT *exec_redirection_undo_list = (REDIRECT *)NULL;-
233-
234/* When greater than zero, value is the `level' of builtins we are-
235 currently executing (e.g. `eval echo a' would have it set to 2). */-
236int executing_builtin = 0;-
237-
238/* Non-zero if we are executing a command list (a;b;c, etc.) */-
239int executing_list = 0;-
240-
241/* Non-zero if failing commands in a command substitution should not exit the-
242 shell even if -e is set. Used to pass the CMD_IGNORE_RETURN flag down to-
243 commands run in command substitutions by parse_and_execute. */-
244int comsub_ignore_return = 0;-
245-
246/* Non-zero if we have just forked and are currently running in a subshell-
247 environment. */-
248int subshell_environment;-
249-
250/* Count of nested subshells, like SHLVL. Available via $BASH_SUBSHELL */-
251int subshell_level = 0;-
252-
253/* Currently-executing shell function. */-
254SHELL_VAR *this_shell_function;-
255-
256/* If non-zero, matches in case and [[ ... ]] are case-insensitive */-
257int match_ignore_case = 0;-
258-
259int executing_command_builtin = 0;-
260-
261struct stat SB; /* used for debugging */-
262-
263static int special_builtin_failed;-
264-
265static COMMAND *currently_executing_command;-
266-
267/* The line number that the currently executing function starts on. */-
268static int function_line_number;-
269-
270/* XXX - set to 1 if we're running the DEBUG trap and we want to show the line-
271 number containing the function name. Used by executing_line_number to-
272 report the correct line number. Kind of a hack. */-
273static int showing_function_line;-
274-
275static int connection_count;-
276-
277/* $LINENO ($BASH_LINENO) for use by an ERR trap. Global so parse_and_execute-
278 can save and restore it. */-
279int line_number_for_err_trap;-
280-
281/* A sort of function nesting level counter */-
282int funcnest = 0;-
283int funcnest_max = 0;-
284-
285int evalnest = 0; /* bash-4.4/bash-5.0 */-
286int evalnest_max = EVALNEST_MAX;-
287-
288int sourcenest = 0;-
289int sourcenest_max = SOURCENEST_MAX;-
290-
291volatile int from_return_trap = 0;-
292-
293int lastpipe_opt = 0;-
294-
295struct fd_bitmap *current_fds_to_close = (struct fd_bitmap *)NULL;-
296-
297#define FD_BITMAP_DEFAULT_SIZE 32-
298-
299/* Functions to allocate and deallocate the structures used to pass-
300 information from the shell to its children about file descriptors-
301 to close. */-
302struct fd_bitmap *-
303new_fd_bitmap (size)-
304 int size;-
305{-
306 struct fd_bitmap *ret;-
307-
308 ret = (struct fd_bitmap *)xmalloc (sizeof (struct fd_bitmap));-
309-
310 ret->size = size;-
311-
312 if (size)
sizeDescription
TRUEevaluated 122425482 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-122425482
313 {-
314 ret->bitmap = (char *)xmalloc (size);-
315 memset (ret->bitmap, '\0', size);-
316 }
executed 122425482 times by 1 test: end of block
Executed by:
  • Self test
122425482
317 else-
318 ret->bitmap = (char *)NULL;
never executed: ret->bitmap = (char *) ((void *)0) ;
0
319 return (ret);
executed 122425482 times by 1 test: return (ret);
Executed by:
  • Self test
122425482
320}-
321-
322void-
323dispose_fd_bitmap (fdbp)-
324 struct fd_bitmap *fdbp;-
325{-
326 FREE (fdbp->bitmap);
executed 122385484 times by 1 test: sh_xfree((fdbp->bitmap), "execute_cmd.c", 326);
Executed by:
  • Self test
fdbp->bitmapDescription
TRUEevaluated 122385484 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-122385484
327 free (fdbp);-
328}
executed 122385484 times by 1 test: end of block
Executed by:
  • Self test
122385484
329-
330void-
331close_fd_bitmap (fdbp)-
332 struct fd_bitmap *fdbp;-
333{-
334 register int i;-
335-
336 if (fdbp)
fdbpDescription
TRUEevaluated 3446 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-3446
337 {-
338 for (i = 0; i < fdbp->size; i++)
i < fdbp->sizeDescription
TRUEevaluated 110272 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3446 times by 1 test
Evaluated by:
  • Self test
3446-110272
339 if (fdbp->bitmap[i])
fdbp->bitmap[i]Description
TRUEevaluated 1026 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 109246 times by 1 test
Evaluated by:
  • Self test
1026-109246
340 {-
341 close (i);-
342 fdbp->bitmap[i] = 0;-
343 }
executed 1026 times by 1 test: end of block
Executed by:
  • Self test
1026
344 }
executed 3446 times by 1 test: end of block
Executed by:
  • Self test
3446
345}
executed 3446 times by 1 test: end of block
Executed by:
  • Self test
3446
346-
347/* Return the line number of the currently executing command. */-
348int-
349executing_line_number ()-
350{-
351 if (executing && showing_function_line == 0 &&
executingDescription
TRUEevaluated 1645807 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5434 times by 1 test
Evaluated by:
  • Self test
showing_function_line == 0Description
TRUEevaluated 1645431 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 376 times by 1 test
Evaluated by:
  • Self test
376-1645807
352 (variable_context == 0 || interactive_shell == 0) &&
variable_context == 0Description
TRUEevaluated 3083 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1642348 times by 1 test
Evaluated by:
  • Self test
interactive_shell == 0Description
TRUEevaluated 1642348 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1642348
353 currently_executing_command)
currently_executing_commandDescription
TRUEevaluated 1644947 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 484 times by 1 test
Evaluated by:
  • Self test
484-1644947
354 {-
355#if defined (COND_COMMAND)-
356 if (currently_executing_command->type == cm_cond)
currently_exec...ype == cm_condDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1644946 times by 1 test
Evaluated by:
  • Self test
1-1644946
357 return currently_executing_command->value.Cond->line;
executed 1 time by 1 test: return currently_executing_command->value.Cond->line;
Executed by:
  • Self test
1
358#endif-
359#if defined (DPAREN_ARITHMETIC)-
360 if (currently_executing_command->type == cm_arith)
currently_exec...pe == cm_arithDescription
TRUEevaluated 18 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1644928 times by 1 test
Evaluated by:
  • Self test
18-1644928
361 return currently_executing_command->value.Arith->line;
executed 18 times by 1 test: return currently_executing_command->value.Arith->line;
Executed by:
  • Self test
18
362#endif-
363#if defined (ARITH_FOR_COMMAND)-
364 if (currently_executing_command->type == cm_arith_for)
currently_exec...= cm_arith_forDescription
TRUEnever evaluated
FALSEevaluated 1644928 times by 1 test
Evaluated by:
  • Self test
0-1644928
365 return currently_executing_command->value.ArithFor->line;
never executed: return currently_executing_command->value.ArithFor->line;
0
366#endif-
367-
368 return line_number;
executed 1644928 times by 1 test: return line_number;
Executed by:
  • Self test
1644928
369 }-
370 else-
371 return line_number;
executed 6294 times by 1 test: return line_number;
Executed by:
  • Self test
6294
372}-
373-
374/* Execute the command passed in COMMAND. COMMAND is exactly what-
375 read_command () places into GLOBAL_COMMAND. See "command.h" for the-
376 details of the command structure.-
377-
378 EXECUTION_SUCCESS or EXECUTION_FAILURE are the only possible-
379 return values. Executing a command with nothing in it returns-
380 EXECUTION_SUCCESS. */-
381int-
382execute_command (command)-
383 COMMAND *command;-
384{-
385 struct fd_bitmap *bitmap;-
386 int result;-
387-
388 current_fds_to_close = (struct fd_bitmap *)NULL;-
389 bitmap = new_fd_bitmap (FD_BITMAP_DEFAULT_SIZE);-
390 begin_unwind_frame ("execute-command");-
391 add_unwind_protect (dispose_fd_bitmap, (char *)bitmap);-
392-
393 /* Just do the command, but not asynchronously. */-
394 result = execute_command_internal (command, 0, NO_PIPE, NO_PIPE, bitmap);-
395-
396 dispose_fd_bitmap (bitmap);-
397 discard_unwind_frame ("execute-command");-
398-
399#if defined (PROCESS_SUBSTITUTION)-
400 /* don't unlink fifos if we're in a shell function; wait until the function-
401 returns. */-
402 if (variable_context == 0 && executing_list == 0)
variable_context == 0Description
TRUEevaluated 8640812 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 113709561 times by 1 test
Evaluated by:
  • Self test
executing_list == 0Description
TRUEevaluated 151946 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8488866 times by 1 test
Evaluated by:
  • Self test
151946-113709561
403 unlink_fifo_list ();
executed 151946 times by 1 test: unlink_fifo_list ();
Executed by:
  • Self test
151946
404#endif /* PROCESS_SUBSTITUTION */-
405-
406 QUIT;
never executed: termsig_handler (terminating_signal);
never executed: throw_to_top_level ();
terminating_signalDescription
TRUEnever evaluated
FALSEevaluated 122350373 times by 1 test
Evaluated by:
  • Self test
interrupt_stateDescription
TRUEnever evaluated
FALSEevaluated 122350373 times by 1 test
Evaluated by:
  • Self test
0-122350373
407 return (result);
executed 122350373 times by 1 test: return (result);
Executed by:
  • Self test
122350373
408}-
409-
410/* Return 1 if TYPE is a shell control structure type. */-
411static int-
412shell_control_structure (type)-
413 enum command_type type;-
414{-
415 switch (type)-
416 {-
417#if defined (ARITH_FOR_COMMAND)-
418 case cm_arith_for:
executed 5223 times by 1 test: case cm_arith_for:
Executed by:
  • Self test
5223
419#endif-
420#if defined (SELECT_COMMAND)-
421 case cm_select:
executed 18 times by 1 test: case cm_select:
Executed by:
  • Self test
18
422#endif-
423#if defined (DPAREN_ARITHMETIC)-
424 case cm_arith:
executed 12952036 times by 1 test: case cm_arith:
Executed by:
  • Self test
12952036
425#endif-
426#if defined (COND_COMMAND)-
427 case cm_cond:
executed 1260 times by 1 test: case cm_cond:
Executed by:
  • Self test
1260
428#endif-
429 case cm_case:
executed 73894342 times by 1 test: case cm_case:
Executed by:
  • Self test
73894342
430 case cm_while:
executed 7785223 times by 1 test: case cm_while:
Executed by:
  • Self test
7785223
431 case cm_until:
executed 24 times by 1 test: case cm_until:
Executed by:
  • Self test
24
432 case cm_if:
executed 16483 times by 1 test: case cm_if:
Executed by:
  • Self test
16483
433 case cm_for:
executed 4028953 times by 1 test: case cm_for:
Executed by:
  • Self test
4028953
434 case cm_group:
executed 3281807 times by 1 test: case cm_group:
Executed by:
  • Self test
3281807
435 case cm_function_def:
executed 22320 times by 1 test: case cm_function_def:
Executed by:
  • Self test
22320
436 return (1);
executed 101987689 times by 1 test: return (1);
Executed by:
  • Self test
101987689
437-
438 default:
executed 253660192 times by 1 test: default:
Executed by:
  • Self test
253660192
439 return (0);
executed 253660192 times by 1 test: return (0);
Executed by:
  • Self test
253660192
440 }-
441}-
442-
443/* A function to use to unwind_protect the redirection undo list-
444 for loops. */-
445static void-
446cleanup_redirects (list)-
447 REDIRECT *list;-
448{-
449 do_redirections (list, RX_ACTIVE);-
450 dispose_redirects (list);-
451}
executed 30627293 times by 1 test: end of block
Executed by:
  • Self test
30627293
452-
453void-
454undo_partial_redirects ()-
455{-
456 if (redirection_undo_list)
redirection_undo_listDescription
TRUEevaluated 5597 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 34681550 times by 1 test
Evaluated by:
  • Self test
5597-34681550
457 {-
458 cleanup_redirects (redirection_undo_list);-
459 redirection_undo_list = (REDIRECT *)NULL;-
460 }
executed 5597 times by 1 test: end of block
Executed by:
  • Self test
5597
461}
executed 34687147 times by 1 test: end of block
Executed by:
  • Self test
34687147
462-
463#if 0-
464/* Function to unwind_protect the redirections for functions and builtins. */-
465static void-
466cleanup_func_redirects (list)-
467 REDIRECT *list;-
468{-
469 do_redirections (list, RX_ACTIVE);-
470}-
471#endif-
472-
473void-
474dispose_exec_redirects ()-
475{-
476 if (exec_redirection_undo_list)
exec_redirection_undo_listDescription
TRUEevaluated 31689 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 34687854 times by 1 test
Evaluated by:
  • Self test
31689-34687854
477 {-
478 dispose_redirects (exec_redirection_undo_list);-
479 exec_redirection_undo_list = (REDIRECT *)NULL;-
480 }
executed 31689 times by 1 test: end of block
Executed by:
  • Self test
31689
481}
executed 34719543 times by 1 test: end of block
Executed by:
  • Self test
34719543
482-
483void-
484dispose_partial_redirects ()-
485{-
486 if (redirection_undo_list)
redirection_undo_listDescription
TRUEevaluated 660672 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-660672
487 {-
488 dispose_redirects (redirection_undo_list);-
489 redirection_undo_list = (REDIRECT *)NULL;-
490 }
executed 660672 times by 1 test: end of block
Executed by:
  • Self test
660672
491}
executed 660672 times by 1 test: end of block
Executed by:
  • Self test
660672
492-
493#if defined (JOB_CONTROL)-
494/* A function to restore the signal mask to its proper value when the shell-
495 is interrupted or errors occur while creating a pipeline. */-
496static int-
497restore_signal_mask (set)-
498 sigset_t *set;-
499{-
500 return (sigprocmask (SIG_SETMASK, set, (sigset_t *)NULL));
executed 1 time by 1 test: return (sigprocmask ( 2 , set, (sigset_t *) ((void *)0) ));
Executed by:
  • Self test
1
501}-
502#endif /* JOB_CONTROL */-
503-
504#ifdef DEBUG-
505/* A debugging function that can be called from gdb, for instance. */-
506void-
507open_files ()-
508{-
509 register int i;-
510 int f, fd_table_size;-
511-
512 fd_table_size = getdtablesize ();-
513-
514 fprintf (stderr, "pid %ld open files:", (long)getpid ());-
515 for (i = 3; i < fd_table_size; i++)
i < fd_table_sizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
516 {-
517 if ((f = fcntl (i, F_GETFD, 0)) != -1)
(f = fcntl (i, 1 , 0)) != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
518 fprintf (stderr, " %d (%s)", i, f ? "close" : "open");
never executed: fprintf ( stderr , " %d (%s)", i, f ? "close" : "open");
0
519 }
never executed: end of block
0
520 fprintf (stderr, "\n");-
521}
never executed: end of block
0
522#endif-
523-
524static void-
525async_redirect_stdin ()-
526{-
527 int fd;-
528-
529 fd = open ("/dev/null", O_RDONLY);-
530 if (fd > 0)
fd > 0Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-8
531 {-
532 dup2 (fd, 0);-
533 close (fd);-
534 }
executed 8 times by 1 test: end of block
Executed by:
  • Self test
8
535 else if (fd < 0)
fd < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
536 internal_error (_("cannot redirect standard input from /dev/null: %s"), strerror (errno));
never executed: internal_error ( dcgettext (((void *)0), "cannot redirect standard input from /dev/null: %s" , 5) , strerror ( (*__errno_location ()) ));
0
537}
executed 8 times by 1 test: end of block
Executed by:
  • Self test
8
538-
539#define DESCRIBE_PID(pid) do { if (interactive) describe_pid (pid); } while (0)-
540-
541/* Execute the command passed in COMMAND, perhaps doing it asynchronously.-
542 COMMAND is exactly what read_command () places into GLOBAL_COMMAND.-
543 ASYNCHROUNOUS, if non-zero, says to do this command in the background.-
544 PIPE_IN and PIPE_OUT are file descriptors saying where input comes-
545 from and where it goes. They can have the value of NO_PIPE, which means-
546 I/O is stdin/stdout.-
547 FDS_TO_CLOSE is a list of file descriptors to close once the child has-
548 been forked. This list often contains the unusable sides of pipes, etc.-
549-
550 EXECUTION_SUCCESS or EXECUTION_FAILURE are the only possible-
551 return values. Executing a command with nothing in it returns-
552 EXECUTION_SUCCESS. */-
553int-
554execute_command_internal (command, asynchronous, pipe_in, pipe_out,-
555 fds_to_close)-
556 COMMAND *command;-
557 int asynchronous;-
558 int pipe_in, pipe_out;-
559 struct fd_bitmap *fds_to_close;-
560{-
561 int exec_result, user_subshell, invert, ignore_return, was_error_trap;-
562 REDIRECT *my_undo_list, *exec_undo_list;-
563 char *tcmd;-
564 volatile int save_line_number;-
565#if defined (PROCESS_SUBSTITUTION)-
566 volatile int ofifo, nfifo, osize, saved_fifo;-
567 volatile char *ofifo_list;-
568#endif-
569-
570 if (breaking || continuing)
breakingDescription
TRUEevaluated 6459626 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 181348925 times by 1 test
Evaluated by:
  • Self test
continuingDescription
TRUEevaluated 140874 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 181208051 times by 1 test
Evaluated by:
  • Self test
140874-181348925
571 return (last_command_exit_value);
executed 6600500 times by 1 test: return (last_command_exit_value);
Executed by:
  • Self test
6600500
572 if (command == 0 || read_but_dont_execute)
command == 0Description
TRUEevaluated 3378607 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 177829444 times by 1 test
Evaluated by:
  • Self test
read_but_dont_executeDescription
TRUEnever evaluated
FALSEevaluated 177829444 times by 1 test
Evaluated by:
  • Self test
0-177829444
573 return (EXECUTION_SUCCESS);
executed 3378607 times by 1 test: return (0);
Executed by:
  • Self test
3378607
574-
575 QUIT;
never executed: termsig_handler (terminating_signal);
never executed: throw_to_top_level ();
terminating_signalDescription
TRUEnever evaluated
FALSEevaluated 177829444 times by 1 test
Evaluated by:
  • Self test
interrupt_stateDescription
TRUEnever evaluated
FALSEevaluated 177829444 times by 1 test
Evaluated by:
  • Self test
0-177829444
576 run_pending_traps ();-
577-
578#if 0-
579 if (running_trap == 0)-
580#endif-
581 currently_executing_command = command;-
582-
583 invert = (command->flags & CMD_INVERT_RETURN) != 0;-
584-
585 /* If we're inverting the return value and `set -e' has been executed,-
586 we don't want a failing command to inadvertently cause the shell-
587 to exit. */-
588 if (exit_immediately_on_error && invert) /* XXX */
exit_immediately_on_errorDescription
TRUEevaluated 90761 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 177738683 times by 1 test
Evaluated by:
  • Self test
invertDescription
TRUEevaluated 57 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 90704 times by 1 test
Evaluated by:
  • Self test
57-177738683
589 command->flags |= CMD_IGNORE_RETURN; /* XXX */
executed 57 times by 1 test: command->flags |= 0x08;
Executed by:
  • Self test
57
590-
591 exec_result = EXECUTION_SUCCESS;-
592-
593 /* If a command was being explicitly run in a subshell, or if it is-
594 a shell control-structure, and it has a pipe, then we do the command-
595 in a subshell. */-
596 if (command->type == cm_subshell && (command->flags & CMD_NO_FORK))
command->type == cm_subshellDescription
TRUEevaluated 5129 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 177824315 times by 1 test
Evaluated by:
  • Self test
(command->flags & 0x40)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5127 times by 1 test
Evaluated by:
  • Self test
2-177824315
597 return (execute_in_subshell (command, asynchronous, pipe_in, pipe_out, fds_to_close));
executed 2 times by 1 test: return (execute_in_subshell (command, asynchronous, pipe_in, pipe_out, fds_to_close));
Executed by:
  • Self test
2
598-
599#if defined (COPROCESS_SUPPORT)-
600 if (command->type == cm_coproc)
command->type == cm_coprocDescription
TRUEevaluated 34 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 177829408 times by 1 test
Evaluated by:
  • Self test
34-177829408
601 return (last_command_exit_value = execute_coproc (command, pipe_in, pipe_out, fds_to_close));
executed 34 times by 1 test: return (last_command_exit_value = execute_coproc (command, pipe_in, pipe_out, fds_to_close));
Executed by:
  • Self test
34
602#endif-
603-
604 user_subshell = command->type == cm_subshell || ((command->flags & CMD_WANT_SUBSHELL) != 0);
command->type == cm_subshellDescription
TRUEevaluated 5127 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 177824281 times by 1 test
Evaluated by:
  • Self test
((command->flags & 0x01) != 0)Description
TRUEnever evaluated
FALSEevaluated 177824281 times by 1 test
Evaluated by:
  • Self test
0-177824281
605-
606#if defined (TIME_BEFORE_SUBSHELL)-
607 if ((command->flags & CMD_TIME_PIPELINE) && user_subshell && asynchronous == 0)-
608 {-
609 command->flags |= CMD_FORCE_SUBSHELL;-
610 exec_result = time_command (command, asynchronous, pipe_in, pipe_out, fds_to_close);-
611 currently_executing_command = (COMMAND *)NULL;-
612 return (exec_result);-
613 }-
614#endif-
615-
616 if (command->type == cm_subshell ||
command->type == cm_subshellDescription
TRUEevaluated 5127 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 177824281 times by 1 test
Evaluated by:
  • Self test
5127-177824281
617 (command->flags & (CMD_WANT_SUBSHELL|CMD_FORCE_SUBSHELL)) ||
(command->flags & (0x01|0x02))Description
TRUEnever evaluated
FALSEevaluated 177824281 times by 1 test
Evaluated by:
  • Self test
0-177824281
618 (shell_control_structure (command->type) &&
shell_control_...command->type)Description
TRUEevaluated 50994182 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 126830099 times by 1 test
Evaluated by:
  • Self test
50994182-126830099
619 (pipe_out != NO_PIPE || pipe_in != NO_PIPE || asynchronous)))
pipe_out != -1Description
TRUEevaluated 473 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 50993709 times by 1 test
Evaluated by:
  • Self test
pipe_in != -1Description
TRUEevaluated 205 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 50993504 times by 1 test
Evaluated by:
  • Self test
asynchronousDescription
TRUEevaluated 51 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 50993453 times by 1 test
Evaluated by:
  • Self test
51-50993709
620 {-
621 pid_t paren_pid;-
622 int s;-
623 char *p;-
624-
625 /* Fork a subshell, turn off the subshell bit, turn off job-
626 control and call execute_command () on the command again. */-
627 line_number_for_err_trap = line_number = command->value.Subshell->line; /* XXX - save value? */-
628 tcmd = make_command_string (command);-
629 paren_pid = make_child (p = savestring (tcmd), asynchronous);-
630-
631 if (user_subshell && signal_is_trapped (ERROR_TRAP) &&
user_subshellDescription
TRUEevaluated 5127 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 729 times by 1 test
Evaluated by:
  • Self test
signal_is_trapped ( 65 +1)Description
TRUEnever evaluated
FALSEevaluated 5127 times by 1 test
Evaluated by:
  • Self test
0-5127
632 signal_in_progress (DEBUG_TRAP) == 0 && running_trap == 0)
signal_in_progress ( 65 ) == 0Description
TRUEnever evaluated
FALSEnever evaluated
running_trap == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
633 {-
634 FREE (the_printed_command_except_trap);
never executed: sh_xfree((the_printed_command_except_trap), "execute_cmd.c", 634);
the_printed_co...nd_except_trapDescription
TRUEnever evaluated
FALSEnever evaluated
0
635 the_printed_command_except_trap = savestring (the_printed_command);-
636 }
never executed: end of block
0
637-
638 if (paren_pid == 0)
paren_pid == 0Description
TRUEevaluated 1112 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4744 times by 1 test
Evaluated by:
  • Self test
1112-4744
639 {-
640#if defined (JOB_CONTROL)-
641 FREE (p); /* child doesn't use pointer */
executed 1112 times by 1 test: sh_xfree((p), "execute_cmd.c", 641);
Executed by:
  • Self test
pDescription
TRUEevaluated 1112 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1112
642#endif-
643 /* We want to run the exit trap for forced {} subshells, and we-
644 want to note this before execute_in_subshell modifies the-
645 COMMAND struct. Need to keep in mind that execute_in_subshell-
646 runs the exit trap for () subshells itself. */-
647 /* This handles { command; } & */-
648 s = user_subshell == 0 && command->type == cm_group && pipe_in == NO_PIPE && pipe_out == NO_PIPE && asynchronous;
user_subshell == 0Description
TRUEevaluated 54 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1058 times by 1 test
Evaluated by:
  • Self test
command->type == cm_groupDescription
TRUEevaluated 46 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
pipe_in == -1Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 30 times by 1 test
Evaluated by:
  • Self test
pipe_out == -1Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
asynchronousDescription
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1058
649 /* run exit trap for : | { ...; } and { ...; } | : */-
650 /* run exit trap for : | ( ...; ) and ( ...; ) | : */-
651 s += user_subshell == 0 && command->type == cm_group && (pipe_in != NO_PIPE || pipe_out != NO_PIPE) && asynchronous == 0;
user_subshell == 0Description
TRUEevaluated 54 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1058 times by 1 test
Evaluated by:
  • Self test
command->type == cm_groupDescription
TRUEevaluated 46 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
pipe_in != -1Description
TRUEevaluated 30 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 16 times by 1 test
Evaluated by:
  • Self test
pipe_out != -1Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
asynchronous == 0Description
TRUEevaluated 37 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1058
652-
653 last_command_exit_value = execute_in_subshell (command, asynchronous, pipe_in, pipe_out, fds_to_close);-
654 if (s)
sDescription
TRUEevaluated 46 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 936 times by 1 test
Evaluated by:
  • Self test
46-936
655 subshell_exit (last_command_exit_value);
executed 46 times by 1 test: subshell_exit (last_command_exit_value);
Executed by:
  • Self test
46
656 else-
657 sh_exit (last_command_exit_value);
executed 936 times by 1 test: sh_exit (last_command_exit_value);
Executed by:
  • Self test
936
658 /* NOTREACHED */-
659 }-
660 else-
661 {-
662 close_pipes (pipe_in, pipe_out);-
663-
664#if defined (PROCESS_SUBSTITUTION) && defined (HAVE_DEV_FD)-
665 if (variable_context == 0) /* wait until shell function completes */
variable_context == 0Description
TRUEevaluated 2839 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1905 times by 1 test
Evaluated by:
  • Self test
1905-2839
666 unlink_fifo_list ();
executed 2839 times by 1 test: unlink_fifo_list ();
Executed by:
  • Self test
2839
667#endif-
668 /* If we are part of a pipeline, and not the end of the pipeline,-
669 then we should simply return and let the last command in the-
670 pipe be waited for. If we are not in a pipeline, or are the-
671 last command in the pipeline, then we wait for the subshell-
672 and return its exit status as usual. */-
673 if (pipe_out != NO_PIPE)
pipe_out != -1Description
TRUEevaluated 535 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4209 times by 1 test
Evaluated by:
  • Self test
535-4209
674 return (EXECUTION_SUCCESS);
executed 535 times by 1 test: return (0);
Executed by:
  • Self test
535
675-
676 stop_pipeline (asynchronous, (COMMAND *)NULL);-
677-
678 if (asynchronous == 0)
asynchronous == 0Description
TRUEevaluated 4163 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 46 times by 1 test
Evaluated by:
  • Self test
46-4163
679 {-
680 was_error_trap = signal_is_trapped (ERROR_TRAP) && signal_is_ignored (ERROR_TRAP) == 0;
signal_is_trapped ( 65 +1)Description
TRUEnever evaluated
FALSEevaluated 4163 times by 1 test
Evaluated by:
  • Self test
signal_is_igno... ( 65 +1) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-4163
681 invert = (command->flags & CMD_INVERT_RETURN) != 0;-
682 ignore_return = (command->flags & CMD_IGNORE_RETURN) != 0;-
683-
684 exec_result = wait_for (paren_pid);-
685-
686 /* If we have to, invert the return value. */-
687 if (invert)
invertDescription
TRUEevaluated 52 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4111 times by 1 test
Evaluated by:
  • Self test
52-4111
688 exec_result = ((exec_result == EXECUTION_SUCCESS)
executed 52 times by 1 test: exec_result = ((exec_result == 0) ? 1 : 0);
Executed by:
  • Self test
(exec_result == 0)Description
TRUEevaluated 26 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 26 times by 1 test
Evaluated by:
  • Self test
26-52
689 ? EXECUTION_FAILURE
executed 52 times by 1 test: exec_result = ((exec_result == 0) ? 1 : 0);
Executed by:
  • Self test
52
690 : EXECUTION_SUCCESS);
executed 52 times by 1 test: exec_result = ((exec_result == 0) ? 1 : 0);
Executed by:
  • Self test
52
691-
692 last_command_exit_value = exec_result;-
693 if (user_subshell && was_error_trap && ignore_return == 0 && invert == 0 && exec_result != EXECUTION_SUCCESS)
user_subshellDescription
TRUEevaluated 3989 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 174 times by 1 test
Evaluated by:
  • Self test
was_error_trapDescription
TRUEnever evaluated
FALSEevaluated 3989 times by 1 test
Evaluated by:
  • Self test
ignore_return == 0Description
TRUEnever evaluated
FALSEnever evaluated
invert == 0Description
TRUEnever evaluated
FALSEnever evaluated
exec_result != 0Description
TRUEnever evaluated
FALSEnever evaluated
0-3989
694 {-
695 save_line_number = line_number;-
696 line_number = line_number_for_err_trap;-
697 run_error_trap ();-
698 line_number = save_line_number;-
699 }
never executed: end of block
0
700-
701 if (user_subshell && ignore_return == 0 && invert == 0 && exit_immediately_on_error && exec_result != EXECUTION_SUCCESS)
user_subshellDescription
TRUEevaluated 3989 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 174 times by 1 test
Evaluated by:
  • Self test
ignore_return == 0Description
TRUEevaluated 2854 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1135 times by 1 test
Evaluated by:
  • Self test
invert == 0Description
TRUEevaluated 2812 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 42 times by 1 test
Evaluated by:
  • Self test
exit_immediately_on_errorDescription
TRUEevaluated 13 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2799 times by 1 test
Evaluated by:
  • Self test
exec_result != 0Description
TRUEevaluated 13 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-3989
702 {-
703 run_pending_traps ();-
704 jump_to_top_level (ERREXIT);-
705 }
never executed: end of block
0
706-
707 return (last_command_exit_value);
executed 4150 times by 1 test: return (last_command_exit_value);
Executed by:
  • Self test
4150
708 }-
709 else-
710 {-
711 DESCRIBE_PID (paren_pid);
never executed: describe_pid (paren_pid);
interactiveDescription
TRUEnever evaluated
FALSEevaluated 46 times by 1 test
Evaluated by:
  • Self test
0-46
712-
713 run_pending_traps ();-
714-
715 /* Posix 2013 2.9.3.1: "the exit status of an asynchronous list-
716 shall be zero." */-
717 last_command_exit_value = 0;-
718 return (EXECUTION_SUCCESS);
executed 46 times by 1 test: return (0);
Executed by:
  • Self test
46
719 }-
720 }-
721 }-
722-
723#if defined (COMMAND_TIMING)-
724 if (command->flags & CMD_TIME_PIPELINE)
command->flags & 0x80Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 177823546 times by 1 test
Evaluated by:
  • Self test
6-177823546
725 {-
726 if (asynchronous)
asynchronousDescription
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
0-6
727 {-
728 command->flags |= CMD_FORCE_SUBSHELL;-
729 exec_result = execute_command_internal (command, 1, pipe_in, pipe_out, fds_to_close);-
730 }
never executed: end of block
0
731 else-
732 {-
733 exec_result = time_command (command, asynchronous, pipe_in, pipe_out, fds_to_close);-
734#if 0-
735 if (running_trap == 0)-
736#endif-
737 currently_executing_command = (COMMAND *)NULL;-
738 }
executed 6 times by 1 test: end of block
Executed by:
  • Self test
6
739 return (exec_result);
executed 6 times by 1 test: return (exec_result);
Executed by:
  • Self test
6
740 }-
741#endif /* COMMAND_TIMING */-
742-
743 if (shell_control_structure (command->type) && command->redirects)
shell_control_...command->type)Description
TRUEevaluated 50993453 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 126830093 times by 1 test
Evaluated by:
  • Self test
command->redirectsDescription
TRUEevaluated 662026 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 50331427 times by 1 test
Evaluated by:
  • Self test
662026-126830093
744 stdin_redir = stdin_redirects (command->redirects);
executed 662026 times by 1 test: stdin_redir = stdin_redirects (command->redirects);
Executed by:
  • Self test
662026
745-
746#if defined (PROCESS_SUBSTITUTION)-
747 if (variable_context != 0)
variable_context != 0Description
TRUEevaluated 164977698 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 12845848 times by 1 test
Evaluated by:
  • Self test
12845848-164977698
748 {-
749 ofifo = num_fifos ();-
750 ofifo_list = copy_fifo_list ((int *)&osize);-
751 begin_unwind_frame ("internal_fifos");-
752 add_unwind_protect (xfree, ofifo_list);-
753 saved_fifo = 1;-
754 }
executed 164977698 times by 1 test: end of block
Executed by:
  • Self test
164977698
755 else-
756 saved_fifo = 0;
executed 12845848 times by 1 test: saved_fifo = 0;
Executed by:
  • Self test
12845848
757#endif-
758-
759 /* Handle WHILE FOR CASE etc. with redirections. (Also '&' input-
760 redirection.) */-
761 if (do_redirections (command->redirects, RX_ACTIVE|RX_UNDOABLE) != 0)
do_redirection...x01|0x02) != 0Description
TRUEnever evaluated
FALSEevaluated 177822193 times by 1 test
Evaluated by:
  • Self test
0-177822193
762 {-
763 undo_partial_redirects ();-
764 dispose_exec_redirects ();-
765#if defined (PROCESS_SUBSTITUTION)-
766 if (saved_fifo)
saved_fifoDescription
TRUEnever evaluated
FALSEnever evaluated
0
767 {-
768 free ((void *)ofifo_list);-
769 discard_unwind_frame ("internal_fifos");-
770 }
never executed: end of block
0
771#endif-
772 return (last_command_exit_value = EXECUTION_FAILURE);
never executed: return (last_command_exit_value = 1);
0
773 }-
774-
775 if (redirection_undo_list)
redirection_undo_listDescription
TRUEevaluated 660672 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 177161521 times by 1 test
Evaluated by:
  • Self test
660672-177161521
776 {-
777 /* XXX - why copy here? */-
778 my_undo_list = (REDIRECT *)copy_redirects (redirection_undo_list);-
779 dispose_partial_redirects ();-
780 }
executed 660672 times by 1 test: end of block
Executed by:
  • Self test
660672
781 else-
782 my_undo_list = (REDIRECT *)NULL;
executed 177161521 times by 1 test: my_undo_list = (REDIRECT *) ((void *)0) ;
Executed by:
  • Self test
177161521
783-
784 if (exec_redirection_undo_list)
exec_redirection_undo_listDescription
TRUEevaluated 26173 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 177796020 times by 1 test
Evaluated by:
  • Self test
26173-177796020
785 {-
786 /* XXX - why copy here? */-
787 exec_undo_list = (REDIRECT *)copy_redirects (exec_redirection_undo_list);-
788 dispose_exec_redirects ();-
789 }
executed 26173 times by 1 test: end of block
Executed by:
  • Self test
26173
790 else-
791 exec_undo_list = (REDIRECT *)NULL;
executed 177796020 times by 1 test: exec_undo_list = (REDIRECT *) ((void *)0) ;
Executed by:
  • Self test
177796020
792-
793 if (my_undo_list || exec_undo_list)
my_undo_listDescription
TRUEevaluated 660672 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 177161521 times by 1 test
Evaluated by:
  • Self test
exec_undo_listDescription
TRUEnever evaluated
FALSEevaluated 177161521 times by 1 test
Evaluated by:
  • Self test
0-177161521
794 begin_unwind_frame ("loop_redirections");
executed 660672 times by 1 test: begin_unwind_frame ("loop_redirections");
Executed by:
  • Self test
660672
795-
796 if (my_undo_list)
my_undo_listDescription
TRUEevaluated 660672 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 177161521 times by 1 test
Evaluated by:
  • Self test
660672-177161521
797 add_unwind_protect ((Function *)cleanup_redirects, my_undo_list);
executed 660672 times by 1 test: add_unwind_protect ((Function *)cleanup_redirects, my_undo_list);
Executed by:
  • Self test
660672
798-
799 if (exec_undo_list)
exec_undo_listDescription
TRUEevaluated 26173 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 177796020 times by 1 test
Evaluated by:
  • Self test
26173-177796020
800 add_unwind_protect ((Function *)dispose_redirects, exec_undo_list);
executed 26173 times by 1 test: add_unwind_protect ((Function *)dispose_redirects, exec_undo_list);
Executed by:
  • Self test
26173
801-
802 ignore_return = (command->flags & CMD_IGNORE_RETURN) != 0;-
803-
804 QUIT;
never executed: termsig_handler (terminating_signal);
never executed: throw_to_top_level ();
terminating_signalDescription
TRUEnever evaluated
FALSEevaluated 177822193 times by 1 test
Evaluated by:
  • Self test
interrupt_stateDescription
TRUEnever evaluated
FALSEevaluated 177822193 times by 1 test
Evaluated by:
  • Self test
0-177822193
805-
806 switch (command->type)-
807 {-
808 case cm_simple:
executed 64710245 times by 1 test: case cm_simple:
Executed by:
  • Self test
64710245
809 {-
810 save_line_number = line_number;-
811 /* We can't rely on variables retaining their values across a-
812 call to execute_simple_command if a longjmp occurs as the-
813 result of a `return' builtin. This is true for sure with gcc. */-
814#if defined (RECYCLES_PIDS)-
815 last_made_pid = NO_PID;-
816#endif-
817 was_error_trap = signal_is_trapped (ERROR_TRAP) && signal_is_ignored (ERROR_TRAP) == 0;
signal_is_trapped ( 65 +1)Description
TRUEevaluated 62 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 64710183 times by 1 test
Evaluated by:
  • Self test
signal_is_igno... ( 65 +1) == 0Description
TRUEevaluated 62 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-64710183
818-
819 if (ignore_return && command->value.Simple)
ignore_returnDescription
TRUEevaluated 13832348 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 50877897 times by 1 test
Evaluated by:
  • Self test
command->value.SimpleDescription
TRUEevaluated 13832348 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-50877897
820 command->value.Simple->flags |= CMD_IGNORE_RETURN;
executed 13832348 times by 1 test: command->value.Simple->flags |= 0x08;
Executed by:
  • Self test
13832348
821 if (command->flags & CMD_STDIN_REDIR)
command->flags & 0x400Description
TRUEevaluated 100 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 64710145 times by 1 test
Evaluated by:
  • Self test
100-64710145
822 command->value.Simple->flags |= CMD_STDIN_REDIR;
executed 100 times by 1 test: command->value.Simple->flags |= 0x400;
Executed by:
  • Self test
100
823-
824 line_number_for_err_trap = line_number = command->value.Simple->line;-
825 exec_result =-
826 execute_simple_command (command->value.Simple, pipe_in, pipe_out,-
827 asynchronous, fds_to_close);-
828 line_number = save_line_number;-
829-
830 /* The temporary environment should be used for only the simple-
831 command immediately following its definition. */-
832 dispose_used_env_vars ();-
833-
834#if (defined (ultrix) && defined (mips)) || defined (C_ALLOCA)-
835 /* Reclaim memory allocated with alloca () on machines which-
836 may be using the alloca emulation code. */-
837 (void) alloca (0);-
838#endif /* (ultrix && mips) || C_ALLOCA */-
839-
840 /* If we forked to do the command, then we must wait_for ()-
841 the child. */-
842-
843 /* XXX - this is something to watch out for if there are problems-
844 when the shell is compiled without job control. Don't worry about-
845 whether or not last_made_pid == last_pid; already_making_children-
846 tells us whether or not there are unwaited-for children to wait-
847 for and reap. */-
848 if (already_making_children && pipe_out == NO_PIPE)
already_making_childrenDescription
TRUEevaluated 51236 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 64648200 times by 1 test
Evaluated by:
  • Self test
pipe_out == -1Description
TRUEevaluated 38402 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 12834 times by 1 test
Evaluated by:
  • Self test
12834-64648200
849 {-
850 stop_pipeline (asynchronous, (COMMAND *)NULL);-
851-
852 if (asynchronous)
asynchronousDescription
TRUEevaluated 148 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 38254 times by 1 test
Evaluated by:
  • Self test
148-38254
853 {-
854 DESCRIBE_PID (last_made_pid);
never executed: describe_pid (last_made_pid);
interactiveDescription
TRUEnever evaluated
FALSEevaluated 148 times by 1 test
Evaluated by:
  • Self test
0-148
855 exec_result = EXECUTION_SUCCESS;-
856 invert = 0; /* async commands always succeed */-
857 }
executed 148 times by 1 test: end of block
Executed by:
  • Self test
148
858 else-
859#if !defined (JOB_CONTROL)-
860 /* Do not wait for asynchronous processes started from-
861 startup files. */-
862 if (last_made_pid != NO_PID && last_made_pid != last_asynchronous_pid)-
863#else-
864 if (last_made_pid != NO_PID)
last_made_pid != (pid_t)-1Description
TRUEevaluated 38254 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-38254
865#endif-
866 /* When executing a shell function that executes other-
867 commands, this causes the last simple command in-
868 the function to be waited for twice. This also causes-
869 subshells forked to execute builtin commands (e.g., in-
870 pipelines) to be waited for twice. */-
871 exec_result = wait_for (last_made_pid);
executed 38254 times by 1 test: exec_result = wait_for (last_made_pid);
Executed by:
  • Self test
38254
872 }
executed 38401 times by 1 test: end of block
Executed by:
  • Self test
38401
873 }-
874-
875 /* 2009/02/13 -- pipeline failure is processed elsewhere. This handles-
876 only the failure of a simple command. */-
877 if (was_error_trap && ignore_return == 0 && invert == 0 && pipe_in == NO_PIPE && pipe_out == NO_PIPE && exec_result != EXECUTION_SUCCESS)
was_error_trapDescription
TRUEevaluated 58 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 64699377 times by 1 test
Evaluated by:
  • Self test
ignore_return == 0Description
TRUEevaluated 52 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
invert == 0Description
TRUEevaluated 49 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
pipe_in == -1Description
TRUEevaluated 46 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
pipe_out == -1Description
TRUEevaluated 44 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
exec_result != 0Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 35 times by 1 test
Evaluated by:
  • Self test
2-64699377
878 {-
879 last_command_exit_value = exec_result;-
880 line_number = line_number_for_err_trap;-
881 run_error_trap ();-
882 line_number = save_line_number;-
883 }
executed 9 times by 1 test: end of block
Executed by:
  • Self test
9
884-
885 if (ignore_return == 0 && invert == 0 &&
ignore_return == 0Description
TRUEevaluated 50867129 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 13832306 times by 1 test
Evaluated by:
  • Self test
invert == 0Description
TRUEevaluated 50867092 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 37 times by 1 test
Evaluated by:
  • Self test
37-50867129
886 ((posixly_correct && interactive == 0 && special_builtin_failed) ||
posixly_correctDescription
TRUEevaluated 773 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 50866319 times by 1 test
Evaluated by:
  • Self test
interactive == 0Description
TRUEevaluated 773 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
special_builtin_failedDescription
TRUEnever evaluated
FALSEevaluated 773 times by 1 test
Evaluated by:
  • Self test
0-50866319
887 (exit_immediately_on_error && pipe_in == NO_PIPE && pipe_out == NO_PIPE && exec_result != EXECUTION_SUCCESS)))
exit_immediately_on_errorDescription
TRUEevaluated 46783 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 50820309 times by 1 test
Evaluated by:
  • Self test
pipe_in == -1Description
TRUEevaluated 41830 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4953 times by 1 test
Evaluated by:
  • Self test
pipe_out == -1Description
TRUEevaluated 36846 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4984 times by 1 test
Evaluated by:
  • Self test
exec_result != 0Description
TRUEevaluated 20 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 36826 times by 1 test
Evaluated by:
  • Self test
20-50820309
888 {-
889 last_command_exit_value = exec_result;-
890 run_pending_traps ();-
891-
892 /* Undo redirections before running exit trap on the way out of-
893 set -e. Report by Mark Farrell 5/19/2014 */-
894 if (exit_immediately_on_error && signal_is_trapped (0) &&
exit_immediately_on_errorDescription
TRUEevaluated 20 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
signal_is_trapped (0)Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 13 times by 1 test
Evaluated by:
  • Self test
0-20
895 unwind_protect_tag_on_stack ("saved-redirects"))
unwind_protect...ed-redirects")Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
3-4
896 run_unwind_frame ("saved-redirects");
executed 3 times by 1 test: run_unwind_frame ("saved-redirects");
Executed by:
  • Self test
3
897-
898 jump_to_top_level (ERREXIT);-
899 }
never executed: end of block
0
900-
901 break;
executed 64699415 times by 1 test: break;
Executed by:
  • Self test
64699415
902-
903 case cm_for:
executed 2014469 times by 1 test: case cm_for:
Executed by:
  • Self test
2014469
904 if (ignore_return)
ignore_returnDescription
TRUEnever evaluated
FALSEevaluated 2014469 times by 1 test
Evaluated by:
  • Self test
0-2014469
905 command->value.For->flags |= CMD_IGNORE_RETURN;
never executed: command->value.For->flags |= 0x08;
0
906 exec_result = execute_for_command (command->value.For);-
907 break;
executed 2002020 times by 1 test: break;
Executed by:
  • Self test
2002020
908-
909#if defined (ARITH_FOR_COMMAND)-
910 case cm_arith_for:
executed 2607 times by 1 test: case cm_arith_for:
Executed by:
  • Self test
2607
911 if (ignore_return)
ignore_returnDescription
TRUEnever evaluated
FALSEevaluated 2607 times by 1 test
Evaluated by:
  • Self test
0-2607
912 command->value.ArithFor->flags |= CMD_IGNORE_RETURN;
never executed: command->value.ArithFor->flags |= 0x08;
0
913 exec_result = execute_arith_for_command (command->value.ArithFor);-
914 break;
executed 2398 times by 1 test: break;
Executed by:
  • Self test
2398
915#endif-
916-
917#if defined (SELECT_COMMAND)-
918 case cm_select:
executed 9 times by 1 test: case cm_select:
Executed by:
  • Self test
9
919 if (ignore_return)
ignore_returnDescription
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
0-9
920 command->value.Select->flags |= CMD_IGNORE_RETURN;
never executed: command->value.Select->flags |= 0x08;
0
921 exec_result = execute_select_command (command->value.Select);-
922 break;
executed 9 times by 1 test: break;
Executed by:
  • Self test
9
923#endif-
924-
925 case cm_case:
executed 36947171 times by 1 test: case cm_case:
Executed by:
  • Self test
36947171
926 if (ignore_return)
ignore_returnDescription
TRUEevaluated 3542 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 36943629 times by 1 test
Evaluated by:
  • Self test
3542-36943629
927 command->value.Case->flags |= CMD_IGNORE_RETURN;
executed 3542 times by 1 test: command->value.Case->flags |= 0x08;
Executed by:
  • Self test
3542
928 exec_result = execute_case_command (command->value.Case);-
929 break;
executed 36940300 times by 1 test: break;
Executed by:
  • Self test
36940300
930-
931 case cm_while:
executed 3891252 times by 1 test: case cm_while:
Executed by:
  • Self test
3891252
932 if (ignore_return)
ignore_returnDescription
TRUEnever evaluated
FALSEevaluated 3891252 times by 1 test
Evaluated by:
  • Self test
0-3891252
933 command->value.While->flags |= CMD_IGNORE_RETURN;
never executed: command->value.While->flags |= 0x08;
0
934 exec_result = execute_while_command (command->value.While);-
935 break;
executed 3889883 times by 1 test: break;
Executed by:
  • Self test
3889883
936-
937 case cm_until:
executed 12 times by 1 test: case cm_until:
Executed by:
  • Self test
12
938 if (ignore_return)
ignore_returnDescription
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • Self test
0-12
939 command->value.While->flags |= CMD_IGNORE_RETURN;
never executed: command->value.While->flags |= 0x08;
0
940 exec_result = execute_until_command (command->value.While);-
941 break;
executed 12 times by 1 test: break;
Executed by:
  • Self test
12
942-
943 case cm_if:
executed 8236 times by 1 test: case cm_if:
Executed by:
  • Self test
8236
944 if (ignore_return)
ignore_returnDescription
TRUEnever evaluated
FALSEevaluated 8236 times by 1 test
Evaluated by:
  • Self test
0-8236
945 command->value.If->flags |= CMD_IGNORE_RETURN;
never executed: command->value.If->flags |= 0x08;
0
946 exec_result = execute_if_command (command->value.If);-
947 break;
executed 8225 times by 1 test: break;
Executed by:
  • Self test
8225
948-
949 case cm_group:
executed 1640536 times by 1 test: case cm_group:
Executed by:
  • Self test
1640536
950-
951 /* This code can be executed from either of two paths: an explicit-
952 '{}' command, or via a function call. If we are executed via a-
953 function call, we have already taken care of the function being-
954 executed in the background (down there in execute_simple_command ()),-
955 and this command should *not* be marked as asynchronous. If we-
956 are executing a regular '{}' group command, and asynchronous == 1,-
957 we must want to execute the whole command in the background, so we-
958 need a subshell, and we want the stuff executed in that subshell-
959 (this group command) to be executed in the foreground of that-
960 subshell (i.e. there will not be *another* subshell forked).-
961-
962 What we do is to force a subshell if asynchronous, and then call-
963 execute_command_internal again with asynchronous still set to 1,-
964 but with the original group command, so the printed command will-
965 look right.-
966-
967 The code above that handles forking off subshells will note that-
968 both subshell and async are on, and turn off async in the child-
969 after forking the subshell (but leave async set in the parent, so-
970 the normal call to describe_pid is made). This turning off-
971 async is *crucial*; if it is not done, this will fall into an-
972 infinite loop of executions through this spot in subshell after-
973 subshell until the process limit is exhausted. */-
974-
975 if (asynchronous)
asynchronousDescription
TRUEnever evaluated
FALSEevaluated 1640536 times by 1 test
Evaluated by:
  • Self test
0-1640536
976 {-
977 command->flags |= CMD_FORCE_SUBSHELL;-
978 exec_result =-
979 execute_command_internal (command, 1, pipe_in, pipe_out,-
980 fds_to_close);-
981 }
never executed: end of block
0
982 else-
983 {-
984 if (ignore_return && command->value.Group->command)
ignore_returnDescription
TRUEevaluated 3624 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1636912 times by 1 test
Evaluated by:
  • Self test
command->value.Group->commandDescription
TRUEevaluated 3624 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1636912
985 command->value.Group->command->flags |= CMD_IGNORE_RETURN;
executed 3624 times by 1 test: command->value.Group->command->flags |= 0x08;
Executed by:
  • Self test
3624
986 exec_result =-
987 execute_command_internal (command->value.Group->command,-
988 asynchronous, pipe_in, pipe_out,-
989 fds_to_close);-
990 }
executed 1634193 times by 1 test: end of block
Executed by:
  • Self test
1634193
991 break;
executed 1634193 times by 1 test: break;
Executed by:
  • Self test
1634193
992-
993 case cm_connection:
executed 62119848 times by 1 test: case cm_connection:
Executed by:
  • Self test
62119848
994 exec_result = execute_connection (command, asynchronous,-
995 pipe_in, pipe_out, fds_to_close);-
996 if (asynchronous)
asynchronousDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 62089467 times by 1 test
Evaluated by:
  • Self test
8-62089467
997 invert = 0; /* XXX */
executed 8 times by 1 test: invert = 0;
Executed by:
  • Self test
8
998-
999 break;
executed 62089475 times by 1 test: break;
Executed by:
  • Self test
62089475
1000-
1001#if defined (DPAREN_ARITHMETIC)-
1002 case cm_arith:
executed 6476018 times by 1 test: case cm_arith:
Executed by:
  • Self test
6476018
1003 was_error_trap = signal_is_trapped (ERROR_TRAP) && signal_is_ignored (ERROR_TRAP) == 0;
signal_is_trapped ( 65 +1)Description
TRUEnever evaluated
FALSEevaluated 6476018 times by 1 test
Evaluated by:
  • Self test
signal_is_igno... ( 65 +1) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-6476018
1004 if (ignore_return)
ignore_returnDescription
TRUEevaluated 4706 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6471312 times by 1 test
Evaluated by:
  • Self test
4706-6471312
1005 command->value.Arith->flags |= CMD_IGNORE_RETURN;
executed 4706 times by 1 test: command->value.Arith->flags |= 0x08;
Executed by:
  • Self test
4706
1006 line_number_for_err_trap = save_line_number = line_number;-
1007 exec_result = execute_arith_command (command->value.Arith);-
1008 line_number = save_line_number;-
1009-
1010 if (was_error_trap && ignore_return == 0 && invert == 0 && exec_result != EXECUTION_SUCCESS)
was_error_trapDescription
TRUEnever evaluated
FALSEevaluated 6476017 times by 1 test
Evaluated by:
  • Self test
ignore_return == 0Description
TRUEnever evaluated
FALSEnever evaluated
invert == 0Description
TRUEnever evaluated
FALSEnever evaluated
exec_result != 0Description
TRUEnever evaluated
FALSEnever evaluated
0-6476017
1011 {-
1012 last_command_exit_value = exec_result;-
1013 save_line_number = line_number;-
1014 line_number = line_number_for_err_trap;-
1015 run_error_trap ();-
1016 line_number = save_line_number;-
1017 }
never executed: end of block
0
1018-
1019 if (ignore_return == 0 && invert == 0 && exit_immediately_on_error && exec_result != EXECUTION_SUCCESS)
ignore_return == 0Description
TRUEevaluated 6471311 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4706 times by 1 test
Evaluated by:
  • Self test
invert == 0Description
TRUEevaluated 6471311 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
exit_immediately_on_errorDescription
TRUEnever evaluated
FALSEevaluated 6471311 times by 1 test
Evaluated by:
  • Self test
exec_result != 0Description
TRUEnever evaluated
FALSEnever evaluated
0-6471311
1020 {-
1021 last_command_exit_value = exec_result;-
1022 run_pending_traps ();-
1023 jump_to_top_level (ERREXIT);-
1024 }
never executed: end of block
0
1025-
1026 break;
executed 6476017 times by 1 test: break;
Executed by:
  • Self test
6476017
1027#endif-
1028-
1029#if defined (COND_COMMAND)-
1030 case cm_cond:
executed 630 times by 1 test: case cm_cond:
Executed by:
  • Self test
630
1031 was_error_trap = signal_is_trapped (ERROR_TRAP) && signal_is_ignored (ERROR_TRAP) == 0;
signal_is_trapped ( 65 +1)Description
TRUEnever evaluated
FALSEevaluated 630 times by 1 test
Evaluated by:
  • Self test
signal_is_igno... ( 65 +1) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-630
1032 if (ignore_return)
ignore_returnDescription
TRUEevaluated 485 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 145 times by 1 test
Evaluated by:
  • Self test
145-485
1033 command->value.Cond->flags |= CMD_IGNORE_RETURN;
executed 485 times by 1 test: command->value.Cond->flags |= 0x08;
Executed by:
  • Self test
485
1034-
1035 line_number_for_err_trap = save_line_number = line_number;-
1036 exec_result = execute_cond_command (command->value.Cond);-
1037 line_number = save_line_number;-
1038-
1039 if (was_error_trap && ignore_return == 0 && invert == 0 && exec_result != EXECUTION_SUCCESS)
was_error_trapDescription
TRUEnever evaluated
FALSEevaluated 629 times by 1 test
Evaluated by:
  • Self test
ignore_return == 0Description
TRUEnever evaluated
FALSEnever evaluated
invert == 0Description
TRUEnever evaluated
FALSEnever evaluated
exec_result != 0Description
TRUEnever evaluated
FALSEnever evaluated
0-629
1040 {-
1041 last_command_exit_value = exec_result;-
1042 save_line_number = line_number;-
1043 line_number = line_number_for_err_trap;-
1044 run_error_trap ();-
1045 line_number = save_line_number;-
1046 }
never executed: end of block
0
1047-
1048 if (ignore_return == 0 && invert == 0 && exit_immediately_on_error && exec_result != EXECUTION_SUCCESS)
ignore_return == 0Description
TRUEevaluated 145 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 484 times by 1 test
Evaluated by:
  • Self test
invert == 0Description
TRUEevaluated 145 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
exit_immediately_on_errorDescription
TRUEnever evaluated
FALSEevaluated 145 times by 1 test
Evaluated by:
  • Self test
exec_result != 0Description
TRUEnever evaluated
FALSEnever evaluated
0-484
1049 {-
1050 last_command_exit_value = exec_result;-
1051 run_pending_traps ();-
1052 jump_to_top_level (ERREXIT);-
1053 }
never executed: end of block
0
1054-
1055 break;
executed 629 times by 1 test: break;
Executed by:
  • Self test
629
1056#endif-
1057 -
1058 case cm_function_def:
executed 11160 times by 1 test: case cm_function_def:
Executed by:
  • Self test
11160
1059 exec_result = execute_intern_function (command->value.Function_def->name,-
1060 command->value.Function_def);-
1061 break;
executed 11159 times by 1 test: break;
Executed by:
  • Self test
11159
1062-
1063 default:
never executed: default:
0
1064 command_error ("execute_command", CMDERR_BADTYPE, command->type, 0);-
1065 }
never executed: end of block
0
1066-
1067 if (my_undo_list)
my_undo_listDescription
TRUEevaluated 660640 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 177093095 times by 1 test
Evaluated by:
  • Self test
660640-177093095
1068 cleanup_redirects (my_undo_list);
executed 660640 times by 1 test: cleanup_redirects (my_undo_list);
Executed by:
  • Self test
660640
1069-
1070 if (exec_undo_list)
exec_undo_listDescription
TRUEevaluated 26141 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 177727594 times by 1 test
Evaluated by:
  • Self test
26141-177727594
1071 dispose_redirects (exec_undo_list);
executed 26141 times by 1 test: dispose_redirects (exec_undo_list);
Executed by:
  • Self test
26141
1072-
1073 if (my_undo_list || exec_undo_list)
my_undo_listDescription
TRUEevaluated 660640 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 177093095 times by 1 test
Evaluated by:
  • Self test
exec_undo_listDescription
TRUEnever evaluated
FALSEevaluated 177093095 times by 1 test
Evaluated by:
  • Self test
0-177093095
1074 discard_unwind_frame ("loop_redirections");
executed 660640 times by 1 test: discard_unwind_frame ("loop_redirections");
Executed by:
  • Self test
660640
1075-
1076#if defined (PROCESS_SUBSTITUTION)-
1077 if (saved_fifo)
saved_fifoDescription
TRUEevaluated 164942946 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 12810789 times by 1 test
Evaluated by:
  • Self test
12810789-164942946
1078 {-
1079 nfifo = num_fifos ();-
1080 if (nfifo > ofifo)
nfifo > ofifoDescription
TRUEevaluated 660604 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 164282342 times by 1 test
Evaluated by:
  • Self test
660604-164282342
1081 close_new_fifos ((char *)ofifo_list, osize);
executed 660604 times by 1 test: close_new_fifos ((char *)ofifo_list, osize);
Executed by:
  • Self test
660604
1082 free ((void *)ofifo_list);-
1083 discard_unwind_frame ("internal_fifos");-
1084 }
executed 164942946 times by 1 test: end of block
Executed by:
  • Self test
164942946
1085#endif-
1086-
1087 /* Invert the return value if we have to */-
1088 if (invert)
invertDescription
TRUEevaluated 113 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 177753622 times by 1 test
Evaluated by:
  • Self test
113-177753622
1089 exec_result = (exec_result == EXECUTION_SUCCESS)
executed 113 times by 1 test: exec_result = (exec_result == 0) ? 1 : 0;
Executed by:
  • Self test
(exec_result == 0)Description
TRUEevaluated 52 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 61 times by 1 test
Evaluated by:
  • Self test
52-113
1090 ? EXECUTION_FAILURE
executed 113 times by 1 test: exec_result = (exec_result == 0) ? 1 : 0;
Executed by:
  • Self test
113
1091 : EXECUTION_SUCCESS;
executed 113 times by 1 test: exec_result = (exec_result == 0) ? 1 : 0;
Executed by:
  • Self test
113
1092-
1093#if defined (DPAREN_ARITHMETIC) || defined (COND_COMMAND)-
1094 /* This is where we set PIPESTATUS from the exit status of the appropriate-
1095 compound commands (the ones that look enough like simple commands to-
1096 cause confusion). We might be able to optimize by not doing this if-
1097 subshell_environment != 0. */-
1098 switch (command->type)-
1099 {-
1100# if defined (DPAREN_ARITHMETIC)-
1101 case cm_arith:
executed 6476017 times by 1 test: case cm_arith:
Executed by:
  • Self test
6476017
1102# endif-
1103# if defined (COND_COMMAND)-
1104 case cm_cond:
executed 629 times by 1 test: case cm_cond:
Executed by:
  • Self test
629
1105# endif-
1106 set_pipestatus_from_exit (exec_result);-
1107 break;
executed 6476646 times by 1 test: break;
Executed by:
  • Self test
6476646
1108 default:
executed 171277089 times by 1 test: default:
Executed by:
  • Self test
171277089
1109 break;
executed 171277089 times by 1 test: break;
Executed by:
  • Self test
171277089
1110 }-
1111#endif-
1112-
1113 last_command_exit_value = exec_result;-
1114 run_pending_traps ();-
1115#if 0-
1116 if (running_trap == 0)-
1117#endif-
1118 currently_executing_command = (COMMAND *)NULL;-
1119-
1120 return (last_command_exit_value);
executed 177753735 times by 1 test: return (last_command_exit_value);
Executed by:
  • Self test
177753735
1121}-
1122-
1123#if defined (COMMAND_TIMING)-
1124-
1125#if defined (HAVE_GETRUSAGE) && defined (HAVE_GETTIMEOFDAY)-
1126extern struct timeval *difftimeval __P((struct timeval *, struct timeval *, struct timeval *));-
1127extern struct timeval *addtimeval __P((struct timeval *, struct timeval *, struct timeval *));-
1128extern int timeval_to_cpu __P((struct timeval *, struct timeval *, struct timeval *));-
1129#endif-
1130-
1131#define POSIX_TIMEFORMAT "real %2R\nuser %2U\nsys %2S"-
1132#define BASH_TIMEFORMAT "\nreal\t%3lR\nuser\t%3lU\nsys\t%3lS"-
1133-
1134static const int precs[] = { 0, 100, 10, 1 };-
1135-
1136/* Expand one `%'-prefixed escape sequence from a time format string. */-
1137static int-
1138mkfmt (buf, prec, lng, sec, sec_fraction)-
1139 char *buf;-
1140 int prec, lng;-
1141 time_t sec;-
1142 int sec_fraction;-
1143{-
1144 time_t min;-
1145 char abuf[INT_STRLEN_BOUND(time_t) + 1];-
1146 int ind, aind;-
1147-
1148 ind = 0;-
1149 abuf[sizeof(abuf) - 1] = '\0';-
1150-
1151 /* If LNG is non-zero, we want to decompose SEC into minutes and seconds. */-
1152 if (lng)
lngDescription
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test
0-18
1153 {-
1154 min = sec / 60;-
1155 sec %= 60;-
1156 aind = sizeof(abuf) - 2;-
1157 do-
1158 abuf[aind--] = (min % 10) + '0';
never executed: abuf[aind--] = (min % 10) + '0';
0
1159 while (min /= 10);
min /= 10Description
TRUEnever evaluated
FALSEnever evaluated
0
1160 aind++;-
1161 while (abuf[aind])
abuf[aind]Description
TRUEnever evaluated
FALSEnever evaluated
0
1162 buf[ind++] = abuf[aind++];
never executed: buf[ind++] = abuf[aind++];
0
1163 buf[ind++] = 'm';-
1164 }
never executed: end of block
0
1165-
1166 /* Now add the seconds. */-
1167 aind = sizeof (abuf) - 2;-
1168 do-
1169 abuf[aind--] = (sec % 10) + '0';
executed 18 times by 1 test: abuf[aind--] = (sec % 10) + '0';
Executed by:
  • Self test
18
1170 while (sec /= 10);
sec /= 10Description
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test
0-18
1171 aind++;-
1172 while (abuf[aind])
abuf[aind]Description
TRUEevaluated 18 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test
18
1173 buf[ind++] = abuf[aind++];
executed 18 times by 1 test: buf[ind++] = abuf[aind++];
Executed by:
  • Self test
18
1174-
1175 /* We want to add a decimal point and PREC places after it if PREC is-
1176 nonzero. PREC is not greater than 3. SEC_FRACTION is between 0-
1177 and 999. */-
1178 if (prec != 0)
prec != 0Description
TRUEevaluated 18 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-18
1179 {-
1180 buf[ind++] = locale_decpoint ();-
1181 for (aind = 1; aind <= prec; aind++)
aind <= precDescription
TRUEevaluated 36 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test
18-36
1182 {-
1183 buf[ind++] = (sec_fraction / precs[aind]) + '0';-
1184 sec_fraction %= precs[aind];-
1185 }
executed 36 times by 1 test: end of block
Executed by:
  • Self test
36
1186 }
executed 18 times by 1 test: end of block
Executed by:
  • Self test
18
1187-
1188 if (lng)
lngDescription
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test
0-18
1189 buf[ind++] = 's';
never executed: buf[ind++] = 's';
0
1190 buf[ind] = '\0';-
1191-
1192 return (ind);
executed 18 times by 1 test: return (ind);
Executed by:
  • Self test
18
1193}-
1194-
1195/* Interpret the format string FORMAT, interpolating the following escape-
1196 sequences:-
1197 %[prec][l][RUS]-
1198-
1199 where the optional `prec' is a precision, meaning the number of-
1200 characters after the decimal point, the optional `l' means to format-
1201 using minutes and seconds (MMmNN[.FF]s), like the `times' builtin',-
1202 and the last character is one of-
1203 -
1204 R number of seconds of `real' time-
1205 U number of seconds of `user' time-
1206 S number of seconds of `system' time-
1207-
1208 An occurrence of `%%' in the format string is translated to a `%'. The-
1209 result is printed to FP, a pointer to a FILE. The other variables are-
1210 the seconds and thousandths of a second of real, user, and system time,-
1211 resectively. */-
1212static void-
1213print_formatted_time (fp, format, rs, rsf, us, usf, ss, ssf, cpu)-
1214 FILE *fp;-
1215 char *format;-
1216 time_t rs;-
1217 int rsf;-
1218 time_t us;-
1219 int usf;-
1220 time_t ss;-
1221 int ssf, cpu;-
1222{-
1223 int prec, lng, len;-
1224 char *str, *s, ts[INT_STRLEN_BOUND (time_t) + sizeof ("mSS.FFFF")];-
1225 time_t sum;-
1226 int sum_frac;-
1227 int sindex, ssize;-
1228-
1229 len = strlen (format);-
1230 ssize = (len + 64) - (len % 64);-
1231 str = (char *)xmalloc (ssize);-
1232 sindex = 0;-
1233-
1234 for (s = format; *s; s++)
*sDescription
TRUEevaluated 114 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
6-114
1235 {-
1236 if (*s != '%' || s[1] == '\0')
*s != '%'Description
TRUEevaluated 96 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test
s[1] == '\0'Description
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test
0-96
1237 {-
1238 RESIZE_MALLOCED_BUFFER (str, sindex, 1, ssize, 64);
never executed: ssize += (64);
never executed: end of block
(sindex) + (1) >= ssizeDescription
TRUEnever evaluated
FALSEevaluated 96 times by 1 test
Evaluated by:
  • Self test
(sindex) + (1) >= ssizeDescription
TRUEnever evaluated
FALSEnever evaluated
0-96
1239 str[sindex++] = *s;-
1240 }
executed 96 times by 1 test: end of block
Executed by:
  • Self test
96
1241 else if (s[1] == '%')
s[1] == '%'Description
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test
0-18
1242 {-
1243 s++;-
1244 RESIZE_MALLOCED_BUFFER (str, sindex, 1, ssize, 64);
never executed: ssize += (64);
never executed: end of block
(sindex) + (1) >= ssizeDescription
TRUEnever evaluated
FALSEnever evaluated
(sindex) + (1) >= ssizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1245 str[sindex++] = *s;-
1246 }
never executed: end of block
0
1247 else if (s[1] == 'P')
s[1] == 'P'Description
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test
0-18
1248 {-
1249 s++;-
1250#if 0-
1251 /* clamp CPU usage at 100% */-
1252 if (cpu > 10000)-
1253 cpu = 10000;-
1254#endif-
1255 sum = cpu / 100;-
1256 sum_frac = (cpu % 100) * 10;-
1257 len = mkfmt (ts, 2, 0, sum, sum_frac);-
1258 RESIZE_MALLOCED_BUFFER (str, sindex, len, ssize, 64);
never executed: ssize += (64);
never executed: end of block
(sindex) + (len) >= ssizeDescription
TRUEnever evaluated
FALSEnever evaluated
(sindex) + (len) >= ssizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1259 strcpy (str + sindex, ts);-
1260 sindex += len;-
1261 }
never executed: end of block
0
1262 else-
1263 {-
1264 prec = 3; /* default is three places past the decimal point. */-
1265 lng = 0; /* default is to not use minutes or append `s' */-
1266 s++;-
1267 if (DIGIT (*s)) /* `precision' */
(*s) >= '0'Description
TRUEevaluated 18 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(*s) <= '9'Description
TRUEevaluated 18 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-18
1268 {-
1269 prec = *s++ - '0';-
1270 if (prec > 3) prec = 3;
never executed: prec = 3;
prec > 3Description
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test
0-18
1271 }
executed 18 times by 1 test: end of block
Executed by:
  • Self test
18
1272 if (*s == 'l') /* `length extender' */
*s == 'l'Description
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test
0-18
1273 {-
1274 lng = 1;-
1275 s++;-
1276 }
never executed: end of block
0
1277 if (*s == 'R' || *s == 'E')
*s == 'R'Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 12 times by 1 test
Evaluated by:
  • Self test
*s == 'E'Description
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • Self test
0-12
1278 len = mkfmt (ts, prec, lng, rs, rsf);
executed 6 times by 1 test: len = mkfmt (ts, prec, lng, rs, rsf);
Executed by:
  • Self test
6
1279 else if (*s == 'U')
*s == 'U'Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
6
1280 len = mkfmt (ts, prec, lng, us, usf);
executed 6 times by 1 test: len = mkfmt (ts, prec, lng, us, usf);
Executed by:
  • Self test
6
1281 else if (*s == 'S')
*s == 'S'Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-6
1282 len = mkfmt (ts, prec, lng, ss, ssf);
executed 6 times by 1 test: len = mkfmt (ts, prec, lng, ss, ssf);
Executed by:
  • Self test
6
1283 else-
1284 {-
1285 internal_error (_("TIMEFORMAT: `%c': invalid format character"), *s);-
1286 free (str);-
1287 return;
never executed: return;
0
1288 }-
1289 RESIZE_MALLOCED_BUFFER (str, sindex, len, ssize, 64);
never executed: ssize += (64);
never executed: end of block
(sindex) + (len) >= ssizeDescription
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test
(sindex) + (len) >= ssizeDescription
TRUEnever evaluated
FALSEnever evaluated
0-18
1290 strcpy (str + sindex, ts);-
1291 sindex += len;-
1292 }
executed 18 times by 1 test: end of block
Executed by:
  • Self test
18
1293 }-
1294-
1295 str[sindex] = '\0';-
1296 fprintf (fp, "%s\n", str);-
1297 fflush (fp);-
1298-
1299 free (str);-
1300}
executed 6 times by 1 test: end of block
Executed by:
  • Self test
6
1301-
1302static int-
1303time_command (command, asynchronous, pipe_in, pipe_out, fds_to_close)-
1304 COMMAND *command;-
1305 int asynchronous, pipe_in, pipe_out;-
1306 struct fd_bitmap *fds_to_close;-
1307{-
1308 int rv, posix_time, old_flags, nullcmd, code;-
1309 time_t rs, us, ss;-
1310 int rsf, usf, ssf;-
1311 int cpu;-
1312 char *time_format;-
1313 volatile procenv_t save_top_level;-
1314-
1315#if defined (HAVE_GETRUSAGE) && defined (HAVE_GETTIMEOFDAY)-
1316 struct timeval real, user, sys;-
1317 struct timeval before, after;-
1318# if defined (HAVE_STRUCT_TIMEZONE)-
1319 struct timezone dtz; /* posix doesn't define this */-
1320# endif-
1321 struct rusage selfb, selfa, kidsb, kidsa; /* a = after, b = before */-
1322#else-
1323# if defined (HAVE_TIMES)-
1324 clock_t tbefore, tafter, real, user, sys;-
1325 struct tms before, after;-
1326# endif-
1327#endif-
1328-
1329#if defined (HAVE_GETRUSAGE) && defined (HAVE_GETTIMEOFDAY)-
1330# if defined (HAVE_STRUCT_TIMEZONE)-
1331 gettimeofday (&before, &dtz);-
1332# else-
1333 gettimeofday (&before, (void *)NULL);-
1334# endif /* !HAVE_STRUCT_TIMEZONE */-
1335 getrusage (RUSAGE_SELF, &selfb);-
1336 getrusage (RUSAGE_CHILDREN, &kidsb);-
1337#else-
1338# if defined (HAVE_TIMES)-
1339 tbefore = times (&before);-
1340# endif-
1341#endif-
1342-
1343 posix_time = command && (command->flags & CMD_TIME_POSIX);
commandDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(command->flags & 0x100)Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
0-6
1344-
1345 nullcmd = (command == 0) || (command->type == cm_simple && command->value.Simple->words == 0 && command->value.Simple->redirects == 0);
(command == 0)Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
command->type == cm_simpleDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
command->value...le->words == 0Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
command->value...redirects == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-6
1346 if (posixly_correct && nullcmd)
posixly_correctDescription
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
nullcmdDescription
TRUEnever evaluated
FALSEnever evaluated
0-6
1347 {-
1348#if defined (HAVE_GETRUSAGE)-
1349 selfb.ru_utime.tv_sec = kidsb.ru_utime.tv_sec = selfb.ru_stime.tv_sec = kidsb.ru_stime.tv_sec = 0;-
1350 selfb.ru_utime.tv_usec = kidsb.ru_utime.tv_usec = selfb.ru_stime.tv_usec = kidsb.ru_stime.tv_usec = 0;-
1351 before.tv_sec = shell_start_time;-
1352 before.tv_usec = 0;-
1353#else-
1354 before.tms_utime = before.tms_stime = before.tms_cutime = before.tms_cstime = 0;-
1355 tbefore = shell_start_time;-
1356#endif-
1357 }
never executed: end of block
0
1358-
1359 old_flags = command->flags;-
1360 COPY_PROCENV (top_level, save_top_level);-
1361 command->flags &= ~(CMD_TIME_PIPELINE|CMD_TIME_POSIX);-
1362 code = setjmp_nosigs (top_level);-
1363 if (code == NOT_JUMPED)
code == 0Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-6
1364 {-
1365 rv = execute_command_internal (command, asynchronous, pipe_in, pipe_out, fds_to_close);-
1366 command->flags = old_flags;-
1367 }
executed 6 times by 1 test: end of block
Executed by:
  • Self test
6
1368 COPY_PROCENV (save_top_level, top_level);-
1369-
1370 rs = us = ss = 0;-
1371 rsf = usf = ssf = cpu = 0;-
1372-
1373#if defined (HAVE_GETRUSAGE) && defined (HAVE_GETTIMEOFDAY)-
1374# if defined (HAVE_STRUCT_TIMEZONE)-
1375 gettimeofday (&after, &dtz);-
1376# else-
1377 gettimeofday (&after, (void *)NULL);-
1378# endif /* !HAVE_STRUCT_TIMEZONE */-
1379 getrusage (RUSAGE_SELF, &selfa);-
1380 getrusage (RUSAGE_CHILDREN, &kidsa);-
1381-
1382 difftimeval (&real, &before, &after);-
1383 timeval_to_secs (&real, &rs, &rsf);-
1384-
1385 addtimeval (&user, difftimeval(&after, &selfb.ru_utime, &selfa.ru_utime),-
1386 difftimeval(&before, &kidsb.ru_utime, &kidsa.ru_utime));-
1387 timeval_to_secs (&user, &us, &usf);-
1388-
1389 addtimeval (&sys, difftimeval(&after, &selfb.ru_stime, &selfa.ru_stime),-
1390 difftimeval(&before, &kidsb.ru_stime, &kidsa.ru_stime));-
1391 timeval_to_secs (&sys, &ss, &ssf);-
1392-
1393 cpu = timeval_to_cpu (&real, &user, &sys);-
1394#else-
1395# if defined (HAVE_TIMES)-
1396 tafter = times (&after);-
1397-
1398 real = tafter - tbefore;-
1399 clock_t_to_secs (real, &rs, &rsf);-
1400-
1401 user = (after.tms_utime - before.tms_utime) + (after.tms_cutime - before.tms_cutime);-
1402 clock_t_to_secs (user, &us, &usf);-
1403-
1404 sys = (after.tms_stime - before.tms_stime) + (after.tms_cstime - before.tms_cstime);-
1405 clock_t_to_secs (sys, &ss, &ssf);-
1406-
1407 cpu = (real == 0) ? 0 : ((user + sys) * 10000) / real;-
1408-
1409# else-
1410 rs = us = ss = 0;-
1411 rsf = usf = ssf = cpu = 0;-
1412# endif-
1413#endif-
1414-
1415 if (posix_time)
posix_timeDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
3
1416 time_format = POSIX_TIMEFORMAT;
executed 3 times by 1 test: time_format = "real %2R\nuser %2U\nsys %2S";
Executed by:
  • Self test
3
1417 else if ((time_format = get_string_value ("TIMEFORMAT")) == 0)
(time_format =...FORMAT")) == 0Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
0-3
1418 {-
1419 if (posixly_correct && nullcmd)
posixly_correctDescription
TRUEnever evaluated
FALSEnever evaluated
nullcmdDescription
TRUEnever evaluated
FALSEnever evaluated
0
1420 time_format = "user\t%2lU\nsys\t%2lS";
never executed: time_format = "user\t%2lU\nsys\t%2lS";
0
1421 else-
1422 time_format = BASH_TIMEFORMAT;
never executed: time_format = "\nreal\t%3lR\nuser\t%3lU\nsys\t%3lS";
0
1423 }-
1424 if (time_format && *time_format)
time_formatDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
*time_formatDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-6
1425 print_formatted_time (stderr, time_format, rs, rsf, us, usf, ss, ssf, cpu);
executed 6 times by 1 test: print_formatted_time ( stderr , time_format, rs, rsf, us, usf, ss, ssf, cpu);
Executed by:
  • Self test
6
1426-
1427 if (code)
codeDescription
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
0-6
1428 sh_longjmp (top_level, code);
never executed: siglongjmp((top_level), (code));
0
1429-
1430 return rv;
executed 6 times by 1 test: return rv;
Executed by:
  • Self test
6
1431}-
1432#endif /* COMMAND_TIMING */-
1433-
1434/* Execute a command that's supposed to be in a subshell. This must be-
1435 called after make_child and we must be running in the child process.-
1436 The caller will return or exit() immediately with the value this returns. */-
1437static int-
1438execute_in_subshell (command, asynchronous, pipe_in, pipe_out, fds_to_close)-
1439 COMMAND *command;-
1440 int asynchronous;-
1441 int pipe_in, pipe_out;-
1442 struct fd_bitmap *fds_to_close;-
1443{-
1444 volatile int user_subshell, user_coproc, invert;-
1445 int return_code, function_value, should_redir_stdin, ois, result;-
1446 volatile COMMAND *tcom;-
1447-
1448 USE_VAR(user_subshell);-
1449 USE_VAR(user_coproc);-
1450 USE_VAR(invert);-
1451 USE_VAR(tcom);-
1452 USE_VAR(asynchronous);-
1453-
1454 subshell_level++;-
1455 should_redir_stdin = (asynchronous && (command->flags & CMD_STDIN_REDIR) &&
asynchronousDescription
TRUEevaluated 20 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1102 times by 1 test
Evaluated by:
  • Self test
(command->flags & 0x400)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 16 times by 1 test
Evaluated by:
  • Self test
4-1102
1456 pipe_in == NO_PIPE &&
pipe_in == -1Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-4
1457 stdin_redirects (command->redirects) == 0);
stdin_redirect...edirects) == 0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-4
1458-
1459 invert = (command->flags & CMD_INVERT_RETURN) != 0;-
1460 user_subshell = command->type == cm_subshell || ((command->flags & CMD_WANT_SUBSHELL) != 0);
command->type == cm_subshellDescription
TRUEevaluated 1060 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 62 times by 1 test
Evaluated by:
  • Self test
((command->flags & 0x01) != 0)Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 54 times by 1 test
Evaluated by:
  • Self test
8-1060
1461 user_coproc = command->type == cm_coproc;-
1462-
1463 command->flags &= ~(CMD_FORCE_SUBSHELL | CMD_WANT_SUBSHELL | CMD_INVERT_RETURN);-
1464-
1465 /* If a command is asynchronous in a subshell (like ( foo ) & or-
1466 the special case of an asynchronous GROUP command where the-
1467 the subshell bit is turned on down in case cm_group: below),-
1468 turn off `asynchronous', so that two subshells aren't spawned.-
1469 XXX - asynchronous used to be set to 0 in this block, but that-
1470 means that setup_async_signals was never run. Now it's set to-
1471 0 after subshell_environment is set appropriately and setup_async_signals-
1472 is run.-
1473-
1474 This seems semantically correct to me. For example,-
1475 ( foo ) & seems to say ``do the command `foo' in a subshell-
1476 environment, but don't wait for that subshell to finish'',-
1477 and "{ foo ; bar ; } &" seems to me to be like functions or-
1478 builtins in the background, which executed in a subshell-
1479 environment. I just don't see the need to fork two subshells. */-
1480-
1481 /* Don't fork again, we are already in a subshell. A `doubly-
1482 async' shell is not interactive, however. */-
1483 if (asynchronous)
asynchronousDescription
TRUEevaluated 20 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1102 times by 1 test
Evaluated by:
  • Self test
20-1102
1484 {-
1485#if defined (JOB_CONTROL)-
1486 /* If a construct like ( exec xxx yyy ) & is given while job-
1487 control is active, we want to prevent exec from putting the-
1488 subshell back into the original process group, carefully-
1489 undoing all the work we just did in make_child. */-
1490 original_pgrp = -1;-
1491#endif /* JOB_CONTROL */-
1492 ois = interactive_shell;-
1493 interactive_shell = 0;-
1494 /* This test is to prevent alias expansion by interactive shells that-
1495 run `(command) &' but to allow scripts that have enabled alias-
1496 expansion with `shopt -s expand_alias' to continue to expand-
1497 aliases. */-
1498 if (ois != interactive_shell)
ois != interactive_shellDescription
TRUEnever evaluated
FALSEevaluated 20 times by 1 test
Evaluated by:
  • Self test
0-20
1499 expand_aliases = 0;
never executed: expand_aliases = 0;
0
1500 }
executed 20 times by 1 test: end of block
Executed by:
  • Self test
20
1501-
1502 /* Subshells are neither login nor interactive. */-
1503 login_shell = interactive = 0;-
1504-
1505 if (user_subshell)
user_subshellDescription
TRUEevaluated 1068 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 54 times by 1 test
Evaluated by:
  • Self test
54-1068
1506 {-
1507 subshell_environment = SUBSHELL_PAREN; /* XXX */-
1508 if (asynchronous)
asynchronousDescription
TRUEevaluated 11 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1057 times by 1 test
Evaluated by:
  • Self test
11-1057
1509 subshell_environment |= SUBSHELL_ASYNC;
executed 11 times by 1 test: subshell_environment |= 0x01;
Executed by:
  • Self test
11
1510 }
executed 1068 times by 1 test: end of block
Executed by:
  • Self test
1068
1511 else-
1512 {-
1513 subshell_environment = 0; /* XXX */-
1514 if (asynchronous)
asynchronousDescription
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 45 times by 1 test
Evaluated by:
  • Self test
9-45
1515 subshell_environment |= SUBSHELL_ASYNC;
executed 9 times by 1 test: subshell_environment |= 0x01;
Executed by:
  • Self test
9
1516 if (pipe_in != NO_PIPE || pipe_out != NO_PIPE)
pipe_in != -1Description
TRUEevaluated 38 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 16 times by 1 test
Evaluated by:
  • Self test
pipe_out != -1Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
7-38
1517 subshell_environment |= SUBSHELL_PIPE;
executed 45 times by 1 test: subshell_environment |= 0x10;
Executed by:
  • Self test
45
1518 if (user_coproc)
user_coprocDescription
TRUEnever evaluated
FALSEevaluated 54 times by 1 test
Evaluated by:
  • Self test
0-54
1519 subshell_environment |= SUBSHELL_COPROC;
never executed: subshell_environment |= 0x40;
0
1520 }
executed 54 times by 1 test: end of block
Executed by:
  • Self test
54
1521-
1522 reset_terminating_signals (); /* in sig.c */-
1523 /* Cancel traps, in trap.c. */-
1524 /* Reset the signal handlers in the child, but don't free the-
1525 trap strings. Set a flag noting that we have to free the-
1526 trap strings if we run trap to change a signal disposition. */-
1527 reset_signal_handlers ();-
1528 subshell_environment |= SUBSHELL_RESETTRAP;-
1529-
1530 /* Make sure restore_original_signals doesn't undo the work done by-
1531 make_child to ensure that asynchronous children are immune to SIGINT-
1532 and SIGQUIT. Turn off asynchronous to make sure more subshells are-
1533 not spawned. */-
1534 if (asynchronous)
asynchronousDescription
TRUEevaluated 20 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1102 times by 1 test
Evaluated by:
  • Self test
20-1102
1535 {-
1536 setup_async_signals ();-
1537 asynchronous = 0;-
1538 }
executed 20 times by 1 test: end of block
Executed by:
  • Self test
20
1539-
1540#if defined (JOB_CONTROL)-
1541 set_sigchld_handler ();-
1542#endif /* JOB_CONTROL */-
1543-
1544 set_sigint_handler ();-
1545-
1546 /* Delete all traces that there were any jobs running. This is-
1547 only for subshells. */-
1548 without_job_control ();-
1549-
1550 if (fds_to_close)
fds_to_closeDescription
TRUEevaluated 1122 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1122
1551 close_fd_bitmap (fds_to_close);
executed 1122 times by 1 test: close_fd_bitmap (fds_to_close);
Executed by:
  • Self test
1122
1552-
1553 do_piping (pipe_in, pipe_out);-
1554-
1555#if defined (COPROCESS_SUPPORT)-
1556 coproc_closeall ();-
1557#endif-
1558-
1559 /* If this is a user subshell, set a flag if stdin was redirected.-
1560 This is used later to decide whether to redirect fd 0 to-
1561 /dev/null for async commands in the subshell. This adds more-
1562 sh compatibility, but I'm not sure it's the right thing to do.-
1563 Note that an input pipe to a compound command suffices to inhibit-
1564 the implicit /dev/null redirection for asynchronous commands-
1565 executed as part of that compound command. */-
1566 if (user_subshell)
user_subshellDescription
TRUEevaluated 1068 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 54 times by 1 test
Evaluated by:
  • Self test
54-1068
1567 {-
1568 stdin_redir = stdin_redirects (command->redirects) || pipe_in != NO_PIPE;
stdin_redirect...nd->redirects)Description
TRUEnever evaluated
FALSEevaluated 1068 times by 1 test
Evaluated by:
  • Self test
pipe_in != -1Description
TRUEevaluated 787 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 281 times by 1 test
Evaluated by:
  • Self test
0-1068
1569#if 0-
1570 restore_default_signal (EXIT_TRAP); /* XXX - reset_signal_handlers above */-
1571#endif-
1572 }
executed 1068 times by 1 test: end of block
Executed by:
  • Self test
1068
1573 else if (shell_control_structure (command->type) && pipe_in != NO_PIPE)
shell_control_...command->type)Description
TRUEevaluated 54 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
pipe_in != -1Description
TRUEevaluated 38 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 16 times by 1 test
Evaluated by:
  • Self test
0-54
1574 stdin_redir = 1;
executed 38 times by 1 test: stdin_redir = 1;
Executed by:
  • Self test
38
1575-
1576 /* If this is an asynchronous command (command &), we want to-
1577 redirect the standard input from /dev/null in the absence of-
1578 any specific redirection involving stdin. */-
1579 if (should_redir_stdin && stdin_redir == 0)
should_redir_stdinDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1118 times by 1 test
Evaluated by:
  • Self test
stdin_redir == 0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1118
1580 async_redirect_stdin ();
executed 4 times by 1 test: async_redirect_stdin ();
Executed by:
  • Self test
4
1581-
1582#if 0-
1583 /* bash-5.0 */-
1584 if (user_subshell && command->type == cm_subshell)-
1585 optimize_subshell_command (command->value.Subshell->command);-
1586#endif-
1587-
1588 /* Do redirections, then dispose of them before recursive call. */-
1589 if (command->redirects)
command->redirectsDescription
TRUEevaluated 70 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1052 times by 1 test
Evaluated by:
  • Self test
70-1052
1590 {-
1591 if (do_redirections (command->redirects, RX_ACTIVE) != 0)
do_redirection...ts, 0x01) != 0Description
TRUEnever evaluated
FALSEevaluated 70 times by 1 test
Evaluated by:
  • Self test
0-70
1592 exit (invert ? EXECUTION_SUCCESS : EXECUTION_FAILURE);
never executed: exit (invert ? 0 : 1);
0
1593-
1594 dispose_redirects (command->redirects);-
1595 command->redirects = (REDIRECT *)NULL;-
1596 }
executed 70 times by 1 test: end of block
Executed by:
  • Self test
70
1597-
1598 if (command->type == cm_subshell)
command->type == cm_subshellDescription
TRUEevaluated 1060 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 62 times by 1 test
Evaluated by:
  • Self test
62-1060
1599 tcom = command->value.Subshell->command;
executed 1060 times by 1 test: tcom = command->value.Subshell->command;
Executed by:
  • Self test
1060
1600 else if (user_coproc)
user_coprocDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 54 times by 1 test
Evaluated by:
  • Self test
8-54
1601 tcom = command->value.Coproc->command;
executed 8 times by 1 test: tcom = command->value.Coproc->command;
Executed by:
  • Self test
8
1602 else-
1603 tcom = command;
executed 54 times by 1 test: tcom = command;
Executed by:
  • Self test
54
1604-
1605 if (command->flags & CMD_TIME_PIPELINE)
command->flags & 0x80Description
TRUEnever evaluated
FALSEevaluated 1122 times by 1 test
Evaluated by:
  • Self test
0-1122
1606 tcom->flags |= CMD_TIME_PIPELINE;
never executed: tcom->flags |= 0x80;
0
1607 if (command->flags & CMD_TIME_POSIX)
command->flags & 0x100Description
TRUEnever evaluated
FALSEevaluated 1122 times by 1 test
Evaluated by:
  • Self test
0-1122
1608 tcom->flags |= CMD_TIME_POSIX;
never executed: tcom->flags |= 0x100;
0
1609 -
1610 /* Make sure the subshell inherits any CMD_IGNORE_RETURN flag. */-
1611 if ((command->flags & CMD_IGNORE_RETURN) && tcom != command)
(command->flags & 0x08)Description
TRUEevaluated 59 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1063 times by 1 test
Evaluated by:
  • Self test
tcom != commandDescription
TRUEevaluated 58 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-1063
1612 tcom->flags |= CMD_IGNORE_RETURN;
executed 58 times by 1 test: tcom->flags |= 0x08;
Executed by:
  • Self test
58
1613-
1614 /* If this is a simple command, tell execute_disk_command that it-
1615 might be able to get away without forking and simply exec.-
1616 This means things like ( sleep 10 ) will only cause one fork.-
1617 If we're timing the command or inverting its return value, however,-
1618 we cannot do this optimization. */-
1619 if ((user_subshell || user_coproc) && (tcom->type == cm_simple || tcom->type == cm_subshell) &&
user_subshellDescription
TRUEevaluated 1068 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 54 times by 1 test
Evaluated by:
  • Self test
user_coprocDescription
TRUEnever evaluated
FALSEevaluated 54 times by 1 test
Evaluated by:
  • Self test
tcom->type == cm_simpleDescription
TRUEevaluated 91 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 977 times by 1 test
Evaluated by:
  • Self test
tcom->type == cm_subshellDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 975 times by 1 test
Evaluated by:
  • Self test
0-1068
1620 ((tcom->flags & CMD_TIME_PIPELINE) == 0) &&
((tcom->flags & 0x80) == 0)Description
TRUEevaluated 93 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-93
1621 ((tcom->flags & CMD_INVERT_RETURN) == 0))
((tcom->flags & 0x04) == 0)Description
TRUEevaluated 87 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
6-87
1622 {-
1623 tcom->flags |= CMD_NO_FORK;-
1624 if (tcom->type == cm_simple)
tcom->type == cm_simpleDescription
TRUEevaluated 85 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
2-85
1625 tcom->value.Simple->flags |= CMD_NO_FORK;
executed 85 times by 1 test: tcom->value.Simple->flags |= 0x40;
Executed by:
  • Self test
85
1626 }
executed 87 times by 1 test: end of block
Executed by:
  • Self test
87
1627-
1628 invert = (tcom->flags & CMD_INVERT_RETURN) != 0;-
1629 tcom->flags &= ~CMD_INVERT_RETURN;-
1630-
1631 result = setjmp_nosigs (top_level);-
1632-
1633 /* If we're inside a function while executing this subshell, we-
1634 need to handle a possible `return'. */-
1635 function_value = 0;-
1636 if (return_catch_flag)
return_catch_flagDescription
TRUEevaluated 792 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 384 times by 1 test
Evaluated by:
  • Self test
384-792
1637 function_value = setjmp_nosigs (return_catch);
executed 792 times by 1 test: function_value = __sigsetjmp ( (return_catch) , 0 ) ;
Executed by:
  • Self test
792
1638-
1639 /* If we're going to exit the shell, we don't want to invert the return-
1640 status. */-
1641 if (result == EXITPROG)
result == 3Description
TRUEevaluated 21 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1156 times by 1 test
Evaluated by:
  • Self test
21-1156
1642 invert = 0, return_code = last_command_exit_value;
executed 21 times by 1 test: invert = 0, return_code = last_command_exit_value;
Executed by:
  • Self test
21
1643 else if (result)
resultDescription
TRUEevaluated 33 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1123 times by 1 test
Evaluated by:
  • Self test
33-1123
1644 return_code = (last_command_exit_value == EXECUTION_SUCCESS) ? EXECUTION_FAILURE : last_command_exit_value;
executed 33 times by 1 test: return_code = (last_command_exit_value == 0) ? 1 : last_command_exit_value;
Executed by:
  • Self test
(last_command_exit_value == 0)Description
TRUEnever evaluated
FALSEevaluated 33 times by 1 test
Evaluated by:
  • Self test
0-33
1645 else if (function_value)
function_valueDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1122 times by 1 test
Evaluated by:
  • Self test
1-1122
1646 return_code = return_catch_value;
executed 1 time by 1 test: return_code = return_catch_value;
Executed by:
  • Self test
1
1647 else-
1648 return_code = execute_command_internal ((COMMAND *)tcom, asynchronous, NO_PIPE, NO_PIPE, fds_to_close);
executed 1122 times by 1 test: return_code = execute_command_internal ((COMMAND *)tcom, asynchronous, -1, -1, fds_to_close);
Executed by:
  • Self test
1122
1649-
1650 /* If we are asked to, invert the return value. */-
1651 if (invert)
invertDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 987 times by 1 test
Evaluated by:
  • Self test
4-987
1652 return_code = (return_code == EXECUTION_SUCCESS) ? EXECUTION_FAILURE
executed 4 times by 1 test: return_code = (return_code == 0) ? 1 : 0;
Executed by:
  • Self test
(return_code == 0)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
2-4
1653 : EXECUTION_SUCCESS;
executed 4 times by 1 test: return_code = (return_code == 0) ? 1 : 0;
Executed by:
  • Self test
4
1654-
1655 /* If we were explicitly placed in a subshell with (), we need-
1656 to do the `shell cleanup' things, such as running traps[0]. */-
1657 if (user_subshell && signal_is_trapped (0))
user_subshellDescription
TRUEevaluated 939 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 52 times by 1 test
Evaluated by:
  • Self test
signal_is_trapped (0)Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 927 times by 1 test
Evaluated by:
  • Self test
12-939
1658 {-
1659 last_command_exit_value = return_code;-
1660 return_code = run_exit_trap ();-
1661 }
executed 12 times by 1 test: end of block
Executed by:
  • Self test
12
1662-
1663#if 0-
1664 subshell_level--; /* don't bother, caller will just exit */-
1665#endif-
1666 return (return_code);
executed 991 times by 1 test: return (return_code);
Executed by:
  • Self test
991
1667 /* NOTREACHED */-
1668}-
1669-
1670#if defined (COPROCESS_SUPPORT)-
1671#define COPROC_MAX 16-
1672-
1673typedef struct cpelement-
1674 {-
1675 struct cpelement *next;-
1676 struct coproc *coproc;-
1677 }-
1678cpelement_t;-
1679 -
1680typedef struct cplist-
1681 {-
1682 struct cpelement *head;-
1683 struct cpelement *tail;-
1684 int ncoproc;-
1685 int lock;-
1686 }-
1687cplist_t;-
1688-
1689static struct cpelement *cpe_alloc __P((struct coproc *));-
1690static void cpe_dispose __P((struct cpelement *));-
1691static struct cpelement *cpl_add __P((struct coproc *));-
1692static struct cpelement *cpl_delete __P((pid_t));-
1693static void cpl_reap __P((void));-
1694static void cpl_flush __P((void));-
1695static void cpl_closeall __P((void));-
1696static struct cpelement *cpl_search __P((pid_t));-
1697static struct cpelement *cpl_searchbyname __P((const char *));-
1698static void cpl_prune __P((void));-
1699-
1700static void coproc_free __P((struct coproc *));-
1701-
1702/* Will go away when there is fully-implemented support for multiple coprocs. */-
1703Coproc sh_coproc = { 0, NO_PID, -1, -1, 0, 0, 0, 0, 0 };-
1704-
1705cplist_t coproc_list = {0, 0, 0};-
1706-
1707/* Functions to manage the list of coprocs */-
1708-
1709static struct cpelement *-
1710cpe_alloc (cp)-
1711 Coproc *cp;-
1712{-
1713 struct cpelement *cpe;-
1714-
1715 cpe = (struct cpelement *)xmalloc (sizeof (struct cpelement));-
1716 cpe->coproc = cp;-
1717 cpe->next = (struct cpelement *)0;-
1718 return cpe;
never executed: return cpe;
0
1719}-
1720-
1721static void-
1722cpe_dispose (cpe)-
1723 struct cpelement *cpe;-
1724{-
1725 free (cpe);-
1726}
never executed: end of block
0
1727-
1728static struct cpelement *-
1729cpl_add (cp)-
1730 Coproc *cp;-
1731{-
1732 struct cpelement *cpe;-
1733-
1734 cpe = cpe_alloc (cp);-
1735-
1736 if (coproc_list.head == 0)
coproc_list.head == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1737 {-
1738 coproc_list.head = coproc_list.tail = cpe;-
1739 coproc_list.ncoproc = 0; /* just to make sure */-
1740 }
never executed: end of block
0
1741 else-
1742 {-
1743 coproc_list.tail->next = cpe;-
1744 coproc_list.tail = cpe;-
1745 }
never executed: end of block
0
1746 coproc_list.ncoproc++;-
1747-
1748 return cpe;
never executed: return cpe;
0
1749}-
1750-
1751static struct cpelement *-
1752cpl_delete (pid)-
1753 pid_t pid;-
1754{-
1755 struct cpelement *prev, *p;-
1756-
1757 for (prev = p = coproc_list.head; p; prev = p, p = p->next)
pDescription
TRUEnever evaluated
FALSEnever evaluated
0
1758 if (p->coproc->c_pid == pid)
p->coproc->c_pid == pidDescription
TRUEnever evaluated
FALSEnever evaluated
0
1759 {-
1760 prev->next = p->next; /* remove from list */-
1761 break;
never executed: break;
0
1762 }-
1763-
1764 if (p == 0)
p == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1765 return 0; /* not found */
never executed: return 0;
0
1766-
1767#if defined (DEBUG)-
1768 itrace("cpl_delete: deleting %d", pid);-
1769#endif-
1770-
1771 /* Housekeeping in the border cases. */-
1772 if (p == coproc_list.head)
p == coproc_list.headDescription
TRUEnever evaluated
FALSEnever evaluated
0
1773 coproc_list.head = coproc_list.head->next;
never executed: coproc_list.head = coproc_list.head->next;
0
1774 else if (p == coproc_list.tail)
p == coproc_list.tailDescription
TRUEnever evaluated
FALSEnever evaluated
0
1775 coproc_list.tail = prev;
never executed: coproc_list.tail = prev;
0
1776-
1777 coproc_list.ncoproc--;-
1778 if (coproc_list.ncoproc == 0)
coproc_list.ncoproc == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1779 coproc_list.head = coproc_list.tail = 0;
never executed: coproc_list.head = coproc_list.tail = 0;
0
1780 else if (coproc_list.ncoproc == 1)
coproc_list.ncoproc == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
1781 coproc_list.tail = coproc_list.head; /* just to make sure */
never executed: coproc_list.tail = coproc_list.head;
0
1782-
1783 return (p);
never executed: return (p);
0
1784}-
1785-
1786static void-
1787cpl_reap ()-
1788{-
1789 struct cpelement *p, *next, *nh, *nt;-
1790-
1791 /* Build a new list by removing dead coprocs and fix up the coproc_list-
1792 pointers when done. */-
1793 nh = nt = next = (struct cpelement *)0;-
1794 for (p = coproc_list.head; p; p = next)
pDescription
TRUEnever evaluated
FALSEnever evaluated
0
1795 {-
1796 next = p->next;-
1797 if (p->coproc->c_flags & COPROC_DEAD)
p->coproc->c_flags & 0x02Description
TRUEnever evaluated
FALSEnever evaluated
0
1798 {-
1799 coproc_list.ncoproc--; /* keep running count, fix up pointers later */-
1800-
1801#if defined (DEBUG)-
1802 itrace("cpl_reap: deleting %d", p->coproc->c_pid);-
1803#endif-
1804-
1805 coproc_dispose (p->coproc);-
1806 cpe_dispose (p);-
1807 }
never executed: end of block
0
1808 else if (nh == 0)
nh == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1809 nh = nt = p;
never executed: nh = nt = p;
0
1810 else-
1811 {-
1812 nt->next = p;-
1813 nt = nt->next;-
1814 }
never executed: end of block
0
1815 }-
1816-
1817 if (coproc_list.ncoproc == 0)
coproc_list.ncoproc == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1818 coproc_list.head = coproc_list.tail = 0;
never executed: coproc_list.head = coproc_list.tail = 0;
0
1819 else-
1820 {-
1821 if (nt)
ntDescription
TRUEnever evaluated
FALSEnever evaluated
0
1822 nt->next = 0;
never executed: nt->next = 0;
0
1823 coproc_list.head = nh;-
1824 coproc_list.tail = nt;-
1825 if (coproc_list.ncoproc == 1)
coproc_list.ncoproc == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
1826 coproc_list.tail = coproc_list.head; /* just to make sure */
never executed: coproc_list.tail = coproc_list.head;
0
1827 }
never executed: end of block
0
1828}-
1829-
1830/* Clear out the list of saved statuses */-
1831static void-
1832cpl_flush ()-
1833{-
1834 struct cpelement *cpe, *p;-
1835-
1836 for (cpe = coproc_list.head; cpe; )
cpeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1837 {-
1838 p = cpe;-
1839 cpe = cpe->next;-
1840-
1841 coproc_dispose (p->coproc);-
1842 cpe_dispose (p);-
1843 }
never executed: end of block
0
1844-
1845 coproc_list.head = coproc_list.tail = 0;-
1846 coproc_list.ncoproc = 0;-
1847}
never executed: end of block
0
1848-
1849static void-
1850cpl_closeall ()-
1851{-
1852 struct cpelement *cpe;-
1853-
1854 for (cpe = coproc_list.head; cpe; cpe = cpe->next)
cpeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1855 coproc_close (cpe->coproc);
never executed: coproc_close (cpe->coproc);
0
1856}
never executed: end of block
0
1857-
1858static void-
1859cpl_fdchk (fd)-
1860 int fd;-
1861{-
1862 struct cpelement *cpe;-
1863-
1864 for (cpe = coproc_list.head; cpe; cpe = cpe->next)
cpeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1865 coproc_checkfd (cpe->coproc, fd);
never executed: coproc_checkfd (cpe->coproc, fd);
0
1866}
never executed: end of block
0
1867-
1868/* Search for PID in the list of coprocs; return the cpelement struct if-
1869 found. If not found, return NULL. */-
1870static struct cpelement *-
1871cpl_search (pid)-
1872 pid_t pid;-
1873{-
1874 struct cpelement *cpe;-
1875-
1876 for (cpe = coproc_list.head ; cpe; cpe = cpe->next)
cpeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1877 if (cpe->coproc->c_pid == pid)
cpe->coproc->c_pid == pidDescription
TRUEnever evaluated
FALSEnever evaluated
0
1878 return cpe;
never executed: return cpe;
0
1879 return (struct cpelement *)NULL;
never executed: return (struct cpelement *) ((void *)0) ;
0
1880}-
1881-
1882/* Search for the coproc named NAME in the list of coprocs; return the-
1883 cpelement struct if found. If not found, return NULL. */-
1884static struct cpelement *-
1885cpl_searchbyname (name)-
1886 const char *name;-
1887{-
1888 struct cpelement *cp;-
1889-
1890 for (cp = coproc_list.head ; cp; cp = cp->next)
cpDescription
TRUEnever evaluated
FALSEnever evaluated
0
1891 if (STREQ (cp->coproc->c_name, name))
never executed: __result = (((const unsigned char *) (const char *) ( cp->coproc->c_name ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( name ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
(cp->coproc->c...] == (name)[0]Description
TRUEnever evaluated
FALSEnever evaluated
__extension__ ... )))); }) == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1892 return cp;
never executed: return cp;
0
1893 return (struct cpelement *)NULL;
never executed: return (struct cpelement *) ((void *)0) ;
0
1894}-
1895-
1896static pid_t-
1897cpl_firstactive ()-
1898{-
1899 struct cpelement *cpe;-
1900-
1901 for (cpe = coproc_list.head ; cpe; cpe = cpe->next)
cpeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1902 if ((cpe->coproc->c_flags & COPROC_DEAD) == 0)
(cpe->coproc->...s & 0x02) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1903 return cpe->coproc->c_pid;
never executed: return cpe->coproc->c_pid;
0
1904 return (pid_t)NO_PID;
never executed: return (pid_t)(pid_t)-1;
0
1905}-
1906-
1907#if 0-
1908static void-
1909cpl_prune ()-
1910{-
1911 struct cpelement *cp;-
1912-
1913 while (coproc_list.head && coproc_list.ncoproc > COPROC_MAX)-
1914 {-
1915 cp = coproc_list.head;-
1916 coproc_list.head = coproc_list.head->next;-
1917 coproc_dispose (cp->coproc);-
1918 cpe_dispose (cp);-
1919 coproc_list.ncoproc--;-
1920 }-
1921}-
1922#endif-
1923-
1924/* These currently use a single global "shell coproc" but are written in a-
1925 way to not preclude additional coprocs later (using the list management-
1926 package above). */-
1927-
1928struct coproc *-
1929getcoprocbypid (pid)-
1930 pid_t pid;-
1931{-
1932#if MULTIPLE_COPROCS-
1933 struct cpelement *p;-
1934-
1935 p = cpl_search (pid);-
1936 return (p ? p->coproc : 0);-
1937#else-
1938 return (pid == sh_coproc.c_pid ? &sh_coproc : 0);
executed 3985831 times by 1 test: return (pid == sh_coproc.c_pid ? &sh_coproc : 0);
Executed by:
  • Self test
3985831
1939#endif-
1940}-
1941-
1942struct coproc *-
1943getcoprocbyname (name)-
1944 const char *name;-
1945{-
1946#if MULTIPLE_COPROCS-
1947 struct cpelement *p;-
1948-
1949 p = cpl_searchbyname (name);-
1950 return (p ? p->coproc : 0);-
1951#else-
1952 return ((sh_coproc.c_name && STREQ (sh_coproc.c_name, name)) ? &sh_coproc : 0);
never executed: return ((sh_coproc.c_name && ((sh_coproc.c_name)[0] == (name)[0] && __extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p ( sh_coproc.c_name ) && __builtin_constant_p ( name ) && (__s1_len = __builtin_strlen ( sh_coproc.c_name ), __s2_len = __...r *) (const char *) ( name ))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) ( name ))[3] - __s2[3]); } } __result; }))) : __builtin_strcmp ( sh_coproc.c_name , name )))); }) == 0)) ? &sh_coproc : 0);
never executed: __result = (((const unsigned char *) (const char *) ( sh_coproc.c_name ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( name ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1953#endif-
1954}-
1955-
1956void-
1957coproc_init (cp)-
1958 struct coproc *cp;-
1959{-
1960 cp->c_name = 0;-
1961 cp->c_pid = NO_PID;-
1962 cp->c_rfd = cp->c_wfd = -1;-
1963 cp->c_rsave = cp->c_wsave = -1;-
1964 cp->c_flags = cp->c_status = cp->c_lock = 0;-
1965}
executed 626 times by 1 test: end of block
Executed by:
  • Self test
626
1966-
1967struct coproc *-
1968coproc_alloc (name, pid)-
1969 char *name;-
1970 pid_t pid;-
1971{-
1972 struct coproc *cp;-
1973-
1974#if MULTIPLE_COPROCS-
1975 cp = (struct coproc *)xmalloc (sizeof (struct coproc));-
1976#else-
1977 cp = &sh_coproc;-
1978#endif-
1979 coproc_init (cp);-
1980 cp->c_lock = 2;-
1981-
1982 cp->c_pid = pid;-
1983 cp->c_name = savestring (name);-
1984#if MULTIPLE_COPROCS-
1985 cpl_add (cp);-
1986#endif-
1987 cp->c_lock = 0;-
1988 return (cp);
executed 22 times by 1 test: return (cp);
Executed by:
  • Self test
22
1989}-
1990-
1991static void-
1992coproc_free (cp)-
1993 struct coproc *cp;-
1994{-
1995 free (cp);-
1996}
never executed: end of block
0
1997-
1998void-
1999coproc_dispose (cp)-
2000 struct coproc *cp;-
2001{-
2002 sigset_t set, oset;-
2003-
2004 if (cp == 0)
cp == 0Description
TRUEnever evaluated
FALSEevaluated 570 times by 1 test
Evaluated by:
  • Self test
0-570
2005 return;
never executed: return;
0
2006-
2007 BLOCK_SIGNAL (SIGCHLD, set, oset);-
2008 cp->c_lock = 3;-
2009 coproc_unsetvars (cp);-
2010 FREE (cp->c_name);
executed 21 times by 1 test: sh_xfree((cp->c_name), "execute_cmd.c", 2010);
Executed by:
  • Self test
cp->c_nameDescription
TRUEevaluated 21 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 549 times by 1 test
Evaluated by:
  • Self test
21-549
2011 coproc_close (cp);-
2012#if MULTIPLE_COPROCS-
2013 coproc_free (cp);-
2014#else-
2015 coproc_init (cp);-
2016 cp->c_lock = 0;-
2017#endif-
2018 UNBLOCK_SIGNAL (oset);-
2019}
executed 570 times by 1 test: end of block