]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
commit bash-20071220 snapshot
authorChet Ramey <chet.ramey@case.edu>
Wed, 7 Dec 2011 14:16:47 +0000 (09:16 -0500)
committerChet Ramey <chet.ramey@case.edu>
Wed, 7 Dec 2011 14:16:47 +0000 (09:16 -0500)
CWRU/CWRU.chlog
CWRU/CWRU.chlog~
execute_cmd.c
lib/sh/getcwd.c
lib/sh/getcwd.c~
patchlevel.h
redir.c
redir.c~
tests/RUN-ONE-TEST

index d67002fb25ef565a5d782f1b3cdd1ce0a5caad7b..d4783850c9d308e53826855dd3583f7ac7bcf231 100644 (file)
@@ -15123,3 +15123,23 @@ builtins/read.def
 doc/bashref.texi, lib/readline/doc/{history,rlman,rluser,rluserman}.texi
        - Slight changes to conform to the latest FSF documentation standards.
          Patch from Karl Berry <karl@freefriends.org>
+
+                                  12/20
+                                  -----
+execute_cmd.c
+       - after calling clear_unwind_protect_list, make sure we reset
+         parse_and_execute_level to 0, since there's nothing left to
+         restore it if top_level_cleanup tests it.  Fixes bug reported
+         by Len Lattanzi <llattanzi@apple.com>
+
+                                  12/31
+                                  -----
+lib/sh/getcwd.c
+       - new function, _path_checkino, checks whether the inode corresponding
+         to the path constructed from the first two arguments is the same as
+         the inode number passed as the third argument
+       - if BROKEN_DIRENT_D_INO is defined, meaning the d_ino/d_fileno
+         member of struct dirent doesn't contain valid values, use
+         _path_checkino instead of directly comparing against d_fileno.
+         Fixes Interix problem reported by Michael Haubenwallner
+         <haubi@gentoo.org>
index 24dbb5aa53b6d9c20a07516c5eb686b1f69f2f9f..3f2610897a738e8f6d710f8d20a70d07f9a6924d 100644 (file)
@@ -15120,6 +15120,14 @@ builtins/read.def
          the argument to the -u option (default 0).  Fix for bug reported
          by b_bashbug@thebellsplace.com
 
-doc/bashref.texi, lib/readline/doc/{history,rlman,rluser}.texi
+doc/bashref.texi, lib/readline/doc/{history,rlman,rluser,rluserman}.texi
        - Slight changes to conform to the latest FSF documentation standards.
          Patch from Karl Berry <karl@freefriends.org>
+
+                                  12/20
+                                  -----
+execute_cmd.c
+       - after calling clear_unwind_protect_list, make sure we reset
+         parse_and_execute_level to 0, since there's nothing left to
+         restore it if top_level_cleanup tests it.  Fixes bug reported
+         by Len Lattanzi <llattanzi@apple.com>
index be51a3334225c4c4ced7cf584c2889d74840f41b..9d6d95e78622fdfa519e36251bed3a0a70e8daf0 100644 (file)
@@ -3915,6 +3915,8 @@ initialize_subshell ()
     shell_variables = shell_variables->down;
 
   clear_unwind_protect_list (0);
+  /* XXX -- are there other things we should be resetting here? */
+  parse_and_execute_level = 0;         /* nothing left to restore it */
 
   /* We're no longer inside a shell function. */
   variable_context = return_catch_flag = 0;
index a05fd70de0f401174582ace39f4175aeff131edf..94bc8122deca27a1db9a0135abeca207751b5252 100644 (file)
@@ -62,6 +62,33 @@ extern int errno;
 #  define NULL 0
 #endif
 
