OpenCoverage

jobs.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/jobs.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* jobs.c - functions that make children, remember them, and handle their termination. */-
2-
3/* This file works with both POSIX and BSD systems. It implements job-
4 control. */-
5-
6/* Copyright (C) 1989-2017 Free Software Foundation, Inc.-
7-
8 This file is part of GNU Bash, the Bourne Again SHell.-
9-
10 Bash is free software: you can redistribute it and/or modify-
11 it under the terms of the GNU General Public License as published by-
12 the Free Software Foundation, either version 3 of the License, or-
13 (at your option) any later version.-
14-
15 Bash is distributed in the hope that it will be useful,-
16 but WITHOUT ANY WARRANTY; without even the implied warranty of-
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
18 GNU General Public License for more details.-
19-
20 You should have received a copy of the GNU General Public License-
21 along with Bash. If not, see <http://www.gnu.org/licenses/>.-
22*/-
23-
24#include "config.h"-
25-
26#include "bashtypes.h"-
27#include "trap.h"-
28#include <stdio.h>-
29#include <signal.h>-
30#include <errno.h>-
31-
32#if defined (HAVE_UNISTD_H)-
33# include <unistd.h>-
34#endif-
35-
36#include "posixtime.h"-
37-
38#if defined (HAVE_SYS_RESOURCE_H) && defined (HAVE_WAIT3) && !defined (_POSIX_VERSION) && !defined (RLIMTYPE)-
39# include <sys/resource.h>-
40#endif /* !_POSIX_VERSION && HAVE_SYS_RESOURCE_H && HAVE_WAIT3 && !RLIMTYPE */-
41-
42#if defined (HAVE_SYS_FILE_H)-
43# include <sys/file.h>-
44#endif-
45-
46#include "filecntl.h"-
47#include <sys/ioctl.h>-
48#if defined (HAVE_SYS_PARAM_H)-
49#include <sys/param.h>-
50#endif-
51-
52#if defined (BUFFERED_INPUT)-
53# include "input.h"-
54#endif-
55-
56/* Need to include this up here for *_TTY_DRIVER definitions. */-
57#include "shtty.h"-
58-
59/* Define this if your output is getting swallowed. It's a no-op on-
60 machines with the termio or termios tty drivers. */-
61/* #define DRAIN_OUTPUT */-
62-
63/* For the TIOCGPGRP and TIOCSPGRP ioctl parameters on HP-UX */-
64#if defined (hpux) && !defined (TERMIOS_TTY_DRIVER)-
65# include <bsdtty.h>-
66#endif /* hpux && !TERMIOS_TTY_DRIVER */-
67-
68#include "bashansi.h"-
69#include "bashintl.h"-
70#include "shell.h"-
71#include "parser.h"-
72#include "jobs.h"-
73#include "execute_cmd.h"-
74#include "flags.h"-
75-
76#include "typemax.h"-
77-
78#include "builtins/builtext.h"-
79#include "builtins/common.h"-
80-
81#if defined (READLINE)-
82# include <readline/readline.h>-
83#endif-
84-
85#if !defined (errno)-
86extern int errno;-
87#endif /* !errno */-
88-
89#if !defined (HAVE_KILLPG)-
90extern int killpg __P((pid_t, int));-
91#endif-
92-
93#if !DEFAULT_CHILD_MAX-
94# define DEFAULT_CHILD_MAX 32-
95#endif-
96-
97#if !MAX_CHILD_MAX-
98# define MAX_CHILD_MAX 32768-
99#endif-
100-
101#if !defined (DEBUG)-
102#define MAX_JOBS_IN_ARRAY 4096 /* production */-
103#else-
104#define MAX_JOBS_IN_ARRAY 128 /* testing */-
105#endif-
106-
107/* XXX for now */-
108#define PIDSTAT_TABLE_SZ 4096-
109#define BGPIDS_TABLE_SZ 512-
110-
111/* Flag values for second argument to delete_job */-
112#define DEL_WARNSTOPPED 1 /* warn about deleting stopped jobs */-
113#define DEL_NOBGPID 2 /* don't add pgrp leader to bgpids */-
114-
115/* Take care of system dependencies that must be handled when waiting for-
116 children. The arguments to the WAITPID macro match those to the Posix.1-
117 waitpid() function. */-
118-
119#if defined (ultrix) && defined (mips) && defined (_POSIX_VERSION)-
120# define WAITPID(pid, statusp, options) \-
121 wait3 ((union wait *)statusp, options, (struct rusage *)0)-
122#else-
123# if defined (_POSIX_VERSION) || defined (HAVE_WAITPID)-
124# define WAITPID(pid, statusp, options) \-
125 waitpid ((pid_t)pid, statusp, options)-
126# else-
127# if defined (HAVE_WAIT3)-
128# define WAITPID(pid, statusp, options) \-
129 wait3 (statusp, options, (struct rusage *)0)-
130# else-
131# define WAITPID(pid, statusp, options) \-
132 wait3 (statusp, options, (int *)0)-
133# endif /* HAVE_WAIT3 */-
134# endif /* !_POSIX_VERSION && !HAVE_WAITPID*/-
135#endif /* !(Ultrix && mips && _POSIX_VERSION) */-
136-
137/* getpgrp () varies between systems. Even systems that claim to be-
138 Posix.1 compatible lie sometimes (Ultrix, SunOS4, apollo). */-
139#if defined (GETPGRP_VOID)-
140# define getpgid(p) getpgrp ()-
141#else-
142# define getpgid(p) getpgrp (p)-
143#endif /* !GETPGRP_VOID */-
144-
145/* If the system needs it, REINSTALL_SIGCHLD_HANDLER will reinstall the-
146 handler for SIGCHLD. */-
147#if defined (MUST_REINSTALL_SIGHANDLERS)-
148# define REINSTALL_SIGCHLD_HANDLER signal (SIGCHLD, sigchld_handler)-
149#else-
150# define REINSTALL_SIGCHLD_HANDLER-
151#endif /* !MUST_REINSTALL_SIGHANDLERS */-
152-
153/* Some systems let waitpid(2) tell callers about stopped children. */-
154#if !defined (WCONTINUED) || defined (WCONTINUED_BROKEN)-
155# undef WCONTINUED-
156# define WCONTINUED 0-
157#endif-
158#if !defined (WIFCONTINUED)-
159# define WIFCONTINUED(s) (0)-
160#endif-
161-
162/* The number of additional slots to allocate when we run out. */-
163#define JOB_SLOTS 8-
164-
165typedef int sh_job_map_func_t __P((JOB *, int, int, int));-
166-
167/* Variables used here but defined in other files. */-
168extern sigset_t top_level_mask;-
169extern WORD_LIST *subst_assign_varlist;-
170-
171extern SigHandler **original_signals;-
172-
173extern void set_original_signal __P((int, SigHandler *));-
174-
175static struct jobstats zerojs = { -1L, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NO_JOB, NO_JOB, 0, 0 };-
176struct jobstats js = { -1L, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NO_JOB, NO_JOB, 0, 0 };-
177-
178ps_index_t pidstat_table[PIDSTAT_TABLE_SZ];-
179struct bgpids bgpids = { 0, 0, 0 };-
180-
181/* The array of known jobs. */-
182JOB **jobs = (JOB **)NULL;-
183-
184#if 0-
185/* The number of slots currently allocated to JOBS. */-
186int job_slots = 0;-
187#endif-
188-
189/* The controlling tty for this shell. */-
190int shell_tty = -1;-
191-
192/* The shell's process group. */-
193pid_t shell_pgrp = NO_PID;-
194-
195/* The terminal's process group. */-
196pid_t terminal_pgrp = NO_PID;-
197-
198/* The process group of the shell's parent. */-
199pid_t original_pgrp = NO_PID;-
200-
201/* The process group of the pipeline currently being made. */-
202pid_t pipeline_pgrp = (pid_t)0;-
203-
204#if defined (PGRP_PIPE)-
205/* Pipes which each shell uses to communicate with the process group leader-
206 until all of the processes in a pipeline have been started. Then the-
207 process leader is allowed to continue. */-
208int pgrp_pipe[2] = { -1, -1 };-
209#endif-
210-
211/* Last child made by the shell. */-
212volatile pid_t last_made_pid = NO_PID;-
213-
214/* Pid of the last asynchronous child. */-
215volatile pid_t last_asynchronous_pid = NO_PID;-
216-
217/* The pipeline currently being built. */-
218PROCESS *the_pipeline = (PROCESS *)NULL;-
219-
220/* If this is non-zero, do job control. */-
221int job_control = 1;-
222-
223/* Are we running in background? (terminal_pgrp != shell_pgrp) */-
224int running_in_background = 0;-
225-
226/* Call this when you start making children. */-
227int already_making_children = 0;-
228-
229/* If this is non-zero, $LINES and $COLUMNS are reset after every process-
230 exits from get_tty_state(). */-
231int check_window_size = CHECKWINSIZE_DEFAULT;-
232-
233PROCESS *last_procsub_child = (PROCESS *)NULL;-
234-
235/* Functions local to this file. */-
236-
237void debug_print_pgrps (void);-
238-
239static sighandler wait_sigint_handler __P((int));-
240static sighandler sigchld_handler __P((int));-
241static sighandler sigcont_sighandler __P((int));-
242static sighandler sigstop_sighandler __P((int));-
243-
244static int waitchld __P((pid_t, int));-
245-
246static PROCESS *find_pipeline __P((pid_t, int, int *));-
247static PROCESS *find_process __P((pid_t, int, int *));-
248-
249static char *current_working_directory __P((void));-
250static char *job_working_directory __P((void));-
251static char *j_strsignal __P((int));-
252static char *printable_job_status __P((int, PROCESS *, int));-
253-
254static PROCESS *find_last_proc __P((int, int));-
255static pid_t find_last_pid __P((int, int));-
256-
257static int set_new_line_discipline __P((int));-
258static int map_over_jobs __P((sh_job_map_func_t *, int, int));-
259static int job_last_stopped __P((int));-
260static int job_last_running __P((int));-
261static int most_recent_job_in_state __P((int, JOB_STATE));-
262static int find_job __P((pid_t, int, PROCESS **));-
263static int print_job __P((JOB *, int, int, int));-
264static int process_exit_status __P((WAIT));-
265static int process_exit_signal __P((WAIT));-
266static int set_job_status_and_cleanup __P((int));-
267-
268static WAIT job_signal_status __P((int));-
269static WAIT raw_job_exit_status __P((int));-
270-
271static void notify_of_job_status __P((void));-
272static void reset_job_indices __P((void));-
273static void cleanup_dead_jobs __P((void));-
274static int processes_in_job __P((int));-
275static void realloc_jobs_list __P((void));-
276static int compact_jobs_list __P((int));-
277static void add_process __P((char *, pid_t));-
278static void print_pipeline __P((PROCESS *, int, int, FILE *));-
279static void pretty_print_job __P((int, int, FILE *));-
280static void set_current_job __P((int));-
281static void reset_current __P((void));-
282static void set_job_running __P((int));-
283static void setjstatus __P((int));-
284static int maybe_give_terminal_to __P((pid_t, pid_t, int));-
285static void mark_all_jobs_as_dead __P((void));-
286static void mark_dead_jobs_as_notified __P((int));-
287static void restore_sigint_handler __P((void));-
288#if defined (PGRP_PIPE)-
289static void pipe_read __P((int *));-
290#endif-
291-
292/* Hash table manipulation */-
293-
294static ps_index_t *pshash_getbucket __P((pid_t));-
295static void pshash_delindex __P((ps_index_t));-
296-
297/* Saved background process status management */-
298static struct pidstat *bgp_add __P((pid_t, int));-
299static int bgp_delete __P((pid_t));-
300static void bgp_clear __P((void));-
301static int bgp_search __P((pid_t));-
302-
303static ps_index_t bgp_getindex __P((void));-
304static void bgp_resize __P((void)); /* XXX */-
305-
306#if defined (ARRAY_VARS)-
307static int *pstatuses; /* list of pipeline statuses */-
308static int statsize;-
309#endif-
310-
311/* Used to synchronize between wait_for and other functions and the SIGCHLD-
312 signal handler. */-
313static int sigchld;-
314static int queue_sigchld;-
315-
316#define QUEUE_SIGCHLD(os) (os) = sigchld, queue_sigchld++-
317-
318#define UNQUEUE_SIGCHLD(os) \-
319 do { \-
320 queue_sigchld--; \-
321 if (queue_sigchld == 0 && os != sigchld) \-
322 waitchld (-1, 0); \-
323 } while (0)-
324-
325static SigHandler *old_tstp, *old_ttou, *old_ttin;-
326static SigHandler *old_cont = (SigHandler *)SIG_DFL;-
327-
328/* A place to temporarily save the current pipeline. */-
329static struct pipeline_saver *saved_pipeline;-
330static int saved_already_making_children;-
331-
332/* Set this to non-zero whenever you don't want the jobs list to change at-
333 all: no jobs deleted and no status change notifications. This is used,-
334 for example, when executing SIGCHLD traps, which may run arbitrary-
335 commands. */-
336static int jobs_list_frozen;-
337-
338static char retcode_name_buffer[64];-
339-
340#if !defined (_POSIX_VERSION)-
341-
342/* These are definitions to map POSIX 1003.1 functions onto existing BSD-
343 library functions and system calls. */-
344#define setpgid(pid, pgrp) setpgrp (pid, pgrp)-
345#define tcsetpgrp(fd, pgrp) ioctl ((fd), TIOCSPGRP, &(pgrp))-
346-
347pid_t-
348tcgetpgrp (fd)-
349 int fd;-
350{-
351 pid_t pgrp;-
352-
353 /* ioctl will handle setting errno correctly. */-
354 if (ioctl (fd, TIOCGPGRP, &pgrp) < 0)-
355 return (-1);-
356 return (pgrp);-
357}-
358-
359#endif /* !_POSIX_VERSION */-
360-
361/* Initialize the global job stats structure and other bookkeeping variables */-
362void-
363init_job_stats ()-
364{-
365 js = zerojs;-
366}
executed 15 times by 1 test: end of block
Executed by:
  • Self test
