OpenCoverage

redir.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/redir.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* redir.c -- Functions to perform input and output redirection. */-
2-
3/* Copyright (C) 1997-2016 Free Software Foundation, Inc.-
4-
5 This file is part of GNU Bash, the Bourne Again SHell.-
6-
7 Bash is free software: you can redistribute it and/or modify-
8 it under the terms of the GNU General Public License as published by-
9 the Free Software Foundation, either version 3 of the License, or-
10 (at your option) any later version.-
11-
12 Bash is distributed in the hope that it will be useful,-
13 but WITHOUT ANY WARRANTY; without even the implied warranty of-
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
15 GNU General Public License for more details.-
16-
17 You should have received a copy of the GNU General Public License-
18 along with Bash. If not, see <http://www.gnu.org/licenses/>.-
19*/-
20-
21#include "config.h"-
22-
23#if !defined (__GNUC__) && !defined (HAVE_ALLOCA_H) && defined (_AIX)-
24 #pragma alloca-
25#endif /* _AIX && RISC6000 && !__GNUC__ */-
26-
27#include <stdio.h>-
28#include "bashtypes.h"-
29#if !defined (_MINIX) && defined (HAVE_SYS_FILE_H)-
30# include <sys/file.h>-
31#endif-
32#include "filecntl.h"-
33#include "posixstat.h"-
34-
35#if defined (HAVE_UNISTD_H)-
36# include <unistd.h>-
37#endif-
38-
39#include <errno.h>-
40-
41#if !defined (errno)-
42extern int errno;-
43#endif-
44-
45#include "bashansi.h"-
46#include "bashintl.h"-
47#include "memalloc.h"-
48-
49#define NEED_FPURGE_DECL-
50-
51#include "shell.h"-
52#include "flags.h"-
53#include "execute_cmd.h"-
54#include "redir.h"-
55#include "trap.h"-
56-
57#if defined (BUFFERED_INPUT)-
58# include "input.h"-
59#endif-
60-
61#define SHELL_FD_BASE 10-
62-
63int expanding_redir;-
64-
65extern REDIRECT *redirection_undo_list;-
66extern REDIRECT *exec_redirection_undo_list;-
67-
68/* Static functions defined and used in this file. */-
69static void add_exec_redirect __P((REDIRECT *));-
70static int add_undo_redirect __P((int, enum r_instruction, int));-
71static int add_undo_close_redirect __P((int));-
72static int expandable_redirection_filename __P((REDIRECT *));-
73static int stdin_redirection __P((enum r_instruction, int));-
74static int undoablefd __P((int));-
75static int do_redirection_internal __P((REDIRECT *, int));-
76-
77static int write_here_document __P((int, WORD_DESC *));-
78static int write_here_string __P((int, WORD_DESC *));-
79static int here_document_to_fd __P((WORD_DESC *, enum r_instruction));-
80-
81static int redir_special_open __P((int, char *, int, int, enum r_instruction));-
82static int noclobber_open __P((char *, int, int, enum r_instruction));-
83static int redir_open __P((char *, int, int, enum r_instruction));-
84-
85static int redir_varassign __P((REDIRECT *, int));-
86static int redir_varvalue __P((REDIRECT *));-
87-
88/* Spare redirector used when translating [N]>&WORD[-] or [N]<&WORD[-] to-
89 a new redirection and when creating the redirection undo list. */-
90static REDIRECTEE rd;-
91-
92/* Set to errno when a here document cannot be created for some reason.-
93 Used to print a reasonable error message. */-
94static int heredoc_errno;-
95-
96#define REDIRECTION_ERROR(r, e, fd) \-
97do { \-
98 if ((r) < 0) \-
99 { \-
100 if (fd >= 0) \-
101 close (fd); \-
102 last_command_exit_value = EXECUTION_FAILURE;\-
103 return ((e) == 0 ? EINVAL : (e));\-
104 } \-
105} while (0)-
106-
107void-
108redirection_error (temp, error)-
109 REDIRECT *temp;-
110 int error;-
111{-
112 char *filename, *allocname;-
113 int oflags;-
114-
115 allocname = 0;-
116 if ((temp->rflags & REDIR_VARASSIGN) && error < 0)
(temp->rflags & 0x01)Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 104 times by 1 test
Evaluated by:
  • Self test
error < 0Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-104
117 filename = allocname = savestring (temp->redirector.filename->word);
executed 8 times by 1 test: filename = allocname = (char *)strcpy (sh_xmalloc((1 + strlen (temp->redirector.filename->word)), "redir.c", 117), (temp->redirector.filename->word));
Executed by:
  • Self test
8
118 else if ((temp->rflags & REDIR_VARASSIGN) == 0 && temp->redirector.dest < 0)
(temp->rflags & 0x01) == 0Description
TRUEevaluated 104 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
temp->redirector.dest < 0Description
TRUEnever evaluated
FALSEevaluated 104 times by 1 test
Evaluated by:
  • Self test
0-104
119 /* This can happen when read_token_word encounters overflow, like in-
120 exec 4294967297>x */-
121 filename = _("file descriptor out of range");
never executed: filename = dcgettext (((void *)0), "file descriptor out of range" , 5) ;
0
122#ifdef EBADF-
123 /* This error can never involve NOCLOBBER */-
124 else if (error != NOCLOBBER_REDIRECT && temp->redirector.dest >= 0 && error == EBADF)
error != -2Description
TRUEevaluated 86 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 19 times by 1 test
Evaluated by:
  • Self test
temp->redirector.dest >= 0Description
TRUEevaluated 86 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
error == 9Description
TRUEevaluated 55 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 31 times by 1 test
Evaluated by:
  • Self test
0-86
125 {-
126 /* If we're dealing with two file descriptors, we have to guess about-
127 which one is invalid; in the cases of r_{duplicating,move}_input and-
128 r_{duplicating,move}_output we're here because dup2() failed. */-
129 switch (temp->instruction)-
130 {-
131 case r_duplicating_input:
never executed: case r_duplicating_input:
0
132 case r_duplicating_output:
never executed: case r_duplicating_output:
0
133 case r_move_input:
never executed: case r_move_input:
0
134 case r_move_output:
never executed: case r_move_output:
0
135 filename = allocname = itos (temp->redirectee.dest);-
136 break;
never executed: break;
0
137 case r_duplicating_input_word:
never executed: case r_duplicating_input_word:
0
138 if (temp->redirector.dest == 0) /* Guess */
temp->redirector.dest == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
139 filename = temp->redirectee.filename->word; /* XXX */
never executed: filename = temp->redirectee.filename->word;
0
140 else-
141 filename = allocname = itos (temp->redirector.dest);
never executed: filename = allocname = itos (temp->redirector.dest);
0
142 break;
never executed: break;
0
143 case r_duplicating_output_word:
executed 55 times by 1 test: case r_duplicating_output_word:
Executed by:
  • Self test
55
144 if (temp->redirector.dest == 1) /* Guess */
temp->redirector.dest == 1Description
TRUEevaluated 55 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-55
145 filename = temp->redirectee.filename->word; /* XXX */
executed 55 times by 1 test: filename = temp->redirectee.filename->word;
Executed by:
  • Self test
55
146 else-
147 filename = allocname = itos (temp->redirector.dest);
never executed: filename = allocname = itos (temp->redirector.dest);
0
148 break;
executed 55 times by 1 test: break;
Executed by:
  • Self test
55
149 default:
never executed: default:
0
150 filename = allocname = itos (temp->redirector.dest);-
151 break;
never executed: break;
0
152 }-
153 }-
154#endif-
155 else if (expandable_redirection_filename (temp))
expandable_red...ilename (temp)Description
TRUEevaluated 50 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-50
156 {-
157 oflags = temp->redirectee.filename->flags;-
158 if (posixly_correct && interactive_shell == 0)
posixly_correctDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 48 times by 1 test
Evaluated by:
  • Self test
interactive_shell == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-48
159 temp->redirectee.filename->flags |= W_NOGLOB;
executed 2 times by 1 test: temp->redirectee.filename->flags |= 0x000020;
Executed by:
  • Self test
2
160 temp->redirectee.filename->flags |= W_NOCOMSUB;-
161 filename = allocname = redirection_expand (temp->redirectee.filename);-
162 temp->redirectee.filename->flags = oflags;-
163 if (filename == 0)
filename == 0Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 42 times by 1 test
Evaluated by:
  • Self test
8-42
164 filename = temp->redirectee.filename->word;
executed 8 times by 1 test: filename = temp->redirectee.filename->word;
Executed by:
  • Self test
8
165 }
executed 50 times by 1 test: end of block
Executed by:
  • Self test
50
166 else if (temp->redirectee.dest < 0)
temp->redirectee.dest < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
167 filename = _("file descriptor out of range");
never executed: filename = dcgettext (((void *)0), "file descriptor out of range" , 5) ;
0
168 else-
169 filename = allocname = itos (temp->redirectee.dest);
never executed: filename = allocname = itos (temp->redirectee.dest);
0
170-
171 switch (error)-
172 {-
173 case AMBIGUOUS_REDIRECT:
executed 9 times by 1 test: case -1:
Executed by:
  • Self test
9
174 internal_error (_("%s: ambiguous redirect"), filename);-
175 break;
executed 9 times by 1 test: break;
Executed by:
  • Self test
9
176-
177 case NOCLOBBER_REDIRECT:
executed 19 times by 1 test: case -2:
Executed by:
  • Self test
19
178 internal_error (_("%s: cannot overwrite existing file"), filename);-
179 break;
executed 19 times by 1 test: break;
Executed by:
  • Self test
19
180-
181#if defined (RESTRICTED_SHELL)-
182 case RESTRICTED_REDIRECT:
executed 2 times by 1 test: case -3:
Executed by:
  • Self test
2
183 internal_error (_("%s: restricted: cannot redirect output"), filename);-
184 break;
executed 2 times by 1 test: break;
Executed by:
  • Self test
2
185#endif /* RESTRICTED_SHELL */-
186-
187 case HEREDOC_REDIRECT:
never executed: case -4:
0
188 internal_error (_("cannot create temp file for here-document: %s"), strerror (heredoc_errno));-
189 break;
never executed: break;
0
190-
191 case BADVAR_REDIRECT:
executed 7 times by 1 test: case -5:
Executed by:
  • Self test
7
192 internal_error (_("%s: cannot assign fd to variable"), filename);-
193 break;
executed 7 times by 1 test: break;
Executed by:
  • Self test
7
194-
195 default:
executed 76 times by 1 test: default:
Executed by:
  • Self test
76
196 internal_error ("%s: %s", filename, strerror (error));-
197 break;
executed 76 times by 1 test: break;
Executed by:
  • Self test
76
198 }-
199-
200 FREE (allocname);
executed 50 times by 1 test: sh_xfree((allocname), "redir.c", 200);
Executed by:
  • Self test
allocnameDescription
TRUEevaluated 50 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 63 times by 1 test
Evaluated by:
  • Self test
50-63
201}
executed 113 times by 1 test: end of block
Executed by:
  • Self test
