1 diff -up bash-4.1/builtins.h.requires bash-4.1/builtins.h
2 --- bash-4.1/builtins.h.requires 2009-01-04 20:32:23.000000000 +0100
3 +++ bash-4.1/builtins.h 2010-08-02 17:42:41.000000000 +0200
5 #define SPECIAL_BUILTIN 0x08 /* This is a Posix `special' builtin. */
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 REQUIRES_BUILTIN 0x40 /* This builtin requires other files. */
13 diff -up bash-4.1/builtins/mkbuiltins.c.requires bash-4.1/builtins/mkbuiltins.c
14 --- bash-4.1/builtins/mkbuiltins.c.requires 2009-01-04 20:32:23.000000000 +0100
15 +++ bash-4.1/builtins/mkbuiltins.c 2010-08-02 17:42:41.000000000 +0200
16 @@ -69,9 +69,15 @@ extern char *strcpy ();
17 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
19 /* Flag values that builtins can have. */
20 +/* These flags are for the C code generator,
21 + the C which is produced (./builtin.c)
22 + includes the flags definitions found
24 #define BUILTIN_FLAG_SPECIAL 0x01
25 #define BUILTIN_FLAG_ASSIGNMENT 0x02
26 #define BUILTIN_FLAG_POSIX_BUILTIN 0x04
27 +#define BUILTIN_FLAG_REQUIRES 0x08
32 @@ -163,10 +169,18 @@ char *posix_builtins[] =
36 +/* The builtin commands that cause requirements on other files. */
37 +static char *requires_builtins[] =
39 + ".", "command", "exec", "source", "inlib",
43 /* Forward declarations. */
44 static int is_special_builtin ();
45 static int is_assignment_builtin ();
46 static int is_posix_builtin ();
47 +static int is_requires_builtin ();
49 #if !defined (HAVE_RENAME)
51 @@ -812,6 +826,9 @@ builtin_handler (self, defs, arg)
52 new->flags |= BUILTIN_FLAG_ASSIGNMENT;
53 if (is_posix_builtin (name))
54 new->flags |= BUILTIN_FLAG_POSIX_BUILTIN;
55 + if (is_requires_builtin (name))
56 + new->flags |= BUILTIN_FLAG_REQUIRES;
59 array_add ((char *)new, defs->builtins);
61 @@ -1229,11 +1246,12 @@ write_builtins (defs, structfile, extern
63 fprintf (structfile, "(sh_builtin_func_t *)0x0, ");
65 - fprintf (structfile, "%s%s%s%s, %s_doc,\n",
66 + fprintf (structfile, "%s%s%s%s%s, %s_doc,\n",
67 "BUILTIN_ENABLED | STATIC_BUILTIN",
68 (builtin->flags & BUILTIN_FLAG_SPECIAL) ? " | SPECIAL_BUILTIN" : "",
69 (builtin->flags & BUILTIN_FLAG_ASSIGNMENT) ? " | ASSIGNMENT_BUILTIN" : "",
70 (builtin->flags & BUILTIN_FLAG_POSIX_BUILTIN) ? " | POSIX_BUILTIN" : "",
71 + (builtin->flags & BUILTIN_FLAG_REQUIRES) ? " | REQUIRES_BUILTIN" : "",
72 document_name (builtin));
75 @@ -1581,6 +1599,13 @@ is_posix_builtin (name)
76 return (_find_in_table (name, posix_builtins));
80 +is_requires_builtin (name)
83 + return (_find_in_table (name, requires_builtins));
86 #if !defined (HAVE_RENAME)
89 diff -up bash-4.1/doc/bash.1.requires bash-4.1/doc/bash.1
90 --- bash-4.1/doc/bash.1.requires 2010-08-02 17:42:41.000000000 +0200
91 +++ bash-4.1/doc/bash.1 2010-08-02 18:09:27.000000000 +0200
92 @@ -231,6 +231,14 @@ The shell becomes restricted (see
97 +Produce the list of files that are required for the
98 +shell script to run. This implies '-n' and is subject
99 +to the same limitations as compile time error checking checking;
100 +Command substitutions, Conditional expressions and
102 +builtin are not parsed so some dependencies may be missed.
105 Equivalent to \fB\-v\fP.
107 diff -up bash-4.1/doc/bashref.texi.requires bash-4.1/doc/bashref.texi
108 --- bash-4.1/doc/bashref.texi.requires 2010-08-02 17:42:41.000000000 +0200
109 +++ bash-4.1/doc/bashref.texi 2010-08-02 18:11:58.000000000 +0200
110 @@ -5343,6 +5343,13 @@ standard. @xref{Bash POSIX Mode}, for a
112 Make the shell a restricted shell (@pxref{The Restricted Shell}).
114 +@item --rpm-requires
115 +Produce the list of files that are required for the
116 +shell script to run. This implies '-n' and is subject
117 +to the same limitations as compile time error checking checking;
118 +Command substitutions, Conditional expressions and @command{eval}
119 +are not parsed so some dependencies may be missed.
122 Equivalent to @option{-v}. Print shell input lines as they're read.
124 diff -up bash-4.1/eval.c.requires bash-4.1/eval.c
125 --- bash-4.1/eval.c.requires 2009-01-04 20:32:26.000000000 +0100
126 +++ bash-4.1/eval.c 2010-08-02 17:42:41.000000000 +0200
127 @@ -53,6 +53,7 @@ extern int last_command_exit_value, stdi
128 extern int need_here_doc;
129 extern int current_command_number, current_command_line_count, line_number;
130 extern int expand_aliases;
131 +extern int rpm_requires;
133 static void send_pwd_to_eterm __P((void));
134 static sighandler alrm_catcher __P((int));
135 @@ -136,7 +137,7 @@ reader_loop ()
137 if (read_command () == 0)
139 - if (interactive_shell == 0 && read_but_dont_execute)
140 + if (interactive_shell == 0 && (read_but_dont_execute && !rpm_requires))
142 last_command_exit_value = EXECUTION_SUCCESS;
143 dispose_command (global_command);
144 diff -up bash-4.1/execute_cmd.c.requires bash-4.1/execute_cmd.c
145 --- bash-4.1/execute_cmd.c.requires 2010-08-02 17:42:41.000000000 +0200
146 +++ bash-4.1/execute_cmd.c 2010-08-02 17:42:41.000000000 +0200
147 @@ -503,6 +503,8 @@ async_redirect_stdin ()
149 #define DESCRIBE_PID(pid) do { if (interactive) describe_pid (pid); } while (0)
151 +extern int rpm_requires;
153 /* Execute the command passed in COMMAND, perhaps doing it asynchrounously.
154 COMMAND is exactly what read_command () places into GLOBAL_COMMAND.
155 ASYNCHROUNOUS, if non-zero, says to do this command in the background.
156 @@ -534,7 +536,13 @@ execute_command_internal (command, async
158 if (breaking || continuing)
159 return (last_command_exit_value);
160 - if (command == 0 || read_but_dont_execute)
161 + if (command == 0 || (read_but_dont_execute && !rpm_requires))
162 + return (EXECUTION_SUCCESS);
163 + if (rpm_requires && command->type == cm_function_def)
164 + return last_command_exit_value =
165 + execute_intern_function (command->value.Function_def->name,
166 + command->value.Function_def->command);
167 + if (read_but_dont_execute)
168 return (EXECUTION_SUCCESS);
171 @@ -5066,7 +5074,7 @@ execute_intern_function (name, function)
173 if (check_identifier (name, posixly_correct) == 0)
175 - if (posixly_correct && interactive_shell == 0)
176 + if (posixly_correct && interactive_shell == 0 && rpm_requires == 0)
178 last_command_exit_value = EX_BADUSAGE;
179 jump_to_top_level (ERREXIT);
180 diff -up bash-4.1/execute_cmd.h.requires bash-4.1/execute_cmd.h
181 --- bash-4.1/execute_cmd.h.requires 2009-01-16 22:20:15.000000000 +0100
182 +++ bash-4.1/execute_cmd.h 2010-08-02 17:42:41.000000000 +0200
184 #define _EXECUTE_CMD_H_
187 +#include "variables.h"
188 +#include "command.h"
190 extern struct fd_bitmap *new_fd_bitmap __P((int));
191 extern void dispose_fd_bitmap __P((struct fd_bitmap *));
192 diff -up bash-4.1/make_cmd.c.requires bash-4.1/make_cmd.c
193 --- bash-4.1/make_cmd.c.requires 2009-09-11 23:26:12.000000000 +0200
194 +++ bash-4.1/make_cmd.c 2010-08-02 17:42:41.000000000 +0200
197 #include "make_cmd.h"
198 #include "dispose_cmd.h"
199 +#include "execute_cmd.h"
200 #include "variables.h"
205 +#include "builtins.h"
207 +#include "builtins/common.h"
209 #if defined (JOB_CONTROL)
213 extern int line_number, current_command_line_count, parser_state;
214 extern int last_command_exit_value;
215 +extern int rpm_requires;
217 +static char *alphabet_set = "abcdefghijklmnopqrstuvwxyz"
218 + "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
221 sh_obj_cache_t wdcache = {0, 0, 0};
222 @@ -820,6 +828,27 @@ make_coproc_command (name, command)
223 return (make_command (cm_coproc, (SIMPLE_COM *)temp));
227 +output_requirement (deptype, filename)
228 +const char *deptype;
231 + if (strchr(filename, '$') || (filename[0] != '/' && strchr(filename, '/')))
235 + if the executable is called via variable substitution we can
236 + not dermine what it is at compile time.
238 + if the executable consists only of characters not in the
239 + alphabet we do not consider it a dependency just an artifact
240 + of shell parsing (ex "exec < ${infile}").
243 + if (strpbrk(filename, alphabet_set))
244 + printf ("%s(%s)\n", deptype, filename);
247 /* Reverse the word list and redirection list in the simple command
248 has just been parsed. It seems simpler to do this here the one
249 time then by any other method that I can think of. */
250 @@ -837,6 +866,27 @@ clean_simple_command (command)
251 REVERSE_LIST (command->value.Simple->redirects, REDIRECT *);
254 + if (rpm_requires && command->value.Simple->words)
260 + cmd0 = command->value.Simple->words->word->word;
261 + b = builtin_address_internal (cmd0, 0);
263 + if (command->value.Simple->words->next)
264 + cmd1 = command->value.Simple->words->next->word->word;
267 + if ( (b->flags & REQUIRES_BUILTIN) && cmd1)
268 + output_requirement ("executable", cmd1);
270 + if (!assignment(cmd0, 0))
271 + output_requirement (find_function(cmd0) ? "function" : "executable", cmd0);
275 parser_state &= ~PST_REDIRLIST;
278 diff -up bash-4.1/shell.c.requires bash-4.1/shell.c
279 --- bash-4.1/shell.c.requires 2010-08-02 17:42:41.000000000 +0200
280 +++ bash-4.1/shell.c 2010-08-02 17:42:41.000000000 +0200
281 @@ -193,6 +193,9 @@ int have_devfd = 0;
282 /* The name of the .(shell)rc file. */
283 static char *bashrc_file = "~/.bashrc";
285 +/* Non-zero if we are finding the scripts requirements. */
288 /* Non-zero means to act more like the Bourne shell on startup. */
289 static int act_like_sh;
291 @@ -251,6 +254,7 @@ static const struct {
292 { "posix", Int, &posixly_correct, (char **)0x0 },
293 { "protected", Int, &protected_mode, (char **)0x0 },
294 { "rcfile", Charp, (int *)0x0, &bashrc_file },
295 + { "rpm-requires", Int, &rpm_requires, (char **)0x0 },
296 #if defined (RESTRICTED_SHELL)
297 { "restricted", Int, &restricted, (char **)0x0 },
299 @@ -485,6 +489,12 @@ main (argc, argv, env)
300 if (dump_translatable_strings)
301 read_but_dont_execute = 1;
305 + read_but_dont_execute = 1;
306 + initialize_shell_builtins ();
309 if (running_setuid && privileged_mode == 0)
310 disable_priv_mode ();