Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/sh When opening a file descritor with "exec n>/file" (an...
details: https://anonhg.NetBSD.org/src/rev/fb19c56309cf
branches: trunk
changeset: 353626:fb19c56309cf
user: kre <kre%NetBSD.org@localhost>
date: Sun May 14 17:27:05 2017 +0000
description:
When opening a file descritor with "exec n>/file" (and similar) only
set the close-on-exec bit when not in posix mode (to comply with posix...)
OK: christos@
diffstat:
bin/sh/redir.c | 6 +++---
bin/sh/sh.1 | 23 ++++++++++++++++++-----
2 files changed, 21 insertions(+), 8 deletions(-)
diffs (85 lines):
diff -r 5b322283c91d -r fb19c56309cf bin/sh/redir.c
--- a/bin/sh/redir.c Sun May 14 15:36:45 2017 +0000
+++ b/bin/sh/redir.c Sun May 14 17:27:05 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: redir.c,v 1.54 2017/04/29 15:14:28 kre Exp $ */
+/* $NetBSD: redir.c,v 1.55 2017/05/14 17:27:05 kre Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)redir.c 8.2 (Berkeley) 5/4/95";
#else
-__RCSID("$NetBSD: redir.c,v 1.54 2017/04/29 15:14:28 kre Exp $");
+__RCSID("$NetBSD: redir.c,v 1.55 2017/05/14 17:27:05 kre Exp $");
#endif
#endif /* not lint */
@@ -338,7 +338,7 @@
abort();
}
- cloexec = fd > 2 && (flags & REDIR_KEEP) == 0;
+ cloexec = fd > 2 && (flags & REDIR_KEEP) == 0 && !posix;
if (f != fd) {
if (copyfd(f, fd, cloexec) < 0) {
int e = errno;
diff -r 5b322283c91d -r fb19c56309cf bin/sh/sh.1
--- a/bin/sh/sh.1 Sun May 14 15:36:45 2017 +0000
+++ b/bin/sh/sh.1 Sun May 14 17:27:05 2017 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: sh.1,v 1.140 2017/05/14 14:14:39 kre Exp $
+.\" $NetBSD: sh.1,v 1.141 2017/05/14 17:27:05 kre Exp $
.\" Copyright (c) 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -382,7 +382,11 @@
the file given by the
.Ev ENV
variable is read at startup by a non-interactive shell.
-It also controls whether the shell treats
+It also controls whether file descriptors greater than 2
+opened using the
+.Ic exec
+built-in command are passed on to utilities executed,
+and whether the shell treats
an empty compound statement as a syntax error (required
by posix) or permits it.
Empty compound statements
@@ -1769,7 +1773,10 @@
command are marked as permanent, so that they are not undone when the
.Ic exec
command finishes.
-File descriptors created via such redirections are marked close-on-exec
+When the
+.Ic posix
+option is not set,
+file descriptors created via such redirections are marked close-on-exec
(see
.Xr open 2
.Dv O_CLOEXEC
@@ -1783,7 +1790,12 @@
(except
.Xr ksh 1 ) ,
made those file descriptors available to exec'ed processes.
-To turn off the close-on-exec mark,
+This behavior is required by the
+.Tn POSIX
+standard, so when the
+.Ic posix
+option is set, this shell also acts that way.
+To be assured the close-on-exec setting is off,
redirect the descriptor to (or from) itself,
either when invoking a command for which the descriptor is wanted open,
or by using
@@ -1795,7 +1807,8 @@
and pass it to all commands invoked subsequently.
Alternatively, see the
.Ic fdflags
-command below.
+command below, which can set, or clear, this, and other,
+file descriptor flags.
.It exit Op Ar exitstatus
Terminate the shell process.
If
Home |
Main Index |
Thread Index |
Old Index