OpenCoverage

source.def

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/builtins/source.def
Source codeSwitch to Preprocessed file
LineSourceCount
1This file is source.def, from which is created source.c.-
2It implements the builtins "." and "source" in Bash.-
3-
4Copyright (C) 1987-2015 Free Software Foundation, Inc.-
5-
6This file is part of GNU Bash, the Bourne Again SHell.-
7-
8Bash is free software: you can redistribute it and/or modify-
9it under the terms of the GNU General Public License as published by-
10the Free Software Foundation, either version 3 of the License, or-
11(at your option) any later version.-
12-
13Bash is distributed in the hope that it will be useful,-
14but WITHOUT ANY WARRANTY; without even the implied warranty of-
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
16GNU General Public License for more details.-
17-
18You should have received a copy of the GNU General Public License-
19along with Bash. If not, see <http://www.gnu.org/licenses/>.-
20-
21$PRODUCES source.c-
22-
23$BUILTIN source-
24$FUNCTION source_builtin-
25$SHORT_DOC source filename [arguments]-
26Execute commands from a file in the current shell.-
27-
28Read and execute commands from FILENAME in the current shell. The-
29entries in $PATH are used to find the directory containing FILENAME.-
30If any ARGUMENTS are supplied, they become the positional parameters-
31when FILENAME is executed.-
32-
33Exit Status:-
34Returns the status of the last command executed in FILENAME; fails if-
35FILENAME cannot be read.-
36$END-
37-
38$BUILTIN .-
39$DOCNAME dot-
40$FUNCTION source_builtin-
41$SHORT_DOC . filename [arguments]-
42Execute commands from a file in the current shell.-
43-
44Read and execute commands from FILENAME in the current shell. The-
45entries in $PATH are used to find the directory containing FILENAME.-
46If any ARGUMENTS are supplied, they become the positional parameters-
47when FILENAME is executed.-
48-
49Exit Status:-
50Returns the status of the last command executed in FILENAME; fails if-
51FILENAME cannot be read.-
52$END-
53-
54#include <config.h>-
55-
56#include "../bashtypes.h"-
57#include "posixstat.h"-
58#include "filecntl.h"-
59#if ! defined(_MINIX) && defined (HAVE_SYS_FILE_H)-
60# include <sys/file.h>-
61#endif-
62#include <errno.h>-
63-
64#if defined (HAVE_UNISTD_H)-
65# include <unistd.h>-
66#endif-
67-
68#include "../bashansi.h"-
69#include "../bashintl.h"-
70-
71#include "../shell.h"-
72#include "../execute_cmd.h"-
73#include "../flags.h"-
74#include "../findcmd.h"-
75#include "common.h"-
76#include "bashgetopt.h"-
77#include "../trap.h"-
78-
79#if !defined (errno)-
80extern int errno;-
81#endif /* !errno */-
82-
83static void maybe_pop_dollar_vars __P((void));-
84-
85/* If non-zero, `.' uses $PATH to look up the script to be sourced. */-
86int source_uses_path = 1;-
87-
88/* If non-zero, `.' looks in the current directory if the filename argument-
89 is not found in the $PATH. */-
90int source_searches_cwd = 1;-
91-
92/* If this . script is supplied arguments, we save the dollar vars and-
93 replace them with the script arguments for the duration of the script's-
94 execution. If the script does not change the dollar vars, we restore-
95 what we saved. If the dollar vars are changed in the script, and we are-
96 not executing a shell function, we leave the new values alone and free-
97 the saved values. */-
98static void-
99maybe_pop_dollar_vars ()-
100{-
101 if (variable_context == 0 && (dollar_vars_changed () & ARGS_SETBLTIN))
variable_context == 0Description
TRUEevaluated 1197 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(dollar_vars_c...ged () & 0x04)Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1190 times by 1 test
Evaluated by:
  • Self test
0-1197
102 dispose_saved_dollar_vars ();
executed 7 times by 1 test: dispose_saved_dollar_vars ();
Executed by:
  • Self test
7
103 else-
104 pop_dollar_vars ();
executed 1190 times by 1 test: pop_dollar_vars ();
Executed by:
  • Self test
1190
105 if (debugging_mode)
debugging_modeDescription
TRUEnever evaluated
FALSEevaluated 1197 times by 1 test
Evaluated by:
  • Self test
0-1197
106 pop_args (); /* restore BASH_ARGC and BASH_ARGV */
never executed: pop_args ();
0
107 set_dollar_vars_unchanged ();-
108 invalidate_cached_quoted_dollar_at (); /* just invalidate to be safe */-
109}
executed 1197 times by 1 test: end of block
Executed by:
  • Self test
