From: Chet Ramey Date: Fri, 1 Nov 2024 18:12:16 +0000 (-0400) Subject: fix some exec builtin duplicate error messages; add LIBRARY_SOURCE back to tags and... X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fffa5d0e7c05d04731fcb113db46d7f85ac39085;p=thirdparty%2Fbash.git fix some exec builtin duplicate error messages; add LIBRARY_SOURCE back to tags and TAGS make targets --- diff --git a/.gitignore b/.gitignore index aabc4c10..2e752951 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ .*~ config.h +buildconf.h config.status config.cache config.log diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index 268b4781..39b971f4 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -10555,3 +10555,14 @@ configure.ac,Makefile.in,support/Makefile.in,doc/Makefile.in - remove some unused variables: BASE_CFLAGS_FOR_BUILD, DEBUGGER_DIR, INTLOBJS, TEXINDEX, TEX, MALLOC, SIGNAMES_SUPPORT From a report by Martin D Kealey + + 10/28 + ----- +builtins/exec.def + - exec_builtin: don't try to print an error message in the cases + where shell_execve prints one, in case we have execfail set + Report from Emanuele Torre + +Makefile.in + - LIBRARY_SOURCE: add back in to tags targets, add definition + Suggestion from Mike Jonkmans diff --git a/Makefile.in b/Makefile.in index 8b62b13e..d55a1843 100644 --- a/Makefile.in +++ b/Makefile.in @@ -463,6 +463,9 @@ LIBDEP = $(GLOB_DEP) $(SHLIB_DEP) $(INTL_DEP) $(READLINE_DEP) $(HISTORY_DEP) \ LIBRARY_LDFLAGS = $(READLINE_LDFLAGS) $(HISTORY_LDFLAGS) $(GLOB_LDFLAGS) \ $(TILDE_LDFLAGS) $(MALLOC_LDFLAGS) $(SHLIB_LDFLAGS) +LIBRARY_SOURCE = $(SHLIB_SOURCE) $(GLOB_SOURCE) \ + $(READLINE_SOURCE) $(MALLOC_SOURCE) + # # The shell itself # @@ -875,11 +878,11 @@ info dvi ps: force force: # unused -TAGS: $(SOURCES) $(BUILTIN_C_SRC) - ( cd $(topdir) && $(ETAGS) $(ETAGSFLAGS) $(SOURCES) $(BUILTIN_C_SRC) ) +TAGS: $(SOURCES) $(BUILTIN_C_SRC) $(LIBRARY_SOURCE) + ( cd $(topdir) && $(ETAGS) $(ETAGSFLAGS) $(SOURCES) $(BUILTIN_C_SRC) $(LIBRARY_SOURCE) ) -tags: $(SOURCES) $(BUILTIN_C_SRC) - ( cd $(topdir) && $(CTAGS) $(CTAGSFLAGS) $(SOURCES) $(BUILTIN_C_SRC) ) +tags: $(SOURCES) $(BUILTIN_C_SRC) $(LIBRARY_SOURCE) + ( cd $(topdir) && $(CTAGS) $(CTAGSFLAGS) $(SOURCES) $(BUILTIN_C_SRC) $(LIBRARY_SOURCE) ) # Targets that actually do things not part of the build diff --git a/builtins/exec.def b/builtins/exec.def index 618882c8..461864b5 100644 --- a/builtins/exec.def +++ b/builtins/exec.def @@ -233,16 +233,23 @@ exec_builtin (WORD_LIST *list) if (cleanenv == 0) adjust_shell_level (1); - if (exit_value == EX_NOTFOUND) /* no duplicate error message */ + /* These are the return statuses for which shell_execve will print a message. */ + if (exit_value == EX_NOTFOUND || exit_value == EX_BINARY_FILE || exit_value == EX_NOEXEC) goto failed_exec; - else if (executable_file (command) == 0) + /* These are the errno values for which shell_execve will print a message. */ +#if defined (EISDIR) + else if (opt == EISDIR || opt == E2BIG || opt == ENOMEM) +#else + else if (opt == E2BIG || opt == ENOMEM) +#endif + goto failed_exec; + else /* catchall */ { + builtin_error ("%s: %s: %s", command, _("cannot execute"), strerror (opt)); + if (executable_file (command) == 0) + exit_value = EX_NOEXEC; /* As per Posix.2, 3.14.6 */ errno = opt; - builtin_error ("%s: %s: %s", command, _("cannot execute"), strerror (errno)); - exit_value = EX_NOEXEC; /* As per Posix.2, 3.14.6 */ } - else - file_error (command); failed_exec: FREE (command); diff --git a/lib/sh/Makefile.in b/lib/sh/Makefile.in index dc7ccbec..8e658cd3 100644 --- a/lib/sh/Makefile.in +++ b/lib/sh/Makefile.in @@ -144,8 +144,8 @@ mostlyclean: clean # Dependencies -${BUILD_DIR}/version.h: ${BUILD_DIR}/config.h ${BUILD_DIR}/Makefile Makefile - -( cd ${BUILD_DIR} && ${MAKE} ${BASH_MAKEFLAGS} version.h ) +#${BUILD_DIR}/version.h: ${BUILD_DIR}/config.h ${BUILD_DIR}/Makefile Makefile +# -( cd ${BUILD_DIR} && ${MAKE} ${BASH_MAKEFLAGS} version.h ) ${BUILD_DIR}/pathnames.h: ${BUILD_DIR}/config.h ${BUILD_DIR}/Makefile Makefile -( cd ${BUILD_DIR} && ${MAKE} ${BASH_MAKEFLAGS} pathnames.h ) diff --git a/tests/exec.right b/tests/exec.right index e65d8cbf..0e908d94 100644 --- a/tests/exec.right +++ b/tests/exec.right @@ -29,8 +29,9 @@ trap -- 'echo EXIT' EXIT trap -- '' SIGTERM trap -- 'echo USR1' SIGUSR1 USR1 -./exec3.sub: line 27: /tmp/bash-notthere: No such file or directory -./exec3.sub: after failed exec: 127 +./exec3.sub: line 38: /tmp/bash-notthere: No such file or directory +./exec3.sub: ENOENT: after failed exec: 127 +./exec3.sub: line 43: exec: bash-notthere: not found trap -- 'echo EXIT' EXIT trap -- '' SIGTERM trap -- 'echo USR1' SIGUSR1 diff --git a/tests/exec16.sub b/tests/exec16.sub index e9d80304..3695fdeb 100644 --- a/tests/exec16.sub +++ b/tests/exec16.sub @@ -10,6 +10,7 @@ set +e set +e ! { set -e ; false ; echo reached async group; } & +wait set +e set -e diff --git a/tests/exec3.sub b/tests/exec3.sub index 81b53b72..0def1bd8 100644 --- a/tests/exec3.sub +++ b/tests/exec3.sub @@ -15,6 +15,14 @@ # added tests for changes in 10/2021 for preserving the traps across a failed # exec +: ${THIS_SH:=./bash} +: ${TMPDIR:=/var/tmp} +TDIR=$TMPDIR/execdir-$$ + +mkdir $TDIR || exit 1 +cp $THIS_SH $TDIR || exit 1 +cd $TDIR || exit 1 + shopt -s execfail trap 'echo EXIT' EXIT @@ -24,14 +32,63 @@ trap kill -s USR1 $$ # should run the trap +# ENOENT -- No such file or directory +# full pathname +rm -f /tmp/bash-notthere exec /tmp/bash-notthere - # make sure we're still around -echo $0: after failed exec: $? +echo $0: ENOENT: after failed exec: $? +# relative pathname +rm -f bash-notthere +exec bash-notthere + +# EACCES - permission denied +rm -f x.sh x.output +echo 'echo bar' > x.sh +exec ./x.sh 2>x.output +string=$(< x.output) +# check for right error message and that we survived the failed exec +case $string in +*denied) ;; +*) echo "$0: EACCES: error message mismatch: $string" ;; +esac +rm -f x.sh x.output + +# E2BIG - Argument list too long +unset BASH_ENV + +rm -f x.sh x.output +echo "export var='$(echo {1..1000500})' ; +exec ${THIS_SH}" > ./x.sh +chmod 755 ./x.sh +${THIS_SH} ./x.sh 2>x.output +string=$(< x.output) +# check for right error message and that we survived the failed exec +case $string in +*list\ too\ long) ;; +*) echo "$0: E2BIG: error message mismatch: $string" ;; +esac +rm -f x.sh x.output + +# EISDIR - is a directory +rm -f x.sh x.output +mkdir xdir-$$ +exec ./xdir-$$ 2>x.output +rmdir ./xdir-$$ +string=$(< x.output) +# check for right error message and that we survived the failed exec +case $string in +*[Ii]s\ a\ directory) ;; +*) echo "$0: EISDIR: error message mismatch: $string" ;; +esac +rm -f x.sh x.output trap kill -s USR1 $$ # should run the trap kill -s TERM $$ # should still be ignored +cd $OLDPWD +rm -rf $TDIR + # this should run the exit trap exit 0 diff --git a/variables.c b/variables.c index f1f7f511..3639487f 100644 --- a/variables.c +++ b/variables.c @@ -59,8 +59,6 @@ #include "alias.h" #include "jobs.h" -#include "version.h" - #include "builtins/getopt.h" #include "builtins/common.h" #include "builtins/builtext.h" @@ -6472,7 +6470,7 @@ sv_shcompat (const char *name) { compat_error: internal_error (_("%s: %s: compatibility value out of range"), name, val); - shell_compatibility_level = DEFAULT_COMPAT_LEVEL; + shell_compatibility_level = default_compatibility_level; set_compatibility_opts (); return; }