From f393ff40ef49c582f614ff44107d1132753693a1 Mon Sep 17 00:00:00 2001 From: Herbert Xu Date: Sat, 12 May 2007 18:00:57 +1000 Subject: [REDIR] Replace copyfd by savefd and use dup2 elsewhere There are two kinds of users to copyfd, those that want to copy an fd to an exact value and those that want to move an fd to a value >= 10. The former can simply use dup2 directly while the latter share a lot of common code that now constitutes savefd. --- src/jobs.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'src/jobs.c') diff --git a/src/jobs.c b/src/jobs.c index 9e28adb..7285d0d 100644 --- a/src/jobs.c +++ b/src/jobs.c @@ -188,18 +188,14 @@ setjobctl(int on) if (on == jobctl || rootshell == 0) return; if (on) { - int ofd; - ofd = fd = open(_PATH_TTY, O_RDWR); + fd = open(_PATH_TTY, O_RDWR); if (fd < 0) { fd += 3; - while (!isatty(fd) && --fd >= 0) - ; + while (!isatty(fd)) + if (--fd < 0) + goto out; } - fd = fcntl(fd, F_DUPFD, 10); - close(ofd); - if (fd < 0) - goto out; - fcntl(fd, F_SETFD, FD_CLOEXEC); + fd = savefd(fd); do { /* while we are in the background */ if ((pgrp = tcgetpgrp(fd)) < 0) { out: -- cgit 1.4.1