]> git.pld-linux.org Git - packages/bash.git/blame_incremental - bash-requires.patch
- loadables patch still needed; files updated
[packages/bash.git] / bash-requires.patch
... / ...
CommitLineData
1diff --git a/builtins.h b/builtins.h
2index dac95fd..5b7e811 100644
3--- a/builtins.h
4+++ b/builtins.h
5@@ -45,6 +45,7 @@
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 */
9+#define REQUIRES_BUILTIN 0x80 /* This builtin requires other files. */
10
11 #define BASE_INDENT 4
12
13diff --git a/builtins/mkbuiltins.c b/builtins/mkbuiltins.c
14index 4f51201..91c25db 100644
15--- a/builtins/mkbuiltins.c
16+++ b/builtins/mkbuiltins.c
17@@ -69,10 +69,15 @@ extern char *strcpy ();
18 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
19
20 /* Flag values that builtins can have. */
21+/* These flags are for the C code generator,
22+ the C which is produced (./builtin.c)
23+ includes the flags definitions found
24+ in ../builtins.h */
25 #define BUILTIN_FLAG_SPECIAL 0x01
26 #define BUILTIN_FLAG_ASSIGNMENT 0x02
27 #define BUILTIN_FLAG_LOCALVAR 0x04
28 #define BUILTIN_FLAG_POSIX_BUILTIN 0x08
29+#define BUILTIN_FLAG_REQUIRES 0x10
30
31 #define BASE_INDENT 4
32
33@@ -173,11 +178,19 @@ char *posix_builtins[] =
34 (char *)NULL
35 };
36
37+/* The builtin commands that cause requirements on other files. */
38+static char *requires_builtins[] =
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 ();
47 static int is_localvar_builtin ();
48 static int is_posix_builtin ();
49+static int is_requires_builtin ();
50
51 #if !defined (HAVE_RENAME)
52 static int rename ();
53@@ -831,6 +844,8 @@ builtin_handler (self, defs, arg)
54 new->flags |= BUILTIN_FLAG_LOCALVAR;
55 if (is_posix_builtin (name))
56 new->flags |= BUILTIN_FLAG_POSIX_BUILTIN;
57+ if (is_requires_builtin (name))
58+ new->flags |= BUILTIN_FLAG_REQUIRES;
59
60 array_add ((char *)new, defs->builtins);
61 building_builtin = 1;
62@@ -1250,12 +1265,13 @@ write_builtins (defs, structfile, externfile)
63 else
64 fprintf (structfile, "(sh_builtin_func_t *)0x0, ");
65
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));
75
76 /* Don't translate short document summaries that are identical
77@@ -1645,6 +1661,13 @@ is_posix_builtin (name)
78 return (_find_in_table (name, posix_builtins));
79 }
80
81+static int
82+is_requires_builtin (name)
83+ char *name;
84+{
85+ return (_find_in_table (name, requires_builtins));
86+}
87+
88 #if !defined (HAVE_RENAME)
89 static int
90 rename (from, to)
91diff --git a/doc/bash.1 b/doc/bash.1
92index d91f1fd..111a66d 100644
93--- a/doc/bash.1
94+++ b/doc/bash.1
95@@ -239,6 +239,14 @@ The shell becomes restricted (see
96 .B "RESTRICTED SHELL"
97 below).
98 .TP
99+.B \-\-rpm-requires
100+Produce the list of files that are required for the
101+shell script to run. This implies '-n' and is subject
102+to the same limitations as compile time error checking checking;
103+Command substitutions, Conditional expressions and
104+.BR eval
105+builtin are not parsed so some dependencies may be missed.
106+.TP
107 .B \-\-verbose
108 Equivalent to \fB\-v\fP.
109 .TP
110diff --git a/doc/bashref.texi b/doc/bashref.texi
111index 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
115 @item --restricted
116 Make the shell a restricted shell (@pxref{The Restricted Shell}).
117
118+@item --rpm-requires
119+Produce the list of files that are required for the
120+shell script to run. This implies '-n' and is subject
121+to the same limitations as compile time error checking checking;
122+Command substitutions, Conditional expressions and @command{eval}
123+are not parsed so some dependencies may be missed.
124+
125 @item --verbose
126 Equivalent to @option{-v}. Print shell input lines as they're read.
127
128diff --git a/eval.c b/eval.c
129index f02d6e4..76c1e8d 100644
130--- a/eval.c
131+++ b/eval.c
132@@ -142,7 +142,8 @@ reader_loop ()
133
134 if (read_command () == 0)
135 {
136- if (interactive_shell == 0 && read_but_dont_execute)
137+
138+ if (interactive_shell == 0 && (read_but_dont_execute && !rpm_requires))
139 {
140 last_command_exit_value = EXECUTION_SUCCESS;
141 dispose_command (global_command);
142diff --git a/execute_cmd.c b/execute_cmd.c
143index 8b3c83a..4eae19c 100644
144--- a/execute_cmd.c
145+++ b/execute_cmd.c
146@@ -538,6 +538,8 @@ async_redirect_stdin ()
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.
155@@ -569,7 +571,13 @@ execute_command_internal (command, asynchronous, pipe_in, pipe_out,
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;
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)
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);
179diff --git a/execute_cmd.h b/execute_cmd.h
180index dc2f15e..506fff4 100644
181--- a/execute_cmd.h
182+++ b/execute_cmd.h
183@@ -22,6 +22,9 @@
184 #define _EXECUTE_CMD_H_
185
186 #include "stdc.h"
187+#include "variables.h"
188+#include "command.h"
189+
190
191 #if defined (ARRAY_VARS)
192 struct func_array_state
193diff --git a/make_cmd.c b/make_cmd.c
194index ecbbfd6..3d8bfa4 100644
195--- a/make_cmd.c
196+++ b/make_cmd.c
197@@ -828,6 +828,27 @@ make_coproc_command (name, command)
198 return (make_command (cm_coproc, (SIMPLE_COM *)temp));
199 }
200
201+static void
202+output_requirement (deptype, filename)
203+const char *deptype;
204+char *filename;
205+{
206+ if (strchr(filename, '$') || (filename[0] != '/' && strchr(filename, '/')))
207+ return;
208+
209+ /*
210+ if the executable is called via variable substitution we can
211+ not dermine what it is at compile time.
212+
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+ */
217+
218+ if (strpbrk(filename, alphabet_set))
219+ printf ("%s(%s)\n", deptype, filename);
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. */
225@@ -845,6 +866,28 @@ clean_simple_command (command)
226 REVERSE_LIST (command->value.Simple->redirects, REDIRECT *);
227 }
228
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;
238+ if (command->value.Simple->words->next)
239+ cmd1 = command->value.Simple->words->next->word->word;
240+
241+ if (b) {
242+ if ( (b->flags & REQUIRES_BUILTIN) && cmd1)
243+ output_requirement ("executable", cmd1);
244+ } else {
245+ if (!assignment(cmd0, 0))
246+ output_requirement (find_function(cmd0) ? "function" : "executable", cmd0);
247+ }
248+ } /*rpm_requires*/
249+
250+
251 parser_state &= ~PST_REDIRLIST;
252 return (command);
253 }
254diff --git a/shell.c b/shell.c
255index a2b2a55..c5d99b3 100644
256--- a/shell.c
257+++ b/shell.c
258@@ -193,6 +193,9 @@ int have_devfd = 0;
259 /* The name of the .(shell)rc file. */
260 static char *bashrc_file = DEFAULT_BASHRC;
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
268@@ -259,6 +262,7 @@ static const struct {
269 { "protected", Int, &protected_mode, (char **)0x0 },
270 #endif
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
276@@ -496,6 +500,12 @@ main (argc, argv, env)
277 if (dump_translatable_strings)
278 read_but_dont_execute = 1;
279
280+ if (rpm_requires)
281+ {
282+ read_but_dont_execute = 1;
283+ initialize_shell_builtins ();
284+ }
285+
286 if (running_setuid && privileged_mode == 0)
287 disable_priv_mode ();
288
289diff --git a/shell.h b/shell.h
290index 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--
3202.17.2
321
This page took 0.027745 seconds and 4 git commands to generate.