]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
commit bash-20070530 snapshot
authorChet Ramey <chet.ramey@case.edu>
Wed, 7 Dec 2011 14:08:44 +0000 (09:08 -0500)
committerChet Ramey <chet.ramey@case.edu>
Wed, 7 Dec 2011 14:08:44 +0000 (09:08 -0500)
16 files changed:
CWRU/CWRU.chlog
CWRU/CWRU.chlog~
MANIFEST
arrayfunc.c
arrayfunc.c~
builtins/mkbuiltins.c
builtins/mkbuiltins.c~
builtins/reserved.def
doc/FAQ
doc/FAQ~
doc/bash.1
jobs.c
jobs.c~
subst.c
subst.c~
tests/RUN-ONE-TEST

index 61aafbca4989a841053c287e140bd591aa5eabbc..b4e572686fcf9cd63fde27490b394fc5eb19f113 100644 (file)
@@ -14699,3 +14699,29 @@ error.c
        - in get_name_for_error, use dollar_vars[0] if the name returned from
          looking in $BASH_SOURCE[0] is the empty string as well as if it's
          null
+
+                                  5/31
+                                  ----
+arrayfunc.c
+       - change array_value_internal to set *RTYPE to 1 if the reference is
+         array[*] and 2 if the reference is array[@]
+
+subst.c
+       - in parameter_brace_expand_word, set the flags returned by the word
+         desc to include W_HASQUOTEDNULL if array_value returns QUOTED_NULL
+         for an array reference like x[*] and the word is quoted.  Fixes bug
+         reported by Christophe Martin <schplurtz@free.fr>
+
+                                   6/1
+                                   ---
+jobs.c
+       - several changes to preserve errno if tcgetpgrp/tcgetattr/tcsetattr
+         fail, for subsequent error messages
+       - change initialize_job_control to turn off job control if the terminal
+         pgrp == -1 or is not equal to shell_pgrp (with an error message)
+       - in initialize_job_control, if the shell has been forced interactive
+         with -i, make sure stderr is hooked to a tty before using it as
+         the controlling terminal.  If it's not, try to open /dev/tty and
+         assign it to shell_tty.  Fixes problems reported by Derek Fawcus
+         <dfawcus@cisco.com>
+         
index 09f9fbd398d13d40fbb8d250dccc6a6bdc0f4daf..07b3b86366ebf8acbefa203a3bbf7315223b20c3 100644 (file)
@@ -14694,3 +14694,28 @@ variables.c,builtins/{declare,setattr,type}.def
 builtins/help.def
        - fix bug in `help' two-column printing to avoid referencing
          shell_builtins[num_shell_builtins]
+
+error.c
+       - in get_name_for_error, use dollar_vars[0] if the name returned from
+         looking in $BASH_SOURCE[0] is the empty string as well as if it's
+         null
+
+                                  5/31
+                                  ----
+arrayfunc.c
+       - change array_value_internal to set *RTYPE to 1 if the reference is
+         array[*] and 2 if the reference is array[@]
+
+subst.c
+       - in parameter_brace_expand_word, set the flags returned by the word
+         desc to include W_HASQUOTEDNULL if array_value returns QUOTED_NULL
+         for an array reference like x[*] and the word is quoted.  Fixes bug
+         reported by Christophe Martin <schplurtz@free.fr>
+
+                                   6/1
+                                   ---
+jobs.c
+       - several changes to preserve errno if tcgetpgrp/tcgetattr/tcsetattr
+         fail, for subsequent error messages
+       - change initialize_job_control to turn off job control if the terminal
+         pgrp == -1 or is not equal to shell_pgrp (with an error message)
index 732527dd21b0b5bf06b7066d7f9b1be62695e166..e788f4ff9d6426131a173b97b9da70587374b964 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -751,6 +751,7 @@ tests/exec4.sub             f
 tests/exec5.sub                f
 tests/exec6.sub                f
 tests/exec7.sub                f
+tests/exec8.sub                f
 tests/exp.tests                f
 tests/exp.right                f
 tests/exp1.sub         f
index 36727a3ce327e4d1bd78ec5f6c0019ed74d25da9..98208bafe773a3f6d438855e6bf477f77c43130f 100644 (file)
@@ -693,8 +693,8 @@ array_variable_part (s, subp, lenp)
 /* Return a string containing the elements in the array and subscript
    described by S.  If the subscript is * or @, obeys quoting rules akin
    to the expansion of $* and $@ including double quoting.  If RTYPE
-   is non-null it gets 1 if the array reference is name[@] or name[*]
-   and 0 otherwise. */
+   is non-null it gets 1 if the array reference is name[*], 2 if the
+   reference is name[@], and 0 otherwise. */
 static char *
 array_value_internal (s, quoted, allow_all, rtype)
      char *s;
@@ -722,7 +722,7 @@ array_value_internal (s, quoted, allow_all, rtype)
   if (ALL_ELEMENT_SUB (t[0]) && t[1] == ']')
     {
       if (rtype)
-       *rtype = 1;
+       *rtype = (t[0] == '*') ? 1 : 2;
       if (allow_all == 0)
        {
          err_badarraysub (s);
index 7a6904d99168f10c3fa322251d3ada684c476a60..36727a3ce327e4d1bd78ec5f6c0019ed74d25da9 100644 (file)
@@ -618,6 +618,8 @@ array_expand_index (s, len)
   if (expok == 0)
     {
       last_command_exit_value = EXECUTION_FAILURE;
+
+      top_level_cleanup ();      
       jump_to_top_level (DISCARD);
     }
   return val;
index 3923b8a06d67df1c22e46abfd5ca507a3fc0fabe..8ebed4bad65e1f3109f305d6cccd3d4f5c35ec63 100644 (file)
@@ -1,7 +1,7 @@
 /* mkbuiltins.c - Create builtins.c, builtext.h, and builtdoc.c from
    a single source file called builtins.def. */
 
-/* Copyright (C) 1987-2006 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2007 Free Software Foundation, Inc.
 
 This file is part of GNU Bash, the Bourne Again SHell.
 
@@ -1080,7 +1080,7 @@ char *structfile_header[] = {
   "/* This file is manufactured by ./mkbuiltins, and should not be",
   "   edited by hand.  See the source to mkbuiltins for details. */",
   "",
-  "/* Copyright (C) 1987-2002 Free Software Foundation, Inc.",
+  "/* Copyright (C) 1987-2007 Free Software Foundation, Inc.",
   "",
   "   This file is part of GNU Bash, the Bourne Again SHell.",
   "",
index 8c737f8ccd84becd38c6e98d5b2c96520e2a89aa..3923b8a06d67df1c22e46abfd5ca507a3fc0fabe 100644 (file)
@@ -1224,7 +1224,7 @@ write_builtins (defs, structfile, externfile)
                    document_name (builtin));
 
                  fprintf
-                   (structfile, "N_(     \"%s\"), (char *)NULL },\n",
+                   (structfile, "     N_(\"%s\"), (char *)NULL },\n",
                     builtin->shortdoc ? builtin->shortdoc : builtin->name);
 
                }
index 8b598b046274ee7191c1a773fc5a7bf3de384179..3a14ad2e5976f3c2083655aaa4bffde04a69b5d4 100644 (file)
@@ -148,7 +148,7 @@ $DOCNAME variable_help
 $SHORT_DOC variables - Names and meanings of some shell variables
 BASH_VERSION   Version information for this Bash.
 CDPATH A colon-separated list of directories to search
-               for directries given as arguments to `cd'.
+               for directories given as arguments to `cd'.
 GLOBIGNORE     A colon-separated list of patterns describing filenames to
                be ignored by pathname expansion.
 #if defined (HISTORY)
diff --git a/doc/FAQ b/doc/FAQ
index b2cf391757fbcd20e6c141c844c8e5ef617bd600..4cebba0942b7b0518c9ebd4743d263020e3375c6 100644 (file)
--- a/doc/FAQ
+++ b/doc/FAQ
@@ -1774,7 +1774,12 @@ this:
        echo .!(.|) *
 
 A solution that works without extended globbing is given in the Unix Shell
-FAQ, posted periodically to comp.unix.shell.
+FAQ, posted periodically to comp.unix.shell.  It's a variant of
+
+       echo .[!.]* ..?* *
+
+(The ..?* catches files with names of three or more characters beginning
+with `..')
 
 Section H:  Where do I go from here?
 
