handle signals at more places in brace expansion; fix for subshells changing terminal process group on signals

This commit is contained in:
Chet Ramey
2022-12-21 09:57:36 -05:00
parent c4a2e37470
commit 001918cdec
11 changed files with 139 additions and 41 deletions
+25
View 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>
+11
View File
@@ -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]);
+3 -3
View 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;
}
+5 -4
View 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);
}
}
+21 -15
View 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.
@@ -11013,18 +11013,20 @@ or
.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.
+16 -11
View 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.
+2 -2
View 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
+53 -6
View File
@@ -23,23 +23,70 @@
#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 */
};
+1
View File
@@ -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
+1
View File
@@ -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. */
+1
View File
@@ -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 */