summaryrefslogtreecommitdiffstats
path: root/bin/sh/jobs.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/jobs.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/jobs.c')
-rw-r--r--bin/sh/jobs.c12
1 files changed, 4 insertions, 8 deletions
diff --git a/bin/sh/jobs.c b/bin/sh/jobs.c
index 54f72ea..163b7e7 100644
--- a/bin/sh/jobs.c
+++ b/bin/sh/jobs.c
@@ -127,11 +127,12 @@ setjobctl(int on)
if (on) {
if (ttyfd != -1)
close(ttyfd);
- if ((ttyfd = open(_PATH_TTY, O_RDWR)) < 0) {
+ if ((ttyfd = open(_PATH_TTY, O_RDWR | O_CLOEXEC)) < 0) {
i = 0;
while (i <= 2 && !isatty(i))
i++;
- if (i > 2 || (ttyfd = fcntl(i, F_DUPFD, 10)) < 0)
+ if (i > 2 ||
+ (ttyfd = fcntl(i, F_DUPFD_CLOEXEC, 10)) < 0)
goto out;
}
if (ttyfd < 10) {
@@ -139,7 +140,7 @@ setjobctl(int on)
* Keep our TTY file descriptor out of the way of
* the user's redirections.
*/
- if ((i = fcntl(ttyfd, F_DUPFD, 10)) < 0) {
+ if ((i = fcntl(ttyfd, F_DUPFD_CLOEXEC, 10)) < 0) {
close(ttyfd);
ttyfd = -1;
goto out;
@@ -147,11 +148,6 @@ setjobctl(int on)
close(ttyfd);
ttyfd = i;
}
- if (fcntl(ttyfd, F_SETFD, FD_CLOEXEC) < 0) {
- close(ttyfd);
- ttyfd = -1;
- goto out;
- }
do { /* while we are in the background */
initialpgrp = tcgetpgrp(ttyfd);
if (initialpgrp < 0) {
OpenPOWER on IntegriCloud