index dd3ea566af60df19ec8281b0435ba49d123b26a1..b2cf391757fbcd20e6c141c844c8e5ef617bd600 100644 (file)
--- a/doc/FAQ~
+++ b/doc/FAQ~
@@ -1,4 +1,4 @@
-This is the Bash FAQ, version 3.35, for Bash version 3.2.
+This is the Bash FAQ, version 3.36, for Bash version 3.2.
 
 This document contains a set of frequently-asked questions concerning
 Bash, the GNU Bourne-Again Shell.  Bash is a freely-available command
@@ -79,6 +79,8 @@ E11) If I resize my xterm while another program is running, why doesn't bash
      notice the change?
 E12) Why don't negative offsets in substring expansion work like I expect?
 E13) Why does filename completion misbehave if a colon appears in the filename?
+E14) Why does quoting the pattern argument to the regular expression matching
+     conditional operator (=~) cause matching to stop working?
 
 Section F:  Things to watch out for on certain Unix versions
 
@@ -1427,6 +1429,34 @@ COMP_WORDBREAKS=${COMP_WORDBREAKS//:}
 You can also quote the colon with a backslash to achieve the same result
 temporarily.
 
+E14) Why does quoting the pattern argument to the regular expression matching
+     conditional operator (=~) cause regexp matching to stop working?
+
+In versions of bash prior to bash-3.2, the effect of quoting the regular
+expression argument to the [[ command's =~ operator was not specified.
+The practical effect was that double-quoting the pattern argument required
+backslashes to quote special pattern characters, which interfered with the
+backslash processing performed by double-quoted word expansion and was
+inconsistent with how the == shell pattern matching operator treated
+quoted characters.
+
+In bash-3.2, the shell was changed to internally quote characters in single-
+and double-quoted string arguments to the =~ operator, which suppresses the
+special meaning of the characters special to regular expression processing
+(`.', `[', `\', `(', `), `*', `+', `?', `{', `|', `^', and `$') and forces
+them to be matched literally.  This is consistent with how the `==' pattern
+matching operator treats quoted portions of its pattern argument.
+
+Since the treatment of quoted string arguments was changed, several issues
+have arisen, chief among them the problem of white space in pattern arguments
+and the differing treatment of quoted strings between bash-3.1 and bash-3.2.
+Both problems may be solved by using a shell variable to hold the pattern.
+Since word splitting is not performed when expanding shell variables in all
+operands of the [[ command, this allows users to quote patterns as they wish
+when assigning the variable, then expand the values to a single string that
+may contain whitespace.  The first problem may be solved by using backslashes
+or any other quoting mechanism to escape the white space in the patterns.
+
 Section F:  Things to watch out for on certain Unix versions
 
 F1) Why can't I use command line editing in my `cmdtool'?
index 5a3d2ee581195c3ee9d14898ef061f19d3bc6675..689de6a1e192ed0261b128e82e636580d93399c7 100644 (file)
@@ -577,7 +577,7 @@ and
 have equal precedence, followed by
 .B ;
 and
-.BR &,
+.BR & ,
 which have equal precedence.
 .PP
 A sequence of one or more newlines may appear in a \fIlist\fP instead
diff --git a/jobs.c b/jobs.c
index 079b54fb5d18e55d0fa02fa25aa513c3f8e05cc7..d94cc5fa3ad8510363eb99b328e62f8f2ba4e2ae 100644 (file)
--- a/jobs.c
+++ b/jobs.c
@@ -1967,7 +1967,7 @@ get_tty_state ()
          /* Only print an error message if we're really interactive at
             this time. */
          if (interactive)
-           sys_error ("[%ld: %d] tcgetattr", (long)getpid (), shell_level);
+           sys_error ("[%ld: %d (%d)] tcgetattr", (long)getpid (), shell_level, tty);
 #endif
          return -1;
        }
@@ -2006,7 +2006,7 @@ set_tty_state ()
          /* Only print an error message if we're really interactive at
             this time. */
          if (interactive)
-           sys_error ("[%ld: %d] tcsetattr", (long)getpid (), shell_level);
+           sys_error ("[%ld: %d (%d)] tcsetattr", (long)getpid (), shell_level, tty);
          return -1;
        }
 #endif /* TERMIOS_TTY_DRIVER */
@@ -3477,6 +3477,10 @@ int
 initialize_job_control (force)
      int force;
 {
+  pid_t t;
+  int t_errno;
+
+  t_errno = -1;
   shell_pgrp = getpgid (0);
 
   if (shell_pgrp == -1)
@@ -3494,10 +3498,21 @@ initialize_job_control (force)
     }
   else
     {
+      shell_tty = -1;
+
+      /* If forced_interactive is set, we skip the normal check that stderr
+        is attached to a tty, so we need to check here.  If it's not, we
+        need to see whether we have a controlling tty by opening /dev/tty,
+        since trying to use job control tty pgrp manipulations on a non-tty
+        is going to fail. */
+      if (forced_interactive && isatty (fileno (stderr)) == 0)
+       shell_tty = open ("/dev/tty", O_RDWR|O_NONBLOCK);
+
       /* Get our controlling terminal.  If job_control is set, or
         interactive is set, then this is an interactive shell no
         matter where fd 2 is directed. */
-      shell_tty = dup (fileno (stderr));       /* fd 2 */
+      if (shell_tty == -1)
+       shell_tty = dup (fileno (stderr));      /* fd 2 */
 
       shell_tty = move_to_high_fd (shell_tty, 1, -1);
 
@@ -3524,6 +3539,9 @@ initialize_job_control (force)
          break;
        }
 
+      if (terminal_pgrp == -1)
+       t_errno = errno;
+
       /* Make sure that we are using the new line discipline. */
       if (set_new_line_discipline (shell_tty) < 0)
        {
@@ -3554,11 +3572,20 @@ initialize_job_control (force)
            {
              if (give_terminal_to (shell_pgrp, 0) < 0)
                {
+                 t_errno = errno;
                  setpgid (0, original_pgrp);
                  shell_pgrp = original_pgrp;
                  job_control = 0;
                }
            }
+
+         if (job_control && ((t = tcgetpgrp (shell_tty)) == -1 || t != shell_pgrp))
+           {
+             if (t_errno != -1)
+               errno = t_errno;
+             sys_error (_("cannot set terminal process group (%d)"), t);
+             job_control = 0;
+           }
        }
       if (job_control == 0)
        internal_error (_("no job control in this shell"));
@@ -3708,7 +3735,7 @@ give_terminal_to (pgrp, force)
      int force;
 {
   sigset_t set, oset;
-  int r;
+  int r, e;
 
   r = 0;
   if (job_control || force)
@@ -3729,12 +3756,15 @@ give_terminal_to (pgrp, force)
            shell_tty, (long)getpid(), (long)pgrp);
 #endif
          r = -1;
+         e = errno;
        }
       else
        terminal_pgrp = pgrp;
       sigprocmask (SIG_SETMASK, &oset, (sigset_t *)NULL);
     }
 
+  if (r == -1)
+    errno = e;
   return r;
 }
 
