]> git.pld-linux.org Git - packages/bash.git/blobdiff - bash-requires.patch
- up to 4.4.5
[packages/bash.git] / bash-requires.patch
index 1e31e75aee691311d1971d975cb69e1e1a0bd7f7..ad58ecbe643f585a756da60bd3b83d0a978978f3 100644 (file)
@@ -1,15 +1,19 @@
-
-Here it is.  If you like it let me know and I will send the patches to 
-the bash maintainer.  Let me know what you think.
-
-Ken
-
-
-
-diff -r -u bash-2.03.orig/builtins/mkbuiltins.c bash-2.03.new/builtins/mkbuiltins.c
---- bash-2.03.orig/builtins/mkbuiltins.c       Tue Sep 15 12:57:16 1998
-+++ bash-2.03.new/builtins/mkbuiltins.c        Fri Jul 16 10:45:54 1999
-@@ -51,8 +51,13 @@
+diff -up bash-4.1/builtins.h.requires bash-4.1/builtins.h
+--- bash-4.1/builtins.h.requires       2009-01-04 20:32:23.000000000 +0100
++++ bash-4.1/builtins.h        2010-08-02 17:42:41.000000000 +0200
+@@ -41,6 +41,8 @@
+ #define ASSIGNMENT_BUILTIN 0x10       /* This builtin takes assignment statements. */
+ #define POSIX_BUILTIN 0x20    /* This builtins is special in the Posix command search order. */
+ #define LOCALVAR_BUILTIN   0x40       /* This builtin creates local variables */
++#define REQUIRES_BUILTIN 0x80 /* This builtin requires other files. */
++
+ #define BASE_INDENT   4
+diff -up bash-4.1/builtins/mkbuiltins.c.requires bash-4.1/builtins/mkbuiltins.c
+--- bash-4.1/builtins/mkbuiltins.c.requires    2009-01-04 20:32:23.000000000 +0100
++++ bash-4.1/builtins/mkbuiltins.c     2010-08-02 17:42:41.000000000 +0200
+@@ -69,10 +69,16 @@ extern char *strcpy ();
  #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
  
  /* Flag values that builtins can have. */
@@ -19,16 +23,19 @@ diff -r -u bash-2.03.orig/builtins/mkbuiltins.c bash-2.03.new/builtins/mkbuiltin
 +    in ../builtins.h */
  #define BUILTIN_FLAG_SPECIAL  0x01
  #define BUILTIN_FLAG_ASSIGNMENT 0x02
-+#define BUILTIN_FLAG_REQUIRES 0x04
+ #define BUILTIN_FLAG_LOCALVAR 0x04
+ #define BUILTIN_FLAG_POSIX_BUILTIN 0x08
++#define BUILTIN_FLAG_REQUIRES 0x10
++
+ #define BASE_INDENT   4
  
- /* If this stream descriptor is non-zero, then write
-    texinfo documentation to it. */
-@@ -126,9 +131,17 @@
+@@ -163,10 +169,18 @@ char *posix_builtins[] =
    (char *)NULL
  };
  
 +/* The builtin commands that cause requirements on other files. */
