Thu Jan 24 17:47:59 2013 UTC ()
use O_CLOEXEC.


(christos)
diff -r1.45 -r1.46 src/usr.bin/ktrace/ktrace.c

cvs diff -r1.45 -r1.46 src/usr.bin/ktrace/ktrace.c (expand / switch to context diff)
--- src/usr.bin/ktrace/ktrace.c 2011/09/16 15:39:26 1.45
+++ src/usr.bin/ktrace/ktrace.c 2013/01/24 17:47:58 1.46
@@ -1,4 +1,4 @@
-/*	$NetBSD: ktrace.c,v 1.45 2011/09/16 15:39:26 joerg Exp $	*/
+/*	$NetBSD: ktrace.c,v 1.46 2013/01/24 17:47:58 christos Exp $	*/
 
 /*-
  * Copyright (c) 1988, 1993
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)ktrace.c	8.2 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: ktrace.c,v 1.45 2011/09/16 15:39:26 joerg Exp $");
+__RCSID("$NetBSD: ktrace.c,v 1.46 2013/01/24 17:47:58 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -70,7 +70,6 @@
 __dead static void usage(void);
 static int do_ktrace(const char *, int, int, int, int, int);
 __dead static void no_ktrace(int);
-static void fset(int fd, int flag);
 static void fclear(int fd, int flag);
 
 #ifdef KTRUSS
@@ -270,17 +269,6 @@
 }
 
 static void
-fset(int fd, int flag)
-{
-	int oflag = fcntl(fd, F_GETFL, 0);
-
-	if (oflag == -1)
-		err(EXIT_FAILURE, "Cannot get file flags");
-	if (fcntl(fd, F_SETFL, oflag | flag) == -1)
-		err(EXIT_FAILURE, "Cannot set file flags");
-}
-
-static void
 fclear(int fd, int flag)
 {
 	int oflag = fcntl(fd, F_GETFL, 0);
@@ -340,11 +328,9 @@
 	    (!tracefile || strcmp(tracefile, "-") == 0)) {
 		int pi[2], dofork;
 
-		if (pipe(pi) < 0)
+		if (pipe2(pi, O_CLOEXEC) == -1)
 			err(EXIT_FAILURE, "pipe(2)");
 
-		fset(pi[0], FD_CLOEXEC);
-		fset(pi[1], FD_CLOEXEC);
 		dofork = (pid == getpid());
 
 		if (dofork) {