OpenCoverage

fg_bg.def

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/builtins/fg_bg.def
Source codeSwitch to Preprocessed file
LineSourceCount
1This file is fg_bg.def, from which is created fg_bg.c.-
2It implements the builtins "bg" and "fg" in Bash.-
3-
4Copyright (C) 1987-2009 Free Software Foundation, Inc.-
5-
6This file is part of GNU Bash, the Bourne Again SHell.-
7-
8Bash is free software: you can redistribute it and/or modify-
9it under the terms of the GNU General Public License as published by-
10the Free Software Foundation, either version 3 of the License, or-
11(at your option) any later version.-
12-
13Bash is distributed in the hope that it will be useful,-
14but WITHOUT ANY WARRANTY; without even the implied warranty of-
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
16GNU General Public License for more details.-
17-
18You should have received a copy of the GNU General Public License-
19along with Bash. If not, see <http://www.gnu.org/licenses/>.-
20-
21$PRODUCES fg_bg.c-
22-
23$BUILTIN fg-
24$FUNCTION fg_builtin-
25$DEPENDS_ON JOB_CONTROL-
26$SHORT_DOC fg [job_spec]-
27Move job to the foreground.-
28-
29Place the job identified by JOB_SPEC in the foreground, making it the-
30current job. If JOB_SPEC is not present, the shell's notion of the-
31current job is used.-
32-
33Exit Status:-
34Status of command placed in foreground, or failure if an error occurs.-
35$END-
36-
37#include <config.h>-
38-
39#include "../bashtypes.h"-
40#include <signal.h>-
41-
42#if defined (HAVE_UNISTD_H)-
43# include <unistd.h>-
44#endif-
45-
46#include "../bashintl.h"-
47-
48#include "../shell.h"-
49#include "../execute_cmd.h"-
50#include "../jobs.h"-
51#include "common.h"-
52#include "bashgetopt.h"-
53-
54#if defined (JOB_CONTROL)-
55static int fg_bg __P((WORD_LIST *, int));-
56-
57/* How to bring a job into the foreground. */-
58int-
59fg_builtin (list)-
60 WORD_LIST *list;-
61{-
62 int fg_bit;-
63 register WORD_LIST *t;-
64-
65 CHECK_HELPOPT (list);
never executed: __result = (((const unsigned char *) (const char *) ( ((list)->word->word) ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "--help" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: return (258);
(list)Description
TRUEevaluated 23 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
(list)->wordDescription
TRUEevaluated 23 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(((list)->word... ("--help")[0]Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 20 times by 1 test
Evaluated by:
  • Self test
__extension__ ... )))); }) == 0Description
TRUEnever evaluated
FALSEevaluated 3 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-23
66-
67 if (job_control == 0)
job_control == 0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 20 times by 1 test
Evaluated by:
  • Self test
4-20
68 {-
69 sh_nojobs ((char *)NULL);-
70 return (EXECUTION_FAILURE);
executed 4 times by 1 test: return (1);
Executed by:
  • Self test
4
71 }-
72-
73 if (no_options (list))
no_options (list)Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 17 times by 1 test
Evaluated by:
  • Self test
3-17
74 return (EX_USAGE);
executed 3 times by 1 test: return (258);
Executed by:
  • Self test
3
75 list = loptend;-
76-
77 /* If the last arg on the line is '&', then start this job in the-
78 background. Else, fg the job. */-
79 for (t = list; t && t->next; t = t->next)
tDescription
TRUEevaluated 17 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
t->nextDescription
TRUEnever evaluated
FALSEevaluated 17 times by 1 test
Evaluated by:
  • Self test
0-17
80 ;
never executed: ;
0
81 fg_bit = (t && t->word->word[0] == '&' && t->word->word[1] == '\0') == 0;
tDescription
TRUEevaluated 17 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
t->word->word[0] == '&'Description
TRUEnever evaluated
FALSEevaluated 17 times by 1 test
Evaluated by:
  • Self test
t->word->word[1] == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
0-17
82-
83 return (fg_bg (list, fg_bit));
executed 17 times by 1 test: return (fg_bg (list, fg_bit));
Executed by:
  • Self test
