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.
8 Here is the latest patch file.
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
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
23 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
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
30 #define BUILTIN_FLAG_SPECIAL 0x01
31 #define BUILTIN_FLAG_ASSIGNMENT 0x02
32 +#define BUILTIN_FLAG_REQUIRES 0x04
34 /* If this stream descriptor is non-zero, then write
35 texinfo documentation to it. */
40 +/* The builtin commands that cause requirements on other files. */
41 +char *requires_builtins[] =
43 + ".", "command", "exec", "source", "inlib",
47 /* Forward declarations. */
48 static int is_special_builtin ();
49 static int is_assignment_builtin ();
50 +static int is_requires_builtin ();
52 #if !defined (HAVE_RENAME)
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;
61 array_add ((char *)new, defs->builtins);
63 @@ -1164,10 +1179,11 @@
65 fprintf (structfile, "(Function *)0x0, ");
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);
76 @@ -1401,6 +1417,13 @@
79 return (_find_in_table (name, assignment_builtins));
83 +is_requires_builtin (name)
86 + return (_find_in_table (name, requires_builtins));
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
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. */
99 /* The thing that we build the array of builtins out of. */
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
105 .B "RESTRICTED SHELL"
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.
115 Equivalent to \fB\-v\fP.
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 @@
122 Make the shell a restricted shell (@pxref{The Restricted Shell}).
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.
132 Equivalent to @samp{-v}.
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
141 +#include "builtins.h"
143 +#include "builtins/common.h"
145 #if defined (JOB_CONTROL)
149 extern int line_number, current_command_line_count;
150 extern int disallow_filename_globbing;
151 +extern int rpm_requires;
153 +char *alphabet_set = "abcdefghijklmnopqrstuvwxyz"
154 + "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
157 make_bare_word (string)
159 return (make_command (cm_function_def, (SIMPLE_COM *)temp));
163 +output_requirement (file)
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.*/
171 + basename = strrchr(file, '/');
179 + if the executable is called via variable substitution we can
180 + not dermine what it is at compile time.
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}").
187 + if ( !strchr(file, '$') && strpbrk(file, alphabet_set) ) {
188 + printf ("executable(%s)\n", file);
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. */
196 command->value.Simple->redirects =
197 REVERSE_LIST (command->value.Simple->redirects, REDIRECT *);
200 + if (rpm_requires && command->value.Simple->words)
206 + cmd0 = command->value.Simple->words->word->word;
207 + b = builtin_address_internal (cmd0, 0);
209 + if (command->value.Simple->words->next) {
210 + cmd1 = command->value.Simple->words->next->word->word;
213 + if ( (b->flags & REQUIRES_BUILTIN) && cmd1){
214 + output_requirement(cmd1);
217 + if (!assignment(cmd0)) {
218 + output_requirement(cmd0);
221 + /* This will not work, the subshell that this runs in does
222 + not get the "requires" commandline argument. */
224 + execute_command(command);
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
235 /* The name of the .(shell)rc file. */
236 static char *bashrc_file = "~/.bashrc";
238 +/* Non-zero if we are finding the scripts requirements. */
241 /* Non-zero means to act more like the Bourne shell on startup. */
242 static int act_like_sh;
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 },
254 if (dump_translatable_strings)
255 read_but_dont_execute = 1;
259 + read_but_dont_execute = 1;
260 + initialize_shell_builtins ();
263 if (running_setuid && privileged_mode == 0)
264 disable_priv_mode ();
267 To unsubscribe: mail -s unsubscribe rpm-list-request@redhat.com < /dev/null