]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
handle signals at more places in brace expansion; fix for subshells changing terminal...
authorChet Ramey <chet.ramey@case.edu>
Wed, 21 Dec 2022 14:57:36 +0000 (09:57 -0500)
committerChet Ramey <chet.ramey@case.edu>
Wed, 21 Dec 2022 14:57:36 +0000 (09:57 -0500)
CWRU/CWRU.chlog
braces.c
builtins/set.def
builtins/type.def
doc/bash.1
doc/bashref.texi
doc/version.texi
examples/loadables/sync.c
jobs.c
quit.h
sig.c

index c59922f729b058c6da3388c5a43308239df47c37..33ec9b4428d7863b8324eefa71ada83b2bf0b497 100644 (file)
@@ -4745,3 +4745,28 @@ builtins/umask.def
                o missing perm characters Xst in action string
                o default `who' equivalent to `a' instead of fixing up later
 
+                                  12/19
+                                  -----
+builtins/type.def
+       - if -a and -P are both supplied, look in the command hash table but
+         continue and perform a $PATH search even if the NAME is hashed.
+         From a report by Adam Vodopjan <adam.vodopjan@gmail.com>
+
+doc/{bash.1,bashref.texi}
+       - type: update description to fix it to what the code actually does
+
+builtins/set.def
+       - set_edit_mode: don't run with_input_from_stdin or with_input_from_stream
+         unless command_execution_string is NULL. Report from
+         Harald van Dijk <harald@gigawatt.nl>
+
+                                  12/20
+                                  -----
+braces.c
+       - array_concat: add a check for interrupts and terminating signals
+         into the inner loop
+
+jobs.c
+       - without_job_control: set original_pgrp == NO_PID since we don't
+         want to be messing with the terminal pgrp if we call end_job_control.
+         From a report from ks1322 ks1322 <ks1322@gmail.com>
index e91d326ea42d39b3f0cabc9dd0e21d7c597e62a0..16eca18e893aaa0148068b37aaa2becc1516d19d 100644 (file)
--- a/braces.c
+++ b/braces.c
@@ -767,6 +767,17 @@ array_concat (arr1, arr2)
 
       for (j = 0; j < len2; j++)
        {
+#if defined (SHELL)
+         if (ISINTERRUPT)
+           {
+             result[len] = (char *)NULL;
+             strvec_dispose (result);
+             result = (char **)NULL;
+             strvec_dispose (arr1);    /* caller expects us to free arr1 */
+           }
+         QUIT;
+#endif
+       
          result[len] = (char *)xmalloc (1 + strlen_1 + strlen (arr2[j]));
          strcpy (result[len], arr1[i]);
          strcpy (result[len] + strlen_1, arr2[j]);
index 4a7c517ec4f7eeb30edf44a54c4285e0424a5c0a..c0d63c5b4667c126b1c812f38ed55243eddd0ba0 100644 (file)
@@ -1,7 +1,7 @@
 This file is set.def, from which is created set.c.
 It implements the "set" and "unset" builtins in Bash.
 
-Copyright (C) 1987-2021 Free Software Foundation, Inc.
+Copyright (C) 1987-2022 Free Software Foundation, Inc.
 
 This file is part of GNU Bash, the Bourne Again SHell.
 
@@ -434,7 +434,7 @@ set_edit_mode (on_or_off, option_name)
     {
       rl_variable_bind ("editing-mode", option_name);
 
-      if (interactive)
+      if (interactive && command_execution_string == 0)
        with_input_from_stdin ();
       no_line_editing = 0;
     }
@@ -443,7 +443,7 @@ set_edit_mode (on_or_off, option_name)
       isemacs = rl_editing_mode == 1;
       if ((isemacs && *option_name == 'e') || (!isemacs && *option_name == 'v'))
        {
-         if (interactive)
+         if (interactive && command_execution_string == 0)
            with_input_from_stream (stdin, "stdin");
          no_line_editing = 1;
        }
index a8e47c0ac44dbffe102bc3dccee0d65298173f8c..a030edd655988909d61e0a232476af4d40ccfd36 100644 (file)
@@ -1,7 +1,7 @@
 This file is type.def, from which is created type.c.
 It implements the builtin "type" in Bash.
 
-Copyright (C) 1987-2020 Free Software Foundation, Inc.
+Copyright (C) 1987-2022 Free Software Foundation, Inc.
 
 This file is part of GNU Bash, the Bourne Again SHell.
 
@@ -163,7 +163,7 @@ type_builtin (list)
          dflags |= CDESC_TYPE;
          dflags &= ~(CDESC_PATH_ONLY|CDESC_SHORTDESC);
          break;
-       case 'P':       /* shorthand for type -ap */
+       case 'P':       /* force path search only plus hash table lookup */
          dflags |= (CDESC_PATH_ONLY|CDESC_FORCE_PATH);
          dflags &= ~(CDESC_TYPE|CDESC_SHORTDESC);
          break;
@@ -242,7 +242,7 @@ describe_command (command, dflags)
 
       found = 1;
 
-      if (all == 0)
+      if (all == 0)            /* type -p returns, any executable file would not have precedence */
        return (1);
     }
 #endif /* ALIAS */
