]>
Commit | Line | Data |
---|---|---|
9ecd8d09 AM |
1 | diff --git a/builtins.h b/builtins.h |
2 | index dac95fd..5b7e811 100644 | |
3 | --- a/builtins.h | |
4 | +++ b/builtins.h | |
5 | @@ -45,6 +45,7 @@ | |
155af773 AM |
6 | #define ASSIGNMENT_BUILTIN 0x10 /* This builtin takes assignment statements. */ |
7 | #define POSIX_BUILTIN 0x20 /* This builtins is special in the Posix command search order. */ | |
8 | #define LOCALVAR_BUILTIN 0x40 /* This builtin creates local variables */ | |
9ecd8d09 | 9 | +#define REQUIRES_BUILTIN 0x80 /* This builtin requires other files. */ |
155af773 AM |
10 | |
11 | #define BASE_INDENT 4 | |
12 | ||
9ecd8d09 AM |
13 | diff --git a/builtins/mkbuiltins.c b/builtins/mkbuiltins.c |
14 | index 4f51201..91c25db 100644 | |
15 | --- a/builtins/mkbuiltins.c | |
16 | +++ b/builtins/mkbuiltins.c | |
17 | @@ -69,10 +69,15 @@ extern char *strcpy (); | |
155af773 AM |
18 | #define whitespace(c) (((c) == ' ') || ((c) == '\t')) |
19 | ||
20 | /* Flag values that builtins can have. */ | |
9ecd8d09 | 21 | +/* These flags are for the C code generator, |
155af773 | 22 | + the C which is produced (./builtin.c) |
9ecd8d09 | 23 | + includes the flags definitions found |
155af773 | 24 | + in ../builtins.h */ |
35373510 | 25 | #define BUILTIN_FLAG_SPECIAL 0x01 |
26 | #define BUILTIN_FLAG_ASSIGNMENT 0x02 | |
155af773 AM |
27 | #define BUILTIN_FLAG_LOCALVAR 0x04 |
28 | #define BUILTIN_FLAG_POSIX_BUILTIN 0x08 | |
9ecd8d09 | 29 | +#define BUILTIN_FLAG_REQUIRES 0x10 |
0b94540b AM |
30 | |
31 | #define BASE_INDENT 4 | |
35373510 | 32 | |
9ecd8d09 | 33 | @@ -173,11 +178,19 @@ char *posix_builtins[] = |
35373510 | 34 | (char *)NULL |
35 | }; | |
36 | ||
37 | +/* The builtin commands that cause requirements on other files. */ | |
155af773 | 38 | +static char *requires_builtins[] = |
35373510 | 39 | +{ |
40 | + ".", "command", "exec", "source", "inlib", | |
41 | + (char *)NULL | |
42 | +}; | |
43 | + | |
44 | /* Forward declarations. */ | |
45 | static int is_special_builtin (); | |
46 | static int is_assignment_builtin (); | |
155af773 | 47 | static int is_localvar_builtin (); |
0b94540b | 48 | static int is_posix_builtin (); |
35373510 | 49 | +static int is_requires_builtin (); |
50 | ||
51 | #if !defined (HAVE_RENAME) | |
9ecd8d09 AM |
52 | static int rename (); |
53 | @@ -831,6 +844,8 @@ builtin_handler (self, defs, arg) | |
54 | new->flags |= BUILTIN_FLAG_LOCALVAR; | |
0b94540b AM |
55 | if (is_posix_builtin (name)) |
56 | new->flags |= BUILTIN_FLAG_POSIX_BUILTIN; | |
35373510 | 57 | + if (is_requires_builtin (name)) |
58 | + new->flags |= BUILTIN_FLAG_REQUIRES; | |
59 | ||
60 | array_add ((char *)new, defs->builtins); | |
61 | building_builtin = 1; | |
9ecd8d09 | 62 | @@ -1250,12 +1265,13 @@ write_builtins (defs, structfile, externfile) |
35373510 | 63 | else |
69ed6004 | 64 | fprintf (structfile, "(sh_builtin_func_t *)0x0, "); |
35373510 | 65 | |
155af773 AM |
66 | - fprintf (structfile, "%s%s%s%s%s, %s_doc,\n", |
67 | + fprintf (structfile, "%s%s%s%s%s%s, %s_doc,\n", | |
35373510 | 68 | "BUILTIN_ENABLED | STATIC_BUILTIN", |
69 | (builtin->flags & BUILTIN_FLAG_SPECIAL) ? " | SPECIAL_BUILTIN" : "", | |
70 | (builtin->flags & BUILTIN_FLAG_ASSIGNMENT) ? " | ASSIGNMENT_BUILTIN" : "", | |
155af773 | 71 | (builtin->flags & BUILTIN_FLAG_LOCALVAR) ? " | LOCALVAR_BUILTIN" : "", |
0b94540b | 72 | (builtin->flags & BUILTIN_FLAG_POSIX_BUILTIN) ? " | POSIX_BUILTIN" : "", |
35373510 | 73 | + (builtin->flags & BUILTIN_FLAG_REQUIRES) ? " | REQUIRES_BUILTIN" : "", |
69ed6004 | 74 | document_name (builtin)); |
35373510 | 75 | |
155af773 | 76 | /* Don't translate short document summaries that are identical |
9ecd8d09 | 77 | @@ -1645,6 +1661,13 @@ is_posix_builtin (name) |
155af773 AM |
78 | return (_find_in_table (name, posix_builtins)); |
79 | } | |
80 | ||
35373510 | 81 | +static int |
82 | +is_requires_builtin (name) | |
83 | + char *name; | |
84 | +{ | |
85 | + return (_find_in_table (name, requires_builtins)); | |
155af773 AM |
86 | +} |
87 | + | |
35373510 | 88 | #if !defined (HAVE_RENAME) |
155af773 AM |
89 | static int |
90 | rename (from, to) | |
9ecd8d09 AM |
91 | diff --git a/doc/bash.1 b/doc/bash.1 |
92 | index d91f1fd..111a66d 100644 | |
93 | --- a/doc/bash.1 | |
94 | +++ b/doc/bash.1 | |
95 | @@ -239,6 +239,14 @@ The shell becomes restricted (see | |
35373510 | 96 | .B "RESTRICTED SHELL" |
97 | below). | |
98 | .TP | |
99 | +.B \-\-rpm-requires | |
9ecd8d09 | 100 | +Produce the list of files that are required for the |
35373510 | 101 | +shell script to run. This implies '-n' and is subject |
102 | +to the same limitations as compile time error checking checking; | |
155af773 AM |
103 | +Command substitutions, Conditional expressions and |
104 | +.BR eval | |
105 | +builtin are not parsed so some dependencies may be missed. | |
106 | +.TP | |
35373510 | 107 | .B \-\-verbose |
9ecd8d09 | 108 | Equivalent to \fB\-v\fP. |
35373510 | 109 | .TP |
9ecd8d09 AM |
110 | diff --git a/doc/bashref.texi b/doc/bashref.texi |
111 | index d33cd57..6fc4d18 100644 | |
112 | --- a/doc/bashref.texi | |
113 | +++ b/doc/bashref.texi | |
114 | @@ -6453,6 +6453,13 @@ standard. @xref{Bash POSIX Mode}, for a description of the Bash | |
35373510 | 115 | @item --restricted |
116 | Make the shell a restricted shell (@pxref{The Restricted Shell}). | |
117 | ||
118 | +@item --rpm-requires | |
9ecd8d09 | 119 | +Produce the list of files that are required for the |
35373510 | 120 | +shell script to run. This implies '-n' and is subject |
121 | +to the same limitations as compile time error checking checking; | |
155af773 AM |
122 | +Command substitutions, Conditional expressions and @command{eval} |
123 | +are not parsed so some dependencies may be missed. | |
35373510 | 124 | + |
125 | @item --verbose | |
155af773 | 126 | Equivalent to @option{-v}. Print shell input lines as they're read. |
35373510 | 127 | |
9ecd8d09 AM |
128 | diff --git a/eval.c b/eval.c |
129 | index f02d6e4..76c1e8d 100644 | |
130 | --- a/eval.c | |
131 | +++ b/eval.c | |
132 | @@ -142,7 +142,8 @@ reader_loop () | |
155af773 AM |
133 | |
134 | if (read_command () == 0) | |
135 | { | |
136 | - if (interactive_shell == 0 && read_but_dont_execute) | |
9ecd8d09 | 137 | + |
155af773 AM |
138 | + if (interactive_shell == 0 && (read_but_dont_execute && !rpm_requires)) |
139 | { | |
140 | last_command_exit_value = EXECUTION_SUCCESS; | |
141 | dispose_command (global_command); | |
9ecd8d09 AM |
142 | diff --git a/execute_cmd.c b/execute_cmd.c |
143 | index 8b3c83a..4eae19c 100644 | |
144 | --- a/execute_cmd.c | |
145 | +++ b/execute_cmd.c | |
146 | @@ -538,6 +538,8 @@ async_redirect_stdin () | |
155af773 AM |
147 | |
148 | #define DESCRIBE_PID(pid) do { if (interactive) describe_pid (pid); } while (0) | |
149 | ||
150 | +extern int rpm_requires; | |
151 | + | |
152 | /* Execute the command passed in COMMAND, perhaps doing it asynchronously. | |
153 | COMMAND is exactly what read_command () places into GLOBAL_COMMAND. | |
154 | ASYNCHROUNOUS, if non-zero, says to do this command in the background. | |
9ecd8d09 | 155 | @@ -569,7 +571,13 @@ execute_command_internal (command, asynchronous, pipe_in, pipe_out, |
155af773 AM |
156 | |
157 | if (breaking || continuing) | |
158 | return (last_command_exit_value); | |
159 | - if (command == 0 || read_but_dont_execute) | |
160 | + if (command == 0 || (read_but_dont_execute && !rpm_requires)) | |
161 | + return (EXECUTION_SUCCESS); | |
162 | + if (rpm_requires && command->type == cm_function_def) | |
163 | + return last_command_exit_value = | |
164 | + execute_intern_function (command->value.Function_def->name, | |
165 | + command->value.Function_def); | |
166 | + if (read_but_dont_execute) | |
167 | return (EXECUTION_SUCCESS); | |
168 | ||
169 | QUIT; | |
9ecd8d09 AM |
170 | @@ -2813,7 +2821,7 @@ execute_for_command (for_command) |
171 | save_line_number = line_number; | |
172 | if (check_identifier (for_command->name, 1) == 0) | |
155af773 AM |
173 | { |
174 | - if (posixly_correct && interactive_shell == 0) | |
175 | + if (posixly_correct && interactive_shell == 0 && rpm_requires == 0) | |
176 | { | |
177 | last_command_exit_value = EX_BADUSAGE; | |
178 | jump_to_top_level (ERREXIT); | |
9ecd8d09 AM |
179 | diff --git a/execute_cmd.h b/execute_cmd.h |
180 | index dc2f15e..506fff4 100644 | |
181 | --- a/execute_cmd.h | |
182 | +++ b/execute_cmd.h | |
183 | @@ -22,6 +22,9 @@ | |
155af773 AM |
184 | #define _EXECUTE_CMD_H_ |
185 | ||
186 | #include "stdc.h" | |
187 | +#include "variables.h" | |
188 | +#include "command.h" | |
35373510 | 189 | + |
35373510 | 190 | |
9ecd8d09 AM |
191 | #if defined (ARRAY_VARS) |
192 | struct func_array_state | |
193 | diff --git a/make_cmd.c b/make_cmd.c | |
194 | index ecbbfd6..3d8bfa4 100644 | |
195 | --- a/make_cmd.c | |
196 | +++ b/make_cmd.c | |
197 | @@ -828,6 +828,27 @@ make_coproc_command (name, command) | |
155af773 | 198 | return (make_command (cm_coproc, (SIMPLE_COM *)temp)); |
35373510 | 199 | } |
200 | ||
155af773 AM |
201 | +static void |
202 | +output_requirement (deptype, filename) | |
203 | +const char *deptype; | |
204 | +char *filename; | |
35373510 | 205 | +{ |
155af773 AM |
206 | + if (strchr(filename, '$') || (filename[0] != '/' && strchr(filename, '/'))) |
207 | + return; | |
35373510 | 208 | + |
9ecd8d09 | 209 | + /* |
155af773 | 210 | + if the executable is called via variable substitution we can |
9ecd8d09 | 211 | + not dermine what it is at compile time. |
35373510 | 212 | + |
155af773 AM |
213 | + if the executable consists only of characters not in the |
214 | + alphabet we do not consider it a dependency just an artifact | |
215 | + of shell parsing (ex "exec < ${infile}"). | |
216 | + */ | |
35373510 | 217 | + |
155af773 AM |
218 | + if (strpbrk(filename, alphabet_set)) |
219 | + printf ("%s(%s)\n", deptype, filename); | |
35373510 | 220 | +} |
221 | + | |
222 | /* Reverse the word list and redirection list in the simple command | |
223 | has just been parsed. It seems simpler to do this here the one | |
224 | time then by any other method that I can think of. */ | |
9ecd8d09 | 225 | @@ -845,6 +866,28 @@ clean_simple_command (command) |
35373510 | 226 | REVERSE_LIST (command->value.Simple->redirects, REDIRECT *); |
227 | } | |
155af773 | 228 | |
35373510 | 229 | + if (rpm_requires && command->value.Simple->words) |
230 | + { | |
231 | + char *cmd0; | |
232 | + char *cmd1; | |
233 | + struct builtin *b; | |
234 | + | |
235 | + cmd0 = command->value.Simple->words->word->word; | |
236 | + b = builtin_address_internal (cmd0, 0); | |
237 | + cmd1 = 0; | |
155af773 AM |
238 | + if (command->value.Simple->words->next) |
239 | + cmd1 = command->value.Simple->words->next->word->word; | |
240 | + | |
35373510 | 241 | + if (b) { |
155af773 AM |
242 | + if ( (b->flags & REQUIRES_BUILTIN) && cmd1) |
243 | + output_requirement ("executable", cmd1); | |
35373510 | 244 | + } else { |
155af773 AM |
245 | + if (!assignment(cmd0, 0)) |
246 | + output_requirement (find_function(cmd0) ? "function" : "executable", cmd0); | |
35373510 | 247 | + } |
248 | + } /*rpm_requires*/ | |
9ecd8d09 | 249 | + |
155af773 AM |
250 | + |
251 | parser_state &= ~PST_REDIRLIST; | |
35373510 | 252 | return (command); |
253 | } | |
9ecd8d09 AM |
254 | diff --git a/shell.c b/shell.c |
255 | index a2b2a55..c5d99b3 100644 | |
256 | --- a/shell.c | |
257 | +++ b/shell.c | |
155af773 | 258 | @@ -193,6 +193,9 @@ int have_devfd = 0; |
35373510 | 259 | /* The name of the .(shell)rc file. */ |
9ecd8d09 | 260 | static char *bashrc_file = DEFAULT_BASHRC; |
35373510 | 261 | |
262 | +/* Non-zero if we are finding the scripts requirements. */ | |
263 | +int rpm_requires; | |
264 | + | |
265 | /* Non-zero means to act more like the Bourne shell on startup. */ | |
266 | static int act_like_sh; | |
267 | ||
9ecd8d09 | 268 | @@ -259,6 +262,7 @@ static const struct { |
155af773 AM |
269 | { "protected", Int, &protected_mode, (char **)0x0 }, |
270 | #endif | |
35373510 | 271 | { "rcfile", Charp, (int *)0x0, &bashrc_file }, |
272 | + { "rpm-requires", Int, &rpm_requires, (char **)0x0 }, | |
273 | #if defined (RESTRICTED_SHELL) | |
274 | { "restricted", Int, &restricted, (char **)0x0 }, | |
275 | #endif | |
9ecd8d09 | 276 | @@ -496,6 +500,12 @@ main (argc, argv, env) |
35373510 | 277 | if (dump_translatable_strings) |
278 | read_but_dont_execute = 1; | |
155af773 | 279 | |
35373510 | 280 | + if (rpm_requires) |
281 | + { | |
282 | + read_but_dont_execute = 1; | |
283 | + initialize_shell_builtins (); | |
284 | + } | |
155af773 | 285 | + |
35373510 | 286 | if (running_setuid && privileged_mode == 0) |
287 | disable_priv_mode (); | |
155af773 | 288 | |
9ecd8d09 AM |
289 | diff --git a/shell.h b/shell.h |
290 | index 8072605..6c4149d 100644 | |
291 | --- a/shell.h | |
292 | +++ b/shell.h | |
293 | @@ -34,12 +34,15 @@ | |
294 | #include "maxpath.h" | |
295 | #include "unwind_prot.h" | |
296 | #include "dispose_cmd.h" | |
297 | +#include "execute_cmd.h" | |
298 | #include "make_cmd.h" | |
299 | #include "ocache.h" | |
300 | #include "subst.h" | |
301 | #include "sig.h" | |
302 | #include "pathnames.h" | |
303 | #include "externs.h" | |
304 | +#include "builtins.h" | |
305 | +#include "builtins/common.h" | |
306 | ||
307 | extern int EOF_Reached; | |
308 | ||
309 | @@ -99,6 +102,9 @@ extern int interactive, interactive_shell; | |
310 | extern int startup_state; | |
311 | extern int reading_shell_script; | |
312 | extern int shell_initialized; | |
313 | +extern int rpm_requires; | |
314 | +static char *alphabet_set = "abcdefghijklmnopqrstuvwxyz" | |
315 | + "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
316 | extern int bash_argv_initialized; | |
317 | extern int subshell_environment; | |
318 | extern int current_command_number; | |
319 | -- | |
320 | 2.17.2 | |
321 |