From: Chet Ramey Date: Wed, 7 Dec 2011 14:16:47 +0000 (-0500) Subject: commit bash-20071220 snapshot X-Git-Tag: bash-4.0-alpha~28 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b246176e885311d81ec0b2f6591b7855bc49bdfe;p=thirdparty%2Fbash.git commit bash-20071220 snapshot --- diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index d67002fb2..d4783850c 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -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 + + 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 + + 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 + diff --git a/CWRU/CWRU.chlog~ b/CWRU/CWRU.chlog~ index 24dbb5aa5..3f2610897 100644 --- a/CWRU/CWRU.chlog~ +++ b/CWRU/CWRU.chlog~ @@ -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 + + 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 diff --git a/execute_cmd.c b/execute_cmd.c index be51a3334..9d6d95e78 100644 --- a/execute_cmd.c +++ b/execute_cmd.c @@ -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; diff --git a/lib/sh/getcwd.c b/lib/sh/getcwd.c index a05fd70de..94bc8122d 100644 --- a/lib/sh/getcwd.c +++ b/lib/sh/getcwd.c @@ -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; diff --git a/lib/sh/getcwd.c~ b/lib/sh/getcwd.c~ index 694cc0660..c1cbaa7e9 100644 --- a/lib/sh/getcwd.c~ +++ b/lib/sh/getcwd.c~ @@ -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); } diff --git a/patchlevel.h b/patchlevel.h index eb962a37c..6d86562fd 100644 --- a/patchlevel.h +++ b/patchlevel.h @@ -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 1da53c0bf..47a6097c8 100644 --- 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); diff --git a/redir.c~ b/redir.c~ index acde46f4a..1da53c0bf 100644 --- 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 diff --git a/tests/RUN-ONE-TEST b/tests/RUN-ONE-TEST index 72ec06a2c..3efcf32d6 100755 --- a/tests/RUN-ONE-TEST +++ b/tests/RUN-ONE-TEST @@ -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