17
84}-
85#endif /* JOB_CONTROL */-
86-
87$BUILTIN bg-
88$FUNCTION bg_builtin-
89$DEPENDS_ON JOB_CONTROL-
90$SHORT_DOC bg [job_spec ...]-
91Move jobs to the background.-
92-
93Place the jobs identified by each JOB_SPEC in the background, as if they-
94had been started with `&'. If JOB_SPEC is not present, the shells notion-
95of the current job is used.-
96-
97Exit Status:-
98Returns success unless job control is not enabled or an error occurs.-
99$END-
100-
101#if defined (JOB_CONTROL)-
102/* How to put a job into the background. */-
103int-
104bg_builtin (list)-
105 WORD_LIST *list;-
106{-
107 int r;-
108-
109 CHECK_HELPOPT (list);
never executed: __result = (((const unsigned char *) (const char *) ( ((list)->word->word) ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "--help" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: return (258);
(list)Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
(list)->wordDescription
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(((list)->word... ("--help")[0]Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
__extension__ ... )))); }) == 0Description
TRUEnever evaluated
FALSEevaluated 3 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-7
110-
111 if (job_control == 0)
job_control == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
1-7
112 {-
113 sh_nojobs ((char *)NULL);-
114 return (EXECUTION_FAILURE);
executed 1 time by 1 test: return (1);
Executed by:
  • Self test
1
115 }-
116-
117 if (no_options (list))
no_options (list)Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
3-4
118 return (EX_USAGE);
executed 3 times by 1 test: return (258);
Executed by:
  • Self test
3
119 list = loptend;-
120-
121 /* This relies on the fact that fg_bg() takes a WORD_LIST *, but only acts-
122 on the first member (if any) of that list. */-
123 r = EXECUTION_SUCCESS;-
124 do-
125 {-
126 if (fg_bg (list, 0) == EXECUTION_FAILURE)
fg_bg (list, 0) == 1Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
0-4
127 r = EXECUTION_FAILURE;
never executed: r = 1;
0
128 if (list)
listDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-4
129 list = list->next;
executed 4 times by 1 test: list = list->next;
Executed by:
  • Self test
4
130 }
executed 4 times by 1 test: end of block
Executed by:
  • Self test
4
131 while (list);
listDescription
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
0-4
132-
133 return r;
executed 4 times by 1 test: return r;
Executed by:
  • Self test
4
134}-
135-
136/* How to put a job into the foreground/background. */-
137static int-
138fg_bg (list, foreground)-
139 WORD_LIST *list;-
140 int foreground;-
141{-
142 sigset_t set, oset;-
143 int job, status, old_async_pid;-
144 JOB *j;-
145-
146 BLOCK_CHILD (set, oset);-
147 job = get_job_spec (list);-
148-
149 if (INVALID_JOB (job))
(job) < 0Description
TRUEnever evaluated
FALSEevaluated 21 times by 1 test
Evaluated by:
  • Self test
(job) >= js.j_jobslotsDescription
TRUEnever evaluated
FALSEevaluated 21 times by 1 test
Evaluated by:
  • Self test
(jobs[(job)]) == 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test
0-21
150 {-
151 if (job != DUP_JOB)
job != -2Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-3
152 sh_badjob (list ? list->word->word : _("current"));
executed 3 times by 1 test: sh_badjob (list ? list->word->word : dcgettext (((void *)0), "current" , 5) );
Executed by:
  • Self test
3
153-
154 goto failure;
executed 3 times by 1 test: goto failure;
Executed by:
  • Self test
3
155 }-
156-
157 j = get_job_by_jid (job);-
158 /* Or if j->pgrp == shell_pgrp. */-
159 if (IS_JOBCONTROL (job) == 0)
((jobs[job]->f...04) != 0) == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 17 times by 1 test
Evaluated by:
  • Self test
1-17
160 {-
161 builtin_error (_("job %d started without job control"), job + 1);-
162 goto failure;
executed 1 time by 1 test: goto failure;
Executed by:
  • Self test
1
163 }-
164-
165 if (foreground == 0)
foreground == 0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 13 times by 1 test
Evaluated by:
  • Self test
4-13
166 {-
167 old_async_pid = last_asynchronous_pid;-
168 last_asynchronous_pid = j->pgrp; /* As per Posix.2 5.4.2 */-
169 }
executed 4 times by 1 test: end of block
Executed by:
  • Self test
4
170-
171 status = start_job (job, foreground);-
172-
173 if (status >= 0)
status >= 0Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-17
174 {-
175 /* win: */-
176 UNBLOCK_CHILD (oset);-
177 return (foreground ? status : EXECUTION_SUCCESS);
executed 17 times by 1 test: return (foreground ? status : 0);
Executed by:
  • Self test
17
178 }-
179 else-
180 {-
181 if (foreground == 0)
foreground == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
182 last_asynchronous_pid = old_async_pid;
never executed: last_asynchronous_pid = old_async_pid;
0
183-
184 failure:
code before this statement never executed: failure:
0
185 UNBLOCK_CHILD (oset);-
186 return (EXECUTION_FAILURE);
executed 4 times by 1 test: return (1);
Executed by:
  • Self test
4
187 }-
188}-
189#endif /* JOB_CONTROL */-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2