summaryrefslogtreecommitdiffstats
path: root/bin/sh/input.c
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2013-05-05 10:51:40 +0000
committerjilles <jilles@FreeBSD.org>2013-05-05 10:51:40 +0000
commit135786413b1346f647980e2c338087f41e2735a2 (patch)
treedaf1ba66bada98a9f310e8dfed5331cec9dd46cd /bin/sh/input.c
parent42b8c0012b80efc0b1d1bacb9d5c45afd8a51301 (diff)
downloadFreeBSD-src-135786413b1346f647980e2c338087f41e2735a2.zip
FreeBSD-src-135786413b1346f647980e2c338087f41e2735a2.tar.gz
sh: Use O_CLOEXEC and F_DUPFD_CLOEXEC instead of separate fcntl() call.
Diffstat (limited to 'bin/sh/input.c')
-rw-r--r--bin/sh/input.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/bin/sh/input.c b/bin/sh/input.c
index 62e82a0..f574f46 100644
--- a/bin/sh/input.c
+++ b/bin/sh/input.c
@@ -397,10 +397,10 @@ setinputfile(const char *fname, int push)
int fd2;
INTOFF;
- if ((fd = open(fname, O_RDONLY)) < 0)
+ if ((fd = open(fname, O_RDONLY | O_CLOEXEC)) < 0)
error("cannot open %s: %s", fname, strerror(errno));
if (fd < 10) {
- fd2 = fcntl(fd, F_DUPFD, 10);
+ fd2 = fcntl(fd, F_DUPFD_CLOEXEC, 10);
close(fd);
if (fd2 < 0)
error("Out of file descriptors");
@@ -412,14 +412,13 @@ setinputfile(const char *fname, int push)
/*
- * Like setinputfile, but takes an open file descriptor. Call this with
- * interrupts off.
+ * Like setinputfile, but takes an open file descriptor (which should have
+ * its FD_CLOEXEC flag already set). Call this with interrupts off.
*/
void
setinputfd(int fd, int push)
{
- (void)fcntl(fd, F_SETFD, FD_CLOEXEC);
if (push) {
pushfile();
parsefile->buf = ckmalloc(BUFSIZ + 1);
OpenPOWER on IntegriCloud