Blame SOURCES/bash-requires.patch

287226
diff -up bash-4.1/builtins.h.requires bash-4.1/builtins.h
287226
--- bash-4.1/builtins.h.requires	2009-01-04 20:32:23.000000000 +0100
287226
+++ bash-4.1/builtins.h	2010-08-02 17:42:41.000000000 +0200
287226
@@ -41,6 +41,8 @@
287226
 #define SPECIAL_BUILTIN 0x08	/* This is a Posix `special' builtin. */
287226
 #define ASSIGNMENT_BUILTIN 0x10	/* This builtin takes assignment statements. */
287226
 #define POSIX_BUILTIN	0x20	/* This builtins is special in the Posix command search order. */
287226
+#define REQUIRES_BUILTIN 0x40	/* This builtin requires other files. */
287226
+
287226
 
287226
 #define BASE_INDENT	4
287226
 
287226
diff -up bash-4.1/builtins/mkbuiltins.c.requires bash-4.1/builtins/mkbuiltins.c
287226
--- bash-4.1/builtins/mkbuiltins.c.requires	2009-01-04 20:32:23.000000000 +0100
287226
+++ bash-4.1/builtins/mkbuiltins.c	2010-08-02 17:42:41.000000000 +0200
287226
@@ -69,9 +69,15 @@ extern char *strcpy ();
287226
 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
287226
 
287226
 /* Flag values that builtins can have. */
287226
+/*  These flags are for the C code generator, 
287226
+    the C which is produced (./builtin.c)
287226
+    includes the flags definitions found 
287226
+    in ../builtins.h */
287226
 #define BUILTIN_FLAG_SPECIAL	0x01
287226
 #define BUILTIN_FLAG_ASSIGNMENT 0x02
287226
 #define BUILTIN_FLAG_POSIX_BUILTIN 0x04
287226
+#define BUILTIN_FLAG_REQUIRES	0x08
287226
+
287226
 
287226
 #define BASE_INDENT	4
287226
 
287226
@@ -163,10 +169,18 @@ char *posix_builtins[] =
287226
   (char *)NULL
287226
 };
287226
 
287226
+/* The builtin commands that cause requirements on other files. */
287226
+static char *requires_builtins[] =
287226
+{
287226
+  ".", "command", "exec", "source", "inlib",
287226
+  (char *)NULL
287226
+};
287226
+
287226
 /* Forward declarations. */
287226
 static int is_special_builtin ();
287226
 static int is_assignment_builtin ();
287226
 static int is_posix_builtin ();
287226
+static int is_requires_builtin ();
287226
 
287226
 #if !defined (HAVE_RENAME)
287226
 static int rename ();
287226
@@ -812,6 +826,9 @@ builtin_handler (self, defs, arg)
287226
     new->flags |= BUILTIN_FLAG_ASSIGNMENT;
287226
   if (is_posix_builtin (name))
287226
     new->flags |= BUILTIN_FLAG_POSIX_BUILTIN;
287226
+  if (is_requires_builtin (name))
287226
+    new->flags |= BUILTIN_FLAG_REQUIRES;
287226
+
287226
 
287226
   array_add ((char *)new, defs->builtins);
287226
   building_builtin = 1;
