psss / rpms / bash

Forked from rpms/bash 6 years ago
Clone
6353abb
diff -upk.orig bash-3.1.orig/builtins/mkbuiltins.c bash-3.1/builtins/mkbuiltins.c
6353abb
--- bash-3.1.orig/builtins/mkbuiltins.c	2005-09-10 16:22:12 +0000
6353abb
+++ bash-3.1/builtins/mkbuiltins.c	2006-01-06 00:42:16 +0000
6353abb
@@ -60,8 +60,13 @@ extern char *strcpy ();
6353abb
 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
6353abb
 
6353abb
 /* Flag values that builtins can have. */
6353abb
+/*  These flags are for the C code generator, 
6353abb
+    the C which is produced (./builtin.c)
6353abb
+    includes the flags definitions found 
6353abb
+    in ../builtins.h */
6353abb
 #define BUILTIN_FLAG_SPECIAL	0x01
6353abb
 #define BUILTIN_FLAG_ASSIGNMENT 0x02
6353abb
+#define BUILTIN_FLAG_REQUIRES	0x04
6353abb
 
6353abb
 #define BASE_INDENT	4
6353abb
 
6353abb
@@ -145,9 +150,17 @@ char *assignment_builtins[] =
6353abb
   (char *)NULL
6353abb
 };
6353abb
 
6353abb
+/* The builtin commands that cause requirements on other files. */
6353abb
+static char *requires_builtins[] =
6353abb
+{
6353abb
+  ".", "command", "exec", "source", "inlib",
6353abb
+  (char *)NULL
6353abb
+};
6353abb
+
6353abb
 /* Forward declarations. */
6353abb
 static int is_special_builtin ();
6353abb
 static int is_assignment_builtin ();
6353abb
+static int is_requires_builtin ();
6353abb
 
6353abb
 #if !defined (HAVE_RENAME)
6353abb
 static int rename ();
6353abb
@@ -791,6 +804,8 @@ builtin_handler (self, defs, arg)
6353abb
     new->flags |= BUILTIN_FLAG_SPECIAL;
6353abb
   if (is_assignment_builtin (name))
6353abb
     new->flags |= BUILTIN_FLAG_ASSIGNMENT;
6353abb
+  if (is_requires_builtin (name))
6353abb
+    new->flags |= BUILTIN_FLAG_REQUIRES;
6353abb
 
6353abb
   array_add ((char *)new, defs->builtins);
6353abb
   building_builtin = 1;
