Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/sh Don't close-on-exec redirections created explicitly f...
details: https://anonhg.NetBSD.org/src/rev/14938542446f
branches: trunk
changeset: 344089:14938542446f
user: christos <christos%NetBSD.org@localhost>
date: Sat Mar 12 21:35:13 2016 +0000
description:
Don't close-on-exec redirections created explicitly for the command being
ran; i.e. we want this to work:
$ cat succ1
#!/bin/sh
./succ2 6>out
$ cat succ2
#!/bin/sh
echo succ2 >&6
$ ./succ1
And this to fail:
$ cat fail1
#!/bin/sh
exec 6> out
echo "fail1" >&6
./fail2
exec 6>&-
$ cat fail2
#!obj.amd64/sh
echo "fail2" >&6
$ ./fail1
./fail2: 6: Bad file descriptor
XXX: Do we want a -k (keep flag on exec to make redirections not close-on-exec?
diffstat:
bin/sh/eval.c | 7 ++++---
bin/sh/redir.c | 6 +++---
bin/sh/redir.h | 9 +++++----
3 files changed, 12 insertions(+), 10 deletions(-)
diffs (78 lines):
diff -r 19e81523bcdd -r 14938542446f bin/sh/eval.c
--- a/bin/sh/eval.c Sat Mar 12 21:20:17 2016 +0000
+++ b/bin/sh/eval.c Sat Mar 12 21:35:13 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: eval.c,v 1.116 2016/03/12 14:59:26 christos Exp $ */
+/* $NetBSD: eval.c,v 1.117 2016/03/12 21:35:13 christos Exp $ */
/*-
* Copyright (c) 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)eval.c 8.9 (Berkeley) 6/8/95";
#else
-__RCSID("$NetBSD: eval.c,v 1.116 2016/03/12 14:59:26 christos Exp $");
+__RCSID("$NetBSD: eval.c,v 1.117 2016/03/12 21:35:13 christos Exp $");
#endif
#endif /* not lint */
@@ -1118,7 +1118,8 @@
#ifdef DEBUG
trputs("normal command: "); trargs(argv);
#endif
- redirect(cmd->ncmd.redirect, vforked ? REDIR_VFORK : 0);
+ redirect(cmd->ncmd.redirect,
+ (vforked ? REDIR_VFORK : 0) | REDIR_KEEP);
if (!vforked)
for (sp = varlist.list ; sp ; sp = sp->next)
setvareq(sp->text, VEXPORT|VSTACK);
diff -r 19e81523bcdd -r 14938542446f bin/sh/redir.c
--- a/bin/sh/redir.c Sat Mar 12 21:20:17 2016 +0000
+++ b/bin/sh/redir.c Sat Mar 12 21:35:13 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: redir.c,v 1.39 2016/01/04 13:57:15 christos Exp $ */
+/* $NetBSD: redir.c,v 1.40 2016/03/12 21:35:13 christos 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.39 2016/01/04 13:57:15 christos Exp $");
+__RCSID("$NetBSD: redir.c,v 1.40 2016/03/12 21:35:13 christos Exp $");
#endif
#endif /* not lint */
@@ -244,7 +244,7 @@
}
if (f != fd) {
- copyfd(f, fd, 1, fd > 2);
+ copyfd(f, fd, 1, fd > 2 && (flags & REDIR_KEEP) == 0);
close(f);
} else if (f > 2)
(void)fcntl(f, F_SETFD, FD_CLOEXEC);
diff -r 19e81523bcdd -r 14938542446f bin/sh/redir.h
--- a/bin/sh/redir.h Sat Mar 12 21:20:17 2016 +0000
+++ b/bin/sh/redir.h Sat Mar 12 21:35:13 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: redir.h,v 1.17 2016/01/04 03:00:24 christos Exp $ */
+/* $NetBSD: redir.h,v 1.18 2016/03/12 21:35:13 christos Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -35,9 +35,10 @@
*/
/* flags passed to redirect */
-#define REDIR_PUSH 01 /* save previous values of file descriptors */
-#define REDIR_BACKQ 02 /* save the command output in memory */
-#define REDIR_VFORK 04 /* running under vfork(2), be careful */
+#define REDIR_PUSH 0x01 /* save previous values of file descriptors */
+#define REDIR_BACKQ 0x02 /* save the command output in memory */
+#define REDIR_VFORK 0x04 /* running under vfork(2), be careful */
+#define REDIR_KEEP 0x08 /* don't close-on-exec */
union node;
void redirect(union node *, int);
Home |
Main Index |
Thread Index |
Old Index