Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/ktrace use O_CLOEXEC.



details:   https://anonhg.NetBSD.org/src/rev/cc72e064e169
branches:  trunk
changeset: 784309:cc72e064e169
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Jan 24 17:47:58 2013 +0000

description:
use O_CLOEXEC.

diffstat:

 usr.bin/ktrace/ktrace.c |  20 +++-----------------
 1 files changed, 3 insertions(+), 17 deletions(-)

diffs (57 lines):

diff -r 9f6aa1292518 -r cc72e064e169 usr.bin/ktrace/ktrace.c
--- a/usr.bin/ktrace/ktrace.c   Thu Jan 24 17:46:30 2013 +0000
+++ b/usr.bin/ktrace/ktrace.c   Thu Jan 24 17:47:58 2013 +0000
@@ -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) {



Home | Main Index | Thread Index | Old Index