From 135786413b1346f647980e2c338087f41e2735a2 Mon Sep 17 00:00:00 2001 From: jilles Date: Sun, 5 May 2013 10:51:40 +0000 Subject: sh: Use O_CLOEXEC and F_DUPFD_CLOEXEC instead of separate fcntl() call. --- bin/sh/input.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'bin/sh/input.c') 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); -- cgit v1.1