-+char *requires_builtins[] =
++static char *requires_builtins[] =
 +{
 +  ".", "command", "exec", "source", "inlib",
 +  (char *)NULL
@@ -37,61 +44,54 @@ diff -r -u bash-2.03.orig/builtins/mkbuiltins.c bash-2.03.new/builtins/mkbuiltin
  /* Forward declarations. */
  static int is_special_builtin ();
  static int is_assignment_builtin ();
+ static int is_localvar_builtin ();
+ static int is_posix_builtin ();
 +static int is_requires_builtin ();
  
  #if !defined (HAVE_RENAME)
- static int rename ();
-@@ -759,6 +772,8 @@
-     new->flags |= BUILTIN_FLAG_SPECIAL;
-   if (is_assignment_builtin (name))
+@@ -812,6 +826,9 @@ builtin_handler (self, defs, arg)
      new->flags |= BUILTIN_FLAG_ASSIGNMENT;
+   if (is_posix_builtin (name))
+     new->flags |= BUILTIN_FLAG_POSIX_BUILTIN;
 +  if (is_requires_builtin (name))
 +    new->flags |= BUILTIN_FLAG_REQUIRES;
++
  
    array_add ((char *)new, defs->builtins);
    building_builtin = 1;
-@@ -1164,10 +1179,11 @@
+@@ -1267,12 +1267,13 @@ write_builtins (defs, structfile, extern
                  else
-                   fprintf (structfile, "(Function *)0x0, ");
+                   fprintf (structfile, "(sh_builtin_func_t *)0x0, ");
  
--                fprintf (structfile, "%s%s%s, %s_doc,\n",
-+                fprintf (structfile, "%s%s%s%s, %s_doc,\n",
+-                fprintf (structfile, "%s%s%s%s%s, %s_doc,\n",
++                fprintf (structfile, "%s%s%s%s%s%s, %s_doc,\n",
                    "BUILTIN_ENABLED | STATIC_BUILTIN",
                    (builtin->flags & BUILTIN_FLAG_SPECIAL) ? " | SPECIAL_BUILTIN" : "",
                    (builtin->flags & BUILTIN_FLAG_ASSIGNMENT) ? " | ASSIGNMENT_BUILTIN" : "",
+                   (builtin->flags & BUILTIN_FLAG_LOCALVAR) ? " | LOCALVAR_BUILTIN" : "",
+                   (builtin->flags & BUILTIN_FLAG_POSIX_BUILTIN) ? " | POSIX_BUILTIN" : "",
 +                  (builtin->flags & BUILTIN_FLAG_REQUIRES) ? " | REQUIRES_BUILTIN" : "",
-                   builtin->docname ? builtin->docname : builtin->name);
+                   document_name (builtin));
+                 /* Don't translate short document summaries that are identical
+@@ -1581,6 +1599,13 @@ is_posix_builtin (name)
+   return (_find_in_table (name, posix_builtins));
+ }
  
-                 fprintf
-@@ -1401,6 +1417,13 @@
-      char *name;
- {
-   return (_find_in_table (name, assignment_builtins));
-+}
-+
 +static int
 +is_requires_builtin (name)
 +     char *name;
 +{
 +  return (_find_in_table (name, requires_builtins));
- }
++}
++
  #if !defined (HAVE_RENAME)
-diff -r -u bash-2.03.orig/builtins.h bash-2.03.new/builtins.h
---- bash-2.03.orig/builtins.h  Fri Jul 18 16:46:36 1997
-+++ bash-2.03.new/builtins.h   Thu Jul 15 16:59:03 1999
-@@ -40,6 +40,7 @@
- #define STATIC_BUILTIN  0x4   /* This builtin is not dynamically loaded. */
- #define SPECIAL_BUILTIN 0x8   /* This is a Posix `special' builtin. */
- #define ASSIGNMENT_BUILTIN 0x10       /* This builtin takes assignment statements. */
-+#define REQUIRES_BUILTIN 0x20 /* This builtin requires other files. */
- /* The thing that we build the array of builtins out of. */
- struct builtin {
-diff -r -u bash-2.03.orig/doc/bash.1 bash-2.03.new/doc/bash.1
---- bash-2.03.orig/doc/bash.1  Wed Jan 20 16:48:04 1999
-+++ bash-2.03.new/doc/bash.1   Fri Jul 16 11:20:00 1999
-@@ -195,6 +195,12 @@
+ static int
+ rename (from, to)
+diff -up bash-4.1/doc/bash.1.requires bash-4.1/doc/bash.1
+--- bash-4.1/doc/bash.1.requires       2010-08-02 17:42:41.000000000 +0200
++++ bash-4.1/doc/bash.1        2010-08-02 18:09:27.000000000 +0200
+@@ -231,6 +231,14 @@ The shell becomes restricted (see
  .B "RESTRICTED SHELL"
  below).
  .TP
@@ -99,15 +99,17 @@ diff -r -u bash-2.03.orig/doc/bash.1 bash-2.03.new/doc/bash.1
 +Produce the list of files that are required for the 
 +shell script to run.  This implies '-n' and is subject
 +to the same limitations as compile time error checking checking;
-+Backticks, [] tests,  and evals are not parsed so some 
-+dependencies may be missed.
++Command substitutions, Conditional expressions and
++.BR eval
++builtin are not parsed so some dependencies may be missed.
++.TP
  .B \-\-verbose
  Equivalent to  \fB\-v\fP.
  .TP
-diff -r -u bash-2.03.orig/doc/bashref.texi bash-2.03.new/doc/bashref.texi
---- bash-2.03.orig/doc/bashref.texi    Wed Jan 20 16:47:01 1999
-+++ bash-2.03.new/doc/bashref.texi     Fri Jul 16 11:21:30 1999
-@@ -3178,6 +3178,13 @@
+diff -up bash-4.1/doc/bashref.texi.requires bash-4.1/doc/bashref.texi
+--- bash-4.1/doc/bashref.texi.requires 2010-08-02 17:42:41.000000000 +0200
++++ bash-4.1/doc/bashref.texi  2010-08-02 18:11:58.000000000 +0200
+@@ -5343,6 +5343,13 @@ standard.  @xref{Bash POSIX Mode}, for a
  @item --restricted
  Make the shell a restricted shell (@pxref{The Restricted Shell}).
  
@@ -115,62 +117,143 @@ diff -r -u bash-2.03.orig/doc/bashref.texi bash-2.03.new/doc/bashref.texi
 +Produce the list of files that are required for the 
 +shell script to run.  This implies '-n' and is subject
 +to the same limitations as compile time error checking checking;
-+Backticks, [] tests,  and evals are not parsed so some 
-+dependencies may be missed.
++Command substitutions, Conditional expressions and @command{eval}
++are not parsed so some dependencies may be missed.
 +
  @item --verbose
- Equivalent to @samp{-v}.
+ Equivalent to @option{-v}.  Print shell input lines as they're read.
+diff -up bash-4.1/eval.c.requires bash-4.1/eval.c
+--- bash-4.1/eval.c.requires   2009-01-04 20:32:26.000000000 +0100
++++ bash-4.1/eval.c    2010-08-02 17:42:41.000000000 +0200
+@@ -53,6 +53,7 @@ extern int last_command_exit_value, stdi
+ extern int current_command_number, current_command_line_count, line_number;
+ extern int expand_aliases;
++extern int rpm_requires;
+ extern char *ps0_prompt;
+ #if defined (HAVE_POSIX_SIGNALS)
+ extern sigset_t top_level_mask;
+@@ -136,7 +137,7 @@ reader_loop ()
+       if (read_command () == 0)
+       {
+-        if (interactive_shell == 0 && read_but_dont_execute)
++        if (interactive_shell == 0 && (read_but_dont_execute && !rpm_requires))
+           {
+             last_command_exit_value = EXECUTION_SUCCESS;
+             dispose_command (global_command);
+diff -up bash-4.1/execute_cmd.c.requires bash-4.1/execute_cmd.c
+--- bash-4.1/execute_cmd.c.requires    2010-08-02 17:42:41.000000000 +0200
++++ bash-4.1/execute_cmd.c     2010-08-02 17:42:41.000000000 +0200
+@@ -503,6 +503,8 @@ async_redirect_stdin ()
+ #define DESCRIBE_PID(pid) do { if (interactive) describe_pid (pid); } while (0)
++extern int rpm_requires;
++
+ /* Execute the command passed in COMMAND, perhaps doing it asynchronously.
+    COMMAND is exactly what read_command () places into GLOBAL_COMMAND.
+    ASYNCHROUNOUS, if non-zero, says to do this command in the background.
+@@ -534,7 +536,13 @@ execute_command_internal (command, async
  
-diff -r -u bash-2.03.orig/make_cmd.c bash-2.03.new/make_cmd.c
---- bash-2.03.orig/make_cmd.c  Tue Jan 12 12:45:36 1999
-+++ bash-2.03.new/make_cmd.c   Fri Jul 16 11:48:18 1999
-@@ -41,6 +41,7 @@
+   if (breaking || continuing)
+     return (last_command_exit_value);
+-  if (command == 0 || read_but_dont_execute)
++  if (command == 0 || (read_but_dont_execute && !rpm_requires))
++    return (EXECUTION_SUCCESS);
++  if (rpm_requires && command->type == cm_function_def)
++    return last_command_exit_value =
++      execute_intern_function (command->value.Function_def->name,
++                              command->value.Function_def);
++  if (read_but_dont_execute)
+     return (EXECUTION_SUCCESS);
+   QUIT;
+@@ -5066,7 +5074,7 @@ execute_intern_function (name, function)
+   if (check_identifier (name, posixly_correct) == 0)
+     {
+-      if (posixly_correct && interactive_shell == 0)
++      if (posixly_correct && interactive_shell == 0 && rpm_requires == 0)
+       {
+         last_command_exit_value = EX_BADUSAGE;
+         jump_to_top_level (ERREXIT);
+diff -up bash-4.1/execute_cmd.h.requires bash-4.1/execute_cmd.h
+--- bash-4.1/execute_cmd.h.requires    2009-01-16 22:20:15.000000000 +0100
++++ bash-4.1/execute_cmd.h     2010-08-02 17:42:41.000000000 +0200
+@@ -22,6 +22,8 @@
+ #define _EXECUTE_CMD_H_
+ #include "stdc.h"
++#include "variables.h"
++#include "command.h"
+ extern struct fd_bitmap *new_fd_bitmap __P((int));
+ extern void dispose_fd_bitmap __P((struct fd_bitmap *));
+diff -up bash-4.1/make_cmd.c.requires bash-4.1/make_cmd.c
+--- bash-4.1/make_cmd.c.requires       2009-09-11 23:26:12.000000000 +0200
++++ bash-4.1/make_cmd.c        2010-08-02 17:42:41.000000000 +0200
+@@ -42,11 +42,15 @@
+ #include "flags.h"
+ #include "make_cmd.h"
+ #include "dispose_cmd.h"
++#include "execute_cmd.h"
+ #include "variables.h"
  #include "subst.h"
  #include "input.h"
+ #include "ocache.h"
  #include "externs.h"
 +#include "builtins.h"
++
++#include "builtins/common.h"
  
  #if defined (JOB_CONTROL)
  #include "jobs.h"
-@@ -48,6 +49,7 @@
- extern int line_number, current_command_line_count;
- extern int disallow_filename_globbing;
+@@ -56,6 +60,10 @@
+ extern int line_number, current_command_line_count, parser_state;
+ extern int last_command_exit_value;
+ extern int shell_initialized;
 +extern int rpm_requires;
++
++static char *alphabet_set = "abcdefghijklmnopqrstuvwxyz"
++                     "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  
- WORD_DESC *
- make_bare_word (string)
-@@ -588,6 +590,24 @@
-   return (make_command (cm_function_def, (SIMPLE_COM *)temp));
+ /* Object caching */
+ sh_obj_cache_t wdcache = {0, 0, 0};
+@@ -820,6 +828,27 @@ make_coproc_command (name, command)
+   return (make_command (cm_coproc, (SIMPLE_COM *)temp));
  }
  
-+void
-+output_requirement (file)
-+char *file;
++static void
++output_requirement (deptype, filename)
++const char *deptype;
++char *filename;
 +{
-+  if (file[0] != '/') {
-+    /* if we are not given a full path name we require the basename
-+       otherwise we require the full path.  This does not work in the
-+       Win/Dos world but I don't know what to do there.*/
-+    char *basename;
-+    basename = strrchr(file, '/');
-+    if (basename) {    
-+      basename++;
-+      file=basename;
-+    }
-+  }  
-+  printf ("bash(%s)\n", file);
++  if (strchr(filename, '$') || (filename[0] != '/' && strchr(filename, '/')))
++    return;
++
++  /* 
++      if the executable is called via variable substitution we can
++      not dermine what it is at compile time.  
++
++      if the executable consists only of characters not in the
++      alphabet we do not consider it a dependency just an artifact
++      of shell parsing (ex "exec < ${infile}").
++  */
++
++  if (strpbrk(filename, alphabet_set))
++    printf ("%s(%s)\n", deptype, filename);
 +}
 +
  /* Reverse the word list and redirection list in the simple command
     has just been parsed.  It seems simpler to do this here the one
     time then by any other method that I can think of. */
-@@ -604,6 +624,25 @@
-       command->value.Simple->redirects =
+@@ -837,6 +866,27 @@ clean_simple_command (command)
        REVERSE_LIST (command->value.Simple->redirects, REDIRECT *);
      }
-+
-+  if (rpm_requires)
++  if (rpm_requires && command->value.Simple->words)
 +    {
 +      char *cmd0;
 +      char *cmd1;
@@ -178,23 +261,26 @@ diff -r -u bash-2.03.orig/make_cmd.c bash-2.03.new/make_cmd.c
 +
 +      cmd0 = command->value.Simple->words->word->word;
 +      b = builtin_address_internal (cmd0, 0);
++      cmd1 = 0;
++      if (command->value.Simple->words->next)
++        cmd1 = command->value.Simple->words->next->word->word;
++
 +      if (b) {
-+      if (b->flags & REQUIRES_BUILTIN){
-+        cmd1 = command->value.Simple->words->next->word->word;
-+        output_requirement(cmd1);
-+      }
++        if ( (b->flags & REQUIRES_BUILTIN) && cmd1)
++          output_requirement ("executable", cmd1);
 +      } else {
-+      if (!assignment(cmd0))
-+        output_requirement(cmd0);
++        if (!assignment(cmd0, 0))
++          output_requirement (find_function(cmd0) ? "function" : "executable", cmd0);
 +      }
 +    } /*rpm_requires*/
++
+   parser_state &= ~PST_REDIRLIST;
    return (command);
  }
-diff -r -u bash-2.03.orig/shell.c bash-2.03.new/shell.c
---- bash-2.03.orig/shell.c     Thu Feb 18 11:42:27 1999
-+++ bash-2.03.new/shell.c      Fri Jul 16 11:30:57 1999
-@@ -170,6 +170,9 @@
+diff -up bash-4.1/shell.c.requires bash-4.1/shell.c
+--- bash-4.1/shell.c.requires  2010-08-02 17:42:41.000000000 +0200
++++ bash-4.1/shell.c   2010-08-02 17:42:41.000000000 +0200
+@@ -193,6 +193,9 @@ int have_devfd = 0;
  /* The name of the .(shell)rc file. */
  static char *bashrc_file = "~/.bashrc";
  
@@ -204,26 +290,24 @@ diff -r -u bash-2.03.orig/shell.c bash-2.03.new/shell.c
  /* Non-zero means to act more like the Bourne shell on startup. */
  static int act_like_sh;
  
-@@ -215,6 +218,7 @@
-   { "norc", Int, &no_rc, (char **)0x0 },
-   { "posix", Int, &posixly_correct, (char **)0x0 },
+@@ -251,6 +254,7 @@ static const struct {
+   { "protected", Int, &protected_mode, (char **)0x0 },
+ #endif
    { "rcfile", Charp, (int *)0x0, &bashrc_file },
 +  { "rpm-requires", Int, &rpm_requires, (char **)0x0 },
  #if defined (RESTRICTED_SHELL)
    { "restricted", Int, &restricted, (char **)0x0 },
  #endif
-@@ -398,6 +402,12 @@
+@@ -485,6 +489,12 @@ main (argc, argv, env)
    if (dump_translatable_strings)
      read_but_dont_execute = 1;
-+
 +  if (rpm_requires)
 +    {
 +      read_but_dont_execute = 1;
 +      initialize_shell_builtins ();
 +    }
++
    if (running_setuid && privileged_mode == 0)
      disable_priv_mode ();
-
-
This page took 0.060378 seconds and 4 git commands to generate.