113
202-
203/* Perform the redirections on LIST. If flags & RX_ACTIVE, then actually-
204 make input and output file descriptors, otherwise just do whatever is-
205 necessary for side effecting. flags & RX_UNDOABLE says to remember-
206 how to undo the redirections later, if non-zero. If flags & RX_CLEXEC-
207 is non-zero, file descriptors opened in do_redirection () have their-
208 close-on-exec flag set. */-
209int-
210do_redirections (list, flags)-
211 REDIRECT *list;-
212 int flags;-
213{-
214 int error;-
215 REDIRECT *temp;-
216-
217 if (flags & RX_UNDOABLE)
flags & 0x02Description
TRUEevaluated 242478214 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 30628501 times by 1 test
Evaluated by:
  • Self test
30628501-242478214
218 {-
219 if (redirection_undo_list)
redirection_undo_listDescription
TRUEnever evaluated
FALSEevaluated 242478214 times by 1 test
Evaluated by:
  • Self test
0-242478214
220 {-
221 dispose_redirects (redirection_undo_list);-
222 redirection_undo_list = (REDIRECT *)NULL;-
223 }
never executed: end of block
0
224 if (exec_redirection_undo_list)
exec_redirection_undo_listDescription
TRUEevaluated 37 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 242478177 times by 1 test
Evaluated by:
  • Self test
37-242478177
225 dispose_exec_redirects ();
executed 37 times by 1 test: dispose_exec_redirects ();
Executed by:
  • Self test
37
226 }
executed 242478214 times by 1 test: end of block
Executed by:
  • Self test
242478214
227-
228 for (temp = list; temp; temp = temp->next)
tempDescription
TRUEevaluated 1366014 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 273105229 times by 1 test
Evaluated by:
  • Self test
1366014-273105229
229 {-
230 error = do_redirection_internal (temp, flags);-
231 if (error)
errorDescription
TRUEevaluated 113 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1364528 times by 1 test
Evaluated by:
  • Self test
113-1364528
232 {-
233 redirection_error (temp, error);-
234 return (error);
executed 113 times by 1 test: return (error);
Executed by:
  • Self test
113
235 }-
236 }
executed 1364528 times by 1 test: end of block
Executed by:
  • Self test
1364528
237 return (0);
executed 273105229 times by 1 test: return (0);
Executed by:
  • Self test
273105229
238}-
239-
240/* Return non-zero if the redirection pointed to by REDIRECT has a-
241 redirectee.filename that can be expanded. */-
242static int-
243expandable_redirection_filename (redirect)-
244 REDIRECT *redirect;-
245{-
246 switch (redirect->instruction)-
247 {-
248 case r_output_direction:
executed 26 times by 1 test: case r_output_direction:
Executed by:
  • Self test
26
249 case r_appending_to:
executed 1 time by 1 test: case r_appending_to:
Executed by:
  • Self test
1
250 case r_input_direction:
executed 16 times by 1 test: case r_input_direction:
Executed by:
  • Self test
16
251 case r_inputa_direction:
never executed: case r_inputa_direction:
0
252 case r_err_and_out:
never executed: case r_err_and_out:
0
253 case r_append_err_and_out:
never executed: case r_append_err_and_out:
0
254 case r_input_output:
never executed: case r_input_output:
0
255 case r_output_force:
never executed: case r_output_force:
0
256 case r_duplicating_input_word:
executed 1 time by 1 test: case r_duplicating_input_word:
Executed by:
  • Self test
1
257 case r_duplicating_output_word:
executed 6 times by 1 test: case r_duplicating_output_word:
Executed by:
  • Self test
6
258 case r_move_input_word:
never executed: case r_move_input_word:
0
259 case r_move_output_word:
never executed: case r_move_output_word:
0
260 return 1;
executed 50 times by 1 test: return 1;
Executed by:
  • Self test
50
261-
262 default:
never executed: default:
0
263 return 0;
never executed: return 0;
0
264 }-
265}-
266-
267/* Expand the word in WORD returning a string. If WORD expands to-
268 multiple words (or no words), then return NULL. */-
269char *-
270redirection_expand (word)-
271 WORD_DESC *word;-
272{-
273 char *result;-
274 WORD_LIST *tlist1, *tlist2;-
275 WORD_DESC *w;-
276 int old;-
277-
278 w = copy_word (word);-
279 if (posixly_correct)
posixly_correctDescription
TRUEevaluated 15 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 667558 times by 1 test
Evaluated by:
  • Self test
15-667558
280 w->flags |= W_NOSPLIT;
executed 15 times by 1 test: w->flags |= 0x000010;
Executed by:
  • Self test
15
281-
282 tlist1 = make_word_list (w, (WORD_LIST *)NULL);-
283 expanding_redir = 1;-
284 /* Now that we've changed the variable search order to ignore the temp-
285 environment, see if we need to change the cached IFS values. */-
286 sv_ifs ("IFS");-
287 tlist2 = expand_words_no_vars (tlist1);-
288 expanding_redir = 0;-
289 /* Now we need to change the variable search order back to include the temp-
290 environment. We force the temp environment search by forcing-
291 executing_builtin to 1. This is what makes `read' get the right values-
292 for the IFS-related cached variables, for example. */-
293 old = executing_builtin;-
294 executing_builtin = 1;-
295 sv_ifs ("IFS");-
296 executing_builtin = old;-
297 dispose_words (tlist1);-
298-
299 if (tlist2 == 0 || tlist2->next)
tlist2 == 0Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 666192 times by 1 test
Evaluated by:
  • Self test
tlist2->nextDescription
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 666185 times by 1 test
Evaluated by:
  • Self test
7-666192
300 {-
301 /* We expanded to no words, or to more than a single word.-
302 Dispose of the word list and return NULL. */-
303 if (tlist2)
tlist2Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
7-9
304 dispose_words (tlist2);
executed 7 times by 1 test: dispose_words (tlist2);
Executed by:
  • Self test
7
305 return ((char *)NULL);
executed 16 times by 1 test: return ((char *) ((void *)0) );
Executed by:
  • Self test
16
306 }-
307 result = string_list (tlist2); /* XXX savestring (tlist2->word->word)? */-
308 dispose_words (tlist2);-
309 return (result);
executed 666185 times by 1 test: return (result);
Executed by:
  • Self test
666185
310}-
311-
312static int-
313write_here_string (fd, redirectee)-
314 int fd;-
315 WORD_DESC *redirectee;-
316{-
317 char *herestr;-
318 int herelen, n, e, old;-
319-
320 expanding_redir = 1;-
321 /* Now that we've changed the variable search order to ignore the temp-
322 environment, see if we need to change the cached IFS values. */-
323 sv_ifs ("IFS");-
324 herestr = expand_string_unsplit_to_string (redirectee->word, 0);-
325 expanding_redir = 0;-
326 /* Now we need to change the variable search order back to include the temp-
327 environment. We force the temp environment search by forcing-
328 executing_builtin to 1. This is what makes `read' get the right values-
329 for the IFS-related cached variables, for example. */-
330 old = executing_builtin;-
331 executing_builtin = 1;-
332 sv_ifs ("IFS");-
333 executing_builtin = old;-
334-
335 herelen = STRLEN (herestr);
(herestr)[1]Description
TRUEevaluated 25 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
(herestr)[2]Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
(herestr)Description
TRUEevaluated 31 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(herestr)[0]Description
TRUEevaluated 31 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-31
336-
337 n = write (fd, herestr, herelen);-
338 if (n == herelen)
n == herelenDescription
TRUEevaluated 31 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-31
339 {-
340 n = write (fd, "\n", 1);-
341 herelen = 1;-
342 }
executed 31 times by 1 test: end of block
Executed by:
  • Self test
31
343 e = errno;-
344 FREE (herestr);
executed 31 times by 1 test: sh_xfree((herestr), "redir.c", 344);
Executed by:
  • Self test
herestrDescription
TRUEevaluated 31 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-31
345 if (n != herelen)
n != herelenDescription
TRUEnever evaluated
FALSEevaluated 31 times by 1 test
Evaluated by:
  • Self test
0-31
346 {-
347 if (e == 0)
e == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
348 e = ENOSPC;
never executed: e = 28 ;
0
349 return e;
never executed: return e;
0
350 }-
351 return 0;
executed 31 times by 1 test: return 0;
Executed by:
  • Self test
31
352} -
353-
354/* Write the text of the here document pointed to by REDIRECTEE to the file-
355 descriptor FD, which is already open to a temp file. Return 0 if the-
356 write is successful, otherwise return errno. */-
357static int-
358write_here_document (fd, redirectee)-
359 int fd;-
360 WORD_DESC *redirectee;-
361{-
362 char *document;-
363 int document_len, fd2, old;-
364 FILE *fp;-
365 register WORD_LIST *t, *tlist;-
366-
367 /* Expand the text if the word that was specified had-
368 no quoting. The text that we expand is treated-
369 exactly as if it were surrounded by double quotes. */-
370-
371 if (redirectee->flags & W_QUOTED)
redirectee->flags & 0x000002Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 72 times by 1 test
Evaluated by:
  • Self test
1-72
372 {-
373 document = redirectee->word;-
374 document_len = strlen (document);-
375 /* Set errno to something reasonable if the write fails. */-
376 if (write (fd, document, document_len) < document_len)
write (fd, doc...< document_lenDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
0-1
377 {-
378 if (errno == 0)
(*__errno_location ()) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
379 errno = ENOSPC;
never executed: (*__errno_location ()) = 28 ;
0
380 return (errno);
never executed: return ( (*__errno_location ()) );
0
381 }-
382 else-
383 return 0;
executed 1 time by 1 test: return 0;
Executed by:
  • Self test
1
384 }-
385-
386 expanding_redir = 1;-
387 /* Now that we've changed the variable search order to ignore the temp-
388 environment, see if we need to change the cached IFS values. */-
389 sv_ifs ("IFS");-
390 tlist = expand_string (redirectee->word, Q_HERE_DOCUMENT);-
391 expanding_redir = 0;-
392 /* Now we need to change the variable search order back to include the temp-
393 environment. We force the temp environment search by forcing-
394 executing_builtin to 1. This is what makes `read' get the right values-
395 for the IFS-related cached variables, for example. */-
396 old = executing_builtin;-
397 executing_builtin = 1;-
398 sv_ifs ("IFS");-
399 executing_builtin = old;-
400-
401 if (tlist)
tlistDescription
TRUEevaluated 72 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-72
402 {-
403 /* Try using buffered I/O (stdio) and writing a word-
404 at a time, letting stdio do the work of buffering-
405 for us rather than managing our own strings. Most-
406 stdios are not particularly fast, however -- this-
407 may need to be reconsidered later. */-
408 if ((fd2 = dup (fd)) < 0 || (fp = fdopen (fd2, "w")) == NULL)
(fd2 = dup (fd)) < 0Description
TRUEnever evaluated
FALSEevaluated 72 times by 1 test
Evaluated by:
  • Self test
(fp = fdopen (...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 72 times by 1 test
Evaluated by:
  • Self test
0-72
409 {-
410 old = errno;-
411 if (fd2 >= 0)
fd2 >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
412 close (fd2);
never executed: close (fd2);
0
413 dispose_words (tlist);-
414 errno = old;-
415 return (errno);
never executed: return ( (*__errno_location ()) );
0
416 }-
417 errno = 0;-
418 for (t = tlist; t; t = t->next)
tDescription
TRUEevaluated 72 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 72 times by 1 test
Evaluated by:
  • Self test
72
419 {-
420 /* This is essentially the body of-
421 string_list_internal expanded inline. */-
422 document = t->word->word;-
423 document_len = strlen (document);-
424 if (t != tlist)
t != tlistDescription
TRUEnever evaluated
FALSEevaluated 72 times by 1 test
Evaluated by:
  • Self test
0-72
425 putc (' ', fp); /* separator */
never executed: _IO_putc ( ' ' , fp ) ;
0
426 fwrite (document, document_len, 1, fp);-
427 if (ferror (fp))
ferror (fp)Description
TRUEnever evaluated
FALSEevaluated 72 times by 1 test
Evaluated by:
  • Self test
0-72
428 {-
429 if (errno == 0)
(*__errno_location ()) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
430 errno = ENOSPC;
never executed: (*__errno_location ()) = 28 ;
0
431 fd2 = errno;-
432 fclose(fp);-
433 dispose_words (tlist);-
434 return (fd2);
never executed: return (fd2);
0
435 }-
436 }
executed 72 times by 1 test: end of block
Executed by:
  • Self test
72
437 dispose_words (tlist);-
438 if (fclose (fp) != 0)
fclose (fp) != 0Description
TRUEnever evaluated
FALSEevaluated 72 times by 1 test
Evaluated by:
  • Self test
0-72
439 {-
440 if (errno == 0)
(*__errno_location ()) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
441 errno = ENOSPC;
never executed: (*__errno_location ()) = 28 ;
0
442 return (errno);
never executed: return ( (*__errno_location ()) );
0
443 }-
444 }
executed 72 times by 1 test: end of block
Executed by:
  • Self test
72
445 return 0;
executed 72 times by 1 test: return 0;
Executed by:
  • Self test
72
446}-
447-
448/* Create a temporary file holding the text of the here document pointed to-
449 by REDIRECTEE, and return a file descriptor open for reading to the temp-
450 file. Return -1 on any error, and make sure errno is set appropriately. */-
451static int-
452here_document_to_fd (redirectee, ri)-
453 WORD_DESC *redirectee;-
454 enum r_instruction ri;-
455{-
456 char *filename;-
457 int r, fd, fd2;-
458-
459 fd = sh_mktmpfd ("sh-thd", MT_USERANDOM|MT_USETMPDIR, &filename);-
460-
461 /* If we failed for some reason other than the file existing, abort */-
462 if (fd < 0)
fd < 0Description
TRUEnever evaluated
FALSEevaluated 105 times by 1 test
Evaluated by:
  • Self test
0-105
463 {-
464 FREE (filename);
never executed: sh_xfree((filename), "redir.c", 464);
filenameDescription
TRUEnever evaluated
FALSEnever evaluated
0
465 return (fd);
never executed: return (fd);
0
466 }-
467-
468 SET_CLOSE_ON_EXEC (fd);-
469-
470 errno = r = 0; /* XXX */-
471 /* write_here_document returns 0 on success, errno on failure. */-
472 if (redirectee->word)
redirectee->wordDescription
TRUEevaluated 105 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-105
473 r = (ri != r_reading_string) ? write_here_document (fd, redirectee)
executed 105 times by 1 test: r = (ri != r_reading_string) ? write_here_document (fd, redirectee) : write_here_string (fd, redirectee);
Executed by:
  • Self test
(ri != r_reading_string)Description
TRUEevaluated 73 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 32 times by 1 test
Evaluated by:
  • Self test
32-105
474 : write_here_string (fd, redirectee);
executed 105 times by 1 test: r = (ri != r_reading_string) ? write_here_document (fd, redirectee) : write_here_string (fd, redirectee);
Executed by:
  • Self test
105
475-
476 if (r)
rDescription
TRUEnever evaluated
FALSEevaluated 104 times by 1 test
Evaluated by:
  • Self test
0-104
477 {-
478 close (fd);-
479 unlink (filename);-
480 free (filename);-
481 errno = r;-
482 return (-1);
never executed: return (-1);
0
483 }-
484-
485 /* In an attempt to avoid races, we close the first fd only after opening-
486 the second. */-
487 /* Make the document really temporary. Also make it the input. */-
488 fd2 = open (filename, O_RDONLY|O_BINARY, 0600);-
489-
490 if (fd2 < 0)
fd2 < 0Description
TRUEnever evaluated
FALSEevaluated 104 times by 1 test
Evaluated by:
  • Self test
0-104
491 {-
492 r = errno;-
493 unlink (filename);-
494 free (filename);-
495 close (fd);-
496 errno = r;-
497 return -1;
never executed: return -1;
0
498 }-
499-
500 close (fd);-
501 if (unlink (filename) < 0)
unlink (filename) < 0Description
TRUEnever evaluated
FALSEevaluated 104 times by 1 test
Evaluated by:
  • Self test
0-104
502 {-
503 r = errno;-
504 close (fd2);-
505 free (filename);-
506 errno = r;-
507 return (-1);
never executed: return (-1);
0
508 }-
509-
510 free (filename);-
511 return (fd2);
executed 104 times by 1 test: return (fd2);
Executed by:
  • Self test
104
512}-
513-
514#define RF_DEVFD 1-
515#define RF_DEVSTDERR 2-
516#define RF_DEVSTDIN 3-
517#define RF_DEVSTDOUT 4-
518#define RF_DEVTCP 5-
519#define RF_DEVUDP 6-
520-
521/* A list of pattern/value pairs for filenames that the redirection-
522 code handles specially. */-
523static STRING_INT_ALIST _redir_special_filenames[] = {-
524#if !defined (HAVE_DEV_FD)-
525 { "/dev/fd/[0-9]*", RF_DEVFD },-
526#endif-
527#if !defined (HAVE_DEV_STDIN)-
528 { "/dev/stderr", RF_DEVSTDERR },-
529 { "/dev/stdin", RF_DEVSTDIN },-
530 { "/dev/stdout", RF_DEVSTDOUT },-
531#endif-
532#if defined (NETWORK_REDIRECTIONS)-
533 { "/dev/tcp/*/*", RF_DEVTCP },-
534 { "/dev/udp/*/*", RF_DEVUDP },-
535#endif-
536 { (char *)NULL, -1 }-
537};-
538-
539static int-
540redir_special_open (spec, filename, flags, mode, ri)-
541 int spec;-
542 char *filename;-
543 int flags, mode;-
544 enum r_instruction ri;-
545{-
546 int fd;-
547#if !defined (HAVE_DEV_FD)-
548 intmax_t lfd;-
549#endif-
550-
551 fd = -1;-
552 switch (spec)-
553 {-
554#if !defined (HAVE_DEV_FD)-
555 case RF_DEVFD:-
556 if (all_digits (filename+8) && legal_number (filename+8, &lfd) && lfd == (int)lfd)-
557 {-
558 fd = lfd;-
559 fd = fcntl (fd, F_DUPFD, SHELL_FD_BASE);-
560 }-
561 else-
562 fd = AMBIGUOUS_REDIRECT;-
563 break;-
564#endif-
565-
566#if !defined (HAVE_DEV_STDIN)-
567 case RF_DEVSTDIN:-
568 fd = fcntl (0, F_DUPFD, SHELL_FD_BASE);-
569 break;-
570 case RF_DEVSTDOUT:-
571 fd = fcntl (1, F_DUPFD, SHELL_FD_BASE);-
572 break;-
573 case RF_DEVSTDERR:-
574 fd = fcntl (2, F_DUPFD, SHELL_FD_BASE);-
575 break;-
576#endif-
577-
578#if defined (NETWORK_REDIRECTIONS)-
579 case RF_DEVTCP:
never executed: case 5:
0
580 case RF_DEVUDP:
never executed: case 6:
0
581#if defined (RESTRICTED_SHELL)-
582 if (restricted)
restrictedDescription
TRUEnever evaluated
FALSEnever evaluated
0
583 return (RESTRICTED_REDIRECT);
never executed: return (-3);
0
584#endif-
585#if defined (HAVE_NETWORK)-
586 fd = netopen (filename);-
587#else-
588 internal_warning (_("/dev/(tcp|udp)/host/port not supported without networking"));-
589 fd = open (filename, flags, mode);-
590#endif-
591 break;
never executed: break;
0
592#endif /* NETWORK_REDIRECTIONS */-
593 }-
594-
595 return fd;
never executed: return fd;
0
596}-
597 -
598/* Open FILENAME with FLAGS in noclobber mode, hopefully avoiding most-
599 race conditions and avoiding the problem where the file is replaced-
600 between the stat(2) and open(2). */-
601static int-
602noclobber_open (filename, flags, mode, ri)-
603 char *filename;-
604 int flags, mode;-
605 enum r_instruction ri;-
606{-
607 int r, fd;-
608 struct stat finfo, finfo2;-
609-
610 /* If the file exists and is a regular file, return an error-
611 immediately. */-
612 r = stat (filename, &finfo);-
613 if (r == 0 && (S_ISREG (finfo.st_mode)))
r == 0Description
TRUEevaluated 19 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 19 times by 1 test
Evaluated by:
  • Self test
( (((( finfo.s...= (0100000)) )Description
TRUEevaluated 19 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-19
614 return (NOCLOBBER_REDIRECT);
executed 19 times by 1 test: return (-2);
Executed by:
  • Self test
19
615-
616 /* If the file was not present (r != 0), make sure we open it-
617 exclusively so that if it is created before we open it, our open-
618 will fail. Make sure that we do not truncate an existing file.-
619 Note that we don't turn on O_EXCL unless the stat failed -- if-
620 the file was not a regular file, we leave O_EXCL off. */-
621 flags &= ~O_TRUNC;-
622 if (r != 0)
r != 0Description
TRUEevaluated 19 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-19
623 {-
624 fd = open (filename, flags|O_EXCL, mode);-
625 return ((fd < 0 && errno == EEXIST) ? NOCLOBBER_REDIRECT : fd);
executed 19 times by 1 test: return ((fd < 0 && (*__errno_location ()) == 17 ) ? -2 : fd);
Executed by:
  • Self test
19
626 }-
627 fd = open (filename, flags, mode);-
628-
629 /* If the open failed, return the file descriptor right away. */-
630 if (fd < 0)
fd < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
631 return (errno == EEXIST ? NOCLOBBER_REDIRECT : fd);
never executed: return ( (*__errno_location ()) == 17 ? -2 : fd);
0
632-
633 /* OK, the open succeeded, but the file may have been changed from a-
634 non-regular file to a regular file between the stat and the open.-
635 We are assuming that the O_EXCL open handles the case where FILENAME-
636 did not exist and is symlinked to an existing file between the stat-
637 and open. */-
638-
639 /* If we can open it and fstat the file descriptor, and neither check-
640 revealed that it was a regular file, and the file has not been replaced,-
641 return the file descriptor. */-
642 if ((fstat (fd, &finfo2) == 0) && (S_ISREG (finfo2.st_mode) == 0) &&
(fstat (fd, &finfo2) == 0)Description
TRUEnever evaluated
FALSEnever evaluated
( (((( finfo2....100000)) == 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
643 r == 0 && (S_ISREG (finfo.st_mode) == 0) &&
r == 0Description
TRUEnever evaluated
FALSEnever evaluated
( (((( finfo.s...100000)) == 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
644 same_file (filename, filename, &finfo, &finfo2))
same_file (fil...info, &finfo2)Description
TRUEnever evaluated
FALSEnever evaluated
0
645 return fd;
never executed: return fd;
0
646-
647 /* The file has been replaced. badness. */-
648 close (fd); -
649 errno = EEXIST;-
650 return (NOCLOBBER_REDIRECT);
never executed: return (-2);
0
651}-
652-
653static int-
654redir_open (filename, flags, mode, ri)-
655 char *filename;-
656 int flags, mode;-
657 enum r_instruction ri;-
658{-
659 int fd, r, e;-
660-
661 r = find_string_in_alist (filename, _redir_special_filenames, 1);-
662 if (r >= 0)
r >= 0Description
TRUEnever evaluated
FALSEevaluated 666015 times by 1 test
Evaluated by:
  • Self test
0-666015
663 return (redir_special_open (r, filename, flags, mode, ri));
never executed: return (redir_special_open (r, filename, flags, mode, ri));
0
664-
665 /* If we are in noclobber mode, you are not allowed to overwrite-
666 existing files. Check before opening. */-
667 if (noclobber && CLOBBERING_REDIRECT (ri))
noclobberDescription
TRUEevaluated 57 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 665958 times by 1 test
Evaluated by:
  • Self test
ri == r_output_directionDescription
TRUEevaluated 38 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 19 times by 1 test
Evaluated by:
  • Self test
ri == r_err_and_outDescription
TRUEnever evaluated
FALSEevaluated 19 times by 1 test
Evaluated by:
  • Self test
0-665958
668 {-
669 fd = noclobber_open (filename, flags, mode, ri);-
670 if (fd == NOCLOBBER_REDIRECT)
fd == -2Description
TRUEevaluated 19 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 19 times by 1 test
Evaluated by:
  • Self test
19
671 return (NOCLOBBER_REDIRECT);
executed 19 times by 1 test: return (-2);
Executed by:
  • Self test
19
672 }
executed 19 times by 1 test: end of block
Executed by:
  • Self test
19
673 else-
674 {-
675 do-
676 {-
677 fd = open (filename, flags, mode);-
678 e = errno;-
679 if (fd < 0 && e == EINTR)
fd < 0Description
TRUEevaluated 20 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 665957 times by 1 test
Evaluated by:
  • Self test
e == 4Description
TRUEnever evaluated
FALSEevaluated 20 times by 1 test
Evaluated by:
  • Self test
0-665957
680 {-
681 QUIT;
never executed: termsig_handler (terminating_signal);
never executed: throw_to_top_level ();
terminating_signalDescription
TRUEnever evaluated
FALSEnever evaluated
interrupt_stateDescription
TRUEnever evaluated
FALSEnever evaluated
0
682 run_pending_traps ();-
683 }
never executed: end of block
0
684 errno = e;-
685 }
executed 665977 times by 1 test: end of block
Executed by:
  • Self test
665977
686 while (fd < 0 && errno == EINTR);
fd < 0Description
TRUEevaluated 20 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 665957 times by 1 test
Evaluated by:
  • Self test
(*__errno_location ()) == 4Description
TRUEnever evaluated
FALSEevaluated 20 times by 1 test
Evaluated by:
  • Self test
0-665957
687-
688#if defined (AFS)-
689 if ((fd < 0) && (errno == EACCES))-
690 {-
691 fd = open (filename, flags & ~O_CREAT, mode);-
692 errno = EACCES; /* restore errno */-
693 }-
694#endif /* AFS */-
695 }
executed 665977 times by 1 test: end of block
Executed by:
  • Self test
665977
696-
697 return fd;
executed 665996 times by 1 test: return fd;
Executed by:
  • Self test
665996
698}-
699-
700static int-
701undoablefd (fd)-
702 int fd;-
703{-
704 int clexec;-
705-
706 clexec = fcntl (fd, F_GETFD, 0);-
707 if (clexec == -1 || (fd >= SHELL_FD_BASE && clexec == 1))
clexec == -1Description
TRUEnever evaluated
FALSEnever evaluated
fd >= 10Description
TRUEnever evaluated
FALSEnever evaluated
clexec == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
708 return 0;
never executed: return 0;
0
709 return 1;
never executed: return 1;
0
710}-
711-
712/* Do the specific redirection requested. Returns errno or one of the-
713 special redirection errors (*_REDIRECT) in case of error, 0 on success.-
714 If flags & RX_ACTIVE is zero, then just do whatever is necessary to-
715 produce the appropriate side effects. flags & RX_UNDOABLE, if non-zero,-
716 says to remember how to undo each redirection. If flags & RX_CLEXEC is-
717 non-zero, then we set all file descriptors > 2 that we open to be-
718 close-on-exec. */-
719static int-
720do_redirection_internal (redirect, flags)-
721 REDIRECT *redirect;-
722 int flags;-
723{-
724 WORD_DESC *redirectee;-
725 int redir_fd, fd, redirector, r, oflags;-
726 intmax_t lfd;-
727 char *redirectee_word;-
728 enum r_instruction ri;-
729 REDIRECT *new_redirect;-
730 REDIRECTEE sd;-
731-
732 redirectee = redirect->redirectee.filename;-
733 redir_fd = redirect->redirectee.dest;-
734 redirector = redirect->redirector.dest;-
735 ri = redirect->instruction;-
736-
737 if (redirect->flags & RX_INTERNAL)
redirect->flags & 0x08Description
TRUEevaluated 698018 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 667996 times by 1 test
Evaluated by:
  • Self test
667996-698018
738 flags |= RX_INTERNAL;
executed 698018 times by 1 test: flags |= 0x08;
Executed by:
  • Self test
698018
739-
740 if (TRANSLATE_REDIRECT (ri))
ri == r_duplicating_input_wordDescription
TRUEevaluated 20 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1365994 times by 1 test
Evaluated by:
  • Self test
ri == r_duplic...ng_output_wordDescription
TRUEevaluated 112 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1365882 times by 1 test
Evaluated by:
  • Self test
ri == r_move_input_wordDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1365879 times by 1 test
Evaluated by:
  • Self test
ri == r_move_output_wordDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1365876 times by 1 test
Evaluated by:
  • Self test
3-1365994
741 {-
742 /* We have [N]>&WORD[-] or [N]<&WORD[-] (or {V}>&WORD[-] or {V}<&WORD-).-
743 and WORD, then translate the redirection into a new one and -
744 continue. */-
745 redirectee_word = redirection_expand (redirectee);-
746-
747 /* XXX - what to do with [N]<&$w- where w is unset or null? ksh93-
748 closes N. */-
749 if (redirectee_word == 0)
redirectee_word == 0Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 121 times by 1 test
Evaluated by:
  • Self test
7-121
750 return (AMBIGUOUS_REDIRECT);
executed 7 times by 1 test: return (-1);
Executed by:
  • Self test
7
751 else if (redirectee_word[0] == '-' && redirectee_word[1] == '\0')
redirectee_word[0] == '-'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 119 times by 1 test
Evaluated by:
  • Self test
redirectee_word[1] == '\0'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-119
752 {-
753 sd = redirect->redirector;-
754 rd.dest = 0;-
755 new_redirect = make_redirection (sd, r_close_this, rd, 0);-
756 }
executed 2 times by 1 test: end of block
Executed by:
  • Self test
2
757 else if (all_digits (redirectee_word))
all_digits (redirectee_word)Description
TRUEevaluated 117 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
2-117
758 {-
759 sd = redirect->redirector;-
760 if (legal_number (redirectee_word, &lfd) && (int)lfd == lfd)
legal_number (...ee_word, &lfd)Description
TRUEevaluated 117 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(int)lfd == lfdDescription
TRUEevaluated 117 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-117
761 rd.dest = lfd;
executed 117 times by 1 test: rd.dest = lfd;
Executed by:
  • Self test
117
762 else-
763 rd.dest = -1; /* XXX */
never executed: rd.dest = -1;
0
764 switch (ri)-
765 {-
766 case r_duplicating_input_word:
executed 18 times by 1 test: case r_duplicating_input_word:
Executed by:
  • Self test
18
767 new_redirect = make_redirection (sd, r_duplicating_input, rd, 0);-
768 break;
executed 18 times by 1 test: break;
Executed by:
  • Self test
18
769 case r_duplicating_output_word:
executed 93 times by 1 test: case r_duplicating_output_word:
Executed by:
  • Self test
93
770 new_redirect = make_redirection (sd, r_duplicating_output, rd, 0);-
771 break;
executed 93 times by 1 test: break;
Executed by:
  • Self test
93
772 case r_move_input_word:
executed 3 times by 1 test: case r_move_input_word:
Executed by:
  • Self test
3
773 new_redirect = make_redirection (sd, r_move_input, rd, 0);-
774 break;
executed 3 times by 1 test: break;
Executed by:
  • Self test
3
775 case r_move_output_word:
executed 3 times by 1 test: case r_move_output_word:
Executed by:
  • Self test
3
776 new_redirect = make_redirection (sd, r_move_output, rd, 0);-
777 break;
executed 3 times by 1 test: break;
Executed by:
  • Self test
3
778 }-
779 }
executed 117 times by 1 test: end of block
Executed by:
  • Self test
117
780 else if (ri == r_duplicating_output_word && (redirect->rflags & REDIR_VARASSIGN) == 0 && redirector == 1)
ri == r_duplic...ng_output_wordDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(redirect->rflags & 0x01) == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
redirector == 1Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2
781 {-
782 sd = redirect->redirector;-
783 rd.filename = make_bare_word (redirectee_word);-
784 new_redirect = make_redirection (sd, r_err_and_out, rd, 0);-
785 }
executed 2 times by 1 test: end of block
Executed by:
  • Self test
2
786 else-
787 {-
788 free (redirectee_word);-
789 return (AMBIGUOUS_REDIRECT);
never executed: return (-1);
0
790 }-
791-
792 free (redirectee_word);-
793-
794 /* Set up the variables needed by the rest of the function from the-
795 new redirection. */-
796 if (new_redirect->instruction == r_err_and_out)
new_redirect->... r_err_and_outDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 119 times by 1 test
Evaluated by:
  • Self test
2-119
797 {-
798 char *alloca_hack;-
799-
800 /* Copy the word without allocating any memory that must be-
801 explicitly freed. */-
802 redirectee = (WORD_DESC *)alloca (sizeof (WORD_DESC));-
803 xbcopy ((char *)new_redirect->redirectee.filename,-
804 (char *)redirectee, sizeof (WORD_DESC));-
805-
806 alloca_hack = (char *)-
807 alloca (1 + strlen (new_redirect->redirectee.filename->word));-
808 redirectee->word = alloca_hack;-
809 strcpy (redirectee->word, new_redirect->redirectee.filename->word);-
810 }
executed 2 times by 1 test: end of block
Executed by:
  • Self test
2
811 else-
812 /* It's guaranteed to be an integer, and shouldn't be freed. */-
813 redirectee = new_redirect->redirectee.filename;
executed 119 times by 1 test: redirectee = new_redirect->redirectee.filename;
Executed by:
  • Self test
119
814-
815 redir_fd = new_redirect->redirectee.dest;-
816 redirector = new_redirect->redirector.dest;-
817 ri = new_redirect->instruction;-
818-
819 /* Overwrite the flags element of the old redirect with the new value. */-
820 redirect->flags = new_redirect->flags;-
821 dispose_redirects (new_redirect);-
822 }
executed 121 times by 1 test: end of block
Executed by:
  • Self test
121
823-
824 switch (ri)-
825 {-
826 case r_output_direction:
executed 4022 times by 1 test: case r_output_direction:
Executed by:
  • Self test
4022
827 case r_appending_to:
executed 15 times by 1 test: case r_appending_to:
Executed by:
  • Self test
15
828 case r_input_direction:
executed 663287 times by 1 test: case r_input_direction:
Executed by:
  • Self test
663287
829 case r_inputa_direction:
never executed: case r_inputa_direction:
0
830 case r_err_and_out: /* command &>filename */
executed 17 times by 1 test: case r_err_and_out:
Executed by:
  • Self test
17
831 case r_append_err_and_out: /* command &>> filename */
executed 2 times by 1 test: case r_append_err_and_out:
Executed by:
  • Self test
2
832 case r_input_output:
executed 18 times by 1 test: case r_input_output:
Executed by:
  • Self test
18
833 case r_output_force:
executed 19 times by 1 test: case r_output_force:
Executed by:
  • Self test
19
834 if (posixly_correct && interactive_shell == 0)
posixly_correctDescription
TRUEevaluated 12 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 667368 times by 1 test
Evaluated by:
  • Self test
interactive_shell == 0Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-667368
835 {-
836 oflags = redirectee->flags;-
837 redirectee->flags |= W_NOGLOB;-
838 }
executed 12 times by 1 test: end of block
Executed by:
  • Self test
12
839 redirectee_word = redirection_expand (redirectee);-
840 if (posixly_correct && interactive_shell == 0)
posixly_correctDescription
TRUEevaluated 12 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 666006 times by 1 test
Evaluated by:
  • Self test
interactive_shell == 0Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-666006
841 redirectee->flags = oflags;
executed 12 times by 1 test: redirectee->flags = oflags;
Executed by:
  • Self test
12
842-
843 if (redirectee_word == 0)
redirectee_word == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 666017 times by 1 test
Evaluated by:
  • Self test
1-666017
844 return (AMBIGUOUS_REDIRECT);
executed 1 time by 1 test: return (-1);
Executed by:
  • Self test
1
845-
846#if defined (RESTRICTED_SHELL)-
847 if (restricted && (WRITE_REDIRECT (ri)))
restrictedDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 666015 times by 1 test
Evaluated by:
  • Self test
ri == r_output_directionDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
ri == r_input_outputDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
ri == r_err_and_outDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
ri == r_appending_toDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
ri == r_append_err_and_outDescription
TRUEnever evaluated
FALSEnever evaluated
ri == r_output_forceDescription
TRUEnever evaluated
FALSEnever evaluated
0-666015
848 {-
849 free (redirectee_word);-
850 return (RESTRICTED_REDIRECT);
executed 2 times by 1 test: return (-3);
Executed by:
  • Self test
2
851 }-
852#endif /* RESTRICTED_SHELL */-
853-
854 fd = redir_open (redirectee_word, redirect->flags, 0666, ri);-
855 free (redirectee_word);-
856-
857 if (fd == NOCLOBBER_REDIRECT || fd == RESTRICTED_REDIRECT)
fd == -2Description
TRUEevaluated 19 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 665996 times by 1 test
Evaluated by:
  • Self test
fd == -3Description
TRUEnever evaluated
FALSEevaluated 665996 times by 1 test
Evaluated by:
  • Self test
0-665996
858 return (fd);
executed 19 times by 1 test: return (fd);
Executed by:
  • Self test
19
859-
860 if (fd < 0)
fd < 0Description
TRUEevaluated 20 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 665976 times by 1 test
Evaluated by:
  • Self test
20-665976
861 return (errno);
executed 20 times by 1 test: return ( (*__errno_location ()) );
Executed by:
  • Self test
20
862-
863 if (flags & RX_ACTIVE)
flags & 0x01Description
TRUEevaluated 665976 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-665976
864 {-
865 if (redirect->rflags & REDIR_VARASSIGN)
redirect->rflags & 0x01Description
TRUEevaluated 13 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 665963 times by 1 test
Evaluated by:
  • Self test
13-665963
866 {-
867 redirector = fcntl (fd, F_DUPFD, SHELL_FD_BASE); /* XXX try this for now */-
868 r = errno;-
869 if (redirector < 0)
redirector < 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 12 times by 1 test
Evaluated by:
  • Self test
1-12
870 sys_error (_("redirection error: cannot duplicate fd"));
executed 1 time by 1 test: sys_error ( dcgettext (((void *)0), "redirection error: cannot duplicate fd" , 5) );
Executed by:
  • Self test
1
871 REDIRECTION_ERROR (redirector, r, fd);
executed 1 time by 1 test: close (fd);
Executed by:
  • Self test
executed 1 time by 1 test: return ((r) == 0 ? 22 : (r));
Executed by:
  • Self test
(redirector) < 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 12 times by 1 test
Evaluated by:
  • Self test
fd >= 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-12
872 }
executed 12 times by 1 test: end of block
Executed by:
  • Self test
12
873-
874 if ((flags & RX_UNDOABLE) && (redirect->rflags & REDIR_VARASSIGN) == 0)
(flags & 0x02)Description
TRUEevaluated 665952 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 23 times by 1 test
Evaluated by:
  • Self test
(redirect->rflags & 0x01) == 0Description
TRUEevaluated 665941 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11 times by 1 test
Evaluated by:
  • Self test
11-665952
875 {-
876 /* Only setup to undo it if the thing to undo is active. */-
877 if ((fd != redirector) && (fcntl (redirector, F_GETFD, 0) != -1))
(fd != redirector)Description
TRUEevaluated 31368 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 634573 times by 1 test
Evaluated by:
  • Self test
(fcntl (redire... 1 , 0) != -1)Description
TRUEevaluated 31344 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 24 times by 1 test
Evaluated by:
  • Self test
24-634573
878 r = add_undo_redirect (redirector, ri, -1);
executed 31344 times by 1 test: r = add_undo_redirect (redirector, ri, -1);
Executed by:
  • Self test
31344
879 else-
880 r = add_undo_close_redirect (redirector);
executed 634597 times by 1 test: r = add_undo_close_redirect (redirector);
Executed by:
  • Self test
634597
881 REDIRECTION_ERROR (r, errno, fd);
never executed: close (fd);
never executed: return (( (*__errno_location ()) ) == 0 ? 22 : ( (*__errno_location ()) ));
(r) < 0Description
TRUEnever evaluated
FALSEevaluated 665941 times by 1 test
Evaluated by:
  • Self test
fd >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0-665941
882 }
executed 665941 times by 1 test: end of block
Executed by:
  • Self test
665941
883-
884#if defined (BUFFERED_INPUT)-
885 /* inhibit call to sync_buffered_stream() for async processes */-
886 if (redirector != 0 || (subshell_environment & SUBSHELL_ASYNC) == 0)
redirector != 0Description
TRUEevaluated 664719 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1256 times by 1 test
Evaluated by:
  • Self test
(subshell_envi...t & 0x01) == 0Description
TRUEevaluated 1256 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-664719
887 check_bash_input (redirector);
executed 665975 times by 1 test: check_bash_input (redirector);
Executed by:
  • Self test
665975
888#endif-
889-
890 /* Make sure there is no pending output before we change the state-
891 of the underlying file descriptor, since the builtins use stdio-
892 for output. */-
893 if (redirector == 1 && fileno (stdout) == redirector)
redirector == 1Description
TRUEevaluated 301 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 665674 times by 1 test
Evaluated by:
  • Self test
fileno ( stdou... == redirectorDescription
TRUEevaluated 301 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-665674
894 {-
895 fflush (stdout);-
896 fpurge (stdout);-
897 }
executed 301 times by 1 test: end of block
Executed by:
  • Self test
301
898 else if (redirector == 2 && fileno (stderr) == redirector)
redirector == 2Description
TRUEevaluated 3699 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 661975 times by 1 test
Evaluated by:
  • Self test
fileno ( stder... == redirectorDescription
TRUEevaluated 3699 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-661975
899 {-
900 fflush (stderr);-
901 fpurge (stderr);-
902 }
executed 3699 times by 1 test: end of block
Executed by:
  • Self test
3699
903-
904 if (redirect->rflags & REDIR_VARASSIGN)
redirect->rflags & 0x01Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 665963 times by 1 test
Evaluated by:
  • Self test
12-665963
905 {-
906 if ((r = redir_varassign (redirect, redirector)) < 0)
(r = redir_var...director)) < 0Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
5-7
907 {-
908 close (redirector);-
909 close (fd);-
910 return (r); /* XXX */
executed 7 times by 1 test: return (r);
Executed by:
  • Self test
7
911 }-
912 }
executed 5 times by 1 test: end of block
Executed by:
  • Self test
5
913 else if ((fd != redirector) && (dup2 (fd, redirector) < 0))
(fd != redirector)Description
TRUEevaluated 31390 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 634573 times by 1 test
Evaluated by:
  • Self test
(dup2 (fd, redirector) < 0)Description
TRUEnever evaluated
FALSEevaluated 31390 times by 1 test
Evaluated by:
  • Self test
0-634573
914 {-
915 close (fd); /* dup2 failed? must be fd limit issue */-
916 return (errno);
never executed: return ( (*__errno_location ()) );
0
917 }-
918-
919#if defined (BUFFERED_INPUT)-
920 /* Do not change the buffered stream for an implicit redirection-
921 of /dev/null to fd 0 for asynchronous commands without job-
922 control (r_inputa_direction). */-
923 if (ri == r_input_direction || ri == r_input_output)
ri == r_input_directionDescription
TRUEevaluated 661909 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4059 times by 1 test
Evaluated by:
  • Self test
ri == r_input_outputDescription
TRUEevaluated 18 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4041 times by 1 test
Evaluated by:
  • Self test
18-661909
924 duplicate_buffered_stream (fd, redirector);
executed 661927 times by 1 test: duplicate_buffered_stream (fd, redirector);
Executed by:
  • Self test
661927
925#endif /* BUFFERED_INPUT */-
926-
927 /*-
928 * If we're remembering, then this is the result of a while, for-
929 * or until loop with a loop redirection, or a function/builtin-
930 * executing in the parent shell with a redirection. In the-
931 * function/builtin case, we want to set all file descriptors > 2-
932 * to be close-on-exec to duplicate the effect of the old-
933 * for i = 3 to NOFILE close(i) loop. In the case of the loops,-
934 * both sh and ksh leave the file descriptors open across execs.-
935 * The Posix standard mentions only the exec builtin.-
936 */-
937 if ((flags & RX_CLEXEC) && (redirector > 2))
(flags & 0x04)Description
TRUEnever evaluated
FALSEevaluated 665968 times by 1 test
Evaluated by:
  • Self test
(redirector > 2)Description
TRUEnever evaluated
FALSEnever evaluated
0-665968
938 SET_CLOSE_ON_EXEC (redirector);
never executed: (fcntl ((redirector), 2 , 1 ));
0
939 }
executed 665968 times by 1 test: end of block
Executed by:
  • Self test
665968
940-
941 if (fd != redirector)
fd != redirectorDescription
TRUEevaluated 31395 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 634573 times by 1 test
Evaluated by:
  • Self test
31395-634573
942 {-
943#if defined (BUFFERED_INPUT)-
944 if (INPUT_REDIRECT (ri))
ri == r_input_directionDescription
TRUEevaluated 27390 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4005 times by 1 test
Evaluated by:
  • Self test
ri == r_inputa_directionDescription
TRUEnever evaluated
FALSEevaluated 4005 times by 1 test
Evaluated by:
  • Self test
ri == r_input_outputDescription
TRUEnever evaluated
FALSEevaluated 4005 times by 1 test
Evaluated by:
  • Self test
0-27390
945 close_buffered_fd (fd);
executed 27390 times by 1 test: close_buffered_fd (fd);
Executed by:
  • Self test
27390
946 else-
947#endif /* !BUFFERED_INPUT */-
948 close (fd); /* Don't close what we just opened! */
executed 4005 times by 1 test: close (fd);
Executed by:
  • Self test
4005
949 }-
950-
951 /* If we are hacking both stdout and stderr, do the stderr-
952 redirection here. XXX - handle {var} here? */-
953 if (ri == r_err_and_out || ri == r_append_err_and_out)
ri == r_err_and_outDescription
TRUEevaluated 17 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 665951 times by 1 test
Evaluated by:
  • Self test
ri == r_append_err_and_outDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 665949 times by 1 test
Evaluated by:
  • Self test
2-665951
954 {-
955 if (flags & RX_ACTIVE)
flags & 0x01Description
TRUEevaluated 19 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-19
956 {-
957 if (flags & RX_UNDOABLE)
flags & 0x02Description
TRUEevaluated 19 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-19
958 add_undo_redirect (2, ri, -1);
executed 19 times by 1 test: add_undo_redirect (2, ri, -1);
Executed by:
  • Self test
19
959 if (dup2 (1, 2) < 0)
dup2 (1, 2) < 0Description
TRUEnever evaluated
FALSEevaluated 19 times by 1 test
Evaluated by:
  • Self test
0-19
960 return (errno);
never executed: return ( (*__errno_location ()) );
0
961 }
executed 19 times by 1 test: end of block
Executed by:
  • Self test
19
962 }
executed 19 times by 1 test: end of block
Executed by:
  • Self test
19
963 break;
executed 665968 times by 1 test: break;
Executed by:
  • Self test
665968
964-
965 case r_reading_until:
executed 73 times by 1 test: case r_reading_until:
Executed by:
  • Self test
73
966 case r_deblank_reading_until:
never executed: case r_deblank_reading_until:
0
967 case r_reading_string:
executed 32 times by 1 test: case r_reading_string:
Executed by:
  • Self test
32
968 /* REDIRECTEE is a pointer to a WORD_DESC containing the text of-
969 the new input. Place it in a temporary file. */-
970 if (redirectee)
redirecteeDescription
TRUEevaluated 105 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-105
971 {-
972 fd = here_document_to_fd (redirectee, ri);-
973-
974 if (fd < 0)
fd < 0Description
TRUEnever evaluated
FALSEevaluated 104 times by 1 test
Evaluated by:
  • Self test
0-104
975 {-
976 heredoc_errno = errno;-
977 return (HEREDOC_REDIRECT);
never executed: return (-4);
0
978 }-
979-
980 if (redirect->rflags & REDIR_VARASSIGN)
redirect->rflags & 0x01Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 103 times by 1 test
Evaluated by:
  • Self test
1-103
981 {-
982 redirector = fcntl (fd, F_DUPFD, SHELL_FD_BASE); /* XXX try this for now */-
983 r = errno;-
984 if (redirector < 0)
redirector < 0Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
0-1
985 sys_error (_("redirection error: cannot duplicate fd"));
never executed: sys_error ( dcgettext (((void *)0), "redirection error: cannot duplicate fd" , 5) );
0
986 REDIRECTION_ERROR (redirector, r, fd);
never executed: close (fd);
never executed: return ((r) == 0 ? 22 : (r));
(redirector) < 0Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
fd >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0-1
987 }
executed 1 time by 1 test: end of block
Executed by:
  • Self test
1
988-
989 if (flags & RX_ACTIVE)
flags & 0x01Description
TRUEevaluated 104 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-104
990 {-
991 if ((flags & RX_UNDOABLE) && (redirect->rflags & REDIR_VARASSIGN) == 0)
(flags & 0x02)Description
TRUEevaluated 104 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(redirect->rflags & 0x01) == 0Description
TRUEevaluated 103 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
0-104
992 {-
993 /* Only setup to undo it if the thing to undo is active. */-
994 if ((fd != redirector) && (fcntl (redirector, F_GETFD, 0) != -1))
(fd != redirector)Description
TRUEevaluated 103 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(fcntl (redire... 1 , 0) != -1)Description
TRUEevaluated 101 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
0-103
995 r = add_undo_redirect (redirector, ri, -1);
executed 101 times by 1 test: r = add_undo_redirect (redirector, ri, -1);
Executed by:
  • Self test
101
996 else-
997 r = add_undo_close_redirect (redirector);
executed 2 times by 1 test: r = add_undo_close_redirect (redirector);
Executed by:
  • Self test
2
998 REDIRECTION_ERROR (r, errno, fd);
never executed: close (fd);
never executed: return (( (*__errno_location ()) ) == 0 ? 22 : ( (*__errno_location ()) ));
(r) < 0Description
TRUEnever evaluated
FALSEevaluated 103 times by 1 test
Evaluated by:
  • Self test
fd >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0-103
999 }
executed 103 times by 1 test: end of block
Executed by:
  • Self test
103
1000-
1001#if defined (BUFFERED_INPUT)-
1002 check_bash_input (redirector);-
1003#endif-
1004 if (redirect->rflags & REDIR_VARASSIGN)
redirect->rflags & 0x01Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 103 times by 1 test
Evaluated by:
  • Self test
1-103
1005 {-
1006 if ((r = redir_varassign (redirect, redirector)) < 0)
(r = redir_var...director)) < 0Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
0-1
1007 {-
1008 close (redirector);-
1009 close (fd);-
1010 return (r); /* XXX */
never executed: return (r);
0
1011 }-
1012 }
executed 1 time by 1 test: end of block
Executed by:
  • Self test
1
1013 else if (fd != redirector && dup2 (fd, redirector) < 0)
fd != redirectorDescription
TRUEevaluated 103 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
dup2 (fd, redirector) < 0Description
TRUEnever evaluated
FALSEevaluated 103 times by 1 test
Evaluated by:
  • Self test
0-103
1014 {-
1015 r = errno;-
1016 close (fd);-
1017 return (r);
never executed: return (r);
0
1018 }-
1019-
1020#if defined (BUFFERED_INPUT)-
1021 duplicate_buffered_stream (fd, redirector);-
1022#endif-
1023-
1024 if ((flags & RX_CLEXEC) && (redirector > 2))
(flags & 0x04)Description
TRUEnever evaluated
FALSEevaluated 104 times by 1 test
Evaluated by:
  • Self test
(redirector > 2)Description
TRUEnever evaluated
FALSEnever evaluated
0-104
1025 SET_CLOSE_ON_EXEC (redirector);
never executed: (fcntl ((redirector), 2 , 1 ));
0
1026 }
executed 104 times by 1 test: end of block
Executed by:
  • Self test
104
1027-
1028 if (fd != redirector)
fd != redirectorDescription
TRUEevaluated 104 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-104
1029#if defined (BUFFERED_INPUT)-
1030 close_buffered_fd (fd);
executed 104 times by 1 test: close_buffered_fd (fd);
Executed by:
  • Self test
104
1031#else-
1032 close (fd);-
1033#endif-
1034 }
executed 104 times by 1 test: end of block
Executed by:
  • Self test
104
1035 break;
executed 104 times by 1 test: break;
Executed by:
  • Self test
104
1036-
1037 case r_duplicating_input:
executed 1389 times by 1 test: case r_duplicating_input:
Executed by:
  • Self test
1389
1038 case r_duplicating_output:
executed 30682 times by 1 test: case r_duplicating_output:
Executed by:
  • Self test
30682
1039 case r_move_input:
executed 5 times by 1 test: case r_move_input:
Executed by:
  • Self test
5
1040 case r_move_output:
executed 3 times by 1 test: case r_move_output:
Executed by:
  • Self test
3
1041 if ((flags & RX_ACTIVE) && (redirect->rflags & REDIR_VARASSIGN))
(flags & 0x01)Description
TRUEevaluated 32079 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(redirect->rflags & 0x01)Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 32068 times by 1 test
Evaluated by:
  • Self test
0-32079
1042 {-
1043 redirector = fcntl (redir_fd, F_DUPFD, SHELL_FD_BASE); /* XXX try this for now */-
1044 r = errno;-
1045 if (redirector < 0)
redirector < 0Description
TRUEnever evaluated
FALSEevaluated 11 times by 1 test
Evaluated by:
  • Self test
0-11
1046 sys_error (_("redirection error: cannot duplicate fd"));
never executed: sys_error ( dcgettext (((void *)0), "redirection error: cannot duplicate fd" , 5) );
0
1047 REDIRECTION_ERROR (redirector, r, -1);
never executed: close (-1);
never executed: return ((r) == 0 ? 22 : (r));
(redirector) < 0Description
TRUEnever evaluated
FALSEevaluated 11 times by 1 test
Evaluated by:
  • Self test
-1 >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0-11
1048 }
executed 11 times by 1 test: end of block
Executed by:
  • Self test
11
1049-
1050 if ((flags & RX_ACTIVE) && (redir_fd != redirector))
(flags & 0x01)Description
TRUEevaluated 32079 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(redir_fd != redirector)Description
TRUEevaluated 32079 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-32079
1051 {-
1052 if ((flags & RX_UNDOABLE) && (redirect->rflags & REDIR_VARASSIGN) == 0)
(flags & 0x02)Description
TRUEevaluated 384 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 31695 times by 1 test
Evaluated by:
  • Self test
(redirect->rflags & 0x01) == 0Description
TRUEevaluated 373 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11 times by 1 test
Evaluated by:
  • Self test
11-31695
1053 {-
1054 /* Only setup to undo it if the thing to undo is active. */-
1055 if (fcntl (redirector, F_GETFD, 0) != -1)
fcntl (redirec..., 1 , 0) != -1Description
TRUEevaluated 353 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 20 times by 1 test
Evaluated by:
  • Self test
20-353
1056 r = add_undo_redirect (redirector, ri, redir_fd);
executed 353 times by 1 test: r = add_undo_redirect (redirector, ri, redir_fd);
Executed by:
  • Self test
353
1057 else-
1058 r = add_undo_close_redirect (redirector);
executed 20 times by 1 test: r = add_undo_close_redirect (redirector);
Executed by:
  • Self test
20
1059 REDIRECTION_ERROR (r, errno, -1);
never executed: close (-1);
never executed: return (( (*__errno_location ()) ) == 0 ? 22 : ( (*__errno_location ()) ));
(r) < 0Description
TRUEnever evaluated
FALSEevaluated 373 times by 1 test
Evaluated by:
  • Self test
-1 >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0-373
1060 }
executed 373 times by 1 test: end of block
Executed by:
  • Self test
373
1061 if ((flags & RX_UNDOABLE) && (ri == r_move_input || ri == r_move_output))
(flags & 0x02)Description
TRUEevaluated 384 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 31695 times by 1 test
Evaluated by:
  • Self test
ri == r_move_inputDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 379 times by 1 test
Evaluated by:
  • Self test
ri == r_move_outputDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 376 times by 1 test
Evaluated by:
  • Self test
3-31695
1062 {-
1063 /* r_move_input and r_move_output add an additional close()-
1064 that needs to be undone */-
1065 if (fcntl (redirector, F_GETFD, 0) != -1)
fcntl (redirec..., 1 , 0) != -1Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
2-6
1066 {-
1067 r = add_undo_redirect (redir_fd, r_close_this, -1);-
1068 REDIRECTION_ERROR (r, errno, -1);
never executed: close (-1);
never executed: return (( (*__errno_location ()) ) == 0 ? 22 : ( (*__errno_location ()) ));
(r) < 0Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
-1 >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0-6
1069 }
executed 6 times by 1 test: end of block
Executed by:
  • Self test
6
1070 }
executed 8 times by 1 test: end of block
Executed by:
  • Self test
8
1071#if defined (BUFFERED_INPUT)-
1072 /* inhibit call to sync_buffered_stream() for async processes */-
1073 if (redirector != 0 || (subshell_environment & SUBSHELL_ASYNC) == 0)
redirector != 0Description
TRUEevaluated 30700 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1379 times by 1 test
Evaluated by:
  • Self test
(subshell_envi...t & 0x01) == 0Description
TRUEevaluated 1379 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-30700
1074 check_bash_input (redirector);
executed 32079 times by 1 test: check_bash_input (redirector);
Executed by:
  • Self test
32079
1075#endif-
1076 if (redirect->rflags & REDIR_VARASSIGN)
redirect->rflags & 0x01Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 32068 times by 1 test
Evaluated by:
  • Self test
11-32068
1077 {-
1078 if ((r = redir_varassign (redirect, redirector)) < 0)
(r = redir_var...director)) < 0Description
TRUEnever evaluated
FALSEevaluated 11 times by 1 test
Evaluated by:
  • Self test
0-11
1079 {-
1080 close (redirector);-
1081 return (r); /* XXX */
never executed: return (r);
0
1082 }-
1083 }
executed 11 times by 1 test: end of block
Executed by:
  • Self test
11
1084 /* This is correct. 2>&1 means dup2 (1, 2); */-
1085 else if (dup2 (redir_fd, redirector) < 0)
dup2 (redir_fd...edirector) < 0Description
TRUEevaluated 55 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 32013 times by 1 test
Evaluated by:
  • Self test
55-32013
1086 return (errno);
executed 55 times by 1 test: return ( (*__errno_location ()) );
Executed by:
  • Self test
55
1087-
1088#if defined (BUFFERED_INPUT)-
1089 if (ri == r_duplicating_input || ri == r_move_input)
ri == r_duplicating_inputDescription
TRUEevaluated 1389 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 30635 times by 1 test
Evaluated by:
  • Self test
ri == r_move_inputDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 30630 times by 1 test
Evaluated by:
  • Self test
5-30635
1090 duplicate_buffered_stream (redir_fd, redirector);
executed 1394 times by 1 test: duplicate_buffered_stream (redir_fd, redirector);
Executed by:
  • Self test
1394
1091#endif /* BUFFERED_INPUT */-
1092-
1093 /* First duplicate the close-on-exec state of redirectee. dup2-
1094 leaves the flag unset on the new descriptor, which means it-
1095 stays open. Only set the close-on-exec bit for file descriptors-
1096 greater than 2 in any case, since 0-2 should always be open-
1097 unless closed by something like `exec 2<&-'. It should always-
1098 be safe to set fds > 2 to close-on-exec if they're being used to-
1099 save file descriptors < 2, since we don't need to preserve the-
1100 state of the close-on-exec flag for those fds -- they should-
1101 always be open. */-
1102 /* if ((already_set || set_unconditionally) && (ok_to_set))-
1103 set_it () */-
1104#if 0-
1105 if (((fcntl (redir_fd, F_GETFD, 0) == 1) || redir_fd < 2 || (flags & RX_CLEXEC)) &&-
1106 (redirector > 2))-
1107#else-
1108 if (((fcntl (redir_fd, F_GETFD, 0) == 1) || (redir_fd < 2 && (flags & RX_INTERNAL)) || (flags & RX_CLEXEC)) &&
(fcntl (redir_fd, 1 , 0) == 1)Description
TRUEevaluated 31697 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 327 times by 1 test
Evaluated by:
  • Self test
redir_fd < 2Description
TRUEevaluated 73 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 254 times by 1 test
Evaluated by:
  • Self test
(flags & 0x08)Description
TRUEnever evaluated
FALSEevaluated 73 times by 1 test
Evaluated by:
  • Self test
(flags & 0x04)Description
TRUEnever evaluated
FALSEevaluated 327 times by 1 test
Evaluated by:
  • Self test
0-31697
1109 (redirector > 2))
(redirector > 2)Description
TRUEevaluated 26112 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5585 times by 1 test
Evaluated by:
  • Self test
5585-26112
1110#endif-
1111 SET_CLOSE_ON_EXEC (redirector);
executed 26112 times by 1 test: (fcntl ((redirector), 2 , 1 ));
Executed by:
  • Self test
26112
1112-
1113 /* When undoing saving of non-standard file descriptors (>=3) using-
1114 file descriptors >= SHELL_FD_BASE, we set the saving fd to be-
1115 close-on-exec and use a flag to decide how to set close-on-exec-
1116 when the fd is restored. */-
1117 if ((redirect->flags & RX_INTERNAL) && (redirect->flags & RX_SAVCLEXEC) && redirector >= 3 && (redir_fd >= SHELL_FD_BASE || (redirect->flags & RX_SAVEFD)))
(redirect->flags & 0x08)Description
TRUEevaluated 31685 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 339 times by 1 test
Evaluated by:
  • Self test
(redirect->flags & 0x20)Description
TRUEevaluated 26110 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5575 times by 1 test
Evaluated by:
  • Self test
redirector >= 3Description
TRUEevaluated 26110 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
redir_fd >= 10Description
TRUEevaluated 26110 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(redirect->flags & 0x40)Description
TRUEnever evaluated
FALSEnever evaluated
0-31685
1118 SET_OPEN_ON_EXEC (redirector);
executed 26110 times by 1 test: (fcntl ((redirector), 2 , 0));
Executed by:
  • Self test
26110
1119 -
1120 /* dup-and-close redirection */-
1121 if (ri == r_move_input || ri == r_move_output)
ri == r_move_inputDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 32019 times by 1 test
Evaluated by:
  • Self test
ri == r_move_outputDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 32016 times by 1 test
Evaluated by:
  • Self test
3-32019
1122 {-
1123 xtrace_fdchk (redir_fd);-
1124-
1125 close (redir_fd);-
1126#if defined (COPROCESS_SUPPORT)-
1127 coproc_fdchk (redir_fd); /* XXX - loses coproc fds */-
1128#endif-
1129 }
executed 8 times by 1 test: end of block
Executed by:
  • Self test
8
1130 }
executed 32024 times by 1 test: end of block
Executed by:
  • Self test
32024
1131 break;
executed 32024 times by 1 test: break;
Executed by:
  • Self test
32024
1132-
1133 case r_close_this:
executed 666433 times by 1 test: case r_close_this:
Executed by:
  • Self test
666433
1134 if (flags & RX_ACTIVE)
flags & 0x01Description
TRUEevaluated 666433 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-666433
1135 {-
1136 if (redirect->rflags & REDIR_VARASSIGN)
redirect->rflags & 0x01Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 666428 times by 1 test
Evaluated by:
  • Self test
5-666428
1137 {-
1138 redirector = redir_varvalue (redirect);-
1139 if (redirector < 0)
redirector < 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
1-4
1140 return AMBIGUOUS_REDIRECT;
executed 1 time by 1 test: return -1;
Executed by:
  • Self test
1
1141 }
executed 4 times by 1 test: end of block
Executed by:
  • Self test
4
1142-
1143 r = 0;-
1144 /* XXX - only if REDIR_VARASSIGN not set? */-
1145 if ((flags & RX_UNDOABLE) && (fcntl (redirector, F_GETFD, 0) != -1))
(flags & 0x02)Description
TRUEevaluated 50 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 666382 times by 1 test
Evaluated by:
  • Self test
(fcntl (redire... 1 , 0) != -1)Description
TRUEevaluated 48 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
2-666382
1146 {-
1147 r = add_undo_redirect (redirector, ri, -1);-
1148 REDIRECTION_ERROR (r, errno, redirector);
never executed: close (redirector);
never executed: return (( (*__errno_location ()) ) == 0 ? 22 : ( (*__errno_location ()) ));
(r) < 0Description
TRUEnever evaluated
FALSEevaluated 48 times by 1 test
Evaluated by:
  • Self test
redirector >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0-48
1149 }
executed 48 times by 1 test: end of block
Executed by:
  • Self test
48
1150-
1151#if defined (COPROCESS_SUPPORT)-
1152 coproc_fdchk (redirector);-
1153#endif-
1154 xtrace_fdchk (redirector);-
1155-
1156#if defined (BUFFERED_INPUT)-
1157 /* inhibit call to sync_buffered_stream() for async processes */-
1158 if (redirector != 0 || (subshell_environment & SUBSHELL_ASYNC) == 0)
redirector != 0Description
TRUEevaluated 666431 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
(subshell_envi...t & 0x01) == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-666431
1159 check_bash_input (redirector);
executed 666432 times by 1 test: check_bash_input (redirector);
Executed by:
  • Self test
666432
1160 r = close_buffered_fd (redirector);-
1161#else /* !BUFFERED_INPUT */-
1162 r = close (redirector);-
1163#endif /* !BUFFERED_INPUT */-
1164-
1165 if (r < 0 && (flags & RX_INTERNAL) && (errno == EIO || errno == ENOSPC))
r < 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 666430 times by 1 test
Evaluated by:
  • Self test
(flags & 0x08)Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
(*__errno_location ()) == 5Description
TRUEnever evaluated
FALSEnever evaluated
(*__errno_location ()) == 28Description
TRUEnever evaluated
FALSEnever evaluated
0-666430
1166 REDIRECTION_ERROR (r, errno, -1);
never executed: close (-1);
never executed: return (( (*__errno_location ()) ) == 0 ? 22 : ( (*__errno_location ()) ));
never executed: end of block
(r) < 0Description
TRUEnever evaluated
FALSEnever evaluated
-1 >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1167 }
executed 666432 times by 1 test: end of block
Executed by:
  • Self test
666432
1168 break;
executed 666432 times by 1 test: break;
Executed by:
  • Self test
666432
1169-
1170 case r_duplicating_input_word:
never executed: case r_duplicating_input_word:
0
1171 case r_duplicating_output_word:
never executed: case r_duplicating_output_word:
0
1172 break;
never executed: break;
0
1173 }-
1174 return (0);
executed 1364528 times by 1 test: return (0);
Executed by:
  • Self test
1364528
1175}-
1176-
1177/* Remember the file descriptor associated with the slot FD,-
1178 on REDIRECTION_UNDO_LIST. Note that the list will be reversed-
1179 before it is executed. Any redirections that need to be undone-
1180 even if REDIRECTION_UNDO_LIST is discarded by the exec builtin-
1181 are also saved on EXEC_REDIRECTION_UNDO_LIST. FDBASE says where to-
1182 start the duplicating. If it's less than SHELL_FD_BASE, we're ok,-
1183 and can use SHELL_FD_BASE (-1 == don't care). If it's >= SHELL_FD_BASE,-
1184 we have to make sure we don't use fdbase to save a file descriptor,-
1185 since we're going to use it later (e.g., make sure we don't save fd 0-
1186 to fd 10 if we have a redirection like 0<&10). If the value of fdbase-
1187 puts the process over its fd limit, causing fcntl to fail, we try-
1188 again with SHELL_FD_BASE. Return 0 on success, -1 on error. */-
1189static int-
1190add_undo_redirect (fd, ri, fdbase)-
1191 int fd;-
1192 enum r_instruction ri;-
1193 int fdbase;-
1194{-
1195 int new_fd, clexec_flag, savefd_flag;-
1196 REDIRECT *new_redirect, *closer, *dummy_redirect;-
1197 REDIRECTEE sd;-
1198-
1199 savefd_flag = 0;-
1200 new_fd = fcntl (fd, F_DUPFD, (fdbase < SHELL_FD_BASE) ? SHELL_FD_BASE : fdbase+1);-
1201 if (new_fd < 0)
new_fd < 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 31870 times by 1 test
Evaluated by:
  • Self test
1-31870
1202 new_fd = fcntl (fd, F_DUPFD, SHELL_FD_BASE);
executed 1 time by 1 test: new_fd = fcntl (fd, 0 , 10);
Executed by:
  • Self test
1
1203 if (new_fd < 0)
new_fd < 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 31870 times by 1 test
Evaluated by:
  • Self test
1-31870
1204 {-
1205 new_fd = fcntl (fd, F_DUPFD, 0);-
1206 savefd_flag = 1;-
1207 }
executed 1 time by 1 test: end of block
Executed by:
  • Self test
1
1208-
1209 if (new_fd < 0)
new_fd < 0Description
TRUEnever evaluated
FALSEevaluated 31871 times by 1 test
Evaluated by:
  • Self test
0-31871
1210 {-
1211 sys_error (_("redirection error: cannot duplicate fd"));-
1212 return (-1);
never executed: return (-1);
0
1213 }-
1214-
1215 clexec_flag = fcntl (fd, F_GETFD, 0);-
1216-
1217 sd.dest = new_fd;-
1218 rd.dest = 0;-
1219 closer = make_redirection (sd, r_close_this, rd, 0);-
1220 closer->flags |= RX_INTERNAL;-
1221 dummy_redirect = copy_redirects (closer);-
1222-
1223 sd.dest = fd;-
1224 rd.dest = new_fd;-
1225 if (fd == 0)
fd == 0Description
TRUEevaluated 1391 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 30480 times by 1 test
Evaluated by:
  • Self test
1391-30480
1226 new_redirect = make_redirection (sd, r_duplicating_input, rd, 0);
executed 1391 times by 1 test: new_redirect = make_redirection (sd, r_duplicating_input, rd, 0);
Executed by:
  • Self test
1391
1227 else-
1228 new_redirect = make_redirection (sd, r_duplicating_output, rd, 0);
executed 30480 times by 1 test: new_redirect = make_redirection (sd, r_duplicating_output, rd, 0);
Executed by:
  • Self test
30480
1229 new_redirect->flags |= RX_INTERNAL;-
1230 if (savefd_flag)
savefd_flagDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 31870 times by 1 test
Evaluated by:
  • Self test
1-31870
1231 new_redirect->flags |= RX_SAVEFD;
executed 1 time by 1 test: new_redirect->flags |= 0x40;
Executed by:
  • Self test
1
1232 if (clexec_flag == 0 && fd >= 3 && (new_fd >= SHELL_FD_BASE || savefd_flag))
clexec_flag == 0Description
TRUEevaluated 31869 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
fd >= 3Description
TRUEevaluated 26200 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5669 times by 1 test
Evaluated by:
  • Self test
new_fd >= 10Description
TRUEevaluated 26200 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
savefd_flagDescription
TRUEnever evaluated
FALSEnever evaluated
0-31869
1233 new_redirect->flags |= RX_SAVCLEXEC;
executed 26200 times by 1 test: new_redirect->flags |= 0x20;
Executed by:
  • Self test
26200
1234 new_redirect->next = closer;-
1235-
1236 closer->next = redirection_undo_list;-
1237 redirection_undo_list = new_redirect;-
1238-
1239 /* Save redirections that need to be undone even if the undo list-
1240 is thrown away by the `exec' builtin. */-
1241 add_exec_redirect (dummy_redirect);-
1242-
1243 /* experimental: if we're saving a redirection to undo for a file descriptor-
1244 above SHELL_FD_BASE, add a redirection to be undone if the exec builtin-
1245 causes redirections to be discarded. There needs to be a difference-
1246 between fds that are used to save other fds and then are the target of-
1247 user redirections and fds that are just the target of user redirections.-
1248 We use the close-on-exec flag to tell the difference; fds > SHELL_FD_BASE-
1249 that have the close-on-exec flag set are assumed to be fds used internally-
1250 to save others. */-
1251 if (fd >= SHELL_FD_BASE && ri != r_close_this && clexec_flag)
fd >= 10Description
TRUEevaluated 32 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 31839 times by 1 test
Evaluated by:
  • Self test
ri != r_close_thisDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 28 times by 1 test
Evaluated by:
  • Self test
clexec_flagDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
1-31839
1252 {-
1253 sd.dest = fd;-
1254 rd.dest = new_fd;-
1255 new_redirect = make_redirection (sd, r_duplicating_output, rd, 0);-
1256 new_redirect->flags |= RX_INTERNAL;-
1257-
1258 add_exec_redirect (new_redirect);-
1259 }
executed 1 time by 1 test: end of block
Executed by:
  • Self test
1
1260-
1261 /* File descriptors used only for saving others should always be-
1262 marked close-on-exec. Unfortunately, we have to preserve the-
1263 close-on-exec state of the file descriptor we are saving, since-
1264 fcntl (F_DUPFD) sets the new file descriptor to remain open-
1265 across execs. If, however, the file descriptor whose state we-
1266 are saving is <= 2, we can just set the close-on-exec flag,-
1267 because file descriptors 0-2 should always be open-on-exec,-
1268 and the restore above in do_redirection() will take care of it. */-
1269 if (clexec_flag || fd < 3)
clexec_flagDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 31869 times by 1 test
Evaluated by:
  • Self test
fd < 3Description
TRUEevaluated 5669 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 26200 times by 1 test
Evaluated by:
  • Self test
2-31869
1270 SET_CLOSE_ON_EXEC (new_fd);
executed 5671 times by 1 test: (fcntl ((new_fd), 2 , 1 ));
Executed by:
  • Self test
5671
1271 else if (redirection_undo_list->flags & RX_SAVCLEXEC)
redirection_un...->flags & 0x20Description
TRUEevaluated 26200 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-26200
1272 SET_CLOSE_ON_EXEC (new_fd);
executed 26200 times by 1 test: (fcntl ((new_fd), 2 , 1 ));
Executed by:
  • Self test
26200
1273-
1274 return (0);
executed 31871 times by 1 test: return (0);
Executed by:
  • Self test
31871
1275}-
1276-
1277/* Set up to close FD when we are finished with the current command-
1278 and its redirections. Return 0 on success, -1 on error. */-
1279static int-
1280add_undo_close_redirect (fd)-
1281 int fd;-
1282{-
1283 REDIRECT *closer;-
1284 REDIRECTEE sd;-
1285-
1286 sd.dest = fd;-
1287 rd.dest = 0;-
1288 closer = make_redirection (sd, r_close_this, rd, 0);-
1289 closer->flags |= RX_INTERNAL;-
1290 closer->next = redirection_undo_list;-
1291 redirection_undo_list = closer;-
1292-
1293 return 0;
executed 634619 times by 1 test: return 0;
Executed by:
  • Self test
634619
1294}-
1295-
1296static void-
1297add_exec_redirect (dummy_redirect)-
1298 REDIRECT *dummy_redirect;-
1299{-
1300 dummy_redirect->next = exec_redirection_undo_list;-
1301 exec_redirection_undo_list = dummy_redirect;-
1302}
executed 31872 times by 1 test: end of block
Executed by:
  • Self test
31872
1303-
1304/* Return 1 if the redirection specified by RI and REDIRECTOR alters the-
1305 standard input. */-
1306static int-
1307stdin_redirection (ri, redirector)-
1308 enum r_instruction ri;-
1309 int redirector;-
1310{-
1311 switch (ri)-
1312 {-
1313 case r_input_direction:
executed 661960 times by 1 test: case r_input_direction:
Executed by:
  • Self test
661960
1314 case r_inputa_direction:
never executed: case r_inputa_direction:
0
1315 case r_input_output:
never executed: case r_input_output:
0
1316 case r_reading_until:
executed 43 times by 1 test: case r_reading_until:
Executed by:
  • Self test
43
1317 case r_deblank_reading_until:
never executed: case r_deblank_reading_until:
0
1318 case r_reading_string:
executed 14 times by 1 test: case r_reading_string:
Executed by:
  • Self test
14
1319 return (1);
executed 662017 times by 1 test: return (1);
Executed by:
  • Self test
662017
1320 case r_duplicating_input:
never executed: case r_duplicating_input:
0
1321 case r_duplicating_input_word:
never executed: case r_duplicating_input_word:
0
1322 case r_close_this:
executed 49 times by 1 test: case r_close_this:
Executed by:
  • Self test
49
1323 return (redirector == 0);
executed 49 times by 1 test: return (redirector == 0);
Executed by:
  • Self test
49
1324 case r_output_direction:
executed 23 times by 1 test: case r_output_direction:
Executed by:
  • Self test
23
1325 case r_appending_to:
executed 5 times by 1 test: case r_appending_to:
Executed by:
  • Self test
5
1326 case r_duplicating_output:
executed 6 times by 1 test: case r_duplicating_output:
Executed by:
  • Self test
6
1327 case r_err_and_out:
never executed: case r_err_and_out:
0
1328 case r_append_err_and_out:
never executed: case r_append_err_and_out:
0
1329 case r_output_force:
never executed: case r_output_force:
0
1330 case r_duplicating_output_word:
never executed: case r_duplicating_output_word:
0
1331 return (0);
executed 34 times by 1 test: return (0);
Executed by:
  • Self test
34
1332 }-
1333 return (0);
never executed: return (0);
0
1334}-
1335-
1336/* Return non-zero if any of the redirections in REDIRS alter the standard-
1337 input. */-
1338int-
1339stdin_redirects (redirs)-
1340 REDIRECT *redirs;-
1341{-
1342 REDIRECT *rp;-
1343 int n;-
1344-
1345 for (n = 0, rp = redirs; rp; rp = rp->next)
rpDescription
TRUEevaluated 662101 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 663102 times by 1 test
Evaluated by:
  • Self test
662101-663102
1346 if ((rp->rflags & REDIR_VARASSIGN) == 0)
(rp->rflags & 0x01) == 0Description
TRUEevaluated 662100 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-662100
1347 n += stdin_redirection (rp->instruction, rp->redirector.dest);
executed 662100 times by 1 test: n += stdin_redirection (rp->instruction, rp->redirector.dest);
Executed by:
  • Self test
662100
1348 return n;
executed 663102 times by 1 test: return n;
Executed by:
  • Self test
663102
1349}-
1350/* bind_var_to_int handles array references */-
1351static int-
1352redir_varassign (redir, fd)-
1353 REDIRECT *redir;-
1354 int fd;-
1355{-
1356 WORD_DESC *w;-
1357 SHELL_VAR *v;-
1358-
1359 w = redir->redirector.filename;-
1360 v = bind_var_to_int (w->word, fd);-
1361 if (v == 0 || readonly_p (v) || noassign_p (v))
v == 0Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test
((((v)->attrib... (0x0000002)))Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 17 times by 1 test
Evaluated by:
  • Self test
((((v)->attrib... (0x0004000)))Description
TRUEnever evaluated
FALSEevaluated 17 times by 1 test
Evaluated by:
  • Self test
0-18
1362 return BADVAR_REDIRECT;
executed 7 times by 1 test: return -5;
Executed by:
  • Self test
7
1363-
1364 stupidly_hack_special_variables (w->word);-
1365 return 0;
executed 17 times by 1 test: return 0;
Executed by:
  • Self test
17
1366}-
1367-
1368/* Handles {array[ind]} for redirection words */-
1369static int-
1370redir_varvalue (redir)-
1371 REDIRECT *redir;-
1372{-
1373 SHELL_VAR *v;-
1374 char *val, *w;-
1375 intmax_t vmax;-
1376 int i;-
1377#if defined (ARRAY_VARS)-
1378 char *sub;-
1379 int len, vr;-
1380#endif-
1381-
1382 w = redir->redirector.filename->word; /* shorthand */-
1383 /* XXX - handle set -u here? */-
1384#if defined (ARRAY_VARS)-
1385 if (vr = valid_array_reference (w, 0))
vr = valid_arr...ference (w, 0)Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
0-5
1386 {-
1387 v = array_variable_part (w, 0, &sub, &len);-
1388 }
never executed: end of block
0
1389 else-
1390#endif-
1391 {-
1392 v = find_variable (w);-
1393#if defined (ARRAY_VARS)-
1394 if (v == 0)
v == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
1-4
1395 {-
1396 v = find_variable_last_nameref (w, 0);-
1397 if (v && nameref_p (v))
vDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
((((v)->attrib... (0x0000800)))Description
TRUEnever evaluated
FALSEnever evaluated
0-1
1398 {-
1399 w = nameref_cell (v);-
1400 if (vr = valid_array_reference (w, 0))
vr = valid_arr...ference (w, 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
1401 v = array_variable_part (w, 0, &sub, &len);
never executed: v = array_variable_part (w, 0, &sub, &len);
0
1402 else-
1403 v = find_variable (w);
never executed: v = find_variable (w);
0
1404 }-
1405 }
executed 1 time by 1 test: end of block
Executed by:
  • Self test
1
1406#endif-
1407 }
executed 5 times by 1 test: end of block
Executed by:
  • Self test
5
1408 -
1409 if (v == 0 || invisible_p (v))
v == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
((((v)->attrib... (0x0001000)))Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
0-4
1410 return -1;
executed 1 time by 1 test: return -1;
Executed by:
  • Self test
1
1411-
1412#if defined (ARRAY_VARS)-
1413 /* get_variable_value handles references to array variables without-
1414 subscripts */-
1415 if (vr && (array_p (v) || assoc_p (v)))
vrDescription
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
((((v)->attrib... (0x0000004)))Description
TRUEnever evaluated
FALSEnever evaluated
((((v)->attrib... (0x0000040)))Description
TRUEnever evaluated
FALSEnever evaluated
0-4
1416 val = get_array_value (w, 0, (int *)NULL, (arrayind_t *)0);
never executed: val = get_array_value (w, 0, (int *) ((void *)0) , (arrayind_t *)0);
0
1417 else-
1418#endif-
1419 val = get_variable_value (v);
executed 4 times by 1 test: val = get_variable_value (v);
Executed by:
  • Self test
4
1420 if (val == 0 || *val == 0)
val == 0Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
*val == 0Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
0-4
1421 return -1;
never executed: return -1;
0
1422-
1423 if (legal_number (val, &vmax) < 0)
legal_number (val, &vmax) < 0Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
0-4
1424 return -1;
never executed: return -1;
0
1425-
1426 i = vmax; /* integer truncation */-
1427 return i;
executed 4 times by 1 test: return i;
Executed by:
  • Self test
4
1428}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2