15
367-
368/* Return the working directory for the current process. Unlike-
369 job_working_directory, this does not call malloc (), nor do any-
370 of the functions it calls. This is so that it can safely be called-
371 from a signal handler. */-
372static char *-
373current_working_directory ()-
374{-
375 char *dir;-
376 static char d[PATH_MAX];-
377-
378 dir = get_string_value ("PWD");-
379-
380 if (dir == 0 && the_current_working_directory && no_symbolic_links)
dir == 0Description
TRUEnever evaluated
FALSEevaluated 43 times by 1 test
Evaluated by:
  • Self test
the_current_working_directoryDescription
TRUEnever evaluated
FALSEnever evaluated
no_symbolic_linksDescription
TRUEnever evaluated
FALSEnever evaluated
0-43
381 dir = the_current_working_directory;
never executed: dir = the_current_working_directory;
0
382-
383 if (dir == 0)
dir == 0Description
TRUEnever evaluated
FALSEevaluated 43 times by 1 test
Evaluated by:
  • Self test
0-43
384 {-
385 dir = getcwd (d, sizeof(d));-
386 if (dir)
dirDescription
TRUEnever evaluated
FALSEnever evaluated
0
387 dir = d;
never executed: dir = d;
0
388 }
never executed: end of block
0
389-
390 return (dir == 0) ? "<unknown>" : dir;
executed 43 times by 1 test: return (dir == 0) ? "<unknown>" : dir;
Executed by:
  • Self test
43
391}-
392-
393/* Return the working directory for the current process. */-
394static char *-
395job_working_directory ()-
396{-
397 char *dir;-
398-
399 dir = get_string_value ("PWD");-
400 if (dir)
dirDescription
TRUEevaluated 42789 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-42789
401 return (savestring (dir));
executed 42789 times by 1 test: return ((char *)strcpy (sh_xmalloc((1 + strlen (dir)), "jobs.c", 401), (dir)));
Executed by:
  • Self test
42789
402-
403 dir = get_working_directory ("job-working-directory");-
404 if (dir)
dirDescription
TRUEnever evaluated
FALSEnever evaluated
0
405 return (dir);
never executed: return (dir);
0
406-
407 return (savestring ("<unknown>"));
never executed: return ((char *)strcpy (sh_xmalloc((1 + strlen ("<unknown>")), "jobs.c", 407), ("<unknown>")));
0
408}-
409-
410void-
411making_children ()-
412{-
413 if (already_making_children)
already_making_childrenDescription
TRUEevaluated 13225 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3980638 times by 1 test
Evaluated by:
  • Self test
13225-3980638
414 return;
executed 13225 times by 1 test: return;
Executed by:
  • Self test
13225
415-
416 already_making_children = 1;-
417 start_pipeline ();-
418}
executed 3980638 times by 1 test: end of block
Executed by:
  • Self test
3980638
419-
420void-
421stop_making_children ()-
422{-
423 already_making_children = 0;-
424}
executed 3982674 times by 1 test: end of block
Executed by:
  • Self test
3982674
425-
426void-
427cleanup_the_pipeline ()-
428{-
429 PROCESS *disposer;-
430 sigset_t set, oset;-
431-
432 BLOCK_CHILD (set, oset);-
433 disposer = the_pipeline;-
434 the_pipeline = (PROCESS *)NULL;-
435 UNBLOCK_CHILD (oset);-
436-
437 if (disposer)
disposerDescription
TRUEevaluated 3253108 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6845 times by 1 test
Evaluated by:
  • Self test
6845-3253108
438 discard_pipeline (disposer);
executed 3253108 times by 1 test: discard_pipeline (disposer);
Executed by:
  • Self test
3253108
439}
executed 3259953 times by 1 test: end of block
Executed by:
  • Self test
3259953
440-
441void-
442discard_last_procsub_child ()-
443{-
444 PROCESS *disposer;-
445 sigset_t set, oset;-
446-
447 BLOCK_CHILD (set, oset);-
448 disposer = last_procsub_child;-
449 last_procsub_child = (PROCESS *)NULL;-
450 UNBLOCK_CHILD (oset);-
451-
452 if (disposer)
disposerDescription
TRUEevaluated 220153 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-220153
453 discard_pipeline (disposer);
executed 220153 times by 1 test: discard_pipeline (disposer);
Executed by:
  • Self test
220153
454}
executed 220153 times by 1 test: end of block
Executed by:
  • Self test
220153
455-
456struct pipeline_saver *-
457alloc_pipeline_saver ()-
458{-
459 struct pipeline_saver *ret;-
460-
461 ret = (struct pipeline_saver *)xmalloc (sizeof (struct pipeline_saver));-
462 ret->pipeline = 0;-
463 ret->next = 0;-
464 return ret;
executed 681117 times by 1 test: return ret;
Executed by:
  • Self test
681117
465}-
466-
467void-
468save_pipeline (clear)-
469 int clear;-
470{-
471 sigset_t set, oset;-
472 struct pipeline_saver *saver;-
473-
474 BLOCK_CHILD (set, oset);-
475 saver = alloc_pipeline_saver ();-
476 saver->pipeline = the_pipeline;-
477 saver->next = saved_pipeline;-
478 saved_pipeline = saver;-
479 if (clear)
clearDescription
TRUEevaluated 681117 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-681117
480 the_pipeline = (PROCESS *)NULL;
executed 681117 times by 1 test: the_pipeline = (PROCESS *) ((void *)0) ;
Executed by:
  • Self test
681117
481 saved_already_making_children = already_making_children;-
482 UNBLOCK_CHILD (oset);-
483}
executed 681117 times by 1 test: end of block
Executed by:
  • Self test
681117
484-
485PROCESS *-
486restore_pipeline (discard)-
487 int discard;-
488{-
489 PROCESS *old_pipeline;-
490 sigset_t set, oset;-
491 struct pipeline_saver *saver;-
492-
493 BLOCK_CHILD (set, oset);-
494 old_pipeline = the_pipeline;-
495 the_pipeline = saved_pipeline->pipeline;-
496 saver = saved_pipeline;-
497 saved_pipeline = saved_pipeline->next;-
498 free (saver);-
499 already_making_children = saved_already_making_children;-
500 UNBLOCK_CHILD (oset);-
501-
502 if (discard && old_pipeline)
discardDescription
TRUEevaluated 2073 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 677660 times by 1 test
Evaluated by:
  • Self test
old_pipelineDescription
TRUEnever evaluated
FALSEevaluated 2073 times by 1 test
Evaluated by:
  • Self test
0-677660
503 {-
504 discard_pipeline (old_pipeline);-
505 return ((PROCESS *)NULL);
never executed: return ((PROCESS *) ((void *)0) );
0
506 }-
507 return old_pipeline;
executed 679733 times by 1 test: return old_pipeline;
Executed by:
  • Self test
679733
508}-
509-
510/* Start building a pipeline. */-
511void-
512start_pipeline ()-
513{-
514 if (the_pipeline)
the_pipelineDescription
TRUEevaluated 3428 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3979468 times by 1 test
Evaluated by:
  • Self test
3428-3979468
515 {-
516 cleanup_the_pipeline ();-
517 pipeline_pgrp = 0;-
518#if defined (PGRP_PIPE)-
519 sh_closepipe (pgrp_pipe);-
520#endif-
521 }
executed 3428 times by 1 test: end of block
Executed by:
  • Self test
3428
522-
523#if defined (PGRP_PIPE)-
524 if (job_control)
job_controlDescription
TRUEevaluated 55 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3982841 times by 1 test
Evaluated by:
  • Self test
55-3982841
525 {-
526 if (pipe (pgrp_pipe) == -1)
pipe (pgrp_pipe) == -1Description
TRUEnever evaluated
FALSEevaluated 55 times by 1 test
Evaluated by:
  • Self test
0-55
527 sys_error (_("start_pipeline: pgrp pipe"));
never executed: sys_error ( dcgettext (((void *)0), "start_pipeline: pgrp pipe" , 5) );
0
528 }
executed 55 times by 1 test: end of block
Executed by:
  • Self test
55
529#endif-
530}
executed 3982896 times by 1 test: end of block
Executed by:
  • Self test
