Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make JobCreatePipe: do fcntl() *after* any fiddling ...
details: https://anonhg.NetBSD.org/src/rev/78bb0ca85682
branches: trunk
changeset: 787168:78bb0ca85682
user: sjg <sjg%NetBSD.org@localhost>
date: Wed Jun 05 03:59:43 2013 +0000
description:
JobCreatePipe: do fcntl() *after* any fiddling of fd's
to avoid leaking descriptors.
Job_ServerStart: set closed on exec for jp_0 and jp_1.
diffstat:
usr.bin/make/job.c | 26 ++++++++++++++------------
1 files changed, 14 insertions(+), 12 deletions(-)
diffs (67 lines):
diff -r 1a2d6719a91a -r 78bb0ca85682 usr.bin/make/job.c
--- a/usr.bin/make/job.c Wed Jun 05 02:51:49 2013 +0000
+++ b/usr.bin/make/job.c Wed Jun 05 03:59:43 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: job.c,v 1.172 2013/03/05 22:01:43 christos Exp $ */
+/* $NetBSD: job.c,v 1.173 2013/06/05 03:59:43 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: job.c,v 1.172 2013/03/05 22:01:43 christos Exp $";
+static char rcsid[] = "$NetBSD: job.c,v 1.173 2013/06/05 03:59:43 sjg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)job.c 8.2 (Berkeley) 3/19/94";
#else
-__RCSID("$NetBSD: job.c,v 1.172 2013/03/05 22:01:43 christos Exp $");
+__RCSID("$NetBSD: job.c,v 1.173 2013/06/05 03:59:43 sjg Exp $");
#endif
#endif /* not lint */
#endif
@@ -401,6 +401,15 @@
if (pipe(job->jobPipe) == -1)
Punt("Cannot create pipe: %s", strerror(errno));
+ for (i = 0; i < 2; i++) {
+ /* Avoid using low numbered fds */
+ fd = fcntl(job->jobPipe[i], F_DUPFD, minfd);
+ if (fd != -1) {
+ close(job->jobPipe[i]);
+ job->jobPipe[i] = fd;
+ }
+ }
+
/* Set close-on-exec flag for both */
(void)fcntl(job->jobPipe[0], F_SETFD, 1);
(void)fcntl(job->jobPipe[1], F_SETFD, 1);
@@ -413,15 +422,6 @@
*/
fcntl(job->jobPipe[0], F_SETFL,
fcntl(job->jobPipe[0], F_GETFL, 0) | O_NONBLOCK);
-
- for (i = 0; i < 2; i++) {
- /* Avoid using low numbered fds */
- fd = fcntl(job->jobPipe[i], F_DUPFD, minfd);
- if (fd != -1) {
- close(job->jobPipe[i]);
- job->jobPipe[i] = fd;
- }
- }
}
/*-
@@ -2812,6 +2812,8 @@
/* Pipe passed in from parent */
tokenWaitJob.inPipe = jp_0;
tokenWaitJob.outPipe = jp_1;
+ (void)fcntl(jp_0, F_SETFD, 1);
+ (void)fcntl(jp_1, F_SETFD, 1);
return;
}
Home |
Main Index |
Thread Index |
Old Index