287226
@@ -1229,11 +1246,12 @@ write_builtins (defs, structfile, extern
287226
 		  else
287226
 		    fprintf (structfile, "(sh_builtin_func_t *)0x0, ");
287226
 
287226
-		  fprintf (structfile, "%s%s%s%s, %s_doc,\n",
287226
+		  fprintf (structfile, "%s%s%s%s%s, %s_doc,\n",
287226
 		    "BUILTIN_ENABLED | STATIC_BUILTIN",
287226
 		    (builtin->flags & BUILTIN_FLAG_SPECIAL) ? " | SPECIAL_BUILTIN" : "",
287226
 		    (builtin->flags & BUILTIN_FLAG_ASSIGNMENT) ? " | ASSIGNMENT_BUILTIN" : "",
287226
 		    (builtin->flags & BUILTIN_FLAG_POSIX_BUILTIN) ? " | POSIX_BUILTIN" : "",
287226
+		    (builtin->flags & BUILTIN_FLAG_REQUIRES) ? " | REQUIRES_BUILTIN" : "",
287226
 		    document_name (builtin));
287226
 
287226
 		  fprintf
287226
@@ -1581,6 +1599,13 @@ is_posix_builtin (name)
287226
   return (_find_in_table (name, posix_builtins));
287226
 }
287226
 
287226
+static int
287226
+is_requires_builtin (name)
287226
+     char *name;
287226
+{
287226
+  return (_find_in_table (name, requires_builtins));
287226
+}
287226
+
287226
 #if !defined (HAVE_RENAME)
287226
 static int
287226
 rename (from, to)
287226
diff -up bash-4.1/doc/bash.1.requires bash-4.1/doc/bash.1
287226
--- bash-4.1/doc/bash.1.requires	2010-08-02 17:42:41.000000000 +0200
287226
+++ bash-4.1/doc/bash.1	2010-08-02 18:09:27.000000000 +0200
287226
@@ -231,6 +231,14 @@ The shell becomes restricted (see
287226
 .B "RESTRICTED SHELL"
287226
 below).
287226
 .TP
287226
+.B \-\-rpm-requires
287226
+Produce the list of files that are required for the 
287226
+shell script to run.  This implies '-n' and is subject
287226
+to the same limitations as compile time error checking checking;
287226
+Command substitutions, Conditional expressions and
287226
+.BR eval
287226
+builtin are not parsed so some dependencies may be missed.
287226
+.TP
287226
 .B \-\-verbose
287226
 Equivalent to  \fB\-v\fP.
287226
 .TP
287226
diff -up bash-4.1/doc/bashref.texi.requires bash-4.1/doc/bashref.texi
287226
--- bash-4.1/doc/bashref.texi.requires	2010-08-02 17:42:41.000000000 +0200
287226
+++ bash-4.1/doc/bashref.texi	2010-08-02 18:11:58.000000000 +0200
287226
@@ -5343,6 +5343,13 @@ standard.  @xref{Bash POSIX Mode}, for a
287226
 @item --restricted
287226
 Make the shell a restricted shell (@pxref{The Restricted Shell}).
287226
 
287226
+@item --rpm-requires
287226
+Produce the list of files that are required for the 
287226
+shell script to run.  This implies '-n' and is subject
287226
+to the same limitations as compile time error checking checking;
287226
+Command substitutions, Conditional expressions and @command{eval}
287226
+are not parsed so some dependencies may be missed.
287226
+
287226
 @item --verbose
287226
 Equivalent to @option{-v}.  Print shell input lines as they're read.
287226
 
287226
diff -up bash-4.1/eval.c.requires bash-4.1/eval.c
287226
--- bash-4.1/eval.c.requires	2009-01-04 20:32:26.000000000 +0100
287226
+++ bash-4.1/eval.c	2010-08-02 17:42:41.000000000 +0200
287226
@@ -53,6 +53,7 @@ extern int last_command_exit_value, stdi
287226
 extern int need_here_doc;
287226
 extern int current_command_number, current_command_line_count, line_number;
287226
 extern int expand_aliases;
287226
+extern int rpm_requires;
287226
 
287226
 static void send_pwd_to_eterm __P((void));
287226
 static sighandler alrm_catcher __P((int));
287226
@@ -136,7 +137,7 @@ reader_loop ()
287226
 
287226
       if (read_command () == 0)
287226
 	{
287226
-	  if (interactive_shell == 0 && read_but_dont_execute)
287226
+	  if (interactive_shell == 0 && (read_but_dont_execute && !rpm_requires))
287226
 	    {
287226
 	      last_command_exit_value = EXECUTION_SUCCESS;
287226
 	      dispose_command (global_command);
287226
diff -up bash-4.1/execute_cmd.c.requires bash-4.1/execute_cmd.c
287226
--- bash-4.1/execute_cmd.c.requires	2010-08-02 17:42:41.000000000 +0200
287226
+++ bash-4.1/execute_cmd.c	2010-08-02 17:42:41.000000000 +0200
287226
@@ -503,6 +503,8 @@ async_redirect_stdin ()
287226
 
287226
 #define DESCRIBE_PID(pid) do { if (interactive) describe_pid (pid); } while (0)
287226
 
287226
+extern int rpm_requires;
287226
+
287226
 /* Execute the command passed in COMMAND, perhaps doing it asynchrounously.
287226
    COMMAND is exactly what read_command () places into GLOBAL_COMMAND.
287226
    ASYNCHROUNOUS, if non-zero, says to do this command in the background.
287226
@@ -534,7 +536,13 @@ execute_command_internal (command, async
287226
 #else
287226
   if (breaking || continuing)
287226
     return (last_command_exit_value);
287226
-  if (command == 0 || read_but_dont_execute)
287226
+  if (command == 0 || (read_but_dont_execute && !rpm_requires))
287226
+    return (EXECUTION_SUCCESS);
287226
+  if (rpm_requires && command->type == cm_function_def)
287226
+    return last_command_exit_value =
287226
+      execute_intern_function (command->value.Function_def->name,
287226
+                              command->value.Function_def->command);
287226
+  if (read_but_dont_execute)
287226
     return (EXECUTION_SUCCESS);
287226
 #endif
287226
 
287226
@@ -5066,7 +5074,7 @@ execute_intern_function (name, function)
287226
 
287226
   if (check_identifier (name, posixly_correct) == 0)
287226
     {
287226
-      if (posixly_correct && interactive_shell == 0)
287226
+      if (posixly_correct && interactive_shell == 0 && rpm_requires == 0)
287226
 	{
287226
 	  last_command_exit_value = EX_BADUSAGE;
287226
 	  jump_to_top_level (ERREXIT);
287226
diff -up bash-4.1/execute_cmd.h.requires bash-4.1/execute_cmd.h
287226
--- bash-4.1/execute_cmd.h.requires	2009-01-16 22:20:15.000000000 +0100
287226
+++ bash-4.1/execute_cmd.h	2010-08-02 17:42:41.000000000 +0200
287226
@@ -22,6 +22,8 @@
287226
 #define _EXECUTE_CMD_H_
287226
 
287226
 #include "stdc.h"
287226
+#include "variables.h"
287226
+#include "command.h"
287226
 
287226
 extern struct fd_bitmap *new_fd_bitmap __P((int));
287226
 extern void dispose_fd_bitmap __P((struct fd_bitmap *));
287226
diff -up bash-4.1/make_cmd.c.requires bash-4.1/make_cmd.c
287226
--- bash-4.1/make_cmd.c.requires	2009-09-11 23:26:12.000000000 +0200
287226
+++ bash-4.1/make_cmd.c	2010-08-02 17:42:41.000000000 +0200
287226
@@ -42,11 +42,15 @@
287226
 #include "flags.h"
287226
 #include "make_cmd.h"
287226
 #include "dispose_cmd.h"
287226
+#include "execute_cmd.h"
287226
 #include "variables.h"
287226
 #include "subst.h"
287226
 #include "input.h"
287226
 #include "ocache.h"
287226
 #include "externs.h"
287226
+#include "builtins.h"
287226
+
287226
+#include "builtins/common.h"
287226
 
287226
 #if defined (JOB_CONTROL)
287226
 #include "jobs.h"
287226
@@ -56,6 +60,10 @@
287226
 
287226
 extern int line_number, current_command_line_count, parser_state;
287226
 extern int last_command_exit_value;
287226
+extern int rpm_requires;
287226
+
287226
+static char *alphabet_set = "abcdefghijklmnopqrstuvwxyz"
287226
+                     "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
287226
 
287226
 /* Object caching */
287226
 sh_obj_cache_t wdcache = {0, 0, 0};
287226
@@ -820,6 +828,27 @@ make_coproc_command (name, command)
287226
   return (make_command (cm_coproc, (SIMPLE_COM *)temp));
287226
 }
287226
 
287226
+static void
287226
+output_requirement (deptype, filename)
287226
+const char *deptype;
287226
+char *filename;
287226
+{
287226
+  if (strchr(filename, '$') || (filename[0] != '/' && strchr(filename, '/')))
287226
+    return;
287226
+
287226
+  /* 
287226
+      if the executable is called via variable substitution we can
287226
+      not dermine what it is at compile time.  
287226
+
287226
+      if the executable consists only of characters not in the
287226
+      alphabet we do not consider it a dependency just an artifact
287226
+      of shell parsing (ex "exec < ${infile}").
287226
+  */
287226
+
287226
+  if (strpbrk(filename, alphabet_set))
287226
+    printf ("%s(%s)\n", deptype, filename);
287226
+}
287226
+
287226
 /* Reverse the word list and redirection list in the simple command
287226
    has just been parsed.  It seems simpler to do this here the one
287226
    time then by any other method that I can think of. */
287226
@@ -837,6 +866,27 @@ clean_simple_command (command)
287226
 	REVERSE_LIST (command->value.Simple->redirects, REDIRECT *);
287226
     }
287226
 
287226
+  if (rpm_requires && command->value.Simple->words)
287226
+    {
287226
+      char *cmd0;
287226
+      char *cmd1;
287226
+      struct builtin *b;
287226
+
287226
+      cmd0 = command->value.Simple->words->word->word;
287226
+      b = builtin_address_internal (cmd0, 0);
287226
+      cmd1 = 0;
287226
+      if (command->value.Simple->words->next)
287226
+        cmd1 = command->value.Simple->words->next->word->word;
287226
+
287226
+      if (b) {
287226
+        if ( (b->flags & REQUIRES_BUILTIN) && cmd1)
287226
+          output_requirement ("executable", cmd1);
287226
+      } else {
287226
+        if (!assignment(cmd0, 0))
287226
+          output_requirement (find_function(cmd0) ? "function" : "executable", cmd0);
287226
+      }
287226
+    } /*rpm_requires*/
287226
+
287226
   parser_state &= ~PST_REDIRLIST;
287226
   return (command);
287226
 }
