OpenCoverage

kill.def

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/builtins/kill.def
Source codeSwitch to Preprocessed file
LineSourceCount
1This file is kill.def, from which is created kill.c.-
2It implements the builtin "kill" in Bash.-
3-
4Copyright (C) 1987-2015 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 kill.c-
22-
23$BUILTIN kill-
24$FUNCTION kill_builtin-
25$SHORT_DOC kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]-
26Send a signal to a job.-
27-
28Send the processes identified by PID or JOBSPEC the signal named by-
29SIGSPEC or SIGNUM. If neither SIGSPEC nor SIGNUM is present, then-
30SIGTERM is assumed.-
31-
32Options:-
33 -s sig SIG is a signal name-
34 -n sig SIG is a signal number-
35 -l list the signal names; if arguments follow `-l' they are-
36 assumed to be signal numbers for which names should be listed-
37 -L synonym for -l-
38-
39Kill is a shell builtin for two reasons: it allows job IDs to be used-
40instead of process IDs, and allows processes to be killed if the limit-
41on processes that you can create is reached.-
42-
43Exit Status:-
44Returns success unless an invalid option is given or an error occurs.-
45$END-
46-
47#include <config.h>-
48-
49#include <stdio.h>-
50#include <errno.h>-
51#if defined (HAVE_UNISTD_H)-
52# ifdef _MINIX-
53# include <sys/types.h>-
54# endif-
55# include <unistd.h>-
56#endif-
57-
58#include "../bashansi.h"-
59#include "../bashintl.h"-
60-
61#include <signal.h>-
62-
63#include "../shell.h"-
64#include "../trap.h"-
65#include "../jobs.h"-
66#include "common.h"-
67-
68/* Not all systems declare ERRNO in errno.h... and some systems #define it! */-
69#if !defined (errno)-
70extern int errno;-
71#endif /* !errno */-
72-
73static void kill_error __P((pid_t, int));-
74-
75#if !defined (CONTINUE_AFTER_KILL_ERROR)-
76# define CONTINUE_OR_FAIL return (EXECUTION_FAILURE)-
77#else-
78# define CONTINUE_OR_FAIL goto continue_killing-
79#endif /* CONTINUE_AFTER_KILL_ERROR */-
80-
81/* Here is the kill builtin. We only have it so that people can type-
82 kill -KILL %1? No, if you fill up the process table this way you-
83 can still kill some. */-
84int-
85kill_builtin (list)-
86 WORD_LIST *list;-
87{-
88 int sig, any_succeeded, listing, saw_signal, dflags;-
89 char *sigspec, *word;-
90 pid_t pid;-
91 intmax_t pid_value;-
92-
93 if (list == 0)
list == 0Description
TRUEnever evaluated
FALSEevaluated 26 times by 1 test
Evaluated by:
  • Self test
0-26
94 {-
95 builtin_usage ();-
96 return (EX_USAGE);
never executed: return (258);
0
97 }-
98 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 26 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(list)->wordDescription
TRUEevaluated 26 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(((list)->word... ("--help")[0]Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
__extension__ ... )))); }) == 0Description
TRUEnever evaluated
FALSEevaluated 24 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-26
99-
100 any_succeeded = listing = saw_signal = 0;-
101 sig = SIGTERM;-
102 sigspec = "TERM";-
103-
104 dflags = DSIG_NOCASE | ((posixly_correct == 0) ? DSIG_SIGPREFIX : 0);-
105 /* Process options. */-
106 while (list)
listDescription
TRUEevaluated 46 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
3-46
107 {-
108 word = list->word->word;-
109-
110 if (ISOPTION (word, 'l') || ISOPTION (word, 'L'))
word[0] == '-'Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 22 times by 1 test
Evaluated by:
  • Self test
word[1] == 'l'Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 19 times by 1 test
Evaluated by:
  • Self test
!word[2]Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
word[0] == '-'Description
TRUEevaluated 19 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 22 times by 1 test
Evaluated by:
  • Self test
word[1] == 'L'Description
TRUEnever evaluated
FALSEevaluated 19 times by 1 test
Evaluated by:
  • Self test
!word[2]Description
TRUEnever evaluated
FALSEnever evaluated
0-24
111 {-
112 listing++;-
113 list = list->next;-
114 }
executed 5 times by 1 test: end of block
Executed by:
  • Self test
5
115 else if (ISOPTION (word, 's') || ISOPTION (word, 'n'))
word[0] == '-'Description
TRUEevaluated 19 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 22 times by 1 test
Evaluated by:
  • Self test
word[1] == 's'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 17 times by 1 test
Evaluated by:
  • Self test
!word[2]Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
word[0] == '-'Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 22 times by 1 test
Evaluated by:
  • Self test
word[1] == 'n'Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11 times by 1 test
Evaluated by:
  • Self test
!word[2]Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-22
116 {-
117 list = list->next;-
118 if (list)
listDescription
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-7
119 {-
120 sigspec = list->word->word;-
121 if (sigspec[0] == '0' && sigspec[1] == '\0')
sigspec[0] == '0'Description
TRUEnever evaluated
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
sigspec[1] == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
0-7
122 sig = 0;
never executed: sig = 0;
0
123 else-
124 sig = decode_signal (sigspec, dflags);
executed 7 times by 1 test: sig = decode_signal (sigspec, dflags);
Executed by:
  • Self test
7
125 list = list->next;-
126 saw_signal++;-
127 }
executed 7 times by 1 test: end of block
Executed by:
  • Self test
7
128 else-
129 {-
130 sh_needarg (word);-
131 return (EXECUTION_FAILURE);
executed 1 time by 1 test: return (1);
Executed by:
  • Self test
1
132 }-
133 }-
134 else if (ISOPTION (word, '-'))
word[0] == '-'Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 22 times by 1 test
Evaluated by:
  • Self test
word[1] == '-'Description
TRUEnever evaluated
FALSEevaluated 11 times by 1 test
Evaluated by:
  • Self test
!word[2]Description
TRUEnever evaluated
FALSEnever evaluated
0-22
135 {-
136 list = list->next;-
137 break;
never executed: break;
0
138 }-
139 else if (ISOPTION (word, '?'))
word[0] == '-'Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 22 times by 1 test
Evaluated by:
  • Self test
word[1] == '?'Description
TRUEnever evaluated
FALSEevaluated 11 times by 1 test
Evaluated by:
  • Self test
!word[2]Description
TRUEnever evaluated
FALSEnever evaluated
0-22
140 {-
141 builtin_usage ();-
142 return (EX_USAGE);
never executed: return (258);
0
143 }-
144 /* If this is a signal specification then process it. We only process-
145 the first one seen; other arguments may signify process groups (e.g,-
146 -num == process group num). */-
147 else if (*word == '-' && saw_signal == 0)
*word == '-'Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 22 times by 1 test
Evaluated by:
  • Self test
saw_signal == 0Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-22
148 {-
149 sigspec = word + 1;-
150 sig = decode_signal (sigspec, dflags);-
151 saw_signal++;-
152 list = list->next;-
153 }
executed 11 times by 1 test: end of block
Executed by:
  • Self test
11
154 else-
155 break;
executed 22 times by 1 test: break;
Executed by:
  • Self test
22
156 }-
157-
158 if (listing)
listingDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 20 times by 1 test
Evaluated by:
  • Self test
5-20
159 return (display_signal_list (list, 0));
executed 5 times by 1 test: return (display_signal_list (list, 0));
Executed by:
  • Self test
5
160-
161 /* OK, we are killing processes. */-
162 if (sig == NO_SIG)
sig == -1Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 19 times by 1 test
Evaluated by:
  • Self test
1-19
163 {-
164 sh_invalidsig (sigspec);-
165 return (EXECUTION_FAILURE);
executed 1 time by 1 test: return (1);
Executed by:
  • Self test
1
166 }-
167-
168 if (list == 0)
list == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test
1-18
169 {-
170 builtin_usage ();-
171 return (EX_USAGE);
executed 1 time by 1 test: return (258);
Executed by:
  • Self test
1
172 }-
173-
174 while (list)
listDescription
TRUEevaluated 19 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test
18-19
175 {-
176 word = list->word->word;-
177-
178 if (*word == '-')
*word == '-'Description
TRUEnever evaluated
FALSEevaluated 19 times by 1 test
Evaluated by:
  • Self test
0-19
179 word++;
never executed: word++;
0
180-
181 /* Use the entire argument in case of minus sign presence. */-
182 if (*word && legal_number (list->word->word, &pid_value) && (pid_value == (pid_t)pid_value))
*wordDescription
TRUEevaluated 18 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
legal_number (...d, &pid_value)Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
(pid_value == ...d_t)pid_value)Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-18
183 {-
184 pid = (pid_t) pid_value;-
185-
186 if (kill_pid (pid, sig, pid < -1) < 0)
kill_pid (pid,... pid < -1) < 0Description
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • Self test
0-10
187 {-
188 if (errno == EINVAL)
(*__errno_location ()) == 22Description
TRUEnever evaluated
FALSEnever evaluated
0
189 sh_invalidsig (sigspec);
never executed: sh_invalidsig (sigspec);
0
190 else-
191 kill_error (pid, errno);
never executed: kill_error (pid, (*__errno_location ()) );
0
192 CONTINUE_OR_FAIL;
never executed: goto continue_killing;
0
193 }-
194 else-
195 any_succeeded++;
executed 10 times by 1 test: any_succeeded++;
Executed by:
  • Self test
10
196 }-
197#if defined (JOB_CONTROL)-
198 else if (*list->word->word && *list->word->word != '%)
*list->word->wordDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
*list->word->word != '%'Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
0-8
199 {-
200 builtin_error (_("%s: arguments must be process or job IDs"), list->word->word);-
201 CONTINUE_OR_FAIL;
never executed: goto continue_killing;
0
202 }-
203 else if (*word)
*wordDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-8
204 /* Posix.2 says you can kill without job control active (4.32.4) */-
205 { /* Must be a job spec. Check it out. */-
206 int job;-
207 sigset_t set, oset;-
208 JOB *j;-
209-
210 BLOCK_CHILD (set, oset);-
211 job = get_job_spec (list);-
212-
213 if (INVALID_JOB (job))
(job) < 0Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
(job) >= js.j_jobslotsDescription
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
(jobs[(job)]) == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
0-8
214 {-
215 if (job != DUP_JOB)
job != -2Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1
216 sh_badjob (list->word->word);
executed 1 time by 1 test: sh_badjob (list->word->word);
Executed by:
  • Self test
1
217 UNBLOCK_CHILD (oset);-
218 CONTINUE_OR_FAIL;
executed 1 time by 1 test: goto continue_killing;
Executed by:
  • Self test
1
219 }-
220-
221 j = get_job_by_jid (job);-
222 /* Job spec used. Kill the process group. If the job was started-
223 without job control, then its pgrp == shell_pgrp, so we have-
224 to be careful. We take the pid of the first job in the pipeline-
225 in that case. */-
226 pid = IS_JOBCONTROL (job) ? j->pgrp : j->pipe->pid;
((jobs[job]->f... & 0x04) != 0)Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-6
227-
228 UNBLOCK_CHILD (oset);-
229-
230 if (kill_pid (pid, sig, 1) < 0)
kill_pid (pid, sig, 1) < 0Description
TRUEnever evaluated
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
0-7
231 {-
232 if (errno == EINVAL)
(*__errno_location ()) == 22Description
TRUEnever evaluated
FALSEnever evaluated
0
233 sh_invalidsig (sigspec);
never executed: sh_invalidsig (sigspec);
0
234 else-
235 kill_error (pid, errno);
never executed: kill_error (pid, (*__errno_location ()) );
0
236 CONTINUE_OR_FAIL;
never executed: goto continue_killing;
0
237 }-
238 else-
239 any_succeeded++;
executed 7 times by 1 test: any_succeeded++;
Executed by:
  • Self test
7
240 }-
241#endif /* !JOB_CONTROL */-
242 else-
243 {-
244 sh_badpid (list->word->word);-
245 CONTINUE_OR_FAIL;
executed 1 time by 1 test: goto continue_killing;
Executed by:
  • Self test
1
246 }-
247 continue_killing:
code before this statement executed 17 times by 1 test: continue_killing:
Executed by:
  • Self test
17
248 list = list->next;-
249 }
executed 19 times by 1 test: end of block
Executed by:
  • Self test
19
250-
251 return (any_succeeded ? EXECUTION_SUCCESS : EXECUTION_FAILURE);
executed 18 times by 1 test: return (any_succeeded ? 0 : 1);
Executed by:
  • Self test
18
252}-
253-
254static void-
255kill_error (pid, e)-
256 pid_t pid;-
257 int e;-
258{-
259 char *x;-
260-
261 x = strerror (e);-
262 if (x == 0)
x == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
263 x = _("Unknown error");
never executed: x = dcgettext (((void *)0), "Unknown error" , 5) ;
0
264 builtin_error ("(%ld) - %s", (long)pid, x);-
265}
never executed: end of block
0
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2