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 ASSIGNMENT_BUILTIN 0x10 /* This builtin takes assignment statements. */
6 #define POSIX_BUILTIN 0x20 /* This builtins is special in the Posix command search order. */
7 #define LOCALVAR_BUILTIN 0x40 /* This builtin creates local variables */
8 +#define REQUIRES_BUILTIN 0x80 /* 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,10 +69,16 @@ 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_LOCALVAR 0x04
27 #define BUILTIN_FLAG_POSIX_BUILTIN 0x08
28 +#define BUILTIN_FLAG_REQUIRES 0x10
33 @@ -163,10 +169,18 @@ char *posix_builtins[] =
37 +/* The builtin commands that cause requirements on other files. */
38 +static char *requires_builtins[] =
40 + ".", "command", "exec", "source", "inlib",
44 /* Forward declarations. */
45 static int is_special_builtin ();
46 static int is_assignment_builtin ();
47 static int is_localvar_builtin ();
48 static int is_posix_builtin ();
49 +static int is_requires_builtin ();
51 #if !defined (HAVE_RENAME)
52 @@ -812,6 +826,9 @@ builtin_handler (self, defs, arg)
53 new->flags |= BUILTIN_FLAG_ASSIGNMENT;
54 if (is_posix_builtin (name))
55 new->flags |= BUILTIN_FLAG_POSIX_BUILTIN;
56 + if (is_requires_builtin (name))
57 + new->flags |= BUILTIN_FLAG_REQUIRES;
60 array_add ((char *)new, defs->builtins);
62 @@ -1267,12 +1267,13 @@ write_builtins (defs, structfile, extern
64 fprintf (structfile, "(sh_builtin_func_t *)0x0, ");
66 - fprintf (structfile, "%s%s%s%s%s, %s_doc,\n",
67 + fprintf (structfile, "%s%s%s%s%s%s, %s_doc,\n",
68 "BUILTIN_ENABLED | STATIC_BUILTIN",
69 (builtin->flags & BUILTIN_FLAG_SPECIAL) ? " | SPECIAL_BUILTIN" : "",
70 (builtin->flags & BUILTIN_FLAG_ASSIGNMENT) ? " | ASSIGNMENT_BUILTIN" : "",
71 (builtin->flags & BUILTIN_FLAG_LOCALVAR) ? " | LOCALVAR_BUILTIN" : "",
72 (builtin->flags & BUILTIN_FLAG_POSIX_BUILTIN) ? " | POSIX_BUILTIN" : "",
73 + (builtin->flags & BUILTIN_FLAG_REQUIRES) ? " | REQUIRES_BUILTIN" : "",
74 document_name (builtin));
76 /* Don't translate short document summaries that are identical
77 @@ -1581,6 +1599,13 @@ is_posix_builtin (name)
78 return (_find_in_table (name, posix_builtins));
82 +is_requires_builtin (name)
85 + return (_find_in_table (name, requires_builtins));
88 #if !defined (HAVE_RENAME)
91 diff -up bash-4.1/doc/bash.1.requires bash-4.1/doc/bash.1
92 --- bash-4.1/doc/bash.1.requires 2010-08-02 17:42:41.000000000 +0200
93 +++ bash-4.1/doc/bash.1 2010-08-02 18:09:27.000000000 +0200
94 @@ -231,6 +231,14 @@ The shell becomes restricted (see
99 +Produce the list of files that are required for the
100 +shell script to run. This implies '-n' and is subject
101 +to the same limitations as compile time error checking checking;
102 +Command substitutions, Conditional expressions and
104 +builtin are not parsed so some dependencies may be missed.
107 Equivalent to \fB\-v\fP.
109 diff -up bash-4.1/doc/bashref.texi.requires bash-4.1/doc/bashref.texi
110 --- bash-4.1/doc/bashref.texi.requires 2010-08-02 17:42:41.000000000 +0200
111 +++ bash-4.1/doc/bashref.texi 2010-08-02 18:11:58.000000000 +0200
112 @@ -5343,6 +5343,13 @@ standard. @xref{Bash POSIX Mode}, for a
114 Make the shell a restricted shell (@pxref{The Restricted Shell}).
116 +@item --rpm-requires
117 +Produce the list of files that are required for the
118 +shell script to run. This implies '-n' and is subject
119 +to the same limitations as compile time error checking checking;
120 +Command substitutions, Conditional expressions and @command{eval}
121 +are not parsed so some dependencies may be missed.
124 Equivalent to @option{-v}. Print shell input lines as they're read.
126 diff -up bash-4.1/eval.c.requires bash-4.1/eval.c
127 --- bash-4.1/eval.c.requires 2009-01-04 20:32:26.000000000 +0100
128 +++ bash-4.1/eval.c 2010-08-02 17:42:41.000000000 +0200
129 @@ -53,6 +53,7 @@ extern int last_command_exit_value, stdi
130 extern int current_command_number, current_command_line_count, line_number;
131 extern int expand_aliases;
132 +extern int rpm_requires;
133 extern char *ps0_prompt;
135 #if defined (HAVE_POSIX_SIGNALS)
136 extern sigset_t top_level_mask;
137 @@ -136,7 +137,7 @@ reader_loop ()
139 if (read_command () == 0)
141 - if (interactive_shell == 0 && read_but_dont_execute)
142 + if (interactive_shell == 0 && (read_but_dont_execute && !rpm_requires))
144 last_command_exit_value = EXECUTION_SUCCESS;
145 dispose_command (global_command);
146 diff -up bash-4.1/execute_cmd.c.requires bash-4.1/execute_cmd.c
147 --- bash-4.1/execute_cmd.c.requires 2010-08-02 17:42:41.000000000 +0200
148 +++ bash-4.1/execute_cmd.c 2010-08-02 17:42:41.000000000 +0200
149 @@ -503,6 +503,8 @@ async_redirect_stdin ()
151 #define DESCRIBE_PID(pid) do { if (interactive) describe_pid (pid); } while (0)
153 +extern int rpm_requires;
155 /* Execute the command passed in COMMAND, perhaps doing it asynchronously.
156 COMMAND is exactly what read_command () places into GLOBAL_COMMAND.
157 ASYNCHROUNOUS, if non-zero, says to do this command in the background.
158 @@ -534,7 +536,13 @@ execute_command_internal (command, async
160 if (breaking || continuing)
161 return (last_command_exit_value);
162 - if (command == 0 || read_but_dont_execute)
163 + if (command == 0 || (read_but_dont_execute && !rpm_requires))
164 + return (EXECUTION_SUCCESS);
165 + if (rpm_requires && command->type == cm_function_def)
166 + return last_command_exit_value =
167 + execute_intern_function (command->value.Function_def->name,
168 + command->value.Function_def);
169 + if (read_but_dont_execute)
170 return (EXECUTION_SUCCESS);
173 @@ -5066,7 +5074,7 @@ execute_intern_function (name, function)
175 if (check_identifier (name, posixly_correct) == 0)
177 - if (posixly_correct && interactive_shell == 0)
178 + if (posixly_correct && interactive_shell == 0 && rpm_requires == 0)
180 last_command_exit_value = EX_BADUSAGE;
181 jump_to_top_level (ERREXIT);
182 diff -up bash-4.1/execute_cmd.h.requires bash-4.1/execute_cmd.h
183 --- bash-4.1/execute_cmd.h.requires 2009-01-16 22:20:15.000000000 +0100
184 +++ bash-4.1/execute_cmd.h 2010-08-02 17:42:41.000000000 +0200
186 #define _EXECUTE_CMD_H_
189 +#include "variables.h"
190 +#include "command.h"
192 extern struct fd_bitmap *new_fd_bitmap __P((int));
193 extern void dispose_fd_bitmap __P((struct fd_bitmap *));
194 diff -up bash-4.1/make_cmd.c.requires bash-4.1/make_cmd.c
195 --- bash-4.1/make_cmd.c.requires 2009-09-11 23:26:12.000000000 +0200
196 +++ bash-4.1/make_cmd.c 2010-08-02 17:42:41.000000000 +0200
199 #include "make_cmd.h"
200 #include "dispose_cmd.h"
201 +#include "execute_cmd.h"
202 #include "variables.h"
207 +#include "builtins.h"
209 +#include "builtins/common.h"
211 #if defined (JOB_CONTROL)
214 extern int line_number, current_command_line_count, parser_state;
215 extern int last_command_exit_value;
216 extern int shell_initialized;
217 +extern int rpm_requires;
219 +static char *alphabet_set = "abcdefghijklmnopqrstuvwxyz"
220 + "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
223 sh_obj_cache_t wdcache = {0, 0, 0};
224 @@ -820,6 +828,27 @@ make_coproc_command (name, command)
225 return (make_command (cm_coproc, (SIMPLE_COM *)temp));
229 +output_requirement (deptype, filename)
230 +const char *deptype;
233 + if (strchr(filename, '$') || (filename[0] != '/' && strchr(filename, '/')))
237 + if the executable is called via variable substitution we can
238 + not dermine what it is at compile time.
240 + if the executable consists only of characters not in the
241 + alphabet we do not consider it a dependency just an artifact
242 + of shell parsing (ex "exec < ${infile}").
245 + if (strpbrk(filename, alphabet_set))
246 + printf ("%s(%s)\n", deptype, filename);
249 /* Reverse the word list and redirection list in the simple command
250 has just been parsed. It seems simpler to do this here the one
251 time then by any other method that I can think of. */
252 @@ -837,6 +866,27 @@ clean_simple_command (command)
253 REVERSE_LIST (command->value.Simple->redirects, REDIRECT *);
256 + if (rpm_requires && command->value.Simple->words)
262 + cmd0 = command->value.Simple->words->word->word;
263 + b = builtin_address_internal (cmd0, 0);
265 + if (command->value.Simple->words->next)
266 + cmd1 = command->value.Simple->words->next->word->word;
269 + if ( (b->flags & REQUIRES_BUILTIN) && cmd1)
270 + output_requirement ("executable", cmd1);
272 + if (!assignment(cmd0, 0))
273 + output_requirement (find_function(cmd0) ? "function" : "executable", cmd0);
277 parser_state &= ~PST_REDIRLIST;
280 diff -up bash-4.1/shell.c.requires bash-4.1/shell.c
281 --- bash-4.1/shell.c.requires 2010-08-02 17:42:41.000000000 +0200
282 +++ bash-4.1/shell.c 2010-08-02 17:42:41.000000000 +0200
283 @@ -193,6 +193,9 @@ int have_devfd = 0;
284 /* The name of the .(shell)rc file. */
285 static char *bashrc_file = "~/.bashrc";
287 +/* Non-zero if we are finding the scripts requirements. */
290 /* Non-zero means to act more like the Bourne shell on startup. */
291 static int act_like_sh;
293 @@ -251,6 +254,7 @@ static const struct {
294 { "protected", Int, &protected_mode, (char **)0x0 },
296 { "rcfile", Charp, (int *)0x0, &bashrc_file },
297 + { "rpm-requires", Int, &rpm_requires, (char **)0x0 },
298 #if defined (RESTRICTED_SHELL)
299 { "restricted", Int, &restricted, (char **)0x0 },
301 @@ -485,6 +489,12 @@ main (argc, argv, env)
302 if (dump_translatable_strings)
303 read_but_dont_execute = 1;
307 + read_but_dont_execute = 1;
308 + initialize_shell_builtins ();
311 if (running_setuid && privileged_mode == 0)
312 disable_priv_mode ();