diff --git a/jobs.c~ b/jobs.c~
index 0ff2d591e86ee9080741c31cf2322976ca98cb18..a5ac4221166490a84e0f57db9db48487e27fa17d 100644 (file)
--- a/jobs.c~
+++ b/jobs.c~
@@ -137,6 +137,8 @@ extern int errno;
 /* The number of additional slots to allocate when we run out. */
 #define JOB_SLOTS 8
 
+#define CTTYFD 2
+
 typedef int sh_job_map_func_t __P((JOB *, int, int, int));
 
 /* Variables used here but defined in other files. */
@@ -1967,7 +1969,7 @@ get_tty_state ()
          /* Only print an error message if we're really interactive at
             this time. */
          if (interactive)
-           sys_error ("[%ld: %d] tcgetattr", (long)getpid (), shell_level);
+           sys_error ("[%ld: %d (%d)] tcgetattr", (long)getpid (), shell_level, tty);
 #endif
          return -1;
        }
@@ -2006,7 +2008,7 @@ set_tty_state ()
          /* Only print an error message if we're really interactive at
             this time. */
          if (interactive)
-           sys_error ("[%ld: %d] tcsetattr", (long)getpid (), shell_level);
+           sys_error ("[%ld: %d (%d)] tcsetattr", (long)getpid (), shell_level, tty);
          return -1;
        }
 #endif /* TERMIOS_TTY_DRIVER */