3982896
531-
532/* Stop building a pipeline. Install the process list in the job array.-
533 This returns the index of the newly installed job.-
534 DEFERRED is a command structure to be executed upon satisfactory-
535 execution exit of this pipeline. */-
536int-
537stop_pipeline (async, deferred)-
538 int async;-
539 COMMAND *deferred;-
540{-
541 register int i, j;-
542 JOB *newjob;-
543 sigset_t set, oset;-
544-
545 BLOCK_CHILD (set, oset);-
546-
547#if defined (PGRP_PIPE)-
548 /* The parent closes the process group synchronization pipe. */-
549 sh_closepipe (pgrp_pipe);-
550#endif-
551-
552 cleanup_dead_jobs ();-
553-
554 if (js.j_jobslots == 0)
js.j_jobslots == 0Description
TRUEevaluated 4761 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 38125 times by 1 test
Evaluated by:
  • Self test
4761-38125
555 {-
556 js.j_jobslots = JOB_SLOTS;-
557 jobs = (JOB **)xmalloc (js.j_jobslots * sizeof (JOB *));-
558-
559 /* Now blank out these new entries. */-
560 for (i = 0; i < js.j_jobslots; i++)
i < js.j_jobslotsDescription
TRUEevaluated 38088 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4761 times by 1 test
Evaluated by:
  • Self test
4761-38088
561 jobs[i] = (JOB *)NULL;
executed 38088 times by 1 test: jobs[i] = (JOB *) ((void *)0) ;
Executed by:
  • Self test
38088
562-
563 js.j_firstj = js.j_lastj = js.j_njobs = 0;-
564 }
executed 4761 times by 1 test: end of block
Executed by:
  • Self test
4761
565-
566 /* Scan from the last slot backward, looking for the next free one. */-
567 /* XXX - revisit this interactive assumption */-
568 /* XXX - this way for now */-
569 if (interactive)
interactiveDescription
TRUEnever evaluated
FALSEevaluated 42886 times by 1 test
Evaluated by:
  • Self test
0-42886
570 {-
571 for (i = js.j_jobslots; i; i--)
iDescription
TRUEnever evaluated
FALSEnever evaluated
0
572 if (jobs[i - 1])
jobs[i - 1]Description
TRUEnever evaluated
FALSEnever evaluated
0
573 break;
never executed: break;
0
574 }
never executed: end of block
0
575 else-
576 {-
577#if 0-
578 /* This wraps around, but makes it inconvenient to extend the array */-
579 for (i = js.j_lastj+1; i != js.j_lastj; i++)-
580 {-
581 if (i >= js.j_jobslots)-
582 i = 0;-
583 if (jobs[i] == 0)-
584 break;-
585 } -
586 if (i == js.j_lastj)-
587 i = js.j_jobslots;-
588#else-
589 /* This doesn't wrap around yet. */-
590 for (i = js.j_lastj ? js.j_lastj + 1 : js.j_lastj; i < js.j_jobslots; i++)
i < js.j_jobslotsDescription
TRUEevaluated 42959 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-42959
591 if (jobs[i] == 0)
jobs[i] == 0Description
TRUEevaluated 42886 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 73 times by 1 test
Evaluated by:
  • Self test
73-42886
592 break;
executed 42886 times by 1 test: break;
Executed by:
  • Self test
42886
593#endif-
594 }
executed 42886 times by 1 test: end of block
Executed by:
  • Self test
42886
595-
596 /* Do we need more room? */-
597-
598 /* First try compaction */-
599 if ((interactive_shell == 0 || subshell_environment) && i == js.j_jobslots && js.j_jobslots >= MAX_JOBS_IN_ARRAY)
interactive_shell == 0Description
TRUEevaluated 42885 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
subshell_environmentDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
i == js.j_jobslotsDescription
TRUEnever evaluated
FALSEevaluated 42886 times by 1 test
Evaluated by:
  • Self test
js.j_jobslots >= 128Description
TRUEnever evaluated
FALSEnever evaluated
0-42886
600 i = compact_jobs_list (0);
never executed: i = compact_jobs_list (0);
0
601-
602 /* If we can't compact, reallocate */-
603 if (i == js.j_jobslots)
i == js.j_jobslotsDescription
TRUEnever evaluated
FALSEevaluated 42886 times by 1 test
Evaluated by:
  • Self test
0-42886
604 {-
605 js.j_jobslots += JOB_SLOTS;-
606 jobs = (JOB **)xrealloc (jobs, (js.j_jobslots * sizeof (JOB *)));-
607-
608 for (j = i; j < js.j_jobslots; j++)
j < js.j_jobslotsDescription
TRUEnever evaluated
FALSEnever evaluated
0
609 jobs[j] = (JOB *)NULL;
never executed: jobs[j] = (JOB *) ((void *)0) ;
0
610 }
never executed: end of block
0
611-
612 /* Add the current pipeline to the job list. */-
613 if (the_pipeline)
the_pipelineDescription
TRUEevaluated 42789 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 97 times by 1 test
Evaluated by:
  • Self test
97-42789
614 {-
615 register PROCESS *p;-
616 int any_running, any_stopped, n;-
617-
618 newjob = (JOB *)xmalloc (sizeof (JOB));-
619-
620 for (n = 1, p = the_pipeline; p->next != the_pipeline; n++, p = p->next)
p->next != the_pipelineDescription
TRUEevaluated 12247 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 42789 times by 1 test
Evaluated by:
  • Self test
12247-42789
621 ;
executed 12247 times by 1 test: ;
Executed by:
  • Self test
12247
622 p->next = (PROCESS *)NULL;-
623 newjob->pipe = REVERSE_LIST (the_pipeline, PROCESS *);
the_pipelineDescription
TRUEevaluated 42789 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
the_pipeline->nextDescription
TRUEevaluated 11969 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 30820 times by 1 test
Evaluated by:
  • Self test
0-42789
624 for (p = newjob->pipe; p->next; p = p->next)
p->nextDescription
TRUEevaluated 12247 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 42789 times by 1 test
Evaluated by:
  • Self test
12247-42789
625 ;
executed 12247 times by 1 test: ;
Executed by:
  • Self test
12247
626 p->next = newjob->pipe;-
627-
628 the_pipeline = (PROCESS *)NULL;-
629 newjob->pgrp = pipeline_pgrp;-
630 pipeline_pgrp = 0;-
631-
632 newjob->flags = 0;-
633-
634 /* Flag to see if in another pgrp. */-
635 if (job_control)
job_controlDescription
TRUEevaluated 45 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 42744 times by 1 test
Evaluated by:
  • Self test
45-42744
636 newjob->flags |= J_JOBCONTROL;
executed 45 times by 1 test: newjob->flags |= 0x04;
Executed by:
  • Self test
45
637-
638 /* Set the state of this pipeline. */-
639 p = newjob->pipe;-
640 any_running = any_stopped = 0;-
641 do-
642 {-
643 any_running |= PRUNNING (p);-
644 any_stopped |= PSTOPPED (p);-
645 p = p->next;-
646 }
executed 55036 times by 1 test: end of block
Executed by:
  • Self test
55036
647 while (p != newjob->pipe);
p != newjob->pipeDescription
TRUEevaluated 12247 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 42789 times by 1 test
Evaluated by:
  • Self test
12247-42789
648-
649 newjob->state = any_running ? JRUNNING : (any_stopped ? JSTOPPED : JDEAD);
any_runningDescription
TRUEevaluated 42786 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
any_stoppedDescription
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
0-42786
650 newjob->wd = job_working_directory ();-
651 newjob->deferred = deferred;-
652-
653 newjob->j_cleanup = (sh_vptrfunc_t *)NULL;-
654 newjob->cleanarg = (PTR_T) NULL;-
655-
656 jobs[i] = newjob;-
657 if (newjob->state == JDEAD && (newjob->flags & J_FOREGROUND))
newjob->state == JDEADDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 42786 times by 1 test
Evaluated by:
  • Self test
(newjob->flags & 0x01)Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
0-42786
658 setjstatus (i);
never executed: setjstatus (i);
0
659 if (newjob->state == JDEAD)
newjob->state == JDEADDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 42786 times by 1 test
Evaluated by:
  • Self test
3-42786
660 {-
661 js.c_reaped += n; /* wouldn't have been done since this was not part of a job */-
662 js.j_ndead++;-
663 }
executed 3 times by 1 test: end of block
Executed by:
  • Self test
3
664 js.c_injobs += n;-
665-
666 js.j_lastj = i;-
667 js.j_njobs++;-
668 }
executed 42789 times by 1 test: end of block
Executed by:
  • Self test
42789
669 else-
670 newjob = (JOB *)NULL;
executed 97 times by 1 test: newjob = (JOB *) ((void *)0) ;
Executed by:
  • Self test
97
671-
672 if (newjob)
newjobDescription
TRUEevaluated 42789 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 97 times by 1 test
Evaluated by:
  • Self test
97-42789
673 js.j_lastmade = newjob;
executed 42789 times by 1 test: js.j_lastmade = newjob;
Executed by:
  • Self test
42789
674-
675 if (async)
asyncDescription
TRUEevaluated 217 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 42669 times by 1 test
Evaluated by:
  • Self test
217-42669
676 {-
677 if (newjob)
newjobDescription
TRUEevaluated 216 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-216
678 {-
679 newjob->flags &= ~J_FOREGROUND;-
680 newjob->flags |= J_ASYNC;-
681 js.j_lastasync = newjob;-
682 }
executed 216 times by 1 test: end of block
Executed by:
  • Self test
216
683 reset_current ();-
684 }
executed 217 times by 1 test: end of block
Executed by:
  • Self test
217
685 else-
686 {-
687 if (newjob)
newjobDescription
TRUEevaluated 42573 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 96 times by 1 test
Evaluated by:
  • Self test
96-42573
688 {-
689 newjob->flags |= J_FOREGROUND;-
690 /*-
691 * !!!!! NOTE !!!!! (chet@ins.cwru.edu)-
692 *-
693 * The currently-accepted job control wisdom says to set the-
694 * terminal's process group n+1 times in an n-step pipeline:-
695 * once in the parent and once in each child. This is where-
696 * the parent gives it away.-
697 *-
698 * Don't give the terminal away if this shell is an asynchronous-
699 * subshell or if we're a (presumably non-interactive) shell running-
700 * in the background.-
701 *-
702 */-
703 if (job_control && newjob->pgrp && (subshell_environment&SUBSHELL_ASYNC) == 0 && running_in_background == 0)
job_controlDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 42568 times by 1 test
Evaluated by:
  • Self test
newjob->pgrpDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(subshell_envi...ent&0x01) == 0Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
running_in_background == 0Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
0-42568
704 maybe_give_terminal_to (shell_pgrp, newjob->pgrp, 0);
never executed: maybe_give_terminal_to (shell_pgrp, newjob->pgrp, 0);
0
705 }
executed 42573 times by 1 test: end of block
Executed by:
  • Self test
42573
706 }
executed 42669 times by 1 test: end of block
Executed by:
  • Self test
42669
707-
708 stop_making_children ();-
709 UNBLOCK_CHILD (oset);-
710 return (newjob ? i : js.j_current);
executed 42886 times by 1 test: return (newjob ? i : js.j_current);
Executed by:
  • Self test
42886
711}-
712-
713/* Functions to manage the list of exited background pids whose status has-
714 been saved.-
715-
716 pidstat_table:-
717-
718 The current implementation is a hash table using a single (separate) arena-
719 for storage that can be allocated and freed as a unit. The size of the hash-
720 table is a multiple of PIDSTAT_TABLE_SZ (4096) and multiple PIDs that hash-
721 to the same value are chained through the bucket_next and bucket_prev-
722 pointers (basically coalesced hashing for collision resolution).-
723-
724 bgpids.storage:-
725-
726 All pid/status storage is done using the circular buffer bgpids.storage.-
727 This must contain at least js.c_childmax entries. The circular buffer is-
728 used to supply the ordered list Posix requires ("the last CHILD_MAX-
729 processes"). To avoid searching the entire storage table for a given PID,-
730 the hash table (pidstat_table) holds pointers into the storage arena and-
731 uses a doubly-linked list of cells (bucket_next/bucket_prev, also pointers-
732 into the arena) to implement collision resolution. */-
733-
734/* The number of elements in bgpids.storage always has to be > js.c_childmax for-
735 the circular buffer to work right. */-
736static void-
737bgp_resize ()-
738{-
739 ps_index_t nsize, nsize_cur, nsize_max;-
740 ps_index_t psi;-
741-
742 if (bgpids.nalloc == 0)
bgpids.nalloc == 0Description
TRUEevaluated 1293 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1293
743 {-
744 /* invalidate hash table when bgpids table is reallocated */-
745 for (psi = 0; psi < PIDSTAT_TABLE_SZ; psi++)
psi < 4096Description
TRUEevaluated 5296128 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1293 times by 1 test
Evaluated by:
  • Self test
1293-5296128
746 pidstat_table[psi] = NO_PIDSTAT;
executed 5296128 times by 1 test: pidstat_table[psi] = (ps_index_t)-1;
Executed by:
  • Self test
5296128
747 nsize = BGPIDS_TABLE_SZ; /* should be power of 2 */-
748 bgpids.head = 0;-
749 }
executed 1293 times by 1 test: end of block
Executed by:
  • Self test
1293
750 else-
751 nsize = bgpids.nalloc;
never executed: nsize = bgpids.nalloc;
0
752-
753 nsize_max = TYPE_MAXIMUM (ps_index_t);-
754 nsize_cur = (ps_index_t)js.c_childmax;-
755 if (nsize_cur < 0) /* overflow */
nsize_cur < 0Description
TRUEnever evaluated
FALSEevaluated 1293 times by 1 test
Evaluated by:
  • Self test
0-1293
756 nsize_cur = MAX_CHILD_MAX;
never executed: nsize_cur = 32768;
0
757-
758 while (nsize > 0 && nsize < nsize_cur) /* > 0 should catch overflow */
nsize > 0Description
TRUEevaluated 7758 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
nsize < nsize_curDescription
TRUEevaluated 6465 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1293 times by 1 test
Evaluated by:
  • Self test
0-7758
759 nsize <<= 1;
executed 6465 times by 1 test: nsize <<= 1;
Executed by:
  • Self test
6465
760 if (nsize > nsize_max || nsize <= 0) /* overflow? */
nsize > nsize_maxDescription
TRUEnever evaluated
FALSEevaluated 1293 times by 1 test
Evaluated by:
  • Self test
nsize <= 0Description
TRUEnever evaluated
FALSEevaluated 1293 times by 1 test
Evaluated by:
  • Self test
0-1293
761 nsize = nsize_max;
never executed: nsize = nsize_max;
0
762 if (nsize > MAX_CHILD_MAX)
nsize > 32768Description
TRUEnever evaluated
FALSEevaluated 1293 times by 1 test
Evaluated by:
  • Self test
0-1293
763 nsize = nsize_max = MAX_CHILD_MAX; /* hard cap */
never executed: nsize = nsize_max = 32768;
0
764-
765 if (bgpids.nalloc < nsize_cur && bgpids.nalloc < nsize_max)
bgpids.nalloc < nsize_curDescription
TRUEevaluated 1293 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
bgpids.nalloc < nsize_maxDescription
TRUEevaluated 1293 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1293
766 {-
767 bgpids.storage = (struct pidstat *)xrealloc (bgpids.storage, nsize * sizeof (struct pidstat));-
768-
769 for (psi = bgpids.nalloc; psi < nsize; psi++)
psi < nsizeDescription
TRUEevaluated 21184512 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1293 times by 1 test
Evaluated by:
  • Self test
1293-21184512
770 bgpids.storage[psi].pid = NO_PID;
executed 21184512 times by 1 test: bgpids.storage[psi].pid = (pid_t)-1;
Executed by:
  • Self test
21184512
771-
772 bgpids.nalloc = nsize;-
773-
774 }
executed 1293 times by 1 test: end of block
Executed by:
  • Self test
1293
775 else if (bgpids.head >= bgpids.nalloc) /* wrap around */
bgpids.head >= bgpids.nallocDescription
TRUEnever evaluated
FALSEnever evaluated
0
776 bgpids.head = 0;
never executed: bgpids.head = 0;
0
777}
executed 1293 times by 1 test: end of block
Executed by:
  • Self test
1293
778-
779static ps_index_t-
780bgp_getindex ()-
781{-
782 if (bgpids.nalloc < (ps_index_t)js.c_childmax || bgpids.head >= bgpids.nalloc)
bgpids.nalloc ...)js.c_childmaxDescription
TRUEevaluated 1293 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 455793 times by 1 test
Evaluated by:
  • Self test
bgpids.head >= bgpids.nallocDescription
TRUEnever evaluated
FALSEevaluated 455793 times by 1 test
Evaluated by:
  • Self test
0-455793
783 bgp_resize ();
executed 1293 times by 1 test: bgp_resize ();
Executed by:
  • Self test
1293
784-
785 pshash_delindex (bgpids.head); /* XXX - clear before reusing */-
786 return bgpids.head++;
executed 457086 times by 1 test: return bgpids.head++;
Executed by:
  • Self test
457086
787}-
788-
789static ps_index_t *-
790pshash_getbucket (pid)-
791 pid_t pid;-
792{-
793 unsigned long hash; /* XXX - u_bits32_t */-
794-
795 hash = pid * 0x9e370001UL;-
796 return (&pidstat_table[hash % PIDSTAT_TABLE_SZ]);
executed 1133627 times by 1 test: return (&pidstat_table[hash % 4096]);
Executed by:
  • Self test
1133627
797}-
798-
799static struct pidstat *-
800bgp_add (pid, status)-
801 pid_t pid;-
802 int status;-
803{-
804 ps_index_t *bucket, psi;-
805 struct pidstat *ps;-
806-
807 /* bucket == existing chain of pids hashing to same value-
808 psi = where were going to put this pid/status */-
809-
810 bucket = pshash_getbucket (pid); /* index into pidstat_table */-
811 psi = bgp_getindex (); /* bgpids.head, index into storage */-
812-
813 /* XXX - what if psi == *bucket? */-
814 if (psi == *bucket)
psi == *bucketDescription
TRUEnever evaluated
FALSEevaluated 457086 times by 1 test
Evaluated by:
  • Self test
0-457086
815 {-
816#ifdef DEBUG-
817 internal_warning ("hashed pid %d (pid %d) collides with bgpids.head, skipping", psi, pid);-
818#endif-
819 bgpids.storage[psi].pid = NO_PID; /* make sure */-
820 psi = bgp_getindex (); /* skip to next one */-
821 }
never executed: end of block
0
822-
823 ps = &bgpids.storage[psi];-
824-
825 ps->pid = pid;-
826 ps->status = status;-
827 ps->bucket_next = *bucket;-
828 ps->bucket_prev = NO_PIDSTAT;-
829-
830 bgpids.npid++;-
831-
832#if 0-
833 if (bgpids.npid > js.c_childmax)-
834 bgp_prune ();-
835#endif-
836-
837 if (ps->bucket_next != NO_PIDSTAT)
ps->bucket_nex...(ps_index_t)-1Description
TRUEnever evaluated
FALSEevaluated 457086 times by 1 test
Evaluated by:
  • Self test
0-457086
838 bgpids.storage[ps->bucket_next].bucket_prev = psi;
never executed: bgpids.storage[ps->bucket_next].bucket_prev = psi;
0
839-
840 *bucket = psi; /* set chain head in hash table */-
841-
842 return ps;
executed 457086 times by 1 test: return ps;
Executed by:
  • Self test
457086
843}-
844-
845static void-
846pshash_delindex (psi)-
847 ps_index_t psi;-
848{-
849 struct pidstat *ps;-
850 ps_index_t *bucket;-
851-
852 ps = &bgpids.storage[psi];-
853 if (ps->pid == NO_PID)
ps->pid == (pid_t)-1Description
TRUEevaluated 457086 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-457086
854 return;
executed 457086 times by 1 test: return;
Executed by:
  • Self test
457086
855-
856 if (ps->bucket_next != NO_PIDSTAT)
ps->bucket_nex...(ps_index_t)-1Description
TRUEnever evaluated
FALSEnever evaluated
0
857 bgpids.storage[ps->bucket_next].bucket_prev = ps->bucket_prev;
never executed: bgpids.storage[ps->bucket_next].bucket_prev = ps->bucket_prev;
0
858 if (ps->bucket_prev != NO_PIDSTAT)
ps->bucket_pre...(ps_index_t)-1Description
TRUEnever evaluated
FALSEnever evaluated
0
859 bgpids.storage[ps->bucket_prev].bucket_next = ps->bucket_next;
never executed: bgpids.storage[ps->bucket_prev].bucket_next = ps->bucket_next;
0
860 else-
861 {-
862 bucket = pshash_getbucket (ps->pid);-
863 *bucket = ps->bucket_next; /* deleting chain head in hash table */-
864 }
never executed: end of block
0
865-
866 /* clear out this cell, just in case */-
867 ps->pid = NO_PID;-
868 ps->bucket_next = ps->bucket_prev = NO_PIDSTAT;-
869}
never executed: end of block
0
870-
871static int-
872bgp_delete (pid)-
873 pid_t pid;-
874{-
875 ps_index_t psi, orig_psi;-
876-
877 if (bgpids.storage == 0 || bgpids.nalloc == 0 || bgpids.npid == 0)
bgpids.storage == 0Description
TRUEevaluated 3310699 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 676540 times by 1 test
Evaluated by:
  • Self test
bgpids.nalloc == 0Description
TRUEnever evaluated
FALSEevaluated 676540 times by 1 test
Evaluated by:
  • Self test
bgpids.npid == 0Description
TRUEnever evaluated
FALSEevaluated 676540 times by 1 test
Evaluated by:
  • Self test
0-3310699
878 return 0;
executed 3310699 times by 1 test: return 0;
Executed by:
  • Self test
3310699
879-
880 /* Search chain using hash to find bucket in pidstat_table */-
881 for (orig_psi = psi = *(pshash_getbucket (pid)); psi != NO_PIDSTAT; psi = bgpids.storage[psi].bucket_next)
psi != (ps_index_t)-1Description
TRUEnever evaluated
FALSEevaluated 676540 times by 1 test
Evaluated by:
  • Self test
0-676540
882 {-
883 if (bgpids.storage[psi].pid == pid)
bgpids.storage[psi].pid == pidDescription
TRUEnever evaluated
FALSEnever evaluated
0
884 break;
never executed: break;
0
885 if (orig_psi == bgpids.storage[psi].bucket_next) /* catch reported bug */
orig_psi == bg...i].bucket_nextDescription
TRUEnever evaluated
FALSEnever evaluated
0
886 {-
887 internal_warning ("bgp_delete: LOOP: psi (%d) == storage[psi].bucket_next", psi);-
888 return 0;
never executed: return 0;
0
889 }-
890 }
never executed: end of block
0
891-
892 if (psi == NO_PIDSTAT)
psi == (ps_index_t)-1Description
TRUEevaluated 676540 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-676540
893 return 0; /* not found */
executed 676540 times by 1 test: return 0;
Executed by:
  • Self test