287226
diff -up bash-4.1/shell.c.requires bash-4.1/shell.c
287226
--- bash-4.1/shell.c.requires	2010-08-02 17:42:41.000000000 +0200
287226
+++ bash-4.1/shell.c	2010-08-02 17:42:41.000000000 +0200
287226
@@ -193,6 +193,9 @@ int have_devfd = 0;
287226
 /* The name of the .(shell)rc file. */
287226
 static char *bashrc_file = "~/.bashrc";
287226
 
287226
+/* Non-zero if we are finding the scripts requirements. */
287226
+int rpm_requires;
287226
+
287226
 /* Non-zero means to act more like the Bourne shell on startup. */
287226
 static int act_like_sh;
287226
 
287226
@@ -251,6 +254,7 @@ static const struct {
287226
   { "posix", Int, &posixly_correct, (char **)0x0 },
287226
   { "protected", Int, &protected_mode, (char **)0x0 },
287226
   { "rcfile", Charp, (int *)0x0, &bashrc_file },
287226
+  { "rpm-requires", Int, &rpm_requires, (char **)0x0 },
287226
 #if defined (RESTRICTED_SHELL)
287226
   { "restricted", Int, &restricted, (char **)0x0 },
287226
 #endif
287226
@@ -485,6 +489,12 @@ main (argc, argv, env)
287226
   if (dump_translatable_strings)
287226
     read_but_dont_execute = 1;
287226
 
287226
+  if (rpm_requires)
287226
+    {
287226
+      read_but_dont_execute = 1;
287226
+      initialize_shell_builtins ();
287226
+    }
287226
+
287226
   if (running_setuid && privileged_mode == 0)
287226
     disable_priv_mode ();
287226