@@ -3477,6 +3479,10 @@ int
 initialize_job_control (force)
      int force;
 {
+  pid_t t;
+  int t_errno;
+
+  t_errno = -1;
   shell_pgrp = getpgid (0);
 
   if (shell_pgrp == -1)
@@ -3494,10 +3500,15 @@ initialize_job_control (force)
     }
   else
     {
+      shell_tty = -1;
+      if (forced_interactive && isatty (fileno (stderr)) == 0)
+       shell_tty = open ("/dev/tty", O_RDWR|O_NONBLOCK);
+
       /* Get our controlling terminal.  If job_control is set, or
         interactive is set, then this is an interactive shell no
         matter where fd 2 is directed. */
-      shell_tty = dup (fileno (stderr));       /* fd 2 */
+      if (shell_tty == -1)
+       shell_tty = dup (fileno (stderr));      /* fd 2 */
 
       shell_tty = move_to_high_fd (shell_tty, 1, -1);
 
@@ -3524,6 +3535,9 @@ initialize_job_control (force)
          break;
        }
 
+      if (terminal_pgrp == -1)
+       t_errno = errno;
+
       /* Make sure that we are using the new line discipline. */
       if (set_new_line_discipline (shell_tty) < 0)
        {
@@ -3554,12 +3568,20 @@ initialize_job_control (force)
            {
              if (give_terminal_to (shell_pgrp, 0) < 0)
                {
+                 t_errno = errno;
                  setpgid (0, original_pgrp);
                  shell_pgrp = original_pgrp;
                  job_control = 0;
-internal_error ("cannot set terminal pgrp to %d: %s", shell_pgrp, strerror (errno));
                }
            }
+
+         if (job_control && ((t = tcgetpgrp (shell_tty)) == -1 || t != shell_pgrp))
+           {
+             if (t_errno != -1)
+               errno = t_errno;
+             sys_error (_("cannot set terminal process group (%d)"), t);
+             job_control = 0;
+           }
        }
       if (job_control == 0)
        internal_error (_("no job control in this shell"));