676540
894-
895#if defined (DEBUG)-
896 itrace("bgp_delete: deleting %d", pid);-
897#endif-
898-
899 pshash_delindex (psi); /* hash table management */-
900-
901 bgpids.npid--;-
902 return 1;
never executed: return 1;
0
903}-
904-
905/* Clear out the list of saved statuses */-
906static void-
907bgp_clear ()-
908{-
909 if (bgpids.storage == 0 || bgpids.nalloc == 0)
bgpids.storage == 0Description
TRUEevaluated 2258 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 138 times by 1 test
Evaluated by:
  • Self test
bgpids.nalloc == 0Description
TRUEnever evaluated
FALSEevaluated 138 times by 1 test
Evaluated by:
  • Self test
0-2258
910 return;
executed 2258 times by 1 test: return;
Executed by:
  • Self test
2258
911-
912 free (bgpids.storage);-
913-
914 bgpids.storage = 0;-
915 bgpids.nalloc = 0;-
916 bgpids.head = 0;-
917-
918 bgpids.npid = 0;-
919}
executed 138 times by 1 test: end of block
Executed by:
  • Self test
138
920-
921/* Search for PID in the list of saved background pids; return its status if-
922 found. If not found, return -1. We hash to the right spot in pidstat_table-
923 and follow the bucket chain to the end. */-
924static int-
925bgp_search (pid)-
926 pid_t pid;-
927{-
928 ps_index_t psi, orig_psi;-
929-
930 if (bgpids.storage == 0 || bgpids.nalloc == 0 || bgpids.npid == 0)
bgpids.storage == 0Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
bgpids.nalloc == 0Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
bgpids.npid == 0Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
0-12
931 return -1;
executed 12 times by 1 test: return -1;
Executed by:
  • Self test
12
932-
933 /* Search chain using hash to find bucket in pidstat_table */-
934 for (orig_psi = psi = *(pshash_getbucket (pid)); psi != NO_PIDSTAT; psi = bgpids.storage[psi].bucket_next)
psi != (ps_index_t)-1Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1
935 {-
936 if (bgpids.storage[psi].pid == pid)
bgpids.storage[psi].pid == pidDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1
937 return (bgpids.storage[psi].status);
executed 1 time by 1 test: return (bgpids.storage[psi].status);
Executed by:
  • Self test
1
938 if (orig_psi == bgpids.storage[psi].bucket_next) /* catch reported bug */
orig_psi == bg...i].bucket_nextDescription
TRUEnever evaluated
FALSEnever evaluated
0
939 {-
940 internal_warning ("bgp_search: LOOP: psi (%d) == storage[psi].bucket_next", psi);-
941 return -1;
never executed: return -1;
0
942 }-
943 }
never executed: end of block
0
944-
945 return -1;
never executed: return -1;
0
946}-
947-
948#if 0-
949static void-
950bgp_prune ()-
951{-
952 return;-
953}-
954#endif-
955-
956/* Reset the values of js.j_lastj and js.j_firstj after one or both have-
957 been deleted. The caller should check whether js.j_njobs is 0 before-
958 calling this. This wraps around, but the rest of the code does not. At-
959 this point, it should not matter. */-
960static void-
961reset_job_indices ()-
962{-
963 int old;-
964-
965 if (jobs[js.j_firstj] == 0)
jobs[js.j_firstj] == 0Description
TRUEevaluated 101 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 34 times by 1 test
Evaluated by:
  • Self test
34-101
966 {-
967 old = js.j_firstj++;-
968 if (old >= js.j_jobslots)
old >= js.j_jobslotsDescription
TRUEnever evaluated
FALSEevaluated 101 times by 1 test
Evaluated by:
  • Self test
0-101
969 old = js.j_jobslots - 1;
never executed: old = js.j_jobslots - 1;
0
970 while (js.j_firstj != old)
js.j_firstj != oldDescription
TRUEevaluated 101 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-101
971 {-
972 if (js.j_firstj >= js.j_jobslots)
js.j_firstj >= js.j_jobslotsDescription
TRUEnever evaluated
FALSEevaluated 101 times by 1 test
Evaluated by:
  • Self test
0-101
973 js.j_firstj = 0;
never executed: js.j_firstj = 0;
0
974 if (jobs[js.j_firstj] || js.j_firstj == old) /* needed if old == 0 */
jobs[js.j_firstj]Description
TRUEevaluated 101 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
js.j_firstj == oldDescription
TRUEnever evaluated
FALSEnever evaluated
0-101
975 break;
executed 101 times by 1 test: break;
Executed by:
  • Self test
101
976 js.j_firstj++;-
977 }
never executed: end of block
0
978 if (js.j_firstj == old)
js.j_firstj == oldDescription
TRUEnever evaluated
FALSEevaluated 101 times by 1 test
Evaluated by:
  • Self test
0-101
979 js.j_firstj = js.j_lastj = js.j_njobs = 0;
never executed: js.j_firstj = js.j_lastj = js.j_njobs = 0;
0
980 }
executed 101 times by 1 test: end of block
Executed by:
  • Self test
101
981 if (jobs[js.j_lastj] == 0)
jobs[js.j_lastj] == 0Description
TRUEevaluated 34 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 101 times by 1 test
Evaluated by:
  • Self test
34-101
982 {-
983 old = js.j_lastj--;-
984 if (old < 0)
old < 0Description
TRUEnever evaluated
FALSEevaluated 34 times by 1 test
Evaluated by:
  • Self test
0-34
985 old = 0;
never executed: old = 0;
0
986 while (js.j_lastj != old)
js.j_lastj != oldDescription
TRUEevaluated 46 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-46
987 {-
988 if (js.j_lastj < 0)
js.j_lastj < 0Description
TRUEnever evaluated
FALSEevaluated 46 times by 1 test
Evaluated by:
  • Self test
0-46
989 js.j_lastj = js.j_jobslots - 1;
never executed: js.j_lastj = js.j_jobslots - 1;
0
990 if (jobs[js.j_lastj] || js.j_lastj == old) /* needed if old == js.j_jobslots */
jobs[js.j_lastj]Description
TRUEevaluated 34 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 12 times by 1 test
Evaluated by:
  • Self test
js.j_lastj == oldDescription
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • Self test
0-34
991 break;
executed 34 times by 1 test: break;
Executed by:
  • Self test
34
992 js.j_lastj--;-
993 }
executed 12 times by 1 test: end of block
Executed by:
  • Self test
12
994 if (js.j_lastj == old)
js.j_lastj == oldDescription
TRUEnever evaluated
FALSEevaluated 34 times by 1 test
Evaluated by:
  • Self test
0-34
995 js.j_firstj = js.j_lastj = js.j_njobs = 0;
never executed: js.j_firstj = js.j_lastj = js.j_njobs = 0;
0
996 }
executed 34 times by 1 test: end of block
Executed by:
  • Self test
34
997}
executed 135 times by 1 test: end of block
Executed by:
  • Self test
135
998 -
999/* Delete all DEAD jobs that the user had received notification about. */-
1000static void-
1001cleanup_dead_jobs ()-
1002{-
1003 register int i;-
1004 int os;-
1005 PROCESS *discard;-
1006-
1007 if (js.j_jobslots == 0 || jobs_list_frozen)
js.j_jobslots == 0Description
TRUEevaluated 250699 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 20809197 times by 1 test
Evaluated by:
  • Self test
jobs_list_frozenDescription
TRUEevaluated 319 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 20808878 times by 1 test
Evaluated by:
  • Self test
319-20809197
1008 return;
executed 251018 times by 1 test: return;
Executed by:
  • Self test
251018
1009-
1010 QUEUE_SIGCHLD(os);-
1011-
1012 /* XXX could use js.j_firstj and js.j_lastj here */-
1013 for (i = 0; i < js.j_jobslots; i++)
i < js.j_jobslotsDescription
TRUEevaluated 166471024 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 20808878 times by 1 test
Evaluated by:
  • Self test
20808878-166471024
1014 {-
1015#if defined (DEBUG)-
1016 if (i < js.j_firstj && jobs[i])
i < js.j_firstjDescription
TRUEevaluated 210 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 166470814 times by 1 test
Evaluated by:
  • Self test
jobs[i]Description
TRUEnever evaluated
FALSEevaluated 210 times by 1 test
Evaluated by:
  • Self test
0-166470814
1017 itrace("cleanup_dead_jobs: job %d non-null before js.j_firstj (%d)", i, js.j_firstj);
never executed: itrace("cleanup_dead_jobs: job %d non-null before js.j_firstj (%d)", i, js.j_firstj);
0
1018 if (i > js.j_lastj && jobs[i])
i > js.j_lastjDescription
TRUEevaluated 145456260 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21014764 times by 1 test
Evaluated by:
  • Self test
jobs[i]Description
TRUEnever evaluated
FALSEevaluated 145456260 times by 1 test
Evaluated by:
  • Self test
0-145456260
1019 itrace("cleanup_dead_jobs: job %d non-null after js.j_lastj (%d)", i, js.j_lastj);
never executed: itrace("cleanup_dead_jobs: job %d non-null after js.j_lastj (%d)", i, js.j_lastj);
0
1020#endif-
1021-
1022 if (jobs[i] && DEADJOB (i) && IS_NOTIFIED (i))
jobs[i]Description
TRUEevaluated 454092 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 166016932 times by 1 test
Evaluated by:
  • Self test
(jobs[(i)]->state == JDEAD)Description
TRUEevaluated 43120 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 410972 times by 1 test
Evaluated by:
  • Self test
((jobs[i]->flags & 0x02) != 0)Description
TRUEevaluated 42747 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 373 times by 1 test
Evaluated by:
  • Self test
373-166016932
1023 delete_job (i, 0);
executed 42747 times by 1 test: delete_job (i, 0);
Executed by:
  • Self test
42747
1024 }
executed 166471024 times by 1 test: end of block
Executed by:
  • Self test
166471024
1025-
1026#if defined (PROCESS_SUBSTITUTION)-
1027 if (last_procsub_child && last_procsub_child->running == PS_DONE)
last_procsub_childDescription
TRUEevaluated 1725473 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 19083405 times by 1 test
Evaluated by:
  • Self test
last_procsub_c...->running == 0Description
TRUEevaluated 456915 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1268558 times by 1 test
Evaluated by:
  • Self test
456915-19083405
1028 {-
1029 bgp_add (last_procsub_child->pid, process_exit_status (last_procsub_child->status)); /* XXX */-
1030 discard = last_procsub_child;-
1031 last_procsub_child = (PROCESS *)NULL;-
1032 discard_pipeline (discard);-
1033 }
executed 456915 times by 1 test: end of block
Executed by:
  • Self test
456915
1034#endif-
1035-
1036#if defined (COPROCESS_SUPPORT)-
1037 coproc_reap ();-
1038#endif-
1039-
1040 UNQUEUE_SIGCHLD(os);
never executed: waitchld (-1, 0);
queue_sigchld == 0Description
TRUEevaluated 20808878 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
os != sigchldDescription
TRUEnever evaluated
FALSEevaluated 20808878 times by 1 test
Evaluated by:
  • Self test
0-20808878
1041}
executed 20808878 times by 1 test: end of block
Executed by:
  • Self test
20808878
1042-
1043static int-
1044processes_in_job (job)-
1045 int job;-
1046{-
1047 int nproc;-
1048 register PROCESS *p;-
1049-
1050 nproc = 0;-
1051 p = jobs[job]->pipe;-
1052 do-
1053 {-
1054 p = p->next;-
1055 nproc++;-
1056 }
executed 148 times by 1 test: end of block
Executed by:
  • Self test
148
1057 while (p != jobs[job]->pipe);
p != jobs[job]->pipeDescription
TRUEevaluated 55 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 93 times by 1 test
Evaluated by:
  • Self test
55-93
1058-
1059 return nproc;
executed 93 times by 1 test: return nproc;
Executed by:
  • Self test
93
1060}-
1061-
1062static void-
1063delete_old_job (pid)-
1064 pid_t pid;-
1065{-
1066 PROCESS *p;-
1067 int job;-
1068-
1069 job = find_job (pid, 0, &p);-
1070 if (job != NO_JOB)
job != -1Description
TRUEnever evaluated
FALSEevaluated 3987239 times by 1 test
Evaluated by:
  • Self test
0-3987239
1071 {-
1072#ifdef DEBUG-
1073 itrace ("delete_old_job: found pid %d in job %d with state %d", pid, job, jobs[job]->state);-
1074#endif-
1075 if (JOBSTATE (job) == JDEAD)
(jobs[(job)]->state) == JDEADDescription
TRUEnever evaluated
FALSEnever evaluated
0
1076 delete_job (job, DEL_NOBGPID);
never executed: delete_job (job, 2);
0
1077 else-
1078 {-
1079#ifdef DEBUG-
1080 internal_warning (_("forked pid %d appears in running job %d"), pid, job+1);-
1081#endif-
1082 if (p)
pDescription
TRUEnever evaluated
FALSEnever evaluated
0
1083 p->pid = 0;
never executed: p->pid = 0;
0
1084 }
never executed: end of block
0
1085 }-
1086}
executed 3987239 times by 1 test: end of block
Executed by:
  • Self test
