1 diff --git a/builtins.h b/builtins.h
5 #define POSIX_BUILTIN 0x20 /* This builtins is special in the Posix command search order. */
6 #define LOCALVAR_BUILTIN 0x40 /* This builtin creates local variables */
7 #define ARRAYREF_BUILTIN 0x80 /* This builtin takes array references as arguments */
8 +#define REQUIRES_BUILTIN 0x100 /* This builtin requires other files. */
12 diff --git a/builtins/mkbuiltins.c b/builtins/mkbuiltins.c
13 --- a/builtins/mkbuiltins.c
14 +++ b/builtins/mkbuiltins.c
15 @@ -69,11 +69,16 @@ extern char *strcpy ();
16 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
18 /* Flag values that builtins can have. */
19 +/* These flags are for the C code generator,
20 + the C which is produced (./builtin.c)
21 + includes the flags definitions found
23 #define BUILTIN_FLAG_SPECIAL 0x01
24 #define BUILTIN_FLAG_ASSIGNMENT 0x02
25 #define BUILTIN_FLAG_LOCALVAR 0x04
26 #define BUILTIN_FLAG_POSIX_BUILTIN 0x08
27 #define BUILTIN_FLAG_ARRAYREF_ARG 0x10
28 +#define BUILTIN_FLAG_REQUIRES 0x20
32 @@ -189,13 +194,21 @@ char *arrayvar_builtins[] =
33 "typeset", "unset", "wait", /*]*/
38 +/* The builtin commands that cause requirements on other files. */
39 +static char *requires_builtins[] =
41 + ".", "command", "exec", "source", "inlib",
45 /* Forward declarations. */
46 static int is_special_builtin ();
47 static int is_assignment_builtin ();
48 static int is_localvar_builtin ();
49 static int is_posix_builtin ();
50 static int is_arrayvar_builtin ();
51 +static int is_requires_builtin ();
53 #if !defined (HAVE_RENAME)
55 @@ -856,6 +869,8 @@ builtin_handler (self, defs, arg)
56 new->flags |= BUILTIN_FLAG_POSIX_BUILTIN;
57 if (is_arrayvar_builtin (name))
58 new->flags |= BUILTIN_FLAG_ARRAYREF_ARG;
59 + if (is_requires_builtin (name))
60 + new->flags |= BUILTIN_FLAG_REQUIRES;
62 array_add ((char *)new, defs->builtins);
64 @@ -1275,13 +1290,14 @@ write_builtins (defs, structfile, externfile)
66 fprintf (structfile, "(sh_builtin_func_t *)0x0, ");
68 - fprintf (structfile, "%s%s%s%s%s%s, %s_doc,\n",
69 + fprintf (structfile, "%s%s%s%s%s%s%s, %s_doc,\n",
70 "BUILTIN_ENABLED | STATIC_BUILTIN",
71 (builtin->flags & BUILTIN_FLAG_SPECIAL) ? " | SPECIAL_BUILTIN" : "",
72 (builtin->flags & BUILTIN_FLAG_ASSIGNMENT) ? " | ASSIGNMENT_BUILTIN" : "",
73 (builtin->flags & BUILTIN_FLAG_LOCALVAR) ? " | LOCALVAR_BUILTIN" : "",
74 (builtin->flags & BUILTIN_FLAG_POSIX_BUILTIN) ? " | POSIX_BUILTIN" : "",
75 (builtin->flags & BUILTIN_FLAG_ARRAYREF_ARG) ? " | ARRAYREF_BUILTIN" : "",
76 + (builtin->flags & BUILTIN_FLAG_REQUIRES) ? " | REQUIRES_BUILTIN" : "",
77 document_name (builtin));
79 /* Don't translate short document summaries that are identical
80 @@ -1678,6 +1694,13 @@ is_arrayvar_builtin (name)
81 return (_find_in_table (name, arrayvar_builtins));
85 +is_requires_builtin (name)
88 + return (_find_in_table (name, requires_builtins));
91 #if !defined (HAVE_RENAME)
94 diff --git a/doc/bash.1 b/doc/bash.1
97 @@ -239,6 +239,14 @@ The shell becomes restricted (see
102 +Produce the list of files that are required for the
103 +shell script to run. This implies '-n' and is subject
104 +to the same limitations as compile time error checking checking;
105 +Command substitutions, Conditional expressions and
107 +builtin are not parsed so some dependencies may be missed.
110 Equivalent to \fB\-v\fP.
112 diff --git a/doc/bashref.texi b/doc/bashref.texi
113 --- a/doc/bashref.texi
114 +++ b/doc/bashref.texi
115 @@ -6927,6 +6927,13 @@ standard. @xref{Bash POSIX Mode}, for a description of the Bash
117 Make the shell a restricted shell (@pxref{The Restricted Shell}).
119 +@item --rpm-requires
120 +Produce the list of files that are required for the
121 +shell script to run. This implies '-n' and is subject
122 +to the same limitations as compile time error checking checking;
123 +Command substitutions, Conditional expressions and @command{eval}
124 +are not parsed so some dependencies may be missed.
127 Equivalent to @option{-v}. Print shell input lines as they're read.
129 diff --git a/eval.c b/eval.c
132 @@ -138,7 +138,8 @@ reader_loop ()
134 if (read_command () == 0)
136 - if (interactive_shell == 0 && read_but_dont_execute)
138 + if (interactive_shell == 0 && (read_but_dont_execute && !rpm_requires))
140 set_exit_status (last_command_exit_value);
141 dispose_command (global_command);
142 diff --git a/execute_cmd.c b/execute_cmd.c
145 @@ -561,6 +561,8 @@ async_redirect_stdin ()
147 #define DESCRIBE_PID(pid) do { if (interactive) describe_pid (pid); } while (0)
149 +extern int rpm_requires;
151 /* Execute the command passed in COMMAND, perhaps doing it asynchronously.
152 COMMAND is exactly what read_command () places into GLOBAL_COMMAND.
153 ASYNCHRONOUS, if non-zero, says to do this command in the background.
154 @@ -592,7 +594,13 @@ execute_command_internal (command, asynchronous, pipe_in, pipe_out,
156 if (breaking || continuing)
157 return (last_command_exit_value);
158 - if (read_but_dont_execute)
159 + if (command == 0 || (read_but_dont_execute && !rpm_requires))
160 + return (EXECUTION_SUCCESS);
161 + if (rpm_requires && command->type == cm_function_def)
162 + return last_command_exit_value =
163 + execute_intern_function (command->value.Function_def->name,
164 + command->value.Function_def);
165 + if (read_but_dont_execute)
166 return (last_command_exit_value);
168 return (EXECUTION_SUCCESS);
169 @@ -2883,7 +2891,7 @@ execute_for_command (for_command)
170 save_line_number = line_number;
171 if (check_identifier (for_command->name, 1) == 0)
173 - if (posixly_correct && interactive_shell == 0)
174 + if (posixly_correct && interactive_shell == 0 && rpm_requires == 0)
176 last_command_exit_value = EX_BADUSAGE;
177 jump_to_top_level (ERREXIT);
178 diff --git a/execute_cmd.h b/execute_cmd.h
182 #define _EXECUTE_CMD_H_
185 +#include "variables.h"
186 +#include "command.h"
189 #if defined (ARRAY_VARS)
190 struct func_array_state
191 diff --git a/make_cmd.c b/make_cmd.c
195 #include "bashintl.h"
198 +#include "builtins.h"
199 +#include "builtins/common.h"
200 #include "execute_cmd.h"
203 @@ -839,6 +841,30 @@ make_coproc_command (name, command)
204 return (make_command (cm_coproc, (SIMPLE_COM *)temp));
208 +output_requirement (deptype, filename)
209 +const char *deptype;
212 + static char *alphabet_set = "abcdefghijklmnopqrstuvwxyz"
213 + "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
215 + if (strchr(filename, '$') || (filename[0] != '/' && strchr(filename, '/')))
219 + if the executable is called via variable substitution we can
220 + not dermine what it is at compile time.
222 + if the executable consists only of characters not in the
223 + alphabet we do not consider it a dependency just an artifact
224 + of shell parsing (ex "exec < ${infile}").
227 + if (strpbrk(filename, alphabet_set))
228 + printf ("%s(%s)\n", deptype, filename);
231 /* Reverse the word list and redirection list in the simple command
232 has just been parsed. It seems simpler to do this here the one
233 time then by any other method that I can think of. */
234 @@ -856,6 +882,28 @@ clean_simple_command (command)
235 REVERSE_LIST (command->value.Simple->redirects, REDIRECT *);
238 + if (rpm_requires && command->value.Simple->words)
244 + cmd0 = command->value.Simple->words->word->word;
245 + b = builtin_address_internal (cmd0, 0);
247 + if (command->value.Simple->words->next)
248 + cmd1 = command->value.Simple->words->next->word->word;
251 + if ( (b->flags & REQUIRES_BUILTIN) && cmd1)
252 + output_requirement ("executable", cmd1);
254 + if (!assignment(cmd0, 0))
255 + output_requirement (find_function(cmd0) ? "function" : "executable", cmd0);
260 parser_state &= ~PST_REDIRLIST;
263 diff --git a/shell.c b/shell.c
266 @@ -196,6 +196,9 @@ int have_devfd = 0;
267 /* The name of the .(shell)rc file. */
268 static char *bashrc_file = DEFAULT_BASHRC;
270 +/* Non-zero if we are finding the scripts requirements. */
273 /* Non-zero means to act more like the Bourne shell on startup. */
274 static int act_like_sh;
276 @@ -266,6 +269,7 @@ static const struct {
277 { "protected", Int, &protected_mode, (char **)0x0 },
279 { "rcfile", Charp, (int *)0x0, &bashrc_file },
280 + { "rpm-requires", Int, &rpm_requires, (char **)0x0 },
281 #if defined (RESTRICTED_SHELL)
282 { "restricted", Int, &restricted, (char **)0x0 },
284 @@ -510,6 +514,12 @@ main (argc, argv, env)
285 read_but_dont_execute = 1;
290 + read_but_dont_execute = 1;
291 + initialize_shell_builtins ();
294 if (running_setuid && privileged_mode == 0)
295 disable_priv_mode ();
297 diff --git a/shell.h b/shell.h
300 @@ -100,6 +100,7 @@ extern int interactive, interactive_shell;
301 extern int startup_state;
302 extern int reading_shell_script;
303 extern int shell_initialized;
304 +extern int rpm_requires;
305 extern int bash_argv_initialized;
306 extern int subshell_environment;
307 extern int current_command_number;