From 97021559abfda74676f5924624211563de076ab5 Mon Sep 17 00:00:00 2001 From: Chet Ramey Date: Mon, 4 Mar 2019 10:48:32 -0500 Subject: [PATCH] commit bash-20190301 snapshot --- CWRU/CWRU.chlog | 11 +++++++++ examples/functions/isnum2 | 2 +- examples/functions/shcat | 2 +- examples/functions/shcat2 | 4 ++-- examples/loadables/fdflags.c | 44 +++++++++++++++++++++++++++++++----- execute_cmd.c | 2 +- tests/RUN-ONE-TEST | 2 +- tests/quote.right | 6 +++++ tests/quote4.sub | 12 ++++++++++ 9 files changed, 73 insertions(+), 12 deletions(-) diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index bb9ccb50c..57f1c6180 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -5420,3 +5420,14 @@ subst.c quoted null as the expansion of "$@", note that we saw it, but still add a quoted null into the result string instead of short-circuiting. Part of fix for bug report from Grisha Levit + + 3/1 + --- +examples/loadables/fdflags.c + - O_CLOEXEC: instead of not using it, synthesize a definition for it + from unused bits in the file status word. It's only used as a + placeholder anyway. Fix from code by Robert Elz + +execute_cmd.c + - execute_connection: call optimize_fork on the rhs of a `;' connection + to attempt to optimize the last simple command in a list diff --git a/examples/functions/isnum2 b/examples/functions/isnum2 index 583e37491..b21974db4 100644 --- a/examples/functions/isnum2 +++ b/examples/functions/isnum2 @@ -20,7 +20,7 @@ isnum2() { case "$1" in - '[-+]' | '') return 1;; # empty or bare `-' or `+' + [-+] | '') return 1;; # empty or bare `-' or `+' [-+]*[!0-9]*) return 1;; # non-digit with leading sign [-+]*) return 0;; # OK *[!0-9]*) return 1;; # non-digit diff --git a/examples/functions/shcat b/examples/functions/shcat index c5d3d630b..84f0391ee 100644 --- a/examples/functions/shcat +++ b/examples/functions/shcat @@ -1,6 +1,6 @@ shcat() { - while read -r line + while IFS= read -r line do echo "$line" done diff --git a/examples/functions/shcat2 b/examples/functions/shcat2 index 6fe90f409..8ceff330b 100644 --- a/examples/functions/shcat2 +++ b/examples/functions/shcat2 @@ -1,8 +1,8 @@ shcat() { - while read -r line + while read -r do - echo "$line" + echo "$REPLY" done } diff --git a/examples/loadables/fdflags.c b/examples/loadables/fdflags.c index 742ade422..fbe52304c 100644 --- a/examples/loadables/fdflags.c +++ b/examples/loadables/fdflags.c @@ -32,6 +32,10 @@ #include "loadables.h" +#ifndef FD_CLOEXEC +# define FD_CLOEXEC 1 +#endif + static const struct { const char *name; @@ -40,37 +44,69 @@ static const struct { #ifdef O_APPEND { "append", O_APPEND }, +#else +# define O_APPEND 0 #endif #ifdef O_ASYNC { "async", O_ASYNC }, +#else +# define O_ASYNC 0 #endif #ifdef O_SYNC { "sync", O_SYNC }, +#else +# define O_SYNC 0 #endif #ifdef O_NONBLOCK { "nonblock", O_NONBLOCK }, +#else +# define O_NONBLOCK 0 #endif #ifdef O_FSYNC { "fsync", O_FSYNC }, +#else +# define O_FSYNC 0 #endif #ifdef O_DSYNC { "dsync", O_DSYNC }, +#else +# define O_DSYNC 0 #endif #ifdef O_RSYNC { "rsync", O_RSYNC }, +#else +# define O_RSYNC 0 #endif #ifdef O_ALT_IO { "altio", O_ALT_IO }, +#else +# define O_ALT_IO 0 #endif #ifdef O_DIRECT { "direct", O_DIRECT }, +#else +# define O_DIRECT 0 #endif #ifdef O_NOATIME { "noatime", O_NOATIME }, +#else +# define O_NOATIME 0 #endif #ifdef O_NOSIGPIPE { "nosigpipe", O_NOSIGPIPE }, +#else +# define O_NOSIGPIPE 0 #endif + +#ifndef O_CLOEXEC +# define ALLFLAGS (O_APPEND|O_ASYNC|O_SYNC|O_NONBLOCK|O_FSYNC|O_DSYNC|\ + O_RSYNC|O_ALT_IO|O_DIRECT|O_NOATIME|O_NOSIGPIPE) + +/* An unsed bit in the file status flags word we can use to pass around the + state of close-on-exec. */ +# define O_CLOEXEC ((~ALLFLAGS) ^ ((~ALLFLAGS) & ((~ALLFLAGS) - 1))) +#endif + #ifdef O_CLOEXEC { "cloexec", O_CLOEXEC }, #endif @@ -113,10 +149,8 @@ getflags(int fd, int p) return -1; } -#ifdef O_CLOEXEC if (c) f |= O_CLOEXEC; -#endif return f & getallflags(); } @@ -201,20 +235,18 @@ setone(int fd, char *v, int verbose) parseflags(v, &pos, &neg); cloexec = -1; -#ifdef O_CLOEXEC + if ((pos & O_CLOEXEC) && (f & O_CLOEXEC) == 0) cloexec = FD_CLOEXEC; if ((neg & O_CLOEXEC) && (f & O_CLOEXEC)) cloexec = 0; -#endif + if (cloexec != -1 && fcntl(fd, F_SETFD, cloexec) == -1) builtin_error("can't set status for fd %d: %s", fd, strerror(errno)); -#ifdef O_CLOEXEC pos &= ~O_CLOEXEC; neg &= ~O_CLOEXEC; f &= ~O_CLOEXEC; -#endif n = f; n |= pos; diff --git a/execute_cmd.c b/execute_cmd.c index 908b88ee8..e4a05e2ed 100644 --- a/execute_cmd.c +++ b/execute_cmd.c @@ -2699,6 +2699,7 @@ execute_connection (command, asynchronous, pipe_in, pipe_out, fds_to_close) QUIT; execute_command (command->value.Connection->first); QUIT; + optimize_fork (command); /* XXX */ exec_result = execute_command_internal (command->value.Connection->second, asynchronous, pipe_in, pipe_out, fds_to_close); @@ -4506,7 +4507,6 @@ run_builtin: if (builtin_is_special) special_builtin_failed = 1; /* XXX - take command builtin into account? */ } - /* In POSIX mode, if there are assignment statements preceding a special builtin, they persist after the builtin completes. */ diff --git a/tests/RUN-ONE-TEST b/tests/RUN-ONE-TEST index 554f3d6ec..58c375b70 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 diff --git a/tests/quote.right b/tests/quote.right index 9fda46a72..303e685dc 100644 --- a/tests/quote.right +++ b/tests/quote.right @@ -174,3 +174,9 @@ argv[1] = 4 4 3 +argv[1] = <^?> +argv[1] = <^?> +argv[1] = <^?> +argv[1] = <^?> +argv[1] = <^?> +argv[1] = <^?> diff --git a/tests/quote4.sub b/tests/quote4.sub index 2805b8f8a..fa24457c9 100644 --- a/tests/quote4.sub +++ b/tests/quote4.sub @@ -74,3 +74,15 @@ set -- '' '' n ${x+"$@" "$@"} n "$@" "$@" n "$@""$@" + +# new tests +unset -v x +v=$'\177' + +recho ''$'\177''' +recho $'\177''' +recho ''$'\177' + +recho ''$v'' +recho ''$v +recho $v'' -- 2.47.2