]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
changes to SIGINT handler while waiting for a child; skip vertical whitespace after...
authorChet Ramey <chet.ramey@case.edu>
Mon, 30 Oct 2023 16:16:07 +0000 (12:16 -0400)
committerChet Ramey <chet.ramey@case.edu>
Mon, 30 Oct 2023 16:16:07 +0000 (12:16 -0400)
CWRU/CWRU.chlog
execute_cmd.c
externs.h
general.c
jobs.c
tests/redir.right
tests/redir11.sub
tests/type.right
tests/type.tests

index 686c4c126dd3fbbdf5466380bb66039c3e93e589..894049104122ca82584fbb4e54328ea2299dba74 100644 (file)
@@ -7910,3 +7910,21 @@ builtins/printf.def
        - printf_builtin: handle field width and precision overflow from
          getint() by ignoring the argument (fieldwidth = 0, precision = -1)
 
+                                  10/26
+                                  -----
+jobs.c
+       - wait_for: rearrange code that sets the SIGINT handler to
+         wait_sigint_handler and saves the old handler to old_sigint_handler
+         to avoid delay before assigning the handler
+         Report from Wenlin Kang <wenlin.kang@windriver.com>
+       - wait_sigint_handler: if cur_sigint_handler (what restore_sigint_handler)
+         just restored or ignored) is INVALID_SIGNAL_HANDLER, set the
+         appropriate SIGINT handler with set_sigint_handler before sending
+         ourselves SIGINT
+
+                                  10/30
+                                  -----
+general.c
+       - legal_number: use the same test (isspace(3)) to skip trailing
+         whitespace that strtoimax uses to skip leading whitespace.
+         Report and patch from Paul Eggert <eggert@cs.ucla.edu>
index 7c3cd195e3bcd590aea6ea977ac6f47a626bc79e..b33cb8360f3b205a170e70ab5cf27668e87a963c 100644 (file)
@@ -5422,7 +5422,7 @@ execute_subshell_builtin_or_function (WORD_LIST *words, REDIRECT *redirects,
       handler = set_sigint_handler ();
       if (handler == SIG_IGN && signal_is_async_ignored (SIGINT) &&
          signal_is_trapped (SIGINT) == 0 && signal_is_hard_ignored (SIGINT) == 0)
-       set_signal_handler (SIGINT, handler);
+       set_signal_handler (SIGINT, SIG_IGN);
     }
 
   if (fds_to_close)
index 34e76059a5a8f1f4f37a4aca75c69bee9e50a802..c6566672062901346ac669c71e75fede6a355aa3 100644 (file)
--- a/externs.h
+++ b/externs.h
@@ -214,7 +214,7 @@ extern void print_clock_t (FILE *, clock_t);
 
 /* Declarations for functions defined in lib/sh/dprintf.c */
 #if !defined (HAVE_DPRINTF)