3987239
1087-
1088/* Reallocate and compress the jobs list. This returns with a jobs array-
1089 whose size is a multiple of JOB_SLOTS and can hold the current number of-
1090 jobs. Heuristics are used to minimize the number of new reallocs. */-
1091static void-
1092realloc_jobs_list ()-
1093{-
1094 sigset_t set, oset;-
1095 int nsize, i, j, ncur, nprev;-
1096 JOB **nlist;-
1097-
1098 ncur = nprev = NO_JOB;-
1099 nsize = ((js.j_njobs + JOB_SLOTS - 1) / JOB_SLOTS);-
1100 nsize *= JOB_SLOTS;-
1101 i = js.j_njobs % JOB_SLOTS;-
1102 if (i == 0 || i > (JOB_SLOTS >> 1))
i == 0Description
TRUEnever evaluated
FALSEnever evaluated
i > (8 >> 1)Description
TRUEnever evaluated
FALSEnever evaluated
0
1103 nsize += JOB_SLOTS;
never executed: nsize += 8;
0
1104-
1105 BLOCK_CHILD (set, oset);-
1106 nlist = (js.j_jobslots == nsize) ? jobs : (JOB **) xmalloc (nsize * sizeof (JOB *));
(js.j_jobslots == nsize)Description
TRUEnever evaluated
FALSEnever evaluated
0
1107-
1108 js.c_reaped = js.j_ndead = 0;-
1109 for (i = j = 0; i < js.j_jobslots; i++)
i < js.j_jobslotsDescription
TRUEnever evaluated
FALSEnever evaluated
0
1110 if (jobs[i])
jobs[i]Description
TRUEnever evaluated
FALSEnever evaluated
0
1111 {-
1112 if (i == js.j_current)
i == js.j_currentDescription
TRUEnever evaluated
FALSEnever evaluated
0
1113 ncur = j;
never executed: ncur = j;
0
1114 if (i == js.j_previous)
i == js.j_previousDescription
TRUEnever evaluated
FALSEnever evaluated
0
1115 nprev = j;
never executed: nprev = j;
0
1116 nlist[j++] = jobs[i];-
1117 if (jobs[i]->state == JDEAD)
jobs[i]->state == JDEADDescription
TRUEnever evaluated
FALSEnever evaluated
0
1118 {-
1119 js.j_ndead++;-
1120 js.c_reaped += processes_in_job (i);-
1121 }
never executed: end of block
0
1122 }
never executed: end of block
0
1123-
1124#if 0-
1125 itrace ("realloc_jobs_list: resize jobs list from %d to %d", js.j_jobslots, nsize);-
1126 itrace ("realloc_jobs_list: j_lastj changed from %d to %d", js.j_lastj, (j > 0) ? j - 1 : 0);-
1127 itrace ("realloc_jobs_list: j_njobs changed from %d to %d", js.j_njobs, j);-
1128 itrace ("realloc_jobs_list: js.j_ndead %d js.c_reaped %d", js.j_ndead, js.c_reaped);-
1129#endif-
1130-
1131 js.j_firstj = 0;-
1132 js.j_lastj = (j > 0) ? j - 1 : 0;
(j > 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
1133 js.j_njobs = j;-
1134 js.j_jobslots = nsize;-
1135-
1136 /* Zero out remaining slots in new jobs list */-
1137 for ( ; j < nsize; j++)
j < nsizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1138 nlist[j] = (JOB *)NULL;
never executed: nlist[j] = (JOB *) ((void *)0) ;
0
1139-
1140 if (jobs != nlist)
jobs != nlistDescription
TRUEnever evaluated
FALSEnever evaluated
0
1141 {-
1142 free (jobs);-
1143 jobs = nlist;-
1144 }
never executed: end of block
0
1145-
1146 if (ncur != NO_JOB)
ncur != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1147 js.j_current = ncur;
never executed: js.j_current = ncur;
0
1148 if (nprev != NO_JOB)
nprev != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1149 js.j_previous = nprev;
never executed: js.j_previous = nprev;
0
1150-
1151 /* Need to reset these */-
1152 if (js.j_current == NO_JOB || js.j_previous == NO_JOB || js.j_current > js.j_lastj || js.j_previous > js.j_lastj)
js.j_current == -1Description
TRUEnever evaluated
FALSEnever evaluated
js.j_previous == -1Description
TRUEnever evaluated
FALSEnever evaluated
js.j_current > js.j_lastjDescription
TRUEnever evaluated
FALSEnever evaluated
js.j_previous > js.j_lastjDescription
TRUEnever evaluated
FALSEnever evaluated
0
1153 reset_current ();
never executed: reset_current ();
0
1154-
1155#if 0-
1156 itrace ("realloc_jobs_list: reset js.j_current (%d) and js.j_previous (%d)", js.j_current, js.j_previous);-
1157#endif-
1158-
1159 UNBLOCK_CHILD (oset);-
1160}
never executed: end of block
0
1161-
1162/* Compact the jobs list by removing dead jobs. Assume that we have filled-
1163 the jobs array to some predefined maximum. Called when the shell is not-
1164 the foreground process (subshell_environment != 0). Returns the first-
1165 available slot in the compacted list. If that value is js.j_jobslots, then-
1166 the list needs to be reallocated. The jobs array may be in new memory if-
1167 this returns > 0 and < js.j_jobslots. FLAGS is reserved for future use. */-
1168static int-
1169compact_jobs_list (flags)-
1170 int flags;-
1171{-
1172 if (js.j_jobslots == 0 || jobs_list_frozen)
js.j_jobslots == 0Description
TRUEnever evaluated
FALSEnever evaluated
jobs_list_frozenDescription
TRUEnever evaluated
FALSEnever evaluated
0
1173 return js.j_jobslots;
never executed: return js.j_jobslots;
0
1174-
1175 reap_dead_jobs ();-
1176 realloc_jobs_list ();-
1177-
1178#if 0-
1179 itrace("compact_jobs_list: returning %d", (js.j_lastj || jobs[js.j_lastj]) ? js.j_lastj + 1 : 0);-
1180#endif-
1181-
1182 return ((js.j_lastj || jobs[js.j_lastj]) ? js.j_lastj + 1 : 0);
never executed: return ((js.j_lastj || jobs[js.j_lastj]) ? js.j_lastj + 1 : 0);
0
1183}-
1184-
1185/* Delete the job at INDEX from the job list. Must be called-
1186 with SIGCHLD blocked. */-
1187void-
1188delete_job (job_index, dflags)-
1189 int job_index, dflags;-
1190{-
1191 register JOB *temp;-
1192 PROCESS *proc;-
1193 int ndel;-
1194-
1195 if (js.j_jobslots == 0 || jobs_list_frozen)
js.j_jobslots == 0Description
TRUEnever evaluated
FALSEevaluated 42764 times by 1 test
Evaluated by:
  • Self test
jobs_list_frozenDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 42761 times by 1 test
Evaluated by:
  • Self test
0-42764
1196 return;
executed 3 times by 1 test: return;
Executed by:
  • Self test
3
1197-
1198 if ((dflags & DEL_WARNSTOPPED) && subshell_environment == 0 && STOPPED (job_index))
(dflags & 1)Description
TRUEevaluated 13 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 42748 times by 1 test
Evaluated by:
  • Self test
subshell_environment == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 12 times by 1 test
Evaluated by:
  • Self test
(jobs[(job_ind...e == JSTOPPED)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
0-42748
1199 internal_warning (_("deleting stopped job %d with process group %ld"), job_index+1, (long)jobs[job_index]->pgrp);
never executed: internal_warning ( dcgettext (((void *)0), "deleting stopped job %d with process group %ld" , 5) , job_index+1, (long)jobs[job_index]->pgrp);
0
1200 temp = jobs[job_index];-
1201 if (temp == 0)
temp == 0Description
TRUEnever evaluated
FALSEevaluated 42761 times by 1 test
Evaluated by:
  • Self test
0-42761
1202 return;
never executed: return;
0
1203-
1204 if ((dflags & DEL_NOBGPID) == 0 && (temp->flags & (J_ASYNC|J_FOREGROUND)) == J_ASYNC)
(dflags & 2) == 0Description
TRUEevaluated 42749 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 12 times by 1 test
Evaluated by:
  • Self test
(temp->flags &...0x01)) == 0x20Description
TRUEevaluated 171 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 42578 times by 1 test
Evaluated by:
  • Self test
12-42749
1205 {-
1206 proc = find_last_proc (job_index, 0);-
1207 if (proc)
procDescription
TRUEevaluated 171 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-171
1208 bgp_add (proc->pid, process_exit_status (proc->status));
executed 171 times by 1 test: bgp_add (proc->pid, process_exit_status (proc->status));
Executed by:
  • Self test
171
1209 }
executed 171 times by 1 test: end of block
Executed by:
  • Self test
171
1210-
1211 jobs[job_index] = (JOB *)NULL;-
1212 if (temp == js.j_lastmade)
temp == js.j_lastmadeDescription
TRUEevaluated 42639 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 122 times by 1 test
Evaluated by:
  • Self test
122-42639
1213 js.j_lastmade = 0;
executed 42639 times by 1 test: js.j_lastmade = 0;
Executed by:
  • Self test
42639
1214 else if (temp == js.j_lastasync)
temp == js.j_lastasyncDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 116 times by 1 test
Evaluated by:
  • Self test
6-116
1215 js.j_lastasync = 0;
executed 6 times by 1 test: js.j_lastasync = 0;
Executed by:
  • Self test
6
1216-
1217 free (temp->wd);-
1218 ndel = discard_pipeline (temp->pipe);-
1219-
1220 js.c_injobs -= ndel;-
1221 if (temp->state == JDEAD)
temp->state == JDEADDescription
TRUEevaluated 42749 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 12 times by 1 test
Evaluated by:
  • Self test
12-42749
1222 {-
1223 js.c_reaped -= ndel;-
1224 js.j_ndead--;-
1225 if (js.c_reaped < 0)
js.c_reaped < 0Description
TRUEnever evaluated
FALSEevaluated 42749 times by 1 test
Evaluated by:
  • Self test
0-42749
1226 {-
1227#ifdef DEBUG-
1228 itrace("delete_job (%d pgrp %d): js.c_reaped (%d) < 0 ndel = %d js.j_ndead = %d", job_index, temp->pgrp, js.c_reaped, ndel, js.j_ndead);-
1229#endif-
1230 js.c_reaped = 0;-
1231 }
never executed: end of block
0
1232 }
executed 42749 times by 1 test: end of block
Executed by:
  • Self test
42749
1233-
1234 if (temp->deferred)
temp->deferredDescription
TRUEnever evaluated
FALSEevaluated 42761 times by 1 test
Evaluated by:
  • Self test
0-42761
1235 dispose_command (temp->deferred);
never executed: dispose_command (temp->deferred);
0
1236-
1237 free (temp);-
1238-
1239 js.j_njobs--;-
1240 if (js.j_njobs == 0)
js.j_njobs == 0Description
TRUEevaluated 42613 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 148 times by 1 test
Evaluated by:
  • Self test
148-42613
1241 js.j_firstj = js.j_lastj = 0;
executed 42613 times by 1 test: js.j_firstj = js.j_lastj = 0;
Executed by:
  • Self test
42613
1242 else if (jobs[js.j_firstj] == 0 || jobs[js.j_lastj] == 0)
jobs[js.j_firstj] == 0Description
TRUEevaluated 101 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 47 times by 1 test
Evaluated by:
  • Self test
jobs[js.j_lastj] == 0Description
TRUEevaluated 34 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 13 times by 1 test
Evaluated by:
  • Self test
13-101
1243 reset_job_indices ();
executed 135 times by 1 test: reset_job_indices ();
Executed by:
  • Self test
135
1244-
1245 if (job_index == js.j_current || job_index == js.j_previous)
job_index == js.j_currentDescription
TRUEevaluated 150 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 42611 times by 1 test
Evaluated by:
  • Self test
job_index == js.j_previousDescription
TRUEevaluated 13 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 42598 times by 1 test
Evaluated by:
  • Self test
13-42611
1246 reset_current ();
executed 163 times by 1 test: reset_current ();
Executed by:
  • Self test
163
1247}
executed 42761 times by 1 test: end of block
Executed by:
  • Self test
42761
1248-
1249/* Must be called with SIGCHLD blocked. */-
1250void-
1251nohup_job (job_index)-
1252 int job_index;-
1253{-
1254 register JOB *temp;-
1255-
1256 if (js.j_jobslots == 0)
js.j_jobslots == 0Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
0-1
1257 return;
never executed: return;
0
1258-
1259 if (temp = jobs[job_index])
temp = jobs[job_index]Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1
1260 temp->flags |= J_NOHUP;
executed 1 time by 1 test: temp->flags |= 0x08;
Executed by:
  • Self test
1
1261}
executed 1 time by 1 test: end of block
Executed by:
  • Self test
1
1262-
1263/* Get rid of the data structure associated with a process chain. */-
1264int-
1265discard_pipeline (chain)-
1266 register PROCESS *chain;-
1267{-
1268 register PROCESS *this, *next;-
1269 int n;-
1270-
1271 this = chain;-
1272 n = 0;-
1273 do-
1274 {-
1275 next = this->next;-
1276 FREE (this->command);
executed 56105 times by 1 test: sh_xfree((this->command), "jobs.c", 1276);
Executed by:
  • Self test
this->commandDescription
TRUEevaluated 56105 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3929241 times by 1 test
Evaluated by:
  • Self test
56105-3929241
1277 free (this);-
1278 n++;-
1279 this = next;-
1280 }
executed 3985346 times by 1 test: end of block
Executed by:
  • Self test
3985346
1281 while (this != chain);
this != chainDescription
TRUEevaluated 12409 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3972937 times by 1 test
Evaluated by:
  • Self test
12409-3972937
1282-
1283 return n;
executed 3972937 times by 1 test: return n;
Executed by:
  • Self test
3972937
1284}-
1285-
1286/* Add this process to the chain being built in the_pipeline.-
1287 NAME is the command string that will be exec'ed later.-
1288 PID is the process id of the child. */-
1289static void-
1290add_process (name, pid)-
1291 char *name;-
1292 pid_t pid;-
1293{-
1294 PROCESS *t, *p;-
1295-
1296#if defined (RECYCLES_PIDS)-
1297 int j;-
1298 p = find_process (pid, 0, &j);-
1299 if (p)-
1300 {-
1301# ifdef DEBUG-
1302 if (j == NO_JOB)-
1303 internal_warning (_("add_process: process %5ld (%s) in the_pipeline"), (long)p->pid, p->command);-
1304# endif-
1305 if (PALIVE (p))-
1306 internal_warning (_("add_process: pid %5ld (%s) marked as still alive"), (long)p->pid, p->command);-
1307 p->running = PS_RECYCLED; /* mark as recycled */-
1308 }-
1309#endif-
1310-
1311 t = (PROCESS *)xmalloc (sizeof (PROCESS));-
1312 t->next = the_pipeline;-
1313 t->pid = pid;-
1314 WSTATUS (t->status) = 0;-
1315 t->running = PS_RUNNING;-
1316 t->command = name;-
1317 the_pipeline = t;-
1318-
1319 if (t->next == 0)
t->next == 0Description
TRUEevaluated 3974965 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 12274 times by 1 test
Evaluated by:
  • Self test
12274-3974965
1320 t->next = t;
executed 3974965 times by 1 test: t->next = t;
Executed by:
  • Self test
3974965
1321 else-
1322 {-
1323 p = t->next;-
1324 while (p->next != t->next)
p->next != t->nextDescription
TRUEevaluated 285 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 12274 times by 1 test
Evaluated by:
  • Self test
285-12274
1325 p = p->next;
executed 285 times by 1 test: p = p->next;
Executed by:
  • Self test
285
1326 p->next = t;-
1327 }
executed 12274 times by 1 test: end of block
Executed by:
  • Self test
12274
1328}-
1329-
1330/* Create a (dummy) PROCESS with NAME, PID, and STATUS, and make it the last-
1331 process in jobs[JID]->pipe. Used by the lastpipe code. */-
1332void-
1333append_process (name, pid, status, jid)-
1334 char *name;-
1335 pid_t pid;-
1336 int status;-
1337 int jid;-
1338{-
1339 PROCESS *t, *p;-
1340-
1341 t = (PROCESS *)xmalloc (sizeof (PROCESS));-
1342 t->next = (PROCESS *)NULL;-
1343 t->pid = pid;-
1344 /* set process exit status using offset discovered by configure */-
1345 t->status = (status & 0xff) << WEXITSTATUS_OFFSET;-
1346 t->running = PS_DONE;-
1347 t->command = name;-
1348-
1349 js.c_reaped++; /* XXX */-
1350-
1351 for (p = jobs[jid]->pipe; p->next != jobs[jid]->pipe; p = p->next)
p->next != jobs[jid]->pipeDescription
TRUEevaluated 13 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 136 times by 1 test
Evaluated by:
  • Self test
13-136
1352 ;
executed 13 times by 1 test: ;
Executed by:
  • Self test
13
1353 p->next = t;-
1354 t->next = jobs[jid]->pipe;-
1355}
executed 136 times by 1 test: end of block
Executed by:
  • Self test
136
1356-
1357#if 0-
1358/* Take the last job and make it the first job. Must be called with-
1359 SIGCHLD blocked. */-
1360int-
1361rotate_the_pipeline ()-
1362{-
1363 PROCESS *p;-
1364-
1365 if (the_pipeline->next == the_pipeline)-
1366 return;-
1367 for (p = the_pipeline; p->next != the_pipeline; p = p->next)-
1368 ;-
1369 the_pipeline = p;-
1370}-
1371-
1372/* Reverse the order of the processes in the_pipeline. Must be called with-
1373 SIGCHLD blocked. */-
1374int-
1375reverse_the_pipeline ()-
1376{-
1377 PROCESS *p, *n;-
1378-
1379 if (the_pipeline->next == the_pipeline)-
1380 return;-
1381-
1382 for (p = the_pipeline; p->next != the_pipeline; p = p->next)-
1383 ;-
1384 p->next = (PROCESS *)NULL;-
1385-
1386 n = REVERSE_LIST (the_pipeline, PROCESS *);-
1387-
1388 the_pipeline = n;-
1389 for (p = the_pipeline; p->next; p = p->next)-
1390 ;-
1391 p->next = the_pipeline;-
1392}-
1393#endif-
1394-
1395/* Map FUNC over the list of jobs. If FUNC returns non-zero,-
1396 then it is time to stop mapping, and that is the return value-
1397 for map_over_jobs. FUNC is called with a JOB, arg1, arg2,-
1398 and INDEX. */-
1399static int-
1400map_over_jobs (func, arg1, arg2)-
1401 sh_job_map_func_t *func;-
1402 int arg1, arg2;-
1403{-
1404 register int i;-
1405 int result;-
1406 sigset_t set, oset;-
1407-
1408 if (js.j_jobslots == 0)
js.j_jobslots == 0Description
TRUEnever evaluated
FALSEevaluated 14 times by 1 test
Evaluated by:
  • Self test
0-14
1409 return 0;
never executed: return 0;
0
1410-
1411 BLOCK_CHILD (set, oset);-
1412-
1413 /* XXX could use js.j_firstj here */-
1414 for (i = result = 0; i < js.j_jobslots; i++)
i < js.j_jobslotsDescription
TRUEevaluated 112 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 14 times by 1 test
Evaluated by:
  • Self test
14-112
1415 {-
1416#if defined (DEBUG)-
1417 if (i < js.j_firstj && jobs[i])
i < js.j_firstjDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 107 times by 1 test
Evaluated by:
  • Self test
jobs[i]Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
0-107
1418 itrace("map_over_jobs: job %d non-null before js.j_firstj (%d)", i, js.j_firstj);
never executed: itrace("map_over_jobs: job %d non-null before js.j_firstj (%d)", i, js.j_firstj);
0
1419 if (i > js.j_lastj && jobs[i])
i > js.j_lastjDescription
TRUEevaluated 74 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 38 times by 1 test
Evaluated by:
  • Self test
jobs[i]Description
TRUEnever evaluated
FALSEevaluated 74 times by 1 test
Evaluated by:
  • Self test
0-74
1420 itrace("map_over_jobs: job %d non-null after js.j_lastj (%d)", i, js.j_lastj);
never executed: itrace("map_over_jobs: job %d non-null after js.j_lastj (%d)", i, js.j_lastj);
0
1421#endif-
1422 if (jobs[i])
jobs[i]Description
TRUEevaluated 29 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 83 times by 1 test
Evaluated by:
  • Self test
29-83
1423 {-
1424 result = (*func)(jobs[i], arg1, arg2, i);-
1425 if (result)
resultDescription
TRUEnever evaluated
FALSEevaluated 29 times by 1 test
Evaluated by:
  • Self test
0-29
1426 break;
never executed: break;
0
1427 }
executed 29 times by 1 test: end of block
Executed by:
  • Self test
29
1428 }
executed 112 times by 1 test: end of block
Executed by:
  • Self test
112
1429-
1430 UNBLOCK_CHILD (oset);-
1431-
1432 return (result);
executed 14 times by 1 test: return (result);
Executed by:
  • Self test
14
1433}-
1434-
1435/* Cause all the jobs in the current pipeline to exit. */-
1436void-
1437terminate_current_pipeline ()-
1438{-
1439 if (pipeline_pgrp && pipeline_pgrp != shell_pgrp)
pipeline_pgrpDescription
TRUEnever evaluated
FALSEnever evaluated
pipeline_pgrp != shell_pgrpDescription
TRUEnever evaluated
FALSEnever evaluated
0
1440 {-
1441 killpg (pipeline_pgrp, SIGTERM);-
1442 killpg (pipeline_pgrp, SIGCONT);-
1443 }
never executed: end of block
0
1444}
never executed: end of block
0
1445-
1446/* Cause all stopped jobs to exit. */-
1447void-
1448terminate_stopped_jobs ()-
1449{-
1450 register int i;-
1451-
1452 /* XXX could use js.j_firstj here */-
1453 for (i = 0; i < js.j_jobslots; i++)
i < js.j_jobslotsDescription
TRUEevaluated 48 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
8-48
1454 {-
1455 if (jobs[i] && STOPPED (i))
jobs[i]Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 43 times by 1 test
Evaluated by:
  • Self test
(jobs[(i)]->state == JSTOPPED)Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
0-43
1456 {-
1457 killpg (jobs[i]->pgrp, SIGTERM);-
1458 killpg (jobs[i]->pgrp, SIGCONT);-
1459 }
never executed: end of block
0
1460 }
executed 48 times by 1 test: end of block
Executed by:
  • Self test
48
1461}
executed 8 times by 1 test: end of block
Executed by:
  • Self test
8
1462-
1463/* Cause all jobs, running or stopped, to receive a hangup signal. If-
1464 a job is marked J_NOHUP, don't send the SIGHUP. */-
1465void-
1466hangup_all_jobs ()-
1467{-
1468 register int i;-
1469-
1470 /* XXX could use js.j_firstj here */-
1471 for (i = 0; i < js.j_jobslots; i++)
i < js.j_jobslotsDescription
TRUEnever evaluated
FALSEnever evaluated
0
1472 {-
1473 if (jobs[i])
jobs[i]Description
TRUEnever evaluated
FALSEnever evaluated
0
1474 {-
1475 if (jobs[i]->flags & J_NOHUP)
jobs[i]->flags & 0x08Description
TRUEnever evaluated
FALSEnever evaluated
0
1476 continue;
never executed: continue;
0
1477 killpg (jobs[i]->pgrp, SIGHUP);-
1478 if (STOPPED (i))
(jobs[(i)]->state == JSTOPPED)Description
TRUEnever evaluated
FALSEnever evaluated
0
1479 killpg (jobs[i]->pgrp, SIGCONT);
never executed: killpg (jobs[i]->pgrp, 18 );
0
1480 }
never executed: end of block
0
1481 }
never executed: end of block
0
1482}
never executed: end of block
0
1483-
1484void-
1485kill_current_pipeline ()-
1486{-
1487 stop_making_children ();-
1488 start_pipeline ();-
1489}
never executed: end of block
0
1490-
1491/* Return the pipeline that PID belongs to. Note that the pipeline-
1492 doesn't have to belong to a job. Must be called with SIGCHLD blocked.-
1493 If JOBP is non-null, return the index of the job containing PID. */-
1494static PROCESS *-
1495find_pipeline (pid, alive_only, jobp)-
1496 pid_t pid;-
1497 int alive_only;-
1498 int *jobp; /* index into jobs list or NO_JOB */-
1499{-
1500 int job;-
1501 PROCESS *p;-
1502-
1503 /* See if this process is in the pipeline that we are building. */-
1504 if (jobp)
jobpDescription
TRUEevaluated 3985838 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3528591 times by 1 test
Evaluated by:
  • Self test
3528591-3985838
1505 *jobp = NO_JOB;
executed 3985838 times by 1 test: *jobp = -1;
Executed by:
  • Self test
3985838
1506 if (the_pipeline)
the_pipelineDescription
TRUEevaluated 7168474 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 345955 times by 1 test
Evaluated by:
  • Self test
345955-7168474
1507 {-
1508 p = the_pipeline;-
1509 do-
1510 {-
1511 /* Return it if we found it. Don't ever return a recycled pid. */-
1512 if (p->pid == pid && ((alive_only == 0 && PRECYCLED(p) == 0) || PALIVE(p)))
p->pid == pidDescription
TRUEevaluated 6507157 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 661317 times by 1 test
Evaluated by:
  • Self test
alive_only == 0Description
TRUEevaluated 3253577 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3253580 times by 1 test
Evaluated by:
  • Self test
(0) == 0Description
TRUEevaluated 3253577 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
((p)->running == 1)Description
TRUEevaluated 3253580 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
( ((( (p)->sta...ff) == 0x7f) )Description
TRUEnever evaluated
FALSEnever evaluated
0-6507157
1513 return (p);
executed 6507157 times by 1 test: return (p);
Executed by:
  • Self test
6507157
1514-
1515 p = p->next;-
1516 }
executed 661317 times by 1 test: end of block
Executed by:
  • Self test
661317
1517 while (p != the_pipeline);
p != the_pipelineDescription
TRUEnever evaluated
FALSEevaluated 661317 times by 1 test
Evaluated by:
  • Self test
0-661317
1518 }
executed 661317 times by 1 test: end of block
Executed by:
  • Self test
661317
1519 /* Now look in the last process substitution pipeline, since that sets $! */-
1520 if (last_procsub_child)
last_procsub_childDescription
TRUEevaluated 731717 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 275555 times by 1 test
Evaluated by:
  • Self test
275555-731717
1521 {-
1522 p = last_procsub_child;-
1523 do-
1524 {-
1525 /* Return it if we found it. Don't ever return a recycled pid. */-
1526 if (p->pid == pid && ((alive_only == 0 && PRECYCLED(p) == 0) || PALIVE(p)))
p->pid == pidDescription
TRUEevaluated 484793 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 246924 times by 1 test
Evaluated by:
  • Self test
alive_only == 0Description
TRUEnever evaluated
FALSEevaluated 484793 times by 1 test
Evaluated by:
  • Self test
(0) == 0Description
TRUEnever evaluated
FALSEnever evaluated
((p)->running == 1)Description
TRUEevaluated 484793 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
( ((( (p)->sta...ff) == 0x7f) )Description
TRUEnever evaluated
FALSEnever evaluated
0-484793
1527 return (p);
executed 484793 times by 1 test: return (p);
Executed by:
  • Self test
484793
1528-
1529 p = p->next;-
1530 }
executed 246924 times by 1 test: end of block
Executed by:
  • Self test
246924
1531 while (p != last_procsub_child);
p != last_procsub_childDescription
TRUEnever evaluated
FALSEevaluated 246924 times by 1 test
Evaluated by:
  • Self test
0-246924
1532 }
executed 246924 times by 1 test: end of block
Executed by:
  • Self test
246924
1533-
1534 job = find_job (pid, alive_only, &p);-
1535 if (jobp)
jobpDescription
TRUEevaluated 247465 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 275014 times by 1 test
Evaluated by:
  • Self test
247465-275014
1536 *jobp = job;
executed 247465 times by 1 test: *jobp = job;
Executed by:
  • Self test
247465
1537 return (job == NO_JOB) ? (PROCESS *)NULL : jobs[job]->pipe;
executed 522479 times by 1 test: return (job == -1) ? (PROCESS *) ((void *)0) : jobs[job]->pipe;
Executed by:
  • Self test
522479
1538}-
1539-
1540/* Return the PROCESS * describing PID. If JOBP is non-null return the index-
1541 into the jobs array of the job containing PID. Must be called with-
1542 SIGCHLD blocked. */-
1543static PROCESS *-
1544find_process (pid, alive_only, jobp)-
1545 pid_t pid;-
1546 int alive_only;-
1547 int *jobp; /* index into jobs list or NO_JOB */-
1548{-
1549 PROCESS *p;-
1550-
1551 p = find_pipeline (pid, alive_only, jobp);-
1552 while (p && p->pid != pid)
pDescription
TRUEevaluated 3805918 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 192444 times by 1 test
Evaluated by:
  • Self test
p->pid != pidDescription
TRUEevaluated 12531 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3793387 times by 1 test
Evaluated by:
  • Self test
12531-3805918
1553 p = p->next;
executed 12531 times by 1 test: p = p->next;
Executed by:
  • Self test
12531
1554 return p;
executed 3985831 times by 1 test: return p;
Executed by:
  • Self test
3985831
1555}-
1556-
1557/* Return the job index that PID belongs to, or NO_JOB if it doesn't-
1558 belong to any job. Must be called with SIGCHLD blocked. */-
1559static int-
1560find_job (pid, alive_only, procp)-
1561 pid_t pid;-
1562 int alive_only;-
1563 PROCESS **procp;-
1564{-
1565 register int i;-
1566 PROCESS *p;-
1567-
1568 /* XXX could use js.j_firstj here, and should check js.j_lastj */-
1569 for (i = 0; i < js.j_jobslots; i++)
i < js.j_jobslotsDescription
TRUEevaluated 59582729 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7433277 times by 1 test
Evaluated by:
  • Self test
7433277-59582729
1570 {-
1571#if defined (DEBUG)-
1572 if (i < js.j_firstj && jobs[i])
i < js.j_firstjDescription
TRUEevaluated 259 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 59582470 times by 1 test
Evaluated by:
  • Self test
jobs[i]Description
TRUEnever evaluated
FALSEevaluated 259 times by 1 test
Evaluated by:
  • Self test
0-59582470
1573 itrace("find_job: job %d non-null before js.j_firstj (%d)", i, js.j_firstj);
never executed: itrace("find_job: job %d non-null before js.j_firstj (%d)", i, js.j_firstj);
0
1574 if (i > js.j_lastj && jobs[i])
i > js.j_lastjDescription
TRUEevaluated 51628090 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7954639 times by 1 test
Evaluated by:
  • Self test
jobs[i]Description
TRUEnever evaluated
FALSEevaluated 51628090 times by 1 test
Evaluated by:
  • Self test
0-51628090
1575 itrace("find_job: job %d non-null after js.j_lastj (%d)", i, js.j_lastj);
never executed: itrace("find_job: job %d non-null after js.j_lastj (%d)", i, js.j_lastj);
0
1576#endif-
1577 if (jobs[i])
jobs[i]Description
TRUEevaluated 582475 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 59000254 times by 1 test
Evaluated by:
  • Self test
582475-59000254
1578 {-
1579 p = jobs[i]->pipe;-
1580-
1581 do-
1582 {-
1583 if (p->pid == pid && ((alive_only == 0 && PRECYCLED(p) == 0) || PALIVE(p)))
p->pid == pidDescription
TRUEevaluated 577921 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 55647 times by 1 test
Evaluated by:
  • Self test
alive_only == 0Description
TRUEevaluated 522907 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 55014 times by 1 test
Evaluated by:
  • Self test
(0) == 0Description
TRUEevaluated 522907 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
((p)->running == 1)Description
TRUEevaluated 55013 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
( ((( (p)->sta...ff) == 0x7f) )Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-577921
1584 {-
1585 if (procp)
procpDescription
TRUEevaluated 330022 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 247899 times by 1 test
Evaluated by:
  • Self test
247899-330022
1586 *procp = p;
executed 330022 times by 1 test: *procp = p;
Executed by:
  • Self test
330022
1587 return (i);
executed 577921 times by 1 test: return (i);
Executed by:
  • Self test
577921
1588 }-
1589-
1590 p = p->next;-
1591 }
executed 55647 times by 1 test: end of block
Executed by:
  • Self test
55647
1592 while (p != jobs[i]->pipe);
p != jobs[i]->pipeDescription
TRUEevaluated 51093 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4554 times by 1 test
Evaluated by:
  • Self test
4554-51093
1593 }
executed 4554 times by 1 test: end of block
Executed by:
  • Self test
4554
1594 }
executed 59004808 times by 1 test: end of block
Executed by:
  • Self test
59004808
1595-
1596 return (NO_JOB);
executed 7433277 times by 1 test: return (-1);
Executed by:
  • Self test
7433277
1597}-
1598-
1599/* Find a job given a PID. If BLOCK is non-zero, block SIGCHLD as-
1600 required by find_job. */-
1601int-
1602get_job_by_pid (pid, block)-
1603 pid_t pid;-
1604 int block;-
1605{-
1606 int job;-
1607 sigset_t set, oset;-
1608-
1609 if (block)
blockDescription
TRUEnever evaluated
FALSEnever evaluated
0
1610 BLOCK_CHILD (set, oset);
never executed: end of block
0
1611-
1612 job = find_job (pid, 0, NULL);-
1613-
1614 if (block)
blockDescription
TRUEnever evaluated
FALSEnever evaluated
0
1615 UNBLOCK_CHILD (oset);
never executed: sigprocmask ( 2 , &oset, (sigset_t *) ((void *)0) );
0
1616-
1617 return job;
never executed: return job;
0
1618}-
1619-
1620/* Print descriptive information about the job with leader pid PID. */-
1621void-
1622describe_pid (pid)-
1623 pid_t pid;-
1624{-
1625 int job;-
1626 sigset_t set, oset;-
1627-
1628 BLOCK_CHILD (set, oset);-
1629-
1630 job = find_job (pid, 0, NULL);-
1631-
1632 if (job != NO_JOB)
job != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1633 fprintf (stderr, "[%d] %ld\n", job + 1, (long)pid);
never executed: fprintf ( stderr , "[%d] %ld\n", job + 1, (long)pid);
0
1634 else-
1635 programming_error (_("describe_pid: %ld: no such pid"), (long)pid);
never executed: programming_error ( dcgettext (((void *)0), "describe_pid: %ld: no such pid" , 5) , (long)pid);
0
1636-
1637 UNBLOCK_CHILD (oset);-
1638}
never executed: end of block
0
1639-
1640static char *-
1641j_strsignal (s)-
1642 int s;-
1643{-
1644 char *x;-
1645-
1646 x = strsignal (s);-
1647 if (x == 0)
x == 0Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
0-5
1648 {-
1649 x = retcode_name_buffer;-
1650 snprintf (x, sizeof(retcode_name_buffer), _("Signal %d"), s);-
1651 }
never executed: end of block
0
1652 return x;
executed 5 times by 1 test: return x;
Executed by:
  • Self test
5
1653}-
1654-
1655static char *-
1656printable_job_status (j, p, format)-
1657 int j;-
1658 PROCESS *p;-
1659 int format;-
1660{-
1661 static char *temp;-
1662 int es;-
1663-
1664 temp = _("Done");-
1665-
1666 if (STOPPED (j) && format == 0)
(jobs[(j)]->state == JSTOPPED)Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 26 times by 1 test
Evaluated by:
  • Self test
format == 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-26
1667 {-
1668 if (posixly_correct == 0 || p == 0 || (WIFSTOPPED (p->status) == 0))
posixly_correct == 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
p == 0Description
TRUEnever evaluated
FALSEnever evaluated
( ((( p->statu...== 0x7f) == 0)Description
TRUEnever evaluated
FALSEnever evaluated
0-3
1669 temp = _("Stopped");
executed 3 times by 1 test: temp = dcgettext (((void *)0), "Stopped" , 5) ;
Executed by:
  • Self test
3
1670 else-
1671 {-
1672 temp = retcode_name_buffer;-
1673 snprintf (temp, sizeof(retcode_name_buffer), _("Stopped(%s)"), signal_name (WSTOPSIG (p->status)));-
1674 }
never executed: end of block
0
1675 }-
1676 else if (RUNNING (j))
(jobs[(j)]->state == JRUNNING)Description
TRUEevaluated 21 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
5-21
1677 temp = _("Running");
executed 21 times by 1 test: temp = dcgettext (((void *)0), "Running" , 5) ;
Executed by:
  • Self test
21
1678 else-
1679 {-
1680 if (WIFSTOPPED (p->status))
((( p->status ...0xff) == 0x7f)Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
0-5
1681 temp = j_strsignal (WSTOPSIG (p->status));
never executed: temp = j_strsignal ( ((( p->status ) & 0xff00) >> 8) );
0
1682 else if (WIFSIGNALED (p->status))
(((signed char... 1) >> 1) > 0)Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-5
1683 temp = j_strsignal (WTERMSIG (p->status));
executed 5 times by 1 test: temp = j_strsignal ( (( p->status ) & 0x7f) );
Executed by:
  • Self test
5
1684 else if (WIFEXITED (p->status))
((( p->status ) & 0x7f) == 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
1685 {-
1686 temp = retcode_name_buffer;-
1687 es = WEXITSTATUS (p->status);-
1688 if (es == 0)
es == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1689 {-
1690 strncpy (temp, _("Done"), sizeof (retcode_name_buffer) - 1);-
1691 temp[sizeof (retcode_name_buffer) - 1] = '\0';-
1692 }
never executed: end of block
0
1693 else if (posixly_correct)
posixly_correctDescription
TRUEnever evaluated
FALSEnever evaluated
0
1694 snprintf (temp, sizeof(retcode_name_buffer), _("Done(%d)"), es);
never executed: snprintf (temp, sizeof(retcode_name_buffer), dcgettext (((void *)0), "Done(%d)" , 5) , es);
0
1695 else-
1696 snprintf (temp, sizeof(retcode_name_buffer), _("Exit %d"), es);
never executed: snprintf (temp, sizeof(retcode_name_buffer), dcgettext (((void *)0), "Exit %d" , 5) , es);
0
1697 }-
1698 else-
1699 temp = _("Unknown status");
never executed: temp = dcgettext (((void *)0), "Unknown status" , 5) ;
0
1700 }-
1701-
1702 return temp;
executed 29 times by 1 test: return temp;
Executed by:
  • Self test
29
1703}-
1704-
1705/* This is the way to print out information on a job if you-
1706 know the index. FORMAT is:-
1707-
1708 JLIST_NORMAL) [1]+ Running emacs-
1709 JLIST_LONG ) [1]+ 2378 Running emacs-
1710 -1 ) [1]+ 2378 emacs-
1711-
1712 JLIST_NORMAL) [1]+ Stopped ls | more-
1713 JLIST_LONG ) [1]+ 2369 Stopped ls-
1714 2367 | more-
1715 JLIST_PID_ONLY)-
1716 Just list the pid of the process group leader (really-
1717 the process group).-
1718 JLIST_CHANGED_ONLY)-
1719 Use format JLIST_NORMAL, but list only jobs about which-
1720 the user has not been notified. */-
1721-
1722/* Print status for pipeline P. If JOB_INDEX is >= 0, it is the index into-
1723 the JOBS array corresponding to this pipeline. FORMAT is as described-
1724 above. Must be called with SIGCHLD blocked.-
1725-
1726 If you're printing a pipeline that's not in the jobs array, like the-
1727 current pipeline as it's being created, pass -1 for JOB_INDEX */-
1728static void-
1729print_pipeline (p, job_index, format, stream)-
1730 PROCESS *p;-
1731 int job_index, format;-
1732 FILE *stream;-
1733{-
1734 PROCESS *first, *last, *show;-
1735 int es, name_padding;-
1736 char *temp;-
1737-
1738 if (p == 0)
p == 0Description
TRUEnever evaluated
FALSEevaluated 29 times by 1 test
Evaluated by:
  • Self test
0-29
1739 return;
never executed: return;
0
1740-
1741 first = last = p;-
1742 while (last->next != first)
last->next != firstDescription
TRUEnever evaluated
FALSEevaluated 29 times by 1 test
Evaluated by:
  • Self test
0-29
1743 last = last->next;
never executed: last = last->next;
0
1744-
1745 for (;;)-
1746 {-
1747 if (p != first)
p != firstDescription
TRUEnever evaluated
FALSEevaluated 29 times by 1 test
Evaluated by:
  • Self test
0-29
1748 fprintf (stream, format ? " " : " |");
never executed: fprintf (stream, format ? " " : " |");
0
1749-
1750 if (format != JLIST_STANDARD)
format != 0Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 24 times by 1 test
Evaluated by:
  • Self test
5-24
1751 fprintf (stream, "%5ld", (long)p->pid);
executed 5 times by 1 test: fprintf (stream, "%5ld", (long)p->pid);
Executed by:
  • Self test
5
1752-
1753 fprintf (stream, " ");-
1754-
1755 if (format > -1 && job_index >= 0)
format > -1Description
TRUEevaluated 29 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
job_index >= 0Description
TRUEevaluated 29 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-29
1756 {-
1757 show = format ? p : last;
formatDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 24 times by 1 test
Evaluated by:
  • Self test
5-24
1758 temp = printable_job_status (job_index, show, format);-
1759-
1760 if (p != first)
p != firstDescription
TRUEnever evaluated
FALSEevaluated 29 times by 1 test
Evaluated by:
  • Self test
0-29
1761 {-
1762 if (format)
formatDescription
TRUEnever evaluated
FALSEnever evaluated
0
1763 {-
1764 if (show->running == first->running &&
show->running ...first->runningDescription
TRUEnever evaluated
FALSEnever evaluated
0
1765 WSTATUS (show->status) == WSTATUS (first->status))
(show->status)...first->status)Description
TRUEnever evaluated
FALSEnever evaluated
0
1766 temp = "";
never executed: temp = "";
0
1767 }
never executed: end of block
0
1768 else-
1769 temp = (char *)NULL;
never executed: temp = (char *) ((void *)0) ;
0
1770 }-
1771-
1772 if (temp)
tempDescription
TRUEevaluated 29 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-29
1773 {-
1774 fprintf (stream, "%s", temp);-
1775-
1776 es = STRLEN (temp);
(temp)[1]Description
TRUEevaluated 29 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(temp)[2]Description
TRUEevaluated 29 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(temp)Description
TRUEevaluated 29 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(temp)[0]Description
TRUEevaluated 29 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-29
1777 if (es == 0)
es == 0Description
TRUEnever evaluated
FALSEevaluated 29 times by 1 test
Evaluated by:
  • Self test
0-29
1778 es = 2; /* strlen ("| ") */
never executed: es = 2;
0
1779 name_padding = LONGEST_SIGNAL_DESC - es;-
1780-
1781 fprintf (stream, "%*s", name_padding, "");-
1782-
1783 if ((WIFSTOPPED (show->status) == 0) &&
( ((( show->st...== 0x7f) == 0)Description
TRUEevaluated 26 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
3-26
1784 (WIFCONTINUED (show->status) == 0) &&
( (( show->sta... 0xffff) == 0)Description
TRUEevaluated 25 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-25
1785 WIFCORED (show->status))
((show->status) & 0200)Description
TRUEnever evaluated
FALSEevaluated 25 times by 1 test
Evaluated by:
  • Self test
0-25
1786 fprintf (stream, _("(core dumped) "));
never executed: fprintf (stream, dcgettext (((void *)0), "(core dumped) " , 5) );
0
1787 }
executed 29 times by 1 test: end of block
Executed by:
  • Self test
29
1788 }
executed 29 times by 1 test: end of block
Executed by:
  • Self test
29
1789-
1790 if (p != first && format)
p != firstDescription
TRUEnever evaluated
FALSEevaluated 29 times by 1 test
Evaluated by:
  • Self test
formatDescription
TRUEnever evaluated
FALSEnever evaluated
0-29
1791 fprintf (stream, "| ");
never executed: fprintf (stream, "| ");
0
1792-
1793 if (p->command)
p->commandDescription
TRUEevaluated 29 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-29
1794 fprintf (stream, "%s", p->command);
executed 29 times by 1 test: fprintf (stream, "%s", p->command);
Executed by:
  • Self test
29
1795-
1796 if (p == last && job_index >= 0)
p == lastDescription
TRUEevaluated 29 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
job_index >= 0Description
TRUEevaluated 29 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-29
1797 {-
1798 temp = current_working_directory ();-
1799-
1800 if (RUNNING (job_index) && (IS_FOREGROUND (job_index) == 0))
(jobs[(job_ind...e == JRUNNING)Description
TRUEevaluated 21 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
(((jobs[job_in...1) != 0) == 0)Description
TRUEevaluated 21 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-21
1801 fprintf (stream, " &");
executed 21 times by 1 test: fprintf (stream, " &");
Executed by:
  • Self test
21
1802-
1803 if (strcmp (temp, jobs[job_index]->wd) != 0)
never executed: __result = (((const unsigned char *) (const char *) ( temp ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( jobs[job_index]->wd ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
__extension__ ... )))); }) != 0Description
TRUEnever evaluated
FALSEevaluated 29 times by 1 test
Evaluated by:
  • Self test
__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-29
1804 fprintf (stream,
never executed: fprintf (stream, dcgettext (((void *)0), " (wd: %s)" , 5) , polite_directory_format (jobs[job_index]->wd));
0
1805 _(" (wd: %s)"), polite_directory_format (jobs[job_index]->wd));
never executed: fprintf (stream, dcgettext (((void *)0), " (wd: %s)" , 5) , polite_directory_format (jobs[job_index]->wd));
0
1806 }
executed 29 times by 1 test: end of block
Executed by:
  • Self test
29
1807-
1808 if (format || (p == last))
formatDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 24 times by 1 test
Evaluated by:
  • Self test
(p == last)Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-24
1809 {-
1810 /* We need to add a CR only if this is an interactive shell, and-
1811 we're reporting the status of a completed job asynchronously.-
1812 We can't really check whether this particular job is being-
1813 reported asynchronously, so just add the CR if the shell is-
1814 currently interactive and asynchronous notification is enabled. */-
1815 if (asynchronous_notification && interactive)
asynchronous_notificationDescription
TRUEnever evaluated
FALSEevaluated 29 times by 1 test
Evaluated by:
  • Self test
interactiveDescription
TRUEnever evaluated
FALSEnever evaluated
0-29
1816 fprintf (stream, "\r\n");
never executed: fprintf (stream, "\r\n");
0
1817 else-
1818 fprintf (stream, "\n");
executed 29 times by 1 test: fprintf (stream, "\n");
Executed by:
  • Self test
29
1819 }-
1820-
1821 if (p == last)
p == lastDescription
TRUEevaluated 29 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-29
1822 break;
executed 29 times by 1 test: break;
Executed by:
  • Self test
29
1823 p = p->next;-
1824 }
never executed: end of block
0
1825 fflush (stream);-
1826}
executed 29 times by 1 test: end of block
Executed by:
  • Self test
29
1827-
1828/* Print information to STREAM about jobs[JOB_INDEX] according to FORMAT.-
1829 Must be called with SIGCHLD blocked or queued with queue_sigchld */-
1830static void-
1831pretty_print_job (job_index, format, stream)-
1832 int job_index, format;-
1833 FILE *stream;-
1834{-
1835 register PROCESS *p;-
1836-
1837 /* Format only pid information about the process group leader? */-
1838 if (format == JLIST_PID_ONLY)
format == 2Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 29 times by 1 test
Evaluated by:
  • Self test
2-29
1839 {-
1840 fprintf (stream, "%ld\n", (long)jobs[job_index]->pipe->pid);-
1841 return;
executed 2 times by 1 test: return;
Executed by:
  • Self test
2
1842 }-
1843-
1844 if (format == JLIST_CHANGED_ONLY)
format == 3Description
TRUEnever evaluated
FALSEevaluated 29 times by 1 test
Evaluated by:
  • Self test
0-29
1845 {-
1846 if (IS_NOTIFIED (job_index))
((jobs[job_ind... & 0x02) != 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
1847 return;
never executed: return;
0
1848 format = JLIST_STANDARD;-
1849 }
never executed: end of block
0
1850-
1851 if (format != JLIST_NONINTERACTIVE)
format != 4Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
5-24
1852 fprintf (stream, "[%d]%c ", job_index + 1,
executed 24 times by 1 test: fprintf (stream, "[%d]%c ", job_index + 1, (job_index == js.j_current) ? '+': (job_index == js.j_previous) ? '-' : ' ');
Executed by:
  • Self test
24
1853 (job_index == js.j_current) ? '+':
executed 24 times by 1 test: fprintf (stream, "[%d]%c ", job_index + 1, (job_index == js.j_current) ? '+': (job_index == js.j_previous) ? '-' : ' ');
Executed by:
  • Self test
24
1854 (job_index == js.j_previous) ? '-' : ' ');
executed 24 times by 1 test: fprintf (stream, "[%d]%c ", job_index + 1, (job_index == js.j_current) ? '+': (job_index == js.j_previous) ? '-' : ' ');
Executed by:
  • Self test
24
1855-
1856 if (format == JLIST_NONINTERACTIVE)
format == 4Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 24 times by 1 test
Evaluated by:
  • Self test
5-24
1857 format = JLIST_LONG;
executed 5 times by 1 test: format = 1;
Executed by:
  • Self test
5
1858-
1859 p = jobs[job_index]->pipe;-
1860-
1861 print_pipeline (p, job_index, format, stream);-
1862-
1863 /* We have printed information about this job. When the job's-
1864 status changes, waitchld () sets the notification flag to 0. */-
1865 jobs[job_index]->flags |= J_NOTIFIED;-
1866}
executed 29 times by 1 test: end of block
Executed by:
  • Self test
29
1867-
1868static int-
1869print_job (job, format, state, job_index)-
1870 JOB *job;-
1871 int format, state, job_index;-
1872{-
1873 if (state == -1 || (JOB_STATE)state == job->state)
state == -1Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 17 times by 1 test
Evaluated by:
  • Self test
(JOB_STATE)state == job->stateDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
7-17
1874 pretty_print_job (job_index, format, stdout);
executed 22 times by 1 test: pretty_print_job (job_index, format, stdout );
Executed by:
  • Self test
22
1875 return (0);
executed 29 times by 1 test: return (0);
Executed by:
  • Self test
29
1876}-
1877-
1878void-
1879list_one_job (job, format, ignore, job_index)-
1880 JOB *job;-
1881 int format, ignore, job_index;-
1882{-
1883 pretty_print_job (job_index, format, stdout);-
1884}
executed 4 times by 1 test: end of block
Executed by:
  • Self test
4
1885-
1886void-
1887list_stopped_jobs (format)-
1888 int format;-
1889{-
1890 cleanup_dead_jobs ();-
1891 map_over_jobs (print_job, format, (int)JSTOPPED);-
1892}
executed 3 times by 1 test: end of block
Executed by:
  • Self test
3
1893-
1894void-
1895list_running_jobs (format)-
1896 int format;-
1897{-
1898 cleanup_dead_jobs ();-
1899 map_over_jobs (print_job, format, (int)JRUNNING);-
1900}
executed 4 times by 1 test: end of block
Executed by:
  • Self test
4
1901-
1902/* List jobs. If FORMAT is non-zero, then the long form of the information-
1903 is printed, else just a short version. */-
1904void-
1905list_all_jobs (format)-
1906 int format;-
1907{-
1908 cleanup_dead_jobs ();-
1909 map_over_jobs (print_job, format, -1);-
1910}
executed 7 times by 1 test: end of block
Executed by:
  • Self test
7
1911-
1912/* Fork, handling errors. Returns the pid of the newly made child, or 0.-
1913 COMMAND is just for remembering the name of the command; we don't do-
1914 anything else with it. ASYNC_P says what to do with the tty. If-
1915 non-zero, then don't give it away. */-
1916pid_t-
1917make_child (command, async_p)-
1918 char *command;-
1919 int async_p;-
1920{-
1921 int forksleep;-
1922 sigset_t set, oset;-
1923 pid_t pid;-
1924-
1925 /* XXX - block SIGTERM here and unblock in child after fork resets the-
1926 set of pending signals? */-
1927 sigemptyset (&set);-
1928 sigaddset (&set, SIGCHLD);-
1929 sigaddset (&set, SIGINT);-
1930 sigemptyset (&oset);-
1931 sigprocmask (SIG_BLOCK, &set, &oset);-
1932-
1933 making_children ();-
1934-
1935 forksleep = 1;-
1936-
1937#if defined (BUFFERED_INPUT)-
1938 /* If default_buffered_input is active, we are reading a script. If-
1939 the command is asynchronous, we have already duplicated /dev/null-
1940 as fd 0, but have not changed the buffered stream corresponding to-
1941 the old fd 0. We don't want to sync the stream in this case. */-
1942 if (default_buffered_input != -1 &&
default_buffered_input != -1Description
TRUEevaluated 3984408 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9455 times by 1 test
Evaluated by:
  • Self test
9455-3984408
1943 (!async_p || default_buffered_input > 0))
!async_pDescription
TRUEevaluated 3305145 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 679263 times by 1 test
Evaluated by:
  • Self test
default_buffered_input > 0Description
TRUEevaluated 679263 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-3305145
1944 sync_buffered_stream (default_buffered_input);
executed 3984408 times by 1 test: sync_buffered_stream (default_buffered_input);
Executed by:
  • Self test
3984408
1945#endif /* BUFFERED_INPUT */-
1946-
1947 RESET_SIGTERM;-
1948-
1949 /* Create the child, handle severe errors. Retry on EAGAIN. */-
1950 while ((pid = fork ()) < 0 && errno == EAGAIN && forksleep < FORKSLEEP_MAX)
(pid = fork ()) < 0Description
TRUEnever evaluated
FALSEevaluated 3993863 times by 1 test
Evaluated by:
  • Self test
(*__errno_location ()) == 11Description
TRUEnever evaluated
FALSEnever evaluated
forksleep < 16Description
TRUEnever evaluated
FALSEnever evaluated
0-3993863
1951 {-
1952 /* bash-4.2 */-
1953 sigprocmask (SIG_SETMASK, &oset, (sigset_t *)NULL);-
1954 /* If we can't create any children, try to reap some dead ones. */-
1955 waitchld (-1, 0);-
1956-
1957 errno = EAGAIN; /* restore errno */-
1958 sys_error ("fork: retry");-
1959 RESET_SIGTERM;-
1960-
1961 if (sleep (forksleep) != 0)
sleep (forksleep) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1962 break;
never executed: break;
0
1963 forksleep <<= 1;-
1964-
1965 if (interrupt_state)
interrupt_stateDescription
TRUEnever evaluated
FALSEnever evaluated
0
1966 break;
never executed: break;
0
1967 sigprocmask (SIG_SETMASK, &set, (sigset_t *)NULL);-
1968 }
never executed: end of block
0
1969-
1970 if (pid != 0)
pid != 0Description
TRUEevaluated 3987239 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6624 times by 1 test
Evaluated by:
  • Self test
6624-3987239
1971 RESET_SIGTERM;
executed 3987239 times by 1 test: end of block
Executed by:
  • Self test
3987239
1972-
1973 if (pid < 0)
pid < 0Description
TRUEnever evaluated
FALSEevaluated 3993863 times by 1 test
Evaluated by:
  • Self test
0-3993863
1974 {-
1975 sys_error ("fork");-
1976-
1977 /* Kill all of the processes in the current pipeline. */-
1978 terminate_current_pipeline ();-
1979-
1980 /* Discard the current pipeline, if any. */-
1981 if (the_pipeline)
the_pipelineDescription
TRUEnever evaluated
FALSEnever evaluated
0
1982 kill_current_pipeline ();
never executed: kill_current_pipeline ();
0
1983-
1984 last_command_exit_value = EX_NOEXEC;-
1985 throw_to_top_level (); /* Reset signals, etc. */-
1986 }
never executed: end of block
0
1987-
1988 if (pid == 0)
pid == 0Description
TRUEevaluated 6624 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3987239 times by 1 test
Evaluated by:
  • Self test
6624-3987239
1989 {-
1990 /* In the child. Give this child the right process group, set the-
1991 signals to the default state for a new process. */-
1992 pid_t mypid;-
1993-
1994 /* If this ends up being changed to modify or use `command' in the-
1995 child process, go back and change callers who free `command' in-
1996 the child process when this returns. */-
1997 mypid = getpid ();-
1998#if defined (BUFFERED_INPUT)-
1999 /* Close default_buffered_input if it's > 0. We don't close it if it's-
2000 0 because that's the file descriptor used when redirecting input,-
2001 and it's wrong to close the file in that case. */-
2002 unset_bash_input (0);-
2003#endif /* BUFFERED_INPUT */-
2004-
2005 CLRINTERRUPT; /* XXX - children have their own interrupt state */-
2006-
2007 /* Restore top-level signal mask. */-
2008 sigprocmask (SIG_SETMASK, &top_level_mask, (sigset_t *)NULL);-
2009-
2010 if (job_control)
job_controlDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6619 times by 1 test
Evaluated by:
  • Self test
5-6619
2011 {-
2012 /* All processes in this pipeline belong in the same-
2013 process group. */-
2014-
2015 if (pipeline_pgrp == 0) /* This is the first child. */
pipeline_pgrp == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
2-3
2016 pipeline_pgrp = mypid;
executed 2 times by 1 test: pipeline_pgrp = mypid;
Executed by:
  • Self test
2
2017-
2018 /* Check for running command in backquotes. */-
2019 if (pipeline_pgrp == shell_pgrp)
pipeline_pgrp == shell_pgrpDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
1-4
2020 ignore_tty_job_signals ();
executed 1 time by 1 test: ignore_tty_job_signals ();
Executed by:
  • Self test
1
2021 else-
2022 default_tty_job_signals ();
executed 4 times by 1 test: default_tty_job_signals ();
Executed by:
  • Self test
4
2023-
2024 /* Set the process group before trying to mess with the terminal's-
2025 process group. This is mandated by POSIX. */-
2026 /* This is in accordance with the Posix 1003.1 standard,-
2027 section B.7.2.4, which says that trying to set the terminal-
2028 process group with tcsetpgrp() to an unused pgrp value (like-
2029 this would have for the first child) is an error. Section-
2030 B.4.3.3, p. 237 also covers this, in the context of job control-
2031 shells. */-
2032 if (setpgid (mypid, pipeline_pgrp) < 0)
setpgid (mypid...line_pgrp) < 0Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
0-5
2033 sys_error (_("child setpgid (%ld to %ld)"), (long)mypid, (long)pipeline_pgrp);
never executed: sys_error ( dcgettext (((void *)0), "child setpgid (%ld to %ld)" , 5) , (long)mypid, (long)pipeline_pgrp);
0
2034-
2035 /* By convention (and assumption above), if-
2036 pipeline_pgrp == shell_pgrp, we are making a child for-
2037 command substitution.-
2038 In this case, we don't want to give the terminal to the-
2039 shell's process group (we could be in the middle of a-
2040 pipeline, for example). */-
2041 if (async_p == 0 && pipeline_pgrp != shell_pgrp && ((subshell_environment&(SUBSHELL_ASYNC|SUBSHELL_PIPE)) == 0) && running_in_background == 0)
async_p == 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
pipeline_pgrp != shell_pgrpDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
((subshell_env...1|0x10)) == 0)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
running_in_background == 0Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
0-3
2042 give_terminal_to (pipeline_pgrp, 0);
never executed: give_terminal_to (pipeline_pgrp, 0);
0
2043-
2044#if defined (PGRP_PIPE)-
2045 if (pipeline_pgrp == mypid)
pipeline_pgrp == mypidDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
2-3
2046 pipe_read (pgrp_pipe);
executed 2 times by 1 test: pipe_read (pgrp_pipe);
Executed by:
  • Self test
2
2047#endif-
2048 }
executed 5 times by 1 test: end of block
Executed by:
  • Self test
5
2049 else /* Without job control... */-
2050 {-
2051 if (pipeline_pgrp == 0)
pipeline_pgrp == 0Description
TRUEevaluated 518 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6101 times by 1 test
Evaluated by:
  • Self test
518-6101
2052 pipeline_pgrp = shell_pgrp;
executed 518 times by 1 test: pipeline_pgrp = shell_pgrp;
Executed by:
  • Self test
518
2053-
2054 /* If these signals are set to SIG_DFL, we encounter the curious-
2055 situation of an interactive ^Z to a running process *working*-
2056 and stopping the process, but being unable to do anything with-
2057 that process to change its state. On the other hand, if they-
2058 are set to SIG_IGN, jobs started from scripts do not stop when-
2059 the shell running the script gets a SIGTSTP and stops. */-
2060-
2061 default_tty_job_signals ();-
2062 }
executed 6619 times by 1 test: end of block
Executed by:
  • Self test
6619
2063-
2064#if defined (PGRP_PIPE)-
2065 /* Release the process group pipe, since our call to setpgid ()-
2066 is done. The last call to sh_closepipe is done in stop_pipeline. */-
2067 sh_closepipe (pgrp_pipe);-
2068#endif /* PGRP_PIPE */-
2069-
2070#if 0-
2071 /* Don't set last_asynchronous_pid in the child */-
2072 if (async_p)-
2073 last_asynchronous_pid = mypid; /* XXX */-
2074 else-
2075#endif-
2076#if defined (RECYCLES_PIDS)-
2077 if (last_asynchronous_pid == mypid)-
2078 /* Avoid pid aliasing. 1 seems like a safe, unusual pid value. */-
2079 last_asynchronous_pid = 1;-
2080#endif-
2081 }
executed 6624 times by 1 test: end of block
Executed by:
  • Self test
6624
2082 else-