@@ -3709,7 +3731,7 @@ give_terminal_to (pgrp, force)
      int force;
 {
   sigset_t set, oset;
-  int r;
+  int r, e;
 
   r = 0;
   if (job_control || force)
@@ -3730,12 +3752,15 @@ give_terminal_to (pgrp, force)
            shell_tty, (long)getpid(), (long)pgrp);
 #endif
          r = -1;
+         e = errno;
        }
       else
        terminal_pgrp = pgrp;
       sigprocmask (SIG_SETMASK, &oset, (sigset_t *)NULL);
     }
 
+  if (r == -1)
+    errno = e;
   return r;
 }
 
diff --git a/subst.c b/subst.c
index 955eba64140656e5195ec5a6fbad94a362d2a2c8..a71229f27b9c43baa4fb7445d195ff3cabc7c377 100644 (file)
--- a/subst.c
+++ b/subst.c
@@ -4958,10 +4958,11 @@ parameter_brace_expand_word (name, var_is_special, quoted)
   char *temp, *tt;
   intmax_t arg_index;
   SHELL_VAR *var;
-  int atype;
+  int atype, rflags;
 
   ret = 0;
   temp = 0;
+  rflags = 0;
 
   /* Handle multiple digit arguments, as in ${11}. */  
   if (legal_number (name, &arg_index))