+/* If the d_fileno member of a struct dirent doesn't return anything useful,
+   we need to check inode number equivalence the hard way.  Return 1 if
+   the inode corresponding to PATH/DIR is identical to THISINO. */
+#if defined (BROKEN_DIRENT_D_INO)
+static int
+_path_checkino (dotp, name, thisino)
+     char *dotp;
+     char *name;
+     ino_t thisino;
+{
+  char *fullpath;
+  int r, e;
+  struct stat st;
+
+  e = errno;
+  fullpath = sh_makepath (dotp, name, MP_RMDOT);
+  if (stat (fullpath, &st) < 0)
+    {
+      errno = e;
+      return 0;
+    }
+  free (fullpath);
+  errno = e;
+  return (st.st_ino == thisino);
+}
+#endif
+    
 /* Get the pathname of the current working directory,
    and put it in SIZE bytes of BUF.  Returns NULL if the
    directory couldn't be determined or SIZE was too small.
@@ -173,7 +200,11 @@ getcwd (buf, size)
              (d->d_name[1] == '\0' ||
                (d->d_name[1] == '.' && d->d_name[2] == '\0')))
            continue;
+#if !defined (BROKEN_DIRENT_D_INO)
          if (mount_point || d->d_fileno == thisino)
+#else
+         if (mount_point || _path_checkino (dotp, d->d_name, thisino))
+#endif
            {
              char *name;
 
index 694cc0660b68d17d073c7f8d907ce3cddbad8c4d..c1cbaa7e9cd71267701c0d381f86b746af6ea3aa 100644 (file)
@@ -62,6 +62,32 @@ extern int errno;
 #  define NULL 0
 #endif
 
+/* If the d_fileno member of a struct dirent doesn't return anything useful,
+   we need to check inode number equivalence the hard way. */
+#if defined (BROKEN_DIRENT_D_INO)
+static int
+_path_checkino (dotp, name, thisino)
+     char *dotp;
+     char *name;
+     ino_t thisino;
+{
+  char *fullpath;
+  int r, e;
+  struct stat st;
+
+  e = errno;
+  fullpath = sh_makepath (dotp, name, MP_RMDOT);
+  if (stat (fullpath, &st) < 0)
+    {
+      errno = e;
+      return 0;
+    }
+  free (fullpath);
+  errno = e;
+  return (st.st_ino == thisino);
+}
+#endif
+    
 /* Get the pathname of the current working directory,
    and put it in SIZE bytes of BUF.  Returns NULL if the
    directory couldn't be determined or SIZE was too small.
@@ -173,7 +199,11 @@ getcwd (buf, size)
              (d->d_name[1] == '\0' ||
                (d->d_name[1] == '.' && d->d_name[2] == '\0')))
            continue;
+#if !defined (BROKEN_DIRENT_D_INO)
          if (mount_point || d->d_fileno == thisino)
+#else
+         if (mount_point || _path_checkino (dotp, d->d_name, thisino))
+#endif
            {
              char *name;
 
@@ -255,19 +285,21 @@ getcwd (buf, size)
 
   {
     size_t len = pathbuf + pathsize - pathp;
+    if (buf == NULL && size <= 0)
+      size = len;
+
+    if ((size_t) size < len)
+      {
+       errno = ERANGE;
+       goto lose2;
+      }
     if (buf == NULL)
       {
-       if (len < (size_t) size)
-         len = size;
-       buf = (char *) malloc (len);
+       buf = (char *) malloc (size);
        if (buf == NULL)
          goto lose2;
       }
-    else if ((size_t) size < len)
-      {
-       errno = ERANGE;
-       goto lose2;
-      }
+
     (void) memcpy((PTR_T) buf, (PTR_T) pathp, len);
   }
 
index eb962a37cb08f472a079efaa99481f0ea97bd289..6d86562fd0d272f130a48a7463035197a51d8fa5 100644 (file)
@@ -25,6 +25,6 @@
    regexp `^#define[   ]*PATCHLEVEL', since that's what support/mkversion.sh
    looks for to find the patch level (for the sccs version string). */
 
-#define PATCHLEVEL 25
+#define PATCHLEVEL 33
 
 #endif /* _PATCHLEVEL_H_ */
diff --git a/redir.c b/redir.c
index 1da53c0bf962b25e3f69f7d1b464cc788a464dd6..47a6097c842ca46803258742e0f7978329fcfbca 100644 (file)
--- a/redir.c
+++ b/redir.c
@@ -778,6 +778,11 @@ do_redirection_internal (redirect, flags)
              fflush (stdout);
              fpurge (stdout);
            }
+         else if (redirector == 2 && fileno (stderr) == redirector)
+           {
+             fflush (stderr);
+             fpurge (stderr);
+           }
 
          if ((fd != redirector) && (dup2 (fd, redirector) < 0))
            return (errno);
index acde46f4a3a3b84607c0b3233a501c0adee83f87..1da53c0bf962b25e3f69f7d1b464cc788a464dd6 100644 (file)
--- a/redir.c~
+++ b/redir.c~
@@ -1,6 +1,6 @@
 /* redir.c -- Functions to perform input and output redirection. */
 
