mirror of
git://git.sv.gnu.org/coreutils.git
synced 2026-02-16 20:33:18 +02:00
New options to set signal handlers for the command being executed. --block-signal suggested by Paul Eggert in http://bugs.gnu.org/34488#71 --default-signal is useful to overcome the POSIX limitation that shell must not override inherited signal state, e.g. the second 'trap' here is a no-op: trap '' PIPE && sh -c 'trap - PIPE ; seq inf | head -n1' Instead use: trap '' PIPE && sh -c 'env --default-signal=PIPE seq inf | head -n1' Similarly, the following will prevent CTRL-C from terminating the program: env --ignore-signal=INT seq inf > /dev/null See https://bugs.gnu.org/34488#8 * NEWS: Mention new options. * doc/coreutils.texi (env invocation): Document new options. * man/env.x: Add example of --default-signal=SIG usage. (SEE ALSO): Mention sigprocmask. * src/env.c (signals): New global variable. (longopts): Add new options. (usage): Print new options. (parse_signal_params): Parse comma-separated list of signals, store in signals variable. (reset_signal_handlers): Set each signal to SIG_DFL/SIG_IGN. (parse_block_signal_params): Parse command-line options. (set_signal_proc_mask): Call sigprocmask to block/unblock signals. (main): Process new options. * src/local.mk (src_env_SOURCES): Add operand2sig.c. * tests/misc/env-signal-handler.sh: New test. * tests/local.mk (all_tests): Add new test.
68 lines
1.7 KiB
Plaintext
68 lines
1.7 KiB
Plaintext
'\" Copyright (C) 1998-2019 Free Software Foundation, Inc.
|
|
'\"
|
|
'\" This is free software. You may redistribute copies of it under the terms
|
|
'\" of the GNU General Public License <https://www.gnu.org/licenses/gpl.html>.
|
|
'\" There is NO WARRANTY, to the extent permitted by law.
|
|
[NAME]
|
|
env \- run a program in a modified environment
|
|
[DESCRIPTION]
|
|
.\" Add any additional description here
|
|
[OPTIONS]
|
|
.SS "\-S/\-\-split\-string usage in scripts"
|
|
The
|
|
.B \-S
|
|
option allows specifying multiple parameters in a script.
|
|
Running a script named
|
|
.B 1.pl
|
|
containing the following first line:
|
|
.PP
|
|
.RS
|
|
.nf
|
|
#!/usr/bin/env \-S perl \-w \-T
|
|
\&...
|
|
.fi
|
|
.RE
|
|
.PP
|
|
Will execute
|
|
.B "perl \-w \-T 1.pl".
|
|
.PP
|
|
Without the
|
|
.B '\-S'
|
|
parameter the script will likely fail with:
|
|
.PP
|
|
.RS
|
|
.nf
|
|
/usr/bin/env: 'perl \-w \-T': No such file or directory
|
|
.fi
|
|
.RE
|
|
.PP
|
|
See the full documentation for more details.
|
|
.PP
|
|
.SS "\-\-default-signal[=SIG]" usage
|
|
This option allows setting a signal handler to its default
|
|
action, which is not possible using the traditional shell
|
|
trap command. The following example ensures that seq
|
|
will be terminated by SIGPIPE no matter how this signal
|
|
is being handled in the process invoking the command.
|
|
|
|
.PP
|
|
.RS
|
|
.nf
|
|
sh \-c 'env \-\-default-signal=PIPE seq inf | head \-n1'
|
|
.fi
|
|
.RE
|
|
.PP
|
|
|
|
[NOTES]
|
|
POSIX's exec(2) pages says:
|
|
.RS
|
|
"many existing applications wrongly assume that they start with certain
|
|
signals set to the default action and/or unblocked.... Therefore, it is best
|
|
not to block or ignore signals across execs without explicit reason to do so,
|
|
and especially not to block signals across execs of arbitrary (not closely
|
|
cooperating) programs."
|
|
.RE
|
|
|
|
[SEE ALSO]
|
|
sigaction(2), sigprocmask(2), signal(7)
|