]> git.pld-linux.org Git - packages/bash.git/blob - bash-requires.patch
- updated to 5.2 patchlevel 11
[packages/bash.git] / bash-requires.patch
1 diff --git a/builtins.h b/builtins.h
2 --- a/builtins.h
3 +++ b/builtins.h
4 @@ -46,6 +46,7 @@
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. */
9  
10  #define BASE_INDENT    4
11  
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'))
17  
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
22 +    in ../builtins.h */
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
29  
30  #define BASE_INDENT    4
31  
32 @@ -189,13 +194,21 @@ char *arrayvar_builtins[] =
33    "typeset", "unset", "wait",          /*]*/
34    (char *)NULL
35  };
36 -       
37 +
38 +/* The builtin commands that cause requirements on other files. */
39 +static char *requires_builtins[] =
40 +{
41 +  ".", "command", "exec", "source", "inlib",
42 +  (char *)NULL
43 +};
44 +
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 ();
52  
53  #if !defined (HAVE_RENAME)
54  static int 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;
61  
62    array_add ((char *)new, defs->builtins);
63    building_builtin = 1;
64 @@ -1275,13 +1290,14 @@ write_builtins (defs, structfile, externfile)
65                   else
66                     fprintf (structfile, "(sh_builtin_func_t *)0x0, ");
67  
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));
78  
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));
82  }
83  
84 +static int
85 +is_requires_builtin (name)
86 +     char *name;
87 +{
88 +  return (_find_in_table (name, requires_builtins));
89 +}
90 +
91  #if !defined (HAVE_RENAME)
92  static int
93  rename (from, to)
94 diff --git a/doc/bash.1 b/doc/bash.1
95 --- a/doc/bash.1
96 +++ b/doc/bash.1
97 @@ -239,6 +239,14 @@ The shell becomes restricted (see
98  .B "RESTRICTED SHELL"
99  below).
100  .TP
101 +.B \-\-rpm-requires
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
106 +.BR eval
107 +builtin are not parsed so some dependencies may be missed.
108 +.TP
109  .B \-\-verbose
110  Equivalent to \fB\-v\fP.
111  .TP
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
116  @item --restricted
117  Make the shell a restricted shell (@pxref{The Restricted Shell}).
118  
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.
125 +
126  @item --verbose
127  Equivalent to @option{-v}.  Print shell input lines as they're read.
128  
129 diff --git a/eval.c b/eval.c
130 --- a/eval.c
131 +++ b/eval.c
132 @@ -138,7 +138,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               set_exit_status (last_command_exit_value);
141               dispose_command (global_command);
142 diff --git a/execute_cmd.c b/execute_cmd.c
143 --- a/execute_cmd.c
144 +++ b/execute_cmd.c
145 @@ -561,6 +561,8 @@ async_redirect_stdin ()
146  
147  #define DESCRIBE_PID(pid) do { if (interactive) describe_pid (pid); } while (0)
148  
149 +extern int rpm_requires;
150 +
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,
155  
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);
167    if (command == 0)
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)
172      {
173 -      if (posixly_correct && interactive_shell == 0)
174 +      if (posixly_correct && interactive_shell == 0 && rpm_requires == 0)
175         {
176           last_command_exit_value = EX_BADUSAGE;
177           jump_to_top_level (ERREXIT);
178 diff --git a/execute_cmd.h b/execute_cmd.h
179 --- a/execute_cmd.h
180 +++ b/execute_cmd.h
181 @@ -22,6 +22,9 @@
182  #define _EXECUTE_CMD_H_
183  
184  #include "stdc.h"
185 +#include "variables.h"
186 +#include "command.h"
187 +
188  
189  #if defined (ARRAY_VARS)
190  struct func_array_state
191 diff --git a/make_cmd.c b/make_cmd.c
192 --- a/make_cmd.c
193 +++ b/make_cmd.c
194 @@ -35,6 +35,8 @@
195  #include "bashintl.h"
196  
197  #include "shell.h"
198 +#include "builtins.h"
199 +#include "builtins/common.h"
200  #include "execute_cmd.h"
201  #include "parser.h"
202  #include "flags.h"
203 @@ -839,6 +841,30 @@ make_coproc_command (name, command)
204    return (make_command (cm_coproc, (SIMPLE_COM *)temp));
205  }
206  
207 +static void
208 +output_requirement (deptype, filename)
209 +const char *deptype;
210 +char *filename;
211 +{
212 +  static char *alphabet_set = "abcdefghijklmnopqrstuvwxyz"
213 +                    "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
214 +
215 +  if (strchr(filename, '$') || (filename[0] != '/' && strchr(filename, '/')))
216 +    return;
217 +
218 +  /*
219 +      if the executable is called via variable substitution we can
220 +      not dermine what it is at compile time.
221 +
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}").
225 +  */
226 +
227 +  if (strpbrk(filename, alphabet_set))
228 +    printf ("%s(%s)\n", deptype, filename);
229 +}
230 +
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 *);
236      }
237  
238 +  if (rpm_requires && command->value.Simple->words)
239 +    {
240 +      char *cmd0;
241 +      char *cmd1;
242 +      struct builtin *b;
243 +
244 +      cmd0 = command->value.Simple->words->word->word;
245 +      b = builtin_address_internal (cmd0, 0);
246 +      cmd1 = 0;
247 +      if (command->value.Simple->words->next)
248 +        cmd1 = command->value.Simple->words->next->word->word;
249 +
250 +      if (b) {
251 +        if ( (b->flags & REQUIRES_BUILTIN) && cmd1)
252 +          output_requirement ("executable", cmd1);
253 +      } else {
254 +        if (!assignment(cmd0, 0))
255 +          output_requirement (find_function(cmd0) ? "function" : "executable", cmd0);
256 +      }
257 +    } /*rpm_requires*/
258 +
259 +
260    parser_state &= ~PST_REDIRLIST;
261    return (command);
262  }
263 diff --git a/shell.c b/shell.c
264 --- a/shell.c
265 +++ 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;
269  
270 +/* Non-zero if we are finding the scripts requirements. */
271 +int rpm_requires;
272 +
273  /* Non-zero means to act more like the Bourne shell on startup. */
274  static int act_like_sh;
275  
276 @@ -266,6 +269,7 @@ static const struct {
277    { "protected", Int, &protected_mode, (char **)0x0 },
278  #endif
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 },
283  #endif
284 @@ -510,6 +514,12 @@ main (argc, argv, env)
285      read_but_dont_execute = 1;
286  #endif
287  
288 +  if (rpm_requires)
289 +    {
290 +      read_but_dont_execute = 1;
291 +      initialize_shell_builtins ();
292 +    }
293 +
294    if (running_setuid && privileged_mode == 0)
295      disable_priv_mode ();
296  
297 diff --git a/shell.h b/shell.h
298 --- a/shell.h
299 +++ 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;
This page took 0.217929 seconds and 4 git commands to generate.