-/* Copyright (C) 1997-2005 Free Software Foundation, Inc.
+/* Copyright (C) 1997-2007 Free Software Foundation, Inc.
 
    This file is part of GNU Bash, the Bourne Again SHell.
 
@@ -43,8 +43,10 @@ extern int errno;
 
 #include "bashansi.h"
 #include "bashintl.h"
-
 #include "memalloc.h"
+
+#define NEED_FPURGE_DECL
+
 #include "shell.h"
 #include "flags.h"
 #include "execute_cmd.h"
@@ -54,6 +56,8 @@ extern int errno;
 #  include "input.h"
 #endif
 
+#define SHELL_FD_BASE  10
+
 int expanding_redir;
 
 extern int posixly_correct;
@@ -481,7 +485,7 @@ redir_special_open (spec, filename, flags, mode, ri)
       if (all_digits (filename+8) && legal_number (filename+8, &lfd) && lfd == (int)lfd)
        {
          fd = lfd;
-         fd = fcntl (fd, F_DUPFD, 10);
+         fd = fcntl (fd, F_DUPFD, SHELL_FD_BASE);
        }
       else
        fd = AMBIGUOUS_REDIRECT;
@@ -490,13 +494,13 @@ redir_special_open (spec, filename, flags, mode, ri)
 
 #if !defined (HAVE_DEV_STDIN)
     case RF_DEVSTDIN:
-      fd = fcntl (0, F_DUPFD, 10);
+      fd = fcntl (0, F_DUPFD, SHELL_FD_BASE);
       break;
     case RF_DEVSTDOUT:
-      fd = fcntl (1, F_DUPFD, 10);
+      fd = fcntl (1, F_DUPFD, SHELL_FD_BASE);
       break;
     case RF_DEVSTDERR:
-      fd = fcntl (2, F_DUPFD, 10);
+      fd = fcntl (2, F_DUPFD, SHELL_FD_BASE);
       break;
 #endif
 
@@ -766,6 +770,15 @@ do_redirection_internal (redirect, flags)
          check_bash_input (redirector);
 #endif
 
+         /* Make sure there is no pending output before we change the state
+            of the underlying file descriptor, since the builtins use stdio
+            for output. */
+         if (redirector == 1 && fileno (stdout) == redirector)
+           {
+             fflush (stdout);
+             fpurge (stdout);
+           }
+
          if ((fd != redirector) && (dup2 (fd, redirector) < 0))
            return (errno);
 
@@ -882,7 +895,6 @@ do_redirection_internal (redirect, flags)
              else
                add_undo_close_redirect (redirector);
            }
-
 #if defined (BUFFERED_INPUT)
          check_bash_input (redirector);
 #endif
@@ -943,8 +955,6 @@ do_redirection_internal (redirect, flags)
   return (0);
 }
 
-#define SHELL_FD_BASE  10
-
 /* Remember the file descriptor associated with the slot FD,
    on REDIRECTION_UNDO_LIST.  Note that the list will be reversed
    before it is executed.  Any redirections that need to be undone
@@ -990,17 +1000,19 @@ add_undo_redirect (fd, ri)
 
   /* experimental:  if we're saving a redirection to undo for a file descriptor
      above SHELL_FD_BASE, add a redirection to be undone if the exec builtin
-     causes redirections to be discarded. */
-  if (fd >= SHELL_FD_BASE && ri != r_close_this)
+     causes redirections to be discarded.  There needs to be a difference
+     between fds that are used to save other fds and then are the target of
+     user redirctions and fds that are just the target of user redirections.
+     We use the close-on-exec flag to tell the difference; fds > SHELL_FD_BASE
+     that have the close-on-exec flag set are assumed to be fds used internally
+     to save others. */
+  if (fd >= SHELL_FD_BASE && ri != r_close_this && clexec_flag)
     {
       rd.dest = new_fd;
       new_redirect = make_redirection (fd, r_duplicating_output, rd);
-#if 0
-      closer = copy_redirects (new_redirect);
-      add_exec_redirect (closer);
-#else
+      new_redirect->flags |= RX_INTERNAL;
+
       add_exec_redirect (new_redirect);
-#endif     
     }
 
   /* File descriptors used only for saving others should always be
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