6353abb
@@ -1208,10 +1223,11 @@ write_builtins (defs, structfile, extern
6353abb
 		  else
6353abb
 		    fprintf (structfile, "(sh_builtin_func_t *)0x0, ");
6353abb
 
6353abb
-		  fprintf (structfile, "%s%s%s, %s_doc,\n",
6353abb
+		  fprintf (structfile, "%s%s%s%s, %s_doc,\n",
6353abb
 		    "BUILTIN_ENABLED | STATIC_BUILTIN",
6353abb
 		    (builtin->flags & BUILTIN_FLAG_SPECIAL) ? " | SPECIAL_BUILTIN" : "",
6353abb
 		    (builtin->flags & BUILTIN_FLAG_ASSIGNMENT) ? " | ASSIGNMENT_BUILTIN" : "",
6353abb
+		    (builtin->flags & BUILTIN_FLAG_REQUIRES) ? " | REQUIRES_BUILTIN" : "",
6353abb
 		    document_name (builtin));
6353abb
 
6353abb
 		  fprintf
6353abb
@@ -1542,6 +1558,13 @@ is_assignment_builtin (name)
6353abb
   return (_find_in_table (name, assignment_builtins));
6353abb
 }
6353abb
 
6353abb
+static int
6353abb
+is_requires_builtin (name)
6353abb
+     char *name;
6353abb
+{
6353abb
+  return (_find_in_table (name, requires_builtins));
6353abb
+}
6353abb
+
6353abb
 #if !defined (HAVE_RENAME)
6353abb
 static int
6353abb
 rename (from, to)
6353abb
diff -upk.orig bash-3.1.orig/builtins.h bash-3.1/builtins.h
6353abb
--- bash-3.1.orig/builtins.h	2004-12-30 18:59:05 +0000
6353abb
+++ bash-3.1/builtins.h	2006-01-06 00:42:16 +0000
6353abb
@@ -40,6 +40,7 @@
6353abb
 #define STATIC_BUILTIN  0x4	/* This builtin is not dynamically loaded. */
6353abb
 #define SPECIAL_BUILTIN 0x8	/* This is a Posix `special' builtin. */
6353abb
 #define ASSIGNMENT_BUILTIN 0x10	/* This builtin takes assignment statements. */
6353abb
+#define REQUIRES_BUILTIN 0x20	/* This builtin requires other files. */
6353abb
 
6353abb
 #define BASE_INDENT	4
6353abb
 
6353abb
diff -upk.orig bash-3.1.orig/doc/bash.1 bash-3.1/doc/bash.1
6353abb
--- bash-3.1.orig/doc/bash.1	2006-01-06 00:41:57 +0000
6353abb
+++ bash-3.1/doc/bash.1	2006-01-06 00:42:16 +0000
6353abb
@@ -231,6 +231,13 @@ The shell becomes restricted (see
6353abb
 .B "RESTRICTED SHELL"
6353abb
 below).
6353abb
 .TP
6353abb
+.B \-\-rpm-requires
6353abb
+Produce the list of files that are required for the 
6353abb
+shell script to run.  This implies '-n' and is subject
6353abb
+to the same limitations as compile time error checking checking;
6353abb
+Backticks, [] tests,  and evals are not parsed so some 
6353abb
+dependencies may be missed.
6353abb
+.TP
6353abb
 .B \-\-verbose
6353abb
 Equivalent to  \fB\-v\fP.
6353abb
 .TP
6353abb
diff -upk.orig bash-3.1.orig/doc/bashref.texi bash-3.1/doc/bashref.texi
6353abb
--- bash-3.1.orig/doc/bashref.texi	2006-01-06 00:41:57 +0000
6353abb
+++ bash-3.1/doc/bashref.texi	2006-01-06 00:42:16 +0000
6353abb
@@ -4898,6 +4898,13 @@ standard.  @xref{Bash POSIX Mode}, for a
6353abb
 @item --restricted
6353abb
 Make the shell a restricted shell (@pxref{The Restricted Shell}).
6353abb
 
6353abb
+@item --rpm-requires
6353abb
+Produce the list of files that are required for the 
6353abb
+shell script to run.  This implies '-n' and is subject
6353abb
+to the same limitations as compile time error checking checking;
6353abb
+Backticks, [] tests,  and evals are not parsed so some 
6353abb
+dependencies may be missed.
6353abb
+
6353abb
 @item --verbose
6353abb
 Equivalent to @option{-v}.  Print shell input lines as they're read.
6353abb
 
6353abb
diff -upk.orig bash-3.1.orig/eval.c bash-3.1/eval.c
6353abb
--- bash-3.1.orig/eval.c	2006-01-06 00:41:57 +0000
6353abb
+++ bash-3.1/eval.c	2006-01-06 00:42:16 +0000
6353abb
@@ -53,6 +53,7 @@ extern int last_command_exit_value, stdi
6353abb
 extern int need_here_doc;
6353abb
 extern int current_command_number, current_command_line_count, line_number;
6353abb
 extern int expand_aliases;
6353abb
+extern int rpm_requires;
6353abb
 
6353abb
 static void send_pwd_to_eterm __P((void));
6353abb
 static sighandler alrm_catcher __P((int));
6353abb
@@ -131,7 +132,7 @@ reader_loop ()
6353abb
 
6353abb
       if (read_command () == 0)
6353abb
 	{
6353abb
-	  if (interactive_shell == 0 && read_but_dont_execute)
6353abb
+	  if (interactive_shell == 0 && (read_but_dont_execute && !rpm_requires))
6353abb
 	    {
6353abb
 	      last_command_exit_value = EXECUTION_SUCCESS;
6353abb
 	      dispose_command (global_command);
6353abb
diff -upk.orig bash-3.1.orig/execute_cmd.c bash-3.1/execute_cmd.c
6353abb
--- bash-3.1.orig/execute_cmd.c	2006-01-06 00:41:57 +0000
6353abb
+++ bash-3.1/execute_cmd.c	2006-01-06 00:42:16 +0000
6353abb
@@ -473,6 +473,8 @@ async_redirect_stdin ()
6353abb
 
6353abb
 #define DESCRIBE_PID(pid) do { if (interactive) describe_pid (pid); } while (0)
6353abb
 
6353abb
+extern int rpm_requires;
6353abb
+
6353abb
 /* Execute the command passed in COMMAND, perhaps doing it asynchrounously.
6353abb
    COMMAND is exactly what read_command () places into GLOBAL_COMMAND.
6353abb
    ASYNCHROUNOUS, if non-zero, says to do this command in the background.
6353abb
@@ -498,7 +500,15 @@ execute_command_internal (command, async
6353abb
   volatile int last_pid;
6353abb
   volatile int save_line_number;
6353abb
 
6353abb
-  if (command == 0 || breaking || continuing || read_but_dont_execute)
6353abb
+  if (command == 0 || breaking || continuing || (read_but_dont_execute && !rpm_requires))
6353abb
+    return (EXECUTION_SUCCESS);
6353abb
+
6353abb
+  if (rpm_requires && command->type == cm_function_def)
6353abb
+    return last_command_exit_value =
6353abb
+      execute_intern_function (command->value.Function_def->name,
6353abb
+			       command->value.Function_def->command);
6353abb
+
6353abb
+  if (read_but_dont_execute)
6353abb
     return (EXECUTION_SUCCESS);
6353abb
 
Roman Rakus 064f291
   QUIT;
6353abb
@@ -3984,7 +3994,7 @@ execute_intern_function (name, function)
6353abb
 
6353abb
   if (check_identifier (name, posixly_correct) == 0)
6353abb
     {
6353abb
-      if (posixly_correct && interactive_shell == 0)
6353abb
+      if (posixly_correct && interactive_shell == 0 && rpm_requires == 0)
6353abb
 	{
6353abb
 	  last_command_exit_value = EX_USAGE;
6353abb
 	  jump_to_top_level (ERREXIT);
6353abb
diff -upk.orig bash-3.1.orig/execute_cmd.h bash-3.1/execute_cmd.h
6353abb
--- bash-3.1.orig/execute_cmd.h	2001-05-07 14:39:37 +0000
6353abb
+++ bash-3.1/execute_cmd.h	2003-04-20 13:20:49 +0000
6353abb
@@ -22,6 +22,8 @@
6353abb
 #define _EXECUTE_CMD_H_
6353abb
 
6353abb
 #include "stdc.h"
6353abb
+#include "variables.h"
6353abb
+#include "command.h"
6353abb
 
6353abb
 extern struct fd_bitmap *new_fd_bitmap __P((int));
6353abb
 extern void dispose_fd_bitmap __P((struct fd_bitmap *));
6353abb
diff -upk.orig bash-3.1.orig/make_cmd.c bash-3.1/make_cmd.c
6353abb
--- bash-3.1.orig/make_cmd.c	2006-01-06 00:41:57 +0000
6353abb
+++ bash-3.1/make_cmd.c	2006-01-06 00:42:16 +0000
6353abb
@@ -41,11 +41,15 @@ Foundation, 59 Temple Place, Suite 330, 
6353abb
 #include "flags.h"
6353abb
 #include "make_cmd.h"
6353abb
 #include "dispose_cmd.h"
6353abb
+#include "execute_cmd.h"
6353abb
 #include "variables.h"
6353abb
 #include "subst.h"
6353abb
 #include "input.h"
6353abb
 #include "ocache.h"
6353abb
 #include "externs.h"
6353abb
+#include "builtins.h"
6353abb
+
6353abb
+#include "builtins/common.h"
6353abb
 
6353abb
 #if defined (JOB_CONTROL)
6353abb
 #include "jobs.h"
6353abb
@@ -55,6 +59,10 @@ Foundation, 59 Temple Place, Suite 330, 
6353abb
 
6353abb
 extern int line_number, current_command_line_count;
6353abb
 extern int last_command_exit_value;
6353abb
+extern int rpm_requires;
6353abb
+
6353abb
+static char *alphabet_set = "abcdefghijklmnopqrstuvwxyz"
6353abb
+                     "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
6353abb
 
6353abb
 /* Object caching */
6353abb
 sh_obj_cache_t wdcache = {0, 0, 0};
6353abb
@@ -784,6 +792,27 @@ make_subshell_command (command)
6353abb
   return (make_command (cm_subshell, (SIMPLE_COM *)temp));
6353abb
 }
6353abb
 
6353abb
+static void
6353abb
+output_requirement (deptype, filename)
6353abb
+const char *deptype;
6353abb
+char *filename;
6353abb
+{
6353abb
+  if (strchr(filename, '$') || (filename[0] != '/' && strchr(filename, '/')))
6353abb
+    return;
6353abb
+
6353abb
+  /* 
6353abb
+      if the executable is called via variable substitution we can
6353abb
+      not dermine what it is at compile time.  
6353abb
+
6353abb
+      if the executable consists only of characters not in the
6353abb
+      alphabet we do not consider it a dependency just an artifact
6353abb
+      of shell parsing (ex "exec < ${infile}").
6353abb
+  */
6353abb
+
6353abb
+  if (strpbrk(filename, alphabet_set))
6353abb
+    printf ("%s(%s)\n", deptype, filename);
6353abb
+}
6353abb
+
6353abb
 /* Reverse the word list and redirection list in the simple command
6353abb
    has just been parsed.  It seems simpler to do this here the one
6353abb
    time then by any other method that I can think of. */
6353abb
@@ -801,6 +830,27 @@ clean_simple_command (command)
6353abb
 	REVERSE_LIST (command->value.Simple->redirects, REDIRECT *);
6353abb
     }
6353abb
 
6353abb
+  if (rpm_requires && command->value.Simple->words)
6353abb
+    {
6353abb
+      char *cmd0;
6353abb
+      char *cmd1;
6353abb
+      struct builtin *b;
6353abb
+
6353abb
+      cmd0 = command->value.Simple->words->word->word;
6353abb
+      b = builtin_address_internal (cmd0, 0);
6353abb
+      cmd1 = 0;
6353abb
+      if (command->value.Simple->words->next)
6353abb
+        cmd1 = command->value.Simple->words->next->word->word;
6353abb
+
6353abb
+      if (b) {
6353abb
+        if ( (b->flags & REQUIRES_BUILTIN) && cmd1)
6353abb
+          output_requirement ("executable", cmd1);
6353abb
+      } else {
6353abb
+        if (!assignment(cmd0, 0))
6353abb
+          output_requirement (find_function(cmd0) ? "function" : "executable", cmd0);
6353abb
+      }
6353abb
+    } /*rpm_requires*/
6353abb
+
6353abb
   return (command);
6353abb
 }
6353abb
 
6353abb
diff -upk.orig bash-3.1.orig/shell.c bash-3.1/shell.c
6353abb
--- bash-3.1.orig/shell.c	2006-01-06 00:41:57 +0000
6353abb
+++ bash-3.1/shell.c	2006-01-06 00:42:16 +0000
6353abb
@@ -175,6 +175,9 @@ int running_under_emacs;
6353abb
 /* The name of the .(shell)rc file. */
6353abb
 static char *bashrc_file = "~/.bashrc";
6353abb
 
6353abb
+/* Non-zero if we are finding the scripts requirements. */
6353abb
+int rpm_requires;
6353abb
+
6353abb
 /* Non-zero means to act more like the Bourne shell on startup. */
6353abb
 static int act_like_sh;
6353abb
 
6353abb
@@ -233,6 +236,7 @@ struct {
6353abb
   { "posix", Int, &posixly_correct, (char **)0x0 },
6353abb
   { "protected", Int, &protected_mode, (char **)0x0 },
6353abb
   { "rcfile", Charp, (int *)0x0, &bashrc_file },
6353abb
+  { "rpm-requires", Int, &rpm_requires, (char **)0x0 },
6353abb
 #if defined (RESTRICTED_SHELL)
6353abb
   { "restricted", Int, &restricted, (char **)0x0 },
6353abb
 #endif
6353abb
@@ -460,6 +464,12 @@ main (argc, argv, env)
6353abb
   if (dump_translatable_strings)
6353abb
     read_but_dont_execute = 1;
6353abb
 
6353abb
+  if (rpm_requires)
6353abb
+    {
6353abb
+      read_but_dont_execute = 1;
6353abb
+      initialize_shell_builtins ();
6353abb
+    }
6353abb
+
6353abb
   if (running_setuid && privileged_mode == 0)
6353abb
     disable_priv_mode ();
6353abb