]> git.pld-linux.org Git - packages/bash.git/blob - bash-requires.patch
Up to 5.2.26
[packages/bash.git] / bash-requires.patch
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
4 @@ -41,6 +41,8 @@
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. */
9 +
10  
11  #define BASE_INDENT    4
12  
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'))
18  
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 
23 +    in ../builtins.h */
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
29 +
30  
31  #define BASE_INDENT    4
32  
33 @@ -163,10 +169,18 @@ 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 @@ -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;
58 +
59  
60    array_add ((char *)new, defs->builtins);
61    building_builtin = 1;
62 @@ -1267,12 +1267,13 @@ write_builtins (defs, structfile, extern
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 @@ -1581,6 +1599,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)
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
95  .B "RESTRICTED SHELL"
96  below).
97  .TP
98 +.B \-\-rpm-requires
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
103 +.BR eval
104 +builtin are not parsed so some dependencies may be missed.
105 +.TP
106  .B \-\-verbose
107  Equivalent to  \fB\-v\fP.
108  .TP
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
113  @item --restricted
114  Make the shell a restricted shell (@pxref{The Restricted Shell}).
115  
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.
122 +
123  @item --verbose
124  Equivalent to @option{-v}.  Print shell input lines as they're read.
125  
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;
134  
135  #if defined (HAVE_POSIX_SIGNALS)
136  extern sigset_t top_level_mask;
137 @@ -136,7 +137,7 @@ reader_loop ()
138  
139        if (read_command () == 0)
140         {
141 -         if (interactive_shell == 0 && read_but_dont_execute)
142 +         if (interactive_shell == 0 && (read_but_dont_execute && !rpm_requires))
143             {
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 ()
150  
151  #define DESCRIBE_PID(pid) do { if (interactive) describe_pid (pid); } while (0)
152  
153 +extern int rpm_requires;
154 +
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
159  
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);
171  
172    QUIT;
173 @@ -5066,7 +5074,7 @@ execute_intern_function (name, function)
174  
175    if (check_identifier (name, posixly_correct) == 0)
176      {
177 -      if (posixly_correct && interactive_shell == 0)
178 +      if (posixly_correct && interactive_shell == 0 && rpm_requires == 0)
179         {
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
185 @@ -22,6 +22,8 @@
186  #define _EXECUTE_CMD_H_
187  
188  #include "stdc.h"
189 +#include "variables.h"
190 +#include "command.h"
191  
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
197 @@ -42,11 +42,15 @@
198  #include "flags.h"
199  #include "make_cmd.h"
200  #include "dispose_cmd.h"
201 +#include "execute_cmd.h"
202  #include "variables.h"
203  #include "subst.h"
204  #include "input.h"
205  #include "ocache.h"
206  #include "externs.h"
207 +#include "builtins.h"
208 +
209 +#include "builtins/common.h"
210  
211  #if defined (JOB_CONTROL)
212  #include "jobs.h"
213 @@ -56,6 +60,10 @@
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;
218 +
219 +static char *alphabet_set = "abcdefghijklmnopqrstuvwxyz"
220 +                     "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
221  
222  /* Object caching */
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));
226  }
227  
228 +static void
229 +output_requirement (deptype, filename)
230 +const char *deptype;
231 +char *filename;
232 +{
233 +  if (strchr(filename, '$') || (filename[0] != '/' && strchr(filename, '/')))
234 +    return;
235 +
236 +  /* 
237 +      if the executable is called via variable substitution we can
238 +      not dermine what it is at compile time.  
239 +
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}").
243 +  */
244 +
245 +  if (strpbrk(filename, alphabet_set))
246 +    printf ("%s(%s)\n", deptype, filename);
247 +}
248 +
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 *);
254      }
255  
256 +  if (rpm_requires && command->value.Simple->words)
257 +    {
258 +      char *cmd0;
259 +      char *cmd1;
260 +      struct builtin *b;
261 +
262 +      cmd0 = command->value.Simple->words->word->word;
263 +      b = builtin_address_internal (cmd0, 0);
264 +      cmd1 = 0;
265 +      if (command->value.Simple->words->next)
266 +        cmd1 = command->value.Simple->words->next->word->word;
267 +
268 +      if (b) {
269 +        if ( (b->flags & REQUIRES_BUILTIN) && cmd1)
270 +          output_requirement ("executable", cmd1);
271 +      } else {
272 +        if (!assignment(cmd0, 0))
273 +          output_requirement (find_function(cmd0) ? "function" : "executable", cmd0);
274 +      }
275 +    } /*rpm_requires*/
276 +
277    parser_state &= ~PST_REDIRLIST;
278    return (command);
279  }
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";
286  
287 +/* Non-zero if we are finding the scripts requirements. */
288 +int rpm_requires;
289 +
290  /* Non-zero means to act more like the Bourne shell on startup. */
291  static int act_like_sh;
292  
293 @@ -251,6 +254,7 @@ static const struct {
294    { "protected", Int, &protected_mode, (char **)0x0 },
295  #endif
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 },
300  #endif
301 @@ -485,6 +489,12 @@ main (argc, argv, env)
302    if (dump_translatable_strings)
303      read_but_dont_execute = 1;
304  
305 +  if (rpm_requires)
306 +    {
307 +      read_but_dont_execute = 1;
308 +      initialize_shell_builtins ();
309 +    }
310 +
311    if (running_setuid && privileged_mode == 0)
312      disable_priv_mode ();
313  
This page took 0.09999 seconds and 3 git commands to generate.