1197
110-
111/* Read and execute commands from the file passed as argument. Guess what.-
112 This cannot be done in a subshell, since things like variable assignments-
113 take place in there. So, I open the file, place it into a large string,-
114 close the file, and then execute the string. */-
115int-
116source_builtin (list)-
117 WORD_LIST *list;-
118{-
119 int result;-
120 char *filename, *debug_trap, *x;-
121-
122 if (no_options (list))
no_options (list)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1403 times by 1 test
Evaluated by:
  • Self test
2-1403
123 return (EX_USAGE);
executed 2 times by 1 test: return (258);
Executed by:
  • Self test
2
124 list = loptend;-
125-
126 if (list == 0)
list == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1401 times by 1 test
Evaluated by:
  • Self test
2-1401
127 {-
128 builtin_error (_("filename argument required"));-
129 builtin_usage ();-
130 return (EX_USAGE);
executed 2 times by 1 test: return (258);
Executed by:
  • Self test
2
131 }-
132-
133#if defined (RESTRICTED_SHELL)-
134 if (restricted && strchr (list->word->word, '/'))
restrictedDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1400 times by 1 test
Evaluated by:
  • Self test
(__extension__...word , '/' )))Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
__builtin_constant_p ( '/' )Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
!__builtin_con...->word->word )Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
( '/' ) == '\0'Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
0-1400
135 {-
136 sh_restricted (list->word->word);-
137 return (EXECUTION_FAILURE);
executed 1 time by 1 test: return (1);
Executed by:
  • Self test
1
138 }-
139#endif-
140-
141 filename = (char *)NULL;-
142 /* XXX -- should this be absolute_pathname? */-
143 if (posixly_correct && strchr (list->word->word, '/'))
posixly_correctDescription
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1391 times by 1 test
Evaluated by:
  • Self test
(__extension__...word , '/' )))Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
__builtin_constant_p ( '/' )Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
!__builtin_con...->word->word )Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
( '/' ) == '\0'Description
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
0-1391
144 filename = savestring (list->word->word);
executed 9 times by 1 test: filename = (char *)strcpy (sh_xmalloc((1 + strlen (list->word->word)), "./source.def", 144), (list->word->word));
Executed by:
  • Self test
9
145 else if (absolute_pathname (list->word->word))
absolute_pathn...t->word->word)Description
TRUEevaluated 1377 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 14 times by 1 test
Evaluated by:
  • Self test
14-1377
146 filename = savestring (list->word->word);
executed 1377 times by 1 test: filename = (char *)strcpy (sh_xmalloc((1 + strlen (list->word->word)), "./source.def", 146), (list->word->word));
Executed by:
  • Self test
1377
147 else if (source_uses_path)
source_uses_pathDescription
TRUEnever evaluated
FALSEevaluated 14 times by 1 test
Evaluated by:
  • Self test
0-14
148 filename = find_path_file (list->word->word);
never executed: filename = find_path_file (list->word->word);
0
149 if (filename == 0)
filename == 0Description
TRUEevaluated 14 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1386 times by 1 test
Evaluated by:
  • Self test