-extern void dprintf (int, const char *, ...))  __attribute__((__format__ (printf, 2, 3));
+extern void dprintf (int, const char *, ...)  __attribute__((__format__ (printf, 2, 3));
 #endif
 
 /* Declarations for functions defined in lib/sh/fmtulong.c */
index aa96566109f53ad0d8d0ff5f3b6f4091de3f95bb..87c4cedad149399252d8971a42b9d1fedca90418 100644 (file)
--- a/general.c
+++ b/general.c
@@ -257,8 +257,9 @@ legal_number (const char *string, intmax_t *result)
   if (errno || ep == string)
     return 0;  /* errno is set on overflow or underflow */
 
-  /* Skip any trailing whitespace, since strtoimax does not. */
-  while (whitespace (*ep))
+  /* Skip any trailing whitespace, since strtoimax does not, using the same
+     test that strtoimax uses for leading whitespace. */
+  while (isspace ((unsigned char) *ep))
     ep++;
 
   /* If *string is not '\0' but *ep is '\0' on return, the entire string
diff --git a/jobs.c b/jobs.c
index b8373cf57b3dd391e573b0f21d90546f2706a46c..59c4647540f5c52de135cfb761b7a9d67ce28f4f 100644 (file)
--- a/jobs.c
+++ b/jobs.c
@@ -2664,6 +2664,10 @@ wait_for_background_pids (struct procstat *ps)
 #define INVALID_SIGNAL_HANDLER (SigHandler *)wait_for_background_pids
 static SigHandler *old_sigint_handler = INVALID_SIGNAL_HANDLER;
 
+/* The current SIGINT handler as set by restore_sigint_handler. Only valid
+   immediately after restore_sigint_handler, used for continuations. */
+static SigHandler *cur_sigint_handler = INVALID_SIGNAL_HANDLER;   
+
 static int wait_sigint_received;
 static int child_caught_sigint;
 
@@ -2681,6 +2685,7 @@ wait_sigint_cleanup (void)
 static void
 restore_sigint_handler (void)
 {
+  cur_sigint_handler = old_sigint_handler;
   if (old_sigint_handler != INVALID_SIGNAL_HANDLER)
     {
       set_signal_handler (SIGINT, old_sigint_handler);
@@ -2703,8 +2708,7 @@ wait_sigint_handler (int sig)
       restore_sigint_handler ();
       /* If we got a SIGINT while in `wait', and SIGINT is trapped, do
         what POSIX.2 says (see builtins/wait.def for more info). */
-      if (this_shell_builtin && this_shell_builtin == wait_builtin &&
-         signal_is_trapped (SIGINT) &&
+      if (signal_is_trapped (SIGINT) &&
          ((sigint_handler = trap_to_sighandler (SIGINT)) == trap_handler))
        {
          trap_handler (SIGINT);        /* set pending_traps[SIGINT] */
@@ -2727,6 +2731,8 @@ wait_sigint_handler (int sig)
     {
       set_exit_status (128+SIGINT);
       restore_sigint_handler ();
+      if (cur_sigint_handler == INVALID_SIGNAL_HANDLER)
+       set_sigint_handler ();          /* XXX - only do this in one place */
       kill (getpid (), SIGINT);
     }
 
@@ -2876,11 +2882,13 @@ wait_for (pid_t pid, int flags)
     {
       SigHandler *temp_sigint_handler;
 
-      temp_sigint_handler = set_signal_handler (SIGINT, wait_sigint_handler);
-      if (temp_sigint_handler == wait_sigint_handler)
-       internal_debug ("wait_for: recursively setting old_sigint_handler to wait_sigint_handler: running_trap = %d", running_trap);
-      else
-       old_sigint_handler = temp_sigint_handler;
+      temp_sigint_handler = old_sigint_handler;
+      old_sigint_handler = set_signal_handler (SIGINT, wait_sigint_handler);
+      if (old_sigint_handler == wait_sigint_handler)
+       {
+         internal_debug ("wait_for: recursively setting old_sigint_handler to wait_sigint_handler: running_trap = %d", running_trap);
+         old_sigint_handler = temp_sigint_handler;
+       }
       waiting_for_child = 0;
       if (old_sigint_handler == SIG_IGN)
        set_signal_handler (SIGINT, old_sigint_handler);
@@ -4105,7 +4113,7 @@ set_job_status_and_cleanup (int job)
                 SIGINT (if we reset the sighandler to the default).
                 In this case, we have to fix things up.  What a crock. */
              if (temp_handler == trap_handler && signal_is_trapped (SIGINT) == 0)
-                 temp_handler = trap_to_sighandler (SIGINT);
+               temp_handler = trap_to_sighandler (SIGINT);
              restore_sigint_handler ();
              if (temp_handler == SIG_DFL)
                termsig_handler (SIGINT);       /* XXX */
index b54efeb30372d208484742baba05e743bcefd190..c5d3779cfda012de05dfdf2e2b5120b89fcc870f 100644 (file)
@@ -160,12 +160,12 @@ foo
 1
 7
 after: 42
-./redir11.sub: line 53: $(ss= declare -i ss): ambiguous redirect
+./redir11.sub: line 55: $(ss= declare -i ss): ambiguous redirect
 after: 42
 a+=3
 foo
 foo
-./redir11.sub: line 75: 42: No such file or directory
+./redir11.sub: line 77: 42: No such file or directory
 42
 ./redir12.sub: line 27: unwritable-file: Permission denied
 1 x =
index d417cdb601d1b89cde8e60ca69f1b44ad12d4858..ca9854cdcda7f1bf28be93e6be3e90533cee7083 100644 (file)
@@ -34,6 +34,8 @@ a=4 b=7 ss=4 declare -i ss
 a=4 b=7 foo
 echo after: $a
 
+exec 7>&- 4>&-
+
 unset a
 a=4 echo foo 2>&1 >&$(foo) | { grep -q 'Bad file' || echo 'redir11 bad 3'; }
 a=1 echo foo 2>&1 >&$(foo) | { grep -q 'Bad file' || echo 'redir11 bad 4'; }
index e7ecbe24963a6f87e6aeeee4e117eefc35507306..817757a4b11efecc38e4e39d4395921749b0f3d3 100644 (file)
@@ -25,15 +25,15 @@ func ()
 }
 while
 while is a shell keyword
-./type.tests: line 59: type: m: not found
-alias m='more'
-alias m='more'
-m is aliased to `more'
+./type.tests: line 59: type: morealias: not found
+alias morealias='more'
+alias morealias='more'
+morealias is aliased to `more'
 alias
-alias m='more'
-alias m='more'
-alias m='more'
-m is aliased to `more'
+alias morealias='more'
+alias morealias='more'
+alias morealias='more'
+morealias is aliased to `more'
 builtin
 builtin is a shell builtin
 /bin/sh
index 13e6cc46397ede751a7874392762cafe89be8650..48c97d7ed5e53fcd782675116494225aba89a12a 100644 (file)
@@ -28,8 +28,6 @@ command -v notthere
 # but this will produce an error message
 command -V notthere
 
-alias m=more
-
 unset -f func 2>/dev/null
 func() { echo this is func; }
 
@@ -52,24 +50,26 @@ command -V func
 command -v while
 command -V while
 
+alias morealias=more
+
 # the following two lines should produce the same output
 # post-3.0 patch makes command -v silent, as posix specifies
 # first test with alias expansion off (should all fail or produce no output)
-type -t m
-type m
-command -v m
+type -t morealias
+type morealias
+command -v morealias
 alias -p
-alias m
+alias morealias
 
 # then test with alias expansion on 
 shopt -s expand_aliases
-type m
-type -t m
-command -v m
+type morealias
+type -t morealias
+command -v morealias
 alias -p
-alias m
+alias morealias
 
-command -V m
+command -V morealias
 shopt -u expand_aliases
 
 command -v builtin
@@ -79,7 +79,7 @@ command -V /bin/sh
 
 unset -f func
 type func
-unalias m
+unalias morealias
 type m
 
 hash -r