]> git.pld-linux.org Git - packages/bash.git/blob - bash-requires.patch
- updated.
[packages/bash.git] / bash-requires.patch
1
2 Jeff Johnson writes:
3 > For background, Ken Estes has a hack to bash2 that will print out the
4 > commands that will be executed by a shell script. The hack is included
5 > in the distributed Red Hat 6.x bash2 package if you are interested.
6
7
8 Here is the latest patch file.
9
10 Notice that I changed the output from "bash()" to "executable()"
11 Since the dependencies work for both bash and sh and really we depend
12 on their being an executable not that this executable is in anyway
13 related to bash.
14
15 Ken
16
17
18
19 diff -u -r bash-2.03.orig/builtins/mkbuiltins.c bash-2.03/builtins/mkbuiltins.c
20 --- bash-2.03.orig/builtins/mkbuiltins.c        Tue Sep 15 12:57:16 1998
21 +++ bash-2.03/builtins/mkbuiltins.c     Fri Jul 16 10:45:54 1999
22 @@ -51,8 +51,13 @@
23  #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
24  
25  /* Flag values that builtins can have. */
26 +/*  These flags are for the C code generator, 
27 +    the C which is produced (./builtin.c)
28 +    includes the flags definitions found 
29 +    in ../builtins.h */
30  #define BUILTIN_FLAG_SPECIAL   0x01
31  #define BUILTIN_FLAG_ASSIGNMENT 0x02
32 +#define BUILTIN_FLAG_REQUIRES  0x04
33  
34  /* If this stream descriptor is non-zero, then write
35     texinfo documentation to it. */
36 @@ -126,9 +131,17 @@
37    (char *)NULL
38  };
39  
40 +/* The builtin commands that cause requirements on other files. */
41 +char *requires_builtins[] =
42 +{
43 +  ".", "command", "exec", "source", "inlib",
44 +  (char *)NULL
45 +};
46 +
47  /* Forward declarations. */
48  static int is_special_builtin ();
49  static int is_assignment_builtin ();
50 +static int is_requires_builtin ();
51  
52  #if !defined (HAVE_RENAME)
53  static int rename ();
54 @@ -759,6 +772,8 @@
55      new->flags |= BUILTIN_FLAG_SPECIAL;
56    if (is_assignment_builtin (name))
57      new->flags |= BUILTIN_FLAG_ASSIGNMENT;
58 +  if (is_requires_builtin (name))
59 +    new->flags |= BUILTIN_FLAG_REQUIRES;
60  
61    array_add ((char *)new, defs->builtins);
62    building_builtin = 1;
63 @@ -1164,10 +1179,11 @@
64                   else
65                     fprintf (structfile, "(Function *)0x0, ");
66  
67 -                 fprintf (structfile, "%s%s%s, %s_doc,\n",
68 +                 fprintf (structfile, "%s%s%s%s, %s_doc,\n",
69                     "BUILTIN_ENABLED | STATIC_BUILTIN",
70                     (builtin->flags & BUILTIN_FLAG_SPECIAL) ? " | SPECIAL_BUILTIN" : "",
71                     (builtin->flags & BUILTIN_FLAG_ASSIGNMENT) ? " | ASSIGNMENT_BUILTIN" : "",
72 +                   (builtin->flags & BUILTIN_FLAG_REQUIRES) ? " | REQUIRES_BUILTIN" : "",
73                     builtin->docname ? builtin->docname : builtin->name);
74  
75                   fprintf
76 @@ -1401,6 +1417,13 @@
77       char *name;
78  {
79    return (_find_in_table (name, assignment_builtins));
80 +}
81 +
82 +static int
83 +is_requires_builtin (name)
84 +     char *name;
85 +{
86 +  return (_find_in_table (name, requires_builtins));
87  }
88  
89  #if !defined (HAVE_RENAME)
90 diff -u -r bash-2.03.orig/builtins.h bash-2.03/builtins.h
91 --- bash-2.03.orig/builtins.h   Fri Jul 18 16:46:36 1997
92 +++ bash-2.03/builtins.h        Thu Jul 15 16:59:03 1999
93 @@ -40,6 +40,7 @@
94  #define STATIC_BUILTIN  0x4    /* This builtin is not dynamically loaded. */
95  #define SPECIAL_BUILTIN 0x8    /* This is a Posix `special' builtin. */
96  #define ASSIGNMENT_BUILTIN 0x10        /* This builtin takes assignment statements. */
97 +#define REQUIRES_BUILTIN 0x20  /* This builtin requires other files. */
98  
99  /* The thing that we build the array of builtins out of. */
100  struct builtin {
101 diff -u -r bash-2.03.orig/doc/bash.1 bash-2.03/doc/bash.1
102 --- bash-2.03.orig/doc/bash.1   Wed Jan 20 16:48:04 1999
103 +++ bash-2.03/doc/bash.1        Fri Jul 16 11:20:00 1999
104 @@ -195,6 +195,12 @@
105  .B "RESTRICTED SHELL"
106  below).
107  .TP
108 +.B \-\-rpm-requires
109 +Produce the list of files that are required for the 
110 +shell script to run.  This implies '-n' and is subject
111 +to the same limitations as compile time error checking checking;
112 +Backticks, [] tests,  and evals are not parsed so some 
113 +dependencies may be missed.
114  .B \-\-verbose
115  Equivalent to  \fB\-v\fP.
116  .TP
117 diff -u -r bash-2.03.orig/doc/bashref.texi bash-2.03/doc/bashref.texi
118 --- bash-2.03.orig/doc/bashref.texi     Wed Jan 20 16:47:01 1999
119 +++ bash-2.03/doc/bashref.texi  Fri Jul 16 11:21:30 1999
120 @@ -3178,6 +3178,13 @@
121  @item --restricted
122  Make the shell a restricted shell (@pxref{The Restricted Shell}).
123  
124 +@item --rpm-requires
125 +Produce the list of files that are required for the 
126 +shell script to run.  This implies '-n' and is subject
127 +to the same limitations as compile time error checking checking;
128 +Backticks, [] tests,  and evals are not parsed so some 
129 +dependencies may be missed.
130 +
131  @item --verbose
132  Equivalent to @samp{-v}.
133  
134 diff -u -r bash-2.03.orig/make_cmd.c bash-2.03/make_cmd.c
135 --- bash-2.03.orig/make_cmd.c   Tue Jan 12 12:45:36 1999
136 +++ bash-2.03/make_cmd.c        Thu Dec  2 16:08:19 1999
137 @@ -41,6 +41,9 @@
138  #include "subst.h"
139  #include "input.h"
140  #include "externs.h"
141 +#include "builtins.h"
142 +
143 +#include "builtins/common.h"
144  
145  #if defined (JOB_CONTROL)
146  #include "jobs.h"
147 @@ -48,6 +51,10 @@
148  
149  extern int line_number, current_command_line_count;
150  extern int disallow_filename_globbing;
151 +extern int rpm_requires;
152 +
153 +char *alphabet_set = "abcdefghijklmnopqrstuvwxyz"
154 +                     "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
155  
156  WORD_DESC *
157  make_bare_word (string)
158 @@ -588,6 +595,36 @@
159    return (make_command (cm_function_def, (SIMPLE_COM *)temp));
160  }
161  
162 +void
163 +output_requirement (file)
164 +char *file;
165 +{
166 +  if ( (file[0] != '/') || strchr(file, '$')) {
167 +    /* if we are not given a full path name we require the basename
168 +       otherwise we require the full path.  This does not work in the
169 +       Win/Dos world but I don't know what to do there.*/
170 +    char *basename;
171 +    basename = strrchr(file, '/');
172 +    if (basename) {    
173 +      basename++;
174 +      file=basename;
175 +    }
176 +  }  
177 +
178 +    /* 
179 +       if the executable is called via variable substitution we can
180 +       not dermine what it is at compile time.  
181 +
182 +       if the executable consists only of characters not in the
183 +       alphabet we do not consider it a dependency just an artifact of
184 +       shell parsing (ex "exec < ${infile}").
185 +    */
186 +
187 +  if ( !strchr(file, '$') && strpbrk(file, alphabet_set) ) {
188 +    printf ("executable(%s)\n", file);
189 +  }
190 +}
191 +
192  /* Reverse the word list and redirection list in the simple command
193     has just been parsed.  It seems simpler to do this here the one
194     time then by any other method that I can think of. */
195 @@ -604,6 +641,35 @@
196        command->value.Simple->redirects =
197         REVERSE_LIST (command->value.Simple->redirects, REDIRECT *);
198      }
199 +
200 +  if (rpm_requires && command->value.Simple->words)
201 +    {
202 +      char *cmd0;
203 +      char *cmd1;
204 +      struct builtin *b;
205 +
206 +      cmd0 = command->value.Simple->words->word->word;
207 +      b = builtin_address_internal (cmd0, 0);
208 +      cmd1 = 0;
209 +      if (command->value.Simple->words->next) {
210 +       cmd1 = command->value.Simple->words->next->word->word;
211 +      }
212 +      if (b) {
213 +       if ( (b->flags & REQUIRES_BUILTIN) && cmd1){
214 +         output_requirement(cmd1);
215 +       }
216 +      } else {
217 +       if (!assignment(cmd0)) {
218 +         output_requirement(cmd0);
219 +       } else {
220 +
221 +         /* This will not work, the subshell that this runs in does
222 +             not get the "requires" commandline argument. */
223 +
224 +         execute_command(command);
225 +       }
226 +      }
227 +    } /*rpm_requires*/
228  
229    return (command);
230  }
231 diff -u -r bash-2.03.orig/shell.c bash-2.03/shell.c
232 --- bash-2.03.orig/shell.c      Thu Feb 18 11:42:27 1999
233 +++ bash-2.03/shell.c   Fri Jul 16 11:30:57 1999
234 @@ -170,6 +170,9 @@
235  /* The name of the .(shell)rc file. */
236  static char *bashrc_file = "~/.bashrc";
237  
238 +/* Non-zero if we are finding the scripts requirements. */
239 +int rpm_requires;
240 +
241  /* Non-zero means to act more like the Bourne shell on startup. */
242  static int act_like_sh;
243  
244 @@ -215,6 +218,7 @@
245    { "norc", Int, &no_rc, (char **)0x0 },
246    { "posix", Int, &posixly_correct, (char **)0x0 },
247    { "rcfile", Charp, (int *)0x0, &bashrc_file },
248 +  { "rpm-requires", Int, &rpm_requires, (char **)0x0 },
249  #if defined (RESTRICTED_SHELL)
250    { "restricted", Int, &restricted, (char **)0x0 },
251  #endif
252 @@ -398,6 +402,12 @@
253  
254    if (dump_translatable_strings)
255      read_but_dont_execute = 1;
256 +
257 +  if (rpm_requires)
258 +    {
259 +      read_but_dont_execute = 1;
260 +      initialize_shell_builtins ();
261 +    }
262  
263    if (running_setuid && privileged_mode == 0)
264      disable_priv_mode ();
265
266 -- 
267 To unsubscribe: mail -s unsubscribe rpm-list-request@redhat.com < /dev/null
268
This page took 0.092297 seconds and 4 git commands to generate.