@@ -345,7 +345,8 @@ describe_command (command, dflags)
            printf ("%s\n", full_path);
 
          free (full_path);
-         return (1);
+         if (all == 0)
+           return (1);
        }
     }
 
index 76660ace61a3fc83c412d0dedec00f4b63aa08b6..f7b2255710808d23614b5dbaf2e1d232f49303d1 100644 (file)
@@ -5,12 +5,12 @@
 .\"    Case Western Reserve University
 .\"    chet.ramey@case.edu
 .\"
-.\"    Last Change: Fri Dec  2 15:53:52 EST 2022
+.\"    Last Change: Mon Dec 19 13:56:57 EST 2022
 .\"
 .\" bash_builtins, strip all but Built-Ins section
 .if \n(zZ=1 .ig zZ
 .if \n(zY=1 .ig zY
-.TH BASH 1 "2022 December 2" "GNU Bash 5.2"
+.TH BASH 1 "2022 December 19" "GNU Bash 5.2"
 .\"
 .\" There's some problem with having a `@'
 .\" in a tagged paragraph with the BSD man macros.
 .I file
 if
 .I name
-is an alias, shell reserved word, function, builtin, or disk file,
+is an alias, shell reserved word, function, builtin, or executable disk file,
 respectively.
 If the
 .I name
-is not found, then nothing is printed, and an exit status of false
-is returned.
+is not found, then nothing is printed, and \fBtype\fP returns a
+non-zero exit status.
 If the
 .B \-p
 option is used,
 .B type
-either returns the name of the disk file
-that would be executed if
+either returns the name of the executable file
+that would be found by searching
+.B $PATH
+if
 .I name
 were specified as a command name,
 or nothing if
@@ -11054,16 +11056,20 @@ If the
 .B \-a
 option is used,
 .B type
-prints all of the places that contain
-an executable named
+prints all of the places that contain a command named
 .IR name .
-This includes aliases and functions,
-if and only if the
-.B \-p
-option is not also used.
-The table of hashed commands is not consulted
+This includes aliases, reserved words, functions, and builtins,
+but the path search options (\fB\-p\fP and \fB\-P\fP)
+can be supplied to restrict the output to executable files.
+\fBtype\fP does not consult the table of hashed commands
 when using
-.BR \-a .
+.B \-a 
+with
+.BR \-p ,
+and only performs a
+.SM
+.B PATH
+search for \fIname\fP.
 The
 .B \-f
 option suppresses shell function lookup, as with the \fBcommand\fP builtin.
index f5872b6b689368cf46c611a122a5a57d270006e1..3ba9919da85d8123963dead9cd84eef12406323f 100644 (file)
@@ -5049,27 +5049,32 @@ For each @var{name}, indicate how it would be interpreted if used as a
 command name.
 
 If the @option{-t} option is used, @code{type} prints a single word
-which is one of @samp{alias}, @samp{function}, @samp{builtin},
-@samp{file} or @samp{keyword},
-if @var{name} is an alias, shell function, shell builtin,
-disk file, or shell reserved word, respectively.
+which is one of @samp{alias}, @samp{keyword}, @samp{function},
+@samp{builtin}, or @samp{file},
+if @var{name} is an alias, shell reserved word, shell function,
+shell builtin, or executable disk file, respectively.
 If the @var{name} is not found, then nothing is printed, and
 @code{type} returns a failure status.
 
 If the @option{-p} option is used, @code{type} either returns the name
-of the disk file that would be executed, or nothing if @option{-t}
-would not return @samp{file}.
+of the executable file that would be found by searching @code{$PATH},
+or nothing if @option{-t} would not return @samp{file}.
 
 The @option{-P} option forces a path search for each @var{name}, even if
 @option{-t} would not return @samp{file}.
 
-If a command is hashed, @option{-p} and @option{-P} print the hashed value,
-which is not necessarily the file that appears first in @code{$PATH}.
+If a @var{name} is present in the table of hashed commands,
+options @option{-p} and @option{-P} print the hashed value, which is not
+necessarily the file that appears first in @code{$PATH}.
 
 If the @option{-a} option is used, @code{type} returns all of the places
-that contain an executable named @var{file}.
-This includes aliases and functions, if and only if the @option{-p} option
-is not also used.
+that contain a command named @var{name}.
+This includes aliases, reserved words, functions, and builtins,
+but the path search options (@option{-p} and @option{-P}) can be supplied
+to restrict the output to executable files.
+If @option{-a} is supplied with @option{-p}, @code{type} does not look
+in the table of hashed commands, and only performs a @code{PATH}
+search for @var{name}.
 
 If the @option{-f} option is used, @code{type} does not attempt to find
 shell functions, as with the @code{command} builtin.
index 66d7d1774ff937c03e190f2224b52b53e4da24e6..7f2ceb5d989f2d8fd22fb285c7f87d68845a62ce 100644 (file)
@@ -2,10 +2,10 @@
 Copyright (C) 1988-2022 Free Software Foundation, Inc.
 @end ignore
 
-@set LASTCHANGE Fri Dec  2 16:14:27 EST 2022
+@set LASTCHANGE Mon Dec 19 13:56:45 EST 2022
 
 @set EDITION 5.2
 @set VERSION 5.2
 
-@set UPDATED 2 December 2022
+@set UPDATED 19 December 2022
 @set UPDATED-MONTH December 2022
index 4fbeee1c4c74e3a7d44f6f4f33fe0a72a47066d4..1eb5497689d686d80db50c0660a91b8c5730da20 100644 (file)
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
+#include <errno.h>
+#include <fcntl.h>
 
 #include "builtins.h"
 #include "shell.h"
+#include "common.h"
 #include "bashgetopt.h"
 
+#ifndef errno
+extern int errno;
+#endif
+
 int
 sync_builtin (list)
      WORD_LIST *list;
 {
-  sync();
-  return (EXECUTION_SUCCESS);
+  int fd, status;
+  WORD_LIST *l;
+  char *fn;
+
+  if (no_options (list))
+    return (EX_USAGE);
+  list = loptend;
+
+  if (list == 0)
+    {  
+      sync();
+      return (EXECUTION_SUCCESS);
+    }
+
+  status = EXECUTION_SUCCESS;
+  for (l = list; l; l = l->next)
+    {
+      fn = l->word->word;
+      fd = open (fn, O_WRONLY);
+      if (fd < 0)
+       fd = open (fn, O_RDONLY);
+
+      if (fd < 0)
+       {
+         file_error (fn);
+         status = EXECUTION_FAILURE;
+         continue;
+       }
+
+      if (fsync (fd) < 0)
+       {
+         builtin_error ("%s: cannot sync: %s", fn, strerror (errno));
+         status = EXECUTION_FAILURE;
+       }
+      close (fd);
+    }
+
+  return (status);
 }
 
 char *sync_doc[] = {
-       "Sync disks.",
-       ""
-       "Force completion of pending disk writes",
+       "Sync disks or specified files.",
+       "",
+       "If one or more FILEs is supplied, force completion of pending writes",
+       "to those files. Otherwise, force completion of any pending disk",
+       "writes.",
+       "",
+       "Exit Status: zero unless any FILE could not be synced.",
        (char *)NULL
 };
 
@@ -48,6 +95,6 @@ struct builtin sync_struct = {
        sync_builtin,           /* function implementing the builtin */
        BUILTIN_ENABLED,        /* initial flags for builtin */
        sync_doc,               /* array of long documentation strings. */
-       "sync",                 /* usage synopsis; becomes short_doc */
+       "sync [file ...]",      /* usage synopsis; becomes short_doc */
        0                       /* reserved for internal use */
 };
diff --git a/jobs.c b/jobs.c
index 76d60315c248072096adbcd2c0b5c5b0cbe8b0dc..1179d907c419630b856df347c0537856f245f23a 100644 (file)
--- a/jobs.c
+++ b/jobs.c
@@ -5025,6 +5025,7 @@ without_job_control ()
 #endif
   delete_all_jobs (0);
   set_job_control (0);
+  original_pgrp = NO_PID;
 }
 
 /* If this shell is interactive, terminate all stopped jobs and
diff --git a/quit.h b/quit.h
index 0af1d121f9a69f999da9532635f854f4b78f8e78..2d6dca4e320d39b7e4b315127ed1ed11c2e81a42 100644 (file)
--- a/quit.h
+++ b/quit.h
@@ -45,6 +45,7 @@ extern volatile sig_atomic_t terminating_signal;
 #define DELINTERRUPT interrupt_state--
 
 #define ISINTERRUPT interrupt_state != 0
+#define ISTERMSIG   terminating_signal != 0
 
 /* The same sort of thing, this time just for signals that would ordinarily
    cause the shell to terminate. */
diff --git a/sig.c b/sig.c
index 72c3212f5f9791fd7a2de47ee4f82d9539e6af64..659545b2edfa4ca31447cb92f9b7b4559c240f3b 100644 (file)
--- a/sig.c
+++ b/sig.c
@@ -613,6 +613,7 @@ termsig_handler (sig)
   if (sig == SIGHUP && (interactive || (subshell_environment & (SUBSHELL_COMSUB|SUBSHELL_PROCSUB))))
     hangup_all_jobs ();
 
+  /* XXX - should we also suppress this call if SUBSHELL_PIPE? */
   if ((subshell_environment & (SUBSHELL_COMSUB|SUBSHELL_PROCSUB)) == 0)
     end_job_control ();
 #endif /* JOB_CONTROL */