@@ -4994,6 +4995,8 @@ parameter_brace_expand_word (name, var_is_special, quoted)
        temp = (*temp && (quoted & (Q_DOUBLE_QUOTES|Q_HERE_DOCUMENT)))
                  ? quote_string (temp)
                  : quote_escapes (temp);
+      else if (atype == 1 && temp && QUOTED_NULL (temp) && (quoted & (Q_DOUBLE_QUOTES|Q_HERE_DOCUMENT)))
+       rflags |= W_HASQUOTEDNULL;
     }
 #endif
   else if (var = find_variable (name))
@@ -5021,6 +5024,7 @@ parameter_brace_expand_word (name, var_is_special, quoted)
     {
       ret = alloc_word_desc ();
       ret->word = temp;
+      ret->flags |= rflags;
     }
   return ret;
 }
index b18d56db7e5a59c4ad7b41754f35baf01337034a..b3250747f20a063cb1635e1d3a901430e7a8a010 100644 (file)
--- a/subst.c~
+++ b/subst.c~
@@ -211,7 +211,6 @@ static WORD_LIST *list_quote_escapes __P((WORD_LIST *));
 static char *dequote_escapes __P((char *));
 static char *make_quoted_char __P((int));
 static WORD_LIST *quote_list __P((WORD_LIST *));
-/*static*/ char *remove_quoted_escapes __P((char *));
 static char *remove_quoted_nulls __P((char *));
 
 static int unquoted_substring __P((char *, char *));
@@ -3201,7 +3200,7 @@ dequote_list (list)
 
 /* Remove CTLESC protecting a CTLESC or CTLNUL in place.  Return the passed
    string. */
-/*static*/ char *
+char *
 remove_quoted_escapes (string)
      char *string;
 {
@@ -4959,10 +4958,11 @@ parameter_brace_expand_word (name, var_is_special, quoted)
   char *temp, *tt;
   intmax_t arg_index;
   SHELL_VAR *var;
-  int atype;
+  int atype, rflags;
 
   ret = 0;
   temp = 0;
+  rflags = 0;
 
   /* Handle multiple digit arguments, as in ${11}. */  
   if (legal_number (name, &arg_index))
@@ -4995,6 +4995,8 @@ parameter_brace_expand_word (name, var_is_special, quoted)
        temp = (*temp && (quoted & (Q_DOUBLE_QUOTES|Q_HERE_DOCUMENT)))
                  ? quote_string (temp)
                  : quote_escapes (temp);
+      else if (atype == 1 && temp && *temp == 0 && (quoted & (Q_DOUBLE_QUOTES|Q_HERE_DOCUMENT)))
+       rflags |= W_HASQUOTEDNULL;
     }
 #endif
   else if (var = find_variable (name))
@@ -5022,6 +5024,7 @@ parameter_brace_expand_word (name, var_is_special, quoted)
     {
       ret = alloc_word_desc ();
       ret->word = temp;
+      ret->flags |= rflags;
     }
   return ret;
 }
index 72ec06a2c1fd8dde92acea5e8ac773e35f1d061b..3efcf32d68e9722024b6ca9d67f9e81b2aa5ac04 100755 (executable)
@@ -1,4 +1,4 @@
-BUILD_DIR=/usr/local/build/bash/bash-current
+BUILD_DIR=/usr/local/build/chet/bash/bash-current
 THIS_SH=$BUILD_DIR/bash
 PATH=$PATH:$BUILD_DIR