4f42077
commit fcc4134a7b76d82d39dea635c41ec593a41d6d19
4f42077
Author: Herbert Xu <herbert@gondor.apana.org.au>
4f42077
Date:   Sun Feb 22 19:29:48 2009 +0800
4f42077
4f42077
    [JOBS] Do not close stderr when /dev/tty fails to open
4f42077
    
4f42077
    As it stands if we fail to open /dev/tty we end up closing stderr
4f42077
    after saving it at a higher fd.
4f42077
    
4f42077
    Thanks to David van Gorkom for reporting this.
4f42077
    
4f42077
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
4f42077
4f42077
diff --git a/src/jobs.c b/src/jobs.c
4f42077
index 69a84f7..b1ab7ab 100644
4f42077
--- a/src/jobs.c
4f42077
+++ b/src/jobs.c
4f42077
@@ -195,6 +195,9 @@ setjobctl(int on)
4f42077
 			while (!isatty(fd))
4f42077
 				if (--fd < 0)
4f42077
 					goto out;
4f42077
+			fd = dup(fd);
4f42077
+			if (fd < 0)
4f42077
+				goto out;
4f42077
 		}
4f42077
 		fd = savefd(fd);
4f42077
 		do { /* while we are in the background */