14-1386
150 {-
151 if (source_searches_cwd == 0)
source_searches_cwd == 0Description
TRUEnever evaluated
FALSEevaluated 14 times by 1 test
Evaluated by:
  • Self test
0-14
152 {-
153 x = printable_filename (list->word->word, 0);-
154 builtin_error (_("%s: file not found"), x);-
155 if (x != list->word->word)
x != list->word->wordDescription
TRUEnever evaluated
FALSEnever evaluated
0
156 free (x);
never executed: sh_xfree((x), "./source.def", 156);
0
157 if (posixly_correct && interactive_shell == 0 && executing_command_builtin == 0)
posixly_correctDescription
TRUEnever evaluated
FALSEnever evaluated
interactive_shell == 0Description
TRUEnever evaluated
FALSEnever evaluated
executing_command_builtin == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
158 {-
159 last_command_exit_value = 1;-
160 jump_to_top_level (EXITPROG);-
161 }
never executed: end of block
0
162 return (EXECUTION_FAILURE);
never executed: return (1);
0
163 }-
164 else-
165 filename = savestring (list->word->word);
executed 14 times by 1 test: filename = (char *)strcpy (sh_xmalloc((1 + strlen (list->word->word)), "./source.def", 165), (list->word->word));
Executed by:
  • Self test
14
166 }-
167-
168 begin_unwind_frame ("source");-
169 add_unwind_protect (xfree, filename);-
170-
171 if (list->next)
list->nextDescription
TRUEevaluated 1207 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 193 times by 1 test
Evaluated by:
  • Self test
193-1207
172 {-
173 push_dollar_vars ();-
174 add_unwind_protect ((Function *)maybe_pop_dollar_vars, (char *)NULL);-
175 if (debugging_mode || shell_compatibility_level <= 44)
debugging_modeDescription
TRUEnever evaluated
FALSEevaluated 1207 times by 1 test
Evaluated by:
  • Self test
shell_compatib...ty_level <= 44Description
TRUEnever evaluated
FALSEevaluated 1207 times by 1 test
Evaluated by:
  • Self test
0-1207
176 init_bash_argv (); /* Initialize BASH_ARGV and BASH_ARGC */
never executed: init_bash_argv ();
0
177 remember_args (list->next, 1);-
178 if (debugging_mode)
debugging_modeDescription
TRUEnever evaluated
FALSEevaluated 1207 times by 1 test
Evaluated by:
  • Self test
0-1207
179 push_args (list->next); /* Update BASH_ARGV and BASH_ARGC */
never executed: push_args (list->next);
0
180 }
executed 1207 times by 1 test: end of block
Executed by:
  • Self test
1207
181 set_dollar_vars_unchanged ();-
182-
183 /* Don't inherit the DEBUG trap unless function_trace_mode (overloaded)-
184 is set. XXX - should sourced files inherit the RETURN trap? Functions-
185 don't. */-
186 debug_trap = TRAP_STRING (DEBUG_TRAP);
signal_is_trapped ( 65 )Description
TRUEevaluated 28 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1372 times by 1 test
Evaluated by:
  • Self test
signal_is_ignored ( 65 ) == 0Description
TRUEevaluated 28 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1372
187 if (debug_trap && function_trace_mode == 0)
debug_trapDescription
TRUEevaluated 28 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1372 times by 1 test
Evaluated by:
  • Self test
function_trace_mode == 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 25 times by 1 test
Evaluated by:
  • Self test
3-1372
188 {-
189 debug_trap = savestring (debug_trap);-
190 add_unwind_protect (xfree, debug_trap);-
191 add_unwind_protect (maybe_set_debug_trap, debug_trap);-
192 restore_default_signal (DEBUG_TRAP);-
193 }
executed 3 times by 1 test: end of block
Executed by:
  • Self test
3
194-
195 result = source_file (filename, (list && list->next));-
196-
197 run_unwind_frame ("source");-
198-
199 return (result);
executed 1386 times by 1 test: return (result);
Executed by:
  • Self test
1386
200}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2