psss / rpms / bash

Forked from rpms/bash 6 years ago
Clone
Roman Rakus 87b6511
diff -up bash-4.0/shell.c.requires bash-4.0/shell.c
Roman Rakus 87b6511
--- bash-4.0/shell.c.requires	2009-01-21 15:28:16.000000000 +0100
Roman Rakus 87b6511
+++ bash-4.0/shell.c	2009-01-21 15:28:16.000000000 +0100
Roman Rakus 87b6511
@@ -193,6 +193,9 @@ int have_devfd = 0;
Roman Rakus d1932ba
 /* The name of the .(shell)rc file. */
Roman Rakus d1932ba
 static char *bashrc_file = "~/.bashrc";
6353abb
 
Roman Rakus d1932ba
+/* Non-zero if we are finding the scripts requirements. */
Roman Rakus d1932ba
+int rpm_requires;
6353abb
+
Roman Rakus d1932ba
 /* Non-zero means to act more like the Bourne shell on startup. */
Roman Rakus d1932ba
 static int act_like_sh;
6353abb
 
Roman Rakus 87b6511
@@ -251,6 +254,7 @@ static const struct {
Roman Rakus d1932ba
   { "posix", Int, &posixly_correct, (char **)0x0 },
Roman Rakus d1932ba
   { "protected", Int, &protected_mode, (char **)0x0 },
Roman Rakus d1932ba
   { "rcfile", Charp, (int *)0x0, &bashrc_file },
Roman Rakus d1932ba
+  { "rpm-requires", Int, &rpm_requires, (char **)0x0 },
Roman Rakus d1932ba
 #if defined (RESTRICTED_SHELL)
Roman Rakus d1932ba
   { "restricted", Int, &restricted, (char **)0x0 },
Roman Rakus d1932ba
 #endif
Roman Rakus 87b6511
@@ -479,6 +483,12 @@ main (argc, argv, env)
Roman Rakus d1932ba
   if (dump_translatable_strings)
Roman Rakus d1932ba
     read_but_dont_execute = 1;
6353abb
 
Roman Rakus d1932ba
+  if (rpm_requires)
Roman Rakus d1932ba
+    {
Roman Rakus d1932ba
+      read_but_dont_execute = 1;
Roman Rakus d1932ba
+      initialize_shell_builtins ();
Roman Rakus d1932ba
+    }
Roman Rakus d1932ba
+
Roman Rakus d1932ba
   if (running_setuid && privileged_mode == 0)
Roman Rakus d1932ba
     disable_priv_mode ();
6353abb
 
Roman Rakus 87b6511
diff -up bash-4.0/doc/bashref.texi.requires bash-4.0/doc/bashref.texi
Roman Rakus 87b6511
--- bash-4.0/doc/bashref.texi.requires	2009-01-21 15:28:16.000000000 +0100
Roman Rakus 87b6511
+++ bash-4.0/doc/bashref.texi	2009-01-21 15:28:16.000000000 +0100
Roman Rakus 87b6511
@@ -5253,6 +5253,13 @@ standard.  @xref{Bash POSIX Mode}, for a
Roman Rakus d1932ba
 @item --restricted
Roman Rakus d1932ba
 Make the shell a restricted shell (@pxref{The Restricted Shell}).
6353abb
 
Roman Rakus d1932ba
+@item --rpm-requires
Roman Rakus d1932ba
+Produce the list of files that are required for the 
Roman Rakus d1932ba
+shell script to run.  This implies '-n' and is subject
Roman Rakus d1932ba
+to the same limitations as compile time error checking checking;
Roman Rakus d1932ba
+Backticks, [] tests,  and evals are not parsed so some 
Roman Rakus d1932ba
+dependencies may be missed.
6353abb
+
Roman Rakus d1932ba
 @item --verbose
Roman Rakus d1932ba
 Equivalent to @option{-v}.  Print shell input lines as they're read.
6353abb
 
Roman Rakus 87b6511
diff -up bash-4.0/doc/bash.1.requires bash-4.0/doc/bash.1
Roman Rakus 87b6511
--- bash-4.0/doc/bash.1.requires	2009-01-21 15:28:16.000000000 +0100
Roman Rakus 87b6511
+++ bash-4.0/doc/bash.1	2009-01-21 15:28:16.000000000 +0100
Roman Rakus 87b6511
@@ -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
Roman Rakus 87b6511
diff -up bash-4.0/make_cmd.c.requires bash-4.0/make_cmd.c
Roman Rakus 87b6511
--- bash-4.0/make_cmd.c.requires	2009-01-04 20:32:38.000000000 +0100
Roman Rakus 87b6511
+++ bash-4.0/make_cmd.c	2009-01-21 15:28:16.000000000 +0100
Roman Rakus 87b6511
@@ -41,11 +41,15 @@
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"
Roman Rakus 87b6511
@@ -55,6 +59,10 @@
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};
Roman Rakus 87b6511
@@ -810,6 +818,27 @@ make_coproc_command (name, command)
Roman Rakus 87b6511
   return (make_command (cm_coproc, (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. */
Roman Rakus 87b6511
@@ -827,6 +856,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
 
Roman Rakus 87b6511
diff -up bash-4.0/execute_cmd.c.requires bash-4.0/execute_cmd.c
Roman Rakus 87b6511
--- bash-4.0/execute_cmd.c.requires	2009-01-21 15:28:16.000000000 +0100
Roman Rakus 87b6511
+++ bash-4.0/execute_cmd.c	2009-01-21 15:28:16.000000000 +0100
Roman Rakus 87b6511
@@ -497,6 +497,8 @@ async_redirect_stdin ()
6353abb
 
Roman Rakus d1932ba
 #define DESCRIBE_PID(pid) do { if (interactive) describe_pid (pid); } while (0)
6353abb
 
Roman Rakus d1932ba
+extern int rpm_requires;
Roman Rakus d1932ba
+
Roman Rakus d1932ba
 /* Execute the command passed in COMMAND, perhaps doing it asynchrounously.
Roman Rakus d1932ba
    COMMAND is exactly what read_command () places into GLOBAL_COMMAND.
Roman Rakus d1932ba
    ASYNCHROUNOUS, if non-zero, says to do this command in the background.
Roman Rakus 87b6511
@@ -528,8 +530,13 @@ execute_command_internal (command, async
Roman Rakus d1932ba
 #else
Roman Rakus d1932ba
   if (breaking || continuing)
Roman Rakus d1932ba
     return (last_command_exit_value);
Roman Rakus d1932ba
-  if (command == 0 || read_but_dont_execute)
Roman Rakus d1932ba
+  if (command == 0 || (read_but_dont_execute && !rpm_requires))
Roman Rakus d1932ba
     return (EXECUTION_SUCCESS);
Roman Rakus d1932ba
+  if (rpm_requires && command->type == cm_function_def)
Roman Rakus d1932ba
+    return last_command_exit_value =
Roman Rakus d1932ba
+      execute_intern_function (command->value.Function_def->name,
Roman Rakus d1932ba
+                              command->value.Function_def->command);
Roman Rakus d1932ba
+
6353abb
 #endif
6353abb
 
Roman Rakus d1932ba
   QUIT;
Roman Rakus 87b6511
@@ -4859,7 +4866,7 @@ execute_intern_function (name, function)
Roman Rakus d1932ba
 
Roman Rakus d1932ba
   if (check_identifier (name, posixly_correct) == 0)
Roman Rakus d1932ba
     {
Roman Rakus d1932ba
-      if (posixly_correct && interactive_shell == 0)
Roman Rakus d1932ba
+      if (posixly_correct && interactive_shell == 0 && rpm_requires == 0)
Roman Rakus d1932ba
 	{
Roman Rakus 87b6511
 	  last_command_exit_value = EX_BADUSAGE;
Roman Rakus d1932ba
 	  jump_to_top_level (ERREXIT);
Roman Rakus 87b6511
diff -up bash-4.0/execute_cmd.h.requires bash-4.0/execute_cmd.h
Roman Rakus 87b6511
--- bash-4.0/execute_cmd.h.requires	2009-01-04 20:32:29.000000000 +0100
Roman Rakus 87b6511
+++ bash-4.0/execute_cmd.h	2009-01-21 15:28:16.000000000 +0100
Roman Rakus d1932ba
@@ -22,6 +22,8 @@
Roman Rakus d1932ba
 #define _EXECUTE_CMD_H_
Roman Rakus d1932ba
 
Roman Rakus d1932ba
 #include "stdc.h"
Roman Rakus d1932ba
+#include "variables.h"
Roman Rakus d1932ba
+#include "command.h"
Roman Rakus d1932ba
 
Roman Rakus d1932ba
 extern struct fd_bitmap *new_fd_bitmap __P((int));
Roman Rakus d1932ba
 extern void dispose_fd_bitmap __P((struct fd_bitmap *));
Roman Rakus 87b6511
diff -up bash-4.0/builtins.h.requires bash-4.0/builtins.h
Roman Rakus 87b6511
--- bash-4.0/builtins.h.requires	2009-01-04 20:32:23.000000000 +0100
Roman Rakus 87b6511
+++ bash-4.0/builtins.h	2009-01-21 16:10:39.000000000 +0100
Roman Rakus 87b6511
@@ -41,6 +41,8 @@
Roman Rakus 87b6511
 #define SPECIAL_BUILTIN 0x08	/* This is a Posix `special' builtin. */
Roman Rakus d1932ba
 #define ASSIGNMENT_BUILTIN 0x10	/* This builtin takes assignment statements. */
Roman Rakus 87b6511
 #define POSIX_BUILTIN	0x20	/* This builtins is special in the Posix command search order. */
Roman Rakus 87b6511
+#define REQUIRES_BUILTIN 0x40	/* This builtin requires other files. */
Roman Rakus 87b6511
+
Roman Rakus d1932ba
 
Roman Rakus d1932ba
 #define BASE_INDENT	4
Roman Rakus d1932ba
 
Roman Rakus 87b6511
diff -up bash-4.0/eval.c.requires bash-4.0/eval.c
Roman Rakus 87b6511
--- bash-4.0/eval.c.requires	2009-01-04 20:32:26.000000000 +0100
Roman Rakus 87b6511
+++ bash-4.0/eval.c	2009-01-21 15:28:16.000000000 +0100
Roman Rakus d1932ba
@@ -53,6 +53,7 @@ extern int last_command_exit_value, stdi
Roman Rakus d1932ba
 extern int need_here_doc;
Roman Rakus d1932ba
 extern int current_command_number, current_command_line_count, line_number;
Roman Rakus d1932ba
 extern int expand_aliases;
Roman Rakus d1932ba
+extern int rpm_requires;
Roman Rakus d1932ba
 
Roman Rakus d1932ba
 static void send_pwd_to_eterm __P((void));
Roman Rakus d1932ba
 static sighandler alrm_catcher __P((int));
Roman Rakus 87b6511
@@ -136,7 +137,7 @@ reader_loop ()
Roman Rakus d1932ba
 
Roman Rakus d1932ba
       if (read_command () == 0)
Roman Rakus d1932ba
 	{
Roman Rakus d1932ba
-	  if (interactive_shell == 0 && read_but_dont_execute)
Roman Rakus d1932ba
+	  if (interactive_shell == 0 && (read_but_dont_execute && !rpm_requires))
Roman Rakus d1932ba
 	    {
Roman Rakus d1932ba
 	      last_command_exit_value = EXECUTION_SUCCESS;
Roman Rakus d1932ba
 	      dispose_command (global_command);
Roman Rakus 87b6511
diff -up bash-4.0/builtins/mkbuiltins.c.requires bash-4.0/builtins/mkbuiltins.c
Roman Rakus 87b6511
--- bash-4.0/builtins/mkbuiltins.c.requires	2009-01-04 20:32:23.000000000 +0100
Roman Rakus 87b6511
+++ bash-4.0/builtins/mkbuiltins.c	2009-01-21 16:16:05.000000000 +0100
Roman Rakus 87b6511
@@ -69,9 +69,15 @@ extern char *strcpy ();
Roman Rakus d1932ba
 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
Roman Rakus d1932ba
 
Roman Rakus d1932ba
 /* Flag values that builtins can have. */
Roman Rakus d1932ba
+/*  These flags are for the C code generator, 
Roman Rakus d1932ba
+    the C which is produced (./builtin.c)
Roman Rakus d1932ba
+    includes the flags definitions found 
Roman Rakus d1932ba
+    in ../builtins.h */
Roman Rakus d1932ba
 #define BUILTIN_FLAG_SPECIAL	0x01
Roman Rakus d1932ba
 #define BUILTIN_FLAG_ASSIGNMENT 0x02
Roman Rakus 87b6511
 #define BUILTIN_FLAG_POSIX_BUILTIN 0x04
Roman Rakus 87b6511
+#define BUILTIN_FLAG_REQUIRES	0x08
Roman Rakus 87b6511
+
Roman Rakus d1932ba
 
Roman Rakus d1932ba
 #define BASE_INDENT	4
Roman Rakus d1932ba
 
Roman Rakus 87b6511
@@ -163,10 +169,18 @@ char *posix_builtins[] =
Roman Rakus d1932ba
   (char *)NULL
Roman Rakus d1932ba
 };
Roman Rakus d1932ba
 
Roman Rakus d1932ba
+/* The builtin commands that cause requirements on other files. */
Roman Rakus d1932ba
+static char *requires_builtins[] =
Roman Rakus d1932ba
+{
Roman Rakus d1932ba
+  ".", "command", "exec", "source", "inlib",
Roman Rakus d1932ba
+  (char *)NULL
Roman Rakus d1932ba
+};
6353abb
+
Roman Rakus d1932ba
 /* Forward declarations. */
Roman Rakus d1932ba
 static int is_special_builtin ();
Roman Rakus d1932ba
 static int is_assignment_builtin ();
Roman Rakus 87b6511
 static int is_posix_builtin ();
Roman Rakus d1932ba
+static int is_requires_builtin ();
Roman Rakus d1932ba
 
Roman Rakus d1932ba
 #if !defined (HAVE_RENAME)
Roman Rakus d1932ba
 static int rename ();
Roman Rakus 87b6511
@@ -812,6 +826,9 @@ builtin_handler (self, defs, arg)
Roman Rakus d1932ba
     new->flags |= BUILTIN_FLAG_ASSIGNMENT;
Roman Rakus 87b6511
   if (is_posix_builtin (name))
Roman Rakus 87b6511
     new->flags |= BUILTIN_FLAG_POSIX_BUILTIN;
Roman Rakus d1932ba
+  if (is_requires_builtin (name))
Roman Rakus d1932ba
+    new->flags |= BUILTIN_FLAG_REQUIRES;
Roman Rakus 87b6511
+
6353abb
 
Roman Rakus d1932ba
   array_add ((char *)new, defs->builtins);
Roman Rakus d1932ba
   building_builtin = 1;
Roman Rakus 87b6511
@@ -1229,11 +1246,12 @@ write_builtins (defs, structfile, extern
Roman Rakus d1932ba
 		  else
Roman Rakus d1932ba
 		    fprintf (structfile, "(sh_builtin_func_t *)0x0, ");
Roman Rakus d1932ba
 
Roman Rakus 87b6511
-		  fprintf (structfile, "%s%s%s%s, %s_doc,\n",
Roman Rakus 87b6511
+		  fprintf (structfile, "%s%s%s%s%s, %s_doc,\n",
Roman Rakus d1932ba
 		    "BUILTIN_ENABLED | STATIC_BUILTIN",
Roman Rakus d1932ba
 		    (builtin->flags & BUILTIN_FLAG_SPECIAL) ? " | SPECIAL_BUILTIN" : "",
Roman Rakus d1932ba
 		    (builtin->flags & BUILTIN_FLAG_ASSIGNMENT) ? " | ASSIGNMENT_BUILTIN" : "",
Roman Rakus 87b6511
 		    (builtin->flags & BUILTIN_FLAG_POSIX_BUILTIN) ? " | POSIX_BUILTIN" : "",
Roman Rakus d1932ba
+		    (builtin->flags & BUILTIN_FLAG_REQUIRES) ? " | REQUIRES_BUILTIN" : "",
Roman Rakus d1932ba
 		    document_name (builtin));
Roman Rakus d1932ba
 
Roman Rakus d1932ba
 		  fprintf
Roman Rakus 87b6511
@@ -1581,6 +1599,13 @@ is_posix_builtin (name)
Roman Rakus 87b6511
   return (_find_in_table (name, posix_builtins));
Roman Rakus d1932ba
 }
Roman Rakus d1932ba
 
Roman Rakus d1932ba
+static int
Roman Rakus d1932ba
+is_requires_builtin (name)
Roman Rakus d1932ba
+     char *name;
Roman Rakus d1932ba
+{
Roman Rakus d1932ba
+  return (_find_in_table (name, requires_builtins));
Roman Rakus d1932ba
+}
Roman Rakus d1932ba
+
Roman Rakus d1932ba
 #if !defined (HAVE_RENAME)
Roman Rakus d1932ba
 static int
Roman Rakus d1932ba
 rename (from, to)