Module Name:    src
Committed By:   christos
Date:           Sat Oct 15 23:00:02 UTC 2011

Modified Files:
        src/lib/libc/citrus: citrus_mmap.c
        src/lib/libc/gen: fstab.c fts.c getcap.c getgrent.c getttyent.c
            getusershell.c initdir.c opendir.c syslog.c utmp.c utmpx.c
        src/lib/libc/locale: localeio.c
        src/lib/libc/net: getaddrinfo.c gethnamaddr.c getnetent.c
            getprotoent_r.c getservent_r.c
        src/lib/libc/resolv: res_init.c
        src/lib/libc/rpc: getnetconfig.c getrpcent.c
        src/lib/libc/sys: adjtime.c clock_settime.c ntp_adjtime.c
            settimeofday.c

Log Message:
close on exec fixes:
- open + fcntl -> open O_CLOEXEC
- configuration database file descriptors that can stay open are now opened
  fopen(db, "re")


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/citrus/citrus_mmap.c
cvs rdiff -u -r1.28 -r1.29 src/lib/libc/gen/fstab.c
cvs rdiff -u -r1.40 -r1.41 src/lib/libc/gen/fts.c
cvs rdiff -u -r1.49 -r1.50 src/lib/libc/gen/getcap.c
cvs rdiff -u -r1.63 -r1.64 src/lib/libc/gen/getgrent.c
cvs rdiff -u -r1.23 -r1.24 src/lib/libc/gen/getttyent.c
cvs rdiff -u -r1.27 -r1.28 src/lib/libc/gen/getusershell.c \
    src/lib/libc/gen/utmpx.c
cvs rdiff -u -r1.1 -r1.2 src/lib/libc/gen/initdir.c
cvs rdiff -u -r1.37 -r1.38 src/lib/libc/gen/opendir.c
cvs rdiff -u -r1.48 -r1.49 src/lib/libc/gen/syslog.c
cvs rdiff -u -r1.9 -r1.10 src/lib/libc/gen/utmp.c
cvs rdiff -u -r1.5 -r1.6 src/lib/libc/locale/localeio.c
cvs rdiff -u -r1.95 -r1.96 src/lib/libc/net/getaddrinfo.c
cvs rdiff -u -r1.76 -r1.77 src/lib/libc/net/gethnamaddr.c
cvs rdiff -u -r1.18 -r1.19 src/lib/libc/net/getnetent.c
cvs rdiff -u -r1.5 -r1.6 src/lib/libc/net/getprotoent_r.c
cvs rdiff -u -r1.10 -r1.11 src/lib/libc/net/getservent_r.c
cvs rdiff -u -r1.22 -r1.23 src/lib/libc/resolv/res_init.c
cvs rdiff -u -r1.18 -r1.19 src/lib/libc/rpc/getnetconfig.c
cvs rdiff -u -r1.21 -r1.22 src/lib/libc/rpc/getrpcent.c
cvs rdiff -u -r1.11 -r1.12 src/lib/libc/sys/adjtime.c \
    src/lib/libc/sys/clock_settime.c src/lib/libc/sys/ntp_adjtime.c
cvs rdiff -u -r1.13 -r1.14 src/lib/libc/sys/settimeofday.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/citrus/citrus_mmap.c
diff -u src/lib/libc/citrus/citrus_mmap.c:1.3 src/lib/libc/citrus/citrus_mmap.c:1.4
--- src/lib/libc/citrus/citrus_mmap.c:1.3	Tue Jan 18 19:52:37 2005
+++ src/lib/libc/citrus/citrus_mmap.c	Sat Oct 15 19:00:01 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: citrus_mmap.c,v 1.3 2005/01/19 00:52:37 mycroft Exp $	*/
+/*	$NetBSD: citrus_mmap.c,v 1.4 2011/10/15 23:00:01 christos Exp $	*/
 
 /*-
  * Copyright (c)2003 Citrus Project,
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: citrus_mmap.c,v 1.3 2005/01/19 00:52:37 mycroft Exp $");
+__RCSID("$NetBSD: citrus_mmap.c,v 1.4 2011/10/15 23:00:01 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -58,12 +58,8 @@ _citrus_map_file(struct _citrus_region *
 
 	_region_init(r, NULL, 0);
 
-	if ((fd = open(path, O_RDONLY)) == -1)
+	if ((fd = open(path, O_RDONLY | O_CLOEXEC)) == -1)
 		return errno;
-	if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
-		ret = errno;
-		goto error;
-	}
 
 	if (fstat(fd, &st)  == -1) {
 		ret = errno;

Index: src/lib/libc/gen/fstab.c
diff -u src/lib/libc/gen/fstab.c:1.28 src/lib/libc/gen/fstab.c:1.29
--- src/lib/libc/gen/fstab.c:1.28	Sat Aug 12 19:49:54 2006
+++ src/lib/libc/gen/fstab.c	Sat Oct 15 19:00:01 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: fstab.c,v 1.28 2006/08/12 23:49:54 christos Exp $	*/
+/*	$NetBSD: fstab.c,v 1.29 2011/10/15 23:00:01 christos Exp $	*/
 
 /*
  * Copyright (c) 1980, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)fstab.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: fstab.c,v 1.28 2006/08/12 23:49:54 christos Exp $");
+__RCSID("$NetBSD: fstab.c,v 1.29 2011/10/15 23:00:01 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -216,7 +216,7 @@ setfsent(void)
 		rewind(_fs_fp);
 		return 1;
 	}
-	if ((_fs_fp = fopen(_PATH_FSTAB, "r")) == NULL) {
+	if ((_fs_fp = fopen(_PATH_FSTAB, "re")) == NULL) {
 		warn("Cannot open `%s'", _PATH_FSTAB);
 		return 0;
 	}

Index: src/lib/libc/gen/fts.c
diff -u src/lib/libc/gen/fts.c:1.40 src/lib/libc/gen/fts.c:1.41
--- src/lib/libc/gen/fts.c:1.40	Mon Nov  2 12:17:34 2009
+++ src/lib/libc/gen/fts.c	Sat Oct 15 19:00:01 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: fts.c,v 1.40 2009/11/02 17:17:34 stacktic Exp $	*/
+/*	$NetBSD: fts.c,v 1.41 2011/10/15 23:00:01 christos Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993, 1994
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)fts.c	8.6 (Berkeley) 8/14/94";
 #else
-__RCSID("$NetBSD: fts.c,v 1.40 2009/11/02 17:17:34 stacktic Exp $");
+__RCSID("$NetBSD: fts.c,v 1.41 2011/10/15 23:00:01 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -195,12 +195,8 @@ fts_open(char * const *argv, int options
 	 * descriptor we run anyway, just more slowly.
 	 */
 	if (!ISSET(FTS_NOCHDIR)) {
-		if ((sp->fts_rfd = open(".", O_RDONLY, 0)) == -1)
+		if ((sp->fts_rfd = open(".", O_RDONLY | O_CLOEXEC, 0)) == -1)
 			SET(FTS_NOCHDIR);
-		else if (fcntl(sp->fts_rfd, F_SETFD, FD_CLOEXEC) == -1) {
-			close(sp->fts_rfd);
-			SET(FTS_NOCHDIR);
-		}
 	}
 
 	if (nitems == 0)
@@ -352,13 +348,10 @@ fts_read(FTS *sp)
 	    (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) {
 		p->fts_info = fts_stat(sp, p, 1);
 		if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
-			if ((p->fts_symfd = open(".", O_RDONLY, 0)) == -1) {
-				p->fts_errno = errno;
-				p->fts_info = FTS_ERR;
-			} else if (fcntl(p->fts_symfd, F_SETFD, FD_CLOEXEC) == -1) {
+			if ((p->fts_symfd = open(".", O_RDONLY | O_CLOEXEC, 0))
+			    == -1) {
 				p->fts_errno = errno;
 				p->fts_info = FTS_ERR;
-				close(p->fts_symfd);
 			} else
 				p->fts_flags |= FTS_SYMFOLLOW;
 		}
@@ -446,13 +439,9 @@ next:	tmp = p;
 			p->fts_info = fts_stat(sp, p, 1);
 			if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
 				if ((p->fts_symfd =
-				    open(".", O_RDONLY, 0)) == -1) {
-					p->fts_errno = errno;
-					p->fts_info = FTS_ERR;
-				} else if (fcntl(p->fts_symfd, F_SETFD, FD_CLOEXEC) == -1) {
+				    open(".", O_RDONLY | O_CLOEXEC, 0)) == -1) {
 					p->fts_errno = errno;
 					p->fts_info = FTS_ERR;
-					close(p->fts_symfd);
 				} else
 					p->fts_flags |= FTS_SYMFOLLOW;
 			}

Index: src/lib/libc/gen/getcap.c
diff -u src/lib/libc/gen/getcap.c:1.49 src/lib/libc/gen/getcap.c:1.50
--- src/lib/libc/gen/getcap.c:1.49	Mon Feb  7 16:39:47 2011
+++ src/lib/libc/gen/getcap.c	Sat Oct 15 19:00:01 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: getcap.c,v 1.49 2011/02/07 21:39:47 joerg Exp $	*/
+/*	$NetBSD: getcap.c,v 1.50 2011/10/15 23:00:01 christos Exp $	*/
 
 /*-
  * Copyright (c) 1992, 1993
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)getcap.c	8.3 (Berkeley) 3/25/94";
 #else
-__RCSID("$NetBSD: getcap.c,v 1.49 2011/02/07 21:39:47 joerg Exp $");
+__RCSID("$NetBSD: getcap.c,v 1.50 2011/10/15 23:00:01 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -789,7 +789,7 @@ cgetnext(char **bp, const char * const *
 	if (dbp == NULL)
 		dbp = db_array;
 
-	if (pfp == NULL && (pfp = fopen(*dbp, "r")) == NULL) {
+	if (pfp == NULL && (pfp = fopen(*dbp, "re")) == NULL) {
 		(void)cgetclose();
 		return -1;
 	}
@@ -812,7 +812,7 @@ cgetnext(char **bp, const char * const *
 						(void)cgetclose();
 						return 0;
 					} else if ((pfp =
-					    fopen(*dbp, "r")) == NULL) {
+					    fopen(*dbp, "re")) == NULL) {
 						(void)cgetclose();
 						return -1;
 					} else

Index: src/lib/libc/gen/getgrent.c
diff -u src/lib/libc/gen/getgrent.c:1.63 src/lib/libc/gen/getgrent.c:1.64
--- src/lib/libc/gen/getgrent.c:1.63	Thu Jun  9 01:11:17 2011
+++ src/lib/libc/gen/getgrent.c	Sat Oct 15 19:00:01 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: getgrent.c,v 1.63 2011/06/09 05:11:17 sjg Exp $	*/
+/*	$NetBSD: getgrent.c,v 1.64 2011/10/15 23:00:01 christos Exp $	*/
 
 /*-
  * Copyright (c) 1999-2000, 2004-2005 The NetBSD Foundation, Inc.
@@ -88,7 +88,7 @@
 #if 0
 static char sccsid[] = "@(#)getgrent.c	8.2 (Berkeley) 3/21/94";
 #else
-__RCSID("$NetBSD: getgrent.c,v 1.63 2011/06/09 05:11:17 sjg Exp $");
+__RCSID("$NetBSD: getgrent.c,v 1.64 2011/10/15 23:00:01 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -304,7 +304,7 @@ __grstart_files(struct __grstate_files *
 	_DIAGASSERT(state != NULL);
 
 	if (state->fp == NULL) {
-		state->fp = fopen(_PATH_GROUP, "r");
+		state->fp = fopen(_PATH_GROUP, "re");
 		if (state->fp == NULL)
 			return NS_UNAVAIL;
 	} else {
@@ -1265,7 +1265,7 @@ __grstart_compat(struct __grstate_compat
 	_DIAGASSERT(state != NULL);
 
 	if (state->fp == NULL) {
-		state->fp = fopen(_PATH_GROUP, "r");
+		state->fp = fopen(_PATH_GROUP, "re");
 		if (state->fp == NULL)
 			return NS_UNAVAIL;
 	} else {

Index: src/lib/libc/gen/getttyent.c
diff -u src/lib/libc/gen/getttyent.c:1.23 src/lib/libc/gen/getttyent.c:1.24
--- src/lib/libc/gen/getttyent.c:1.23	Mon Apr 17 19:29:21 2006
+++ src/lib/libc/gen/getttyent.c	Sat Oct 15 19:00:01 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: getttyent.c,v 1.23 2006/04/17 23:29:21 salo Exp $	*/
+/*	$NetBSD: getttyent.c,v 1.24 2011/10/15 23:00:01 christos Exp $	*/
 
 /*
  * Copyright (c) 1989, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)getttyent.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: getttyent.c,v 1.23 2006/04/17 23:29:21 salo Exp $");
+__RCSID("$NetBSD: getttyent.c,v 1.24 2011/10/15 23:00:01 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -223,7 +223,7 @@ setttyentpath(const char *path)
 	if (tf) {
 		rewind(tf);
 		return 1;
-	} else if ((tf = fopen(path, "r")) != NULL)
+	} else if ((tf = fopen(path, "re")) != NULL)
 		return 1;
 	return 0;
 }

Index: src/lib/libc/gen/getusershell.c
diff -u src/lib/libc/gen/getusershell.c:1.27 src/lib/libc/gen/getusershell.c:1.28
--- src/lib/libc/gen/getusershell.c:1.27	Mon Apr 28 16:22:59 2008
+++ src/lib/libc/gen/getusershell.c	Sat Oct 15 19:00:01 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: getusershell.c,v 1.27 2008/04/28 20:22:59 martin Exp $	*/
+/*	$NetBSD: getusershell.c,v 1.28 2011/10/15 23:00:01 christos Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2005 The NetBSD Foundation, Inc.
@@ -63,7 +63,7 @@
 #if 0
 static char sccsid[] = "@(#)getusershell.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: getusershell.c,v 1.27 2008/04/28 20:22:59 martin Exp $");
+__RCSID("$NetBSD: getusershell.c,v 1.28 2011/10/15 23:00:01 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -133,7 +133,7 @@ _files_start(struct files_state *state)
 	_DIAGASSERT(state != NULL);
 
 	if (state->fp == NULL) {
-		state->fp = fopen(_PATH_SHELLS, "r");
+		state->fp = fopen(_PATH_SHELLS, "re");
 		if (state->fp == NULL)
 			return NS_UNAVAIL;
 	} else {
Index: src/lib/libc/gen/utmpx.c
diff -u src/lib/libc/gen/utmpx.c:1.27 src/lib/libc/gen/utmpx.c:1.28
--- src/lib/libc/gen/utmpx.c:1.27	Fri Sep 16 21:52:29 2011
+++ src/lib/libc/gen/utmpx.c	Sat Oct 15 19:00:02 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: utmpx.c,v 1.27 2011/09/17 01:52:29 christos Exp $	 */
+/*	$NetBSD: utmpx.c,v 1.28 2011/10/15 23:00:02 christos Exp $	 */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 #include <sys/cdefs.h>
 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: utmpx.c,v 1.27 2011/09/17 01:52:29 christos Exp $");
+__RCSID("$NetBSD: utmpx.c,v 1.28 2011/10/15 23:00:02 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -120,7 +120,7 @@ getutxent()
 	if (fp == NULL) {
 		struct stat st;
 
-		if ((fp = fopen(utfile, "r+")) == NULL)
+		if ((fp = fopen(utfile, "re+")) == NULL)
 			if ((fp = fopen(utfile, "w+")) == NULL) {
 				if ((fp = fopen(utfile, "r")) == NULL)
 					goto fail;

Index: src/lib/libc/gen/initdir.c
diff -u src/lib/libc/gen/initdir.c:1.1 src/lib/libc/gen/initdir.c:1.2
--- src/lib/libc/gen/initdir.c:1.1	Sat Sep 25 22:26:59 2010
+++ src/lib/libc/gen/initdir.c	Sat Oct 15 19:00:01 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: initdir.c,v 1.1 2010/09/26 02:26:59 yamt Exp $	*/
+/*	$NetBSD: initdir.c,v 1.2 2011/10/15 23:00:01 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1993
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: initdir.c,v 1.1 2010/09/26 02:26:59 yamt Exp $");
+__RCSID("$NetBSD: initdir.c,v 1.2 2011/10/15 23:00:01 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -153,8 +153,7 @@ retry:
 		 */
 		if (flags & DTF_REWIND) {
 			(void) close(fd);
-			if ((fd = open(name, O_RDONLY)) == -1 ||
-			    fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
+			if ((fd = open(name, O_RDONLY | O_CLOEXEC)) == -1) {
 				dirp->dd_buf = buf;
 				return errno;
 			}

Index: src/lib/libc/gen/opendir.c
diff -u src/lib/libc/gen/opendir.c:1.37 src/lib/libc/gen/opendir.c:1.38
--- src/lib/libc/gen/opendir.c:1.37	Sat Sep 25 22:26:59 2010
+++ src/lib/libc/gen/opendir.c	Sat Oct 15 19:00:01 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: opendir.c,v 1.37 2010/09/26 02:26:59 yamt Exp $	*/
+/*	$NetBSD: opendir.c,v 1.38 2011/10/15 23:00:01 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)opendir.c	8.7 (Berkeley) 12/10/94";
 #else
-__RCSID("$NetBSD: opendir.c,v 1.37 2010/09/26 02:26:59 yamt Exp $");
+__RCSID("$NetBSD: opendir.c,v 1.38 2011/10/15 23:00:01 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -77,7 +77,7 @@ __opendir2(const char *name, int flags)
 {
 	int fd;
 
-	if ((fd = open(name, O_RDONLY | O_NONBLOCK)) == -1)
+	if ((fd = open(name, O_RDONLY | O_NONBLOCK | O_CLOEXEC)) == -1)
 		return NULL;
 	return __opendir_common(fd, name, flags);
 }
@@ -86,6 +86,8 @@ __opendir2(const char *name, int flags)
 DIR *
 _fdopendir(int fd)
 {
+	if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
+		return NULL;
 
 	return __opendir_common(fd, NULL, DTF_HIDEW|DTF_NODUP);
 }
@@ -100,13 +102,11 @@ __opendir_common(int fd, const char *nam
 	struct statvfs sfb;
 	int error;
 
-	if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
-		goto error;
 	if (fstat(fd, &sb) || !S_ISDIR(sb.st_mode)) {
 		errno = ENOTDIR;
 		goto error;
 	}
-	if ((dirp = (DIR *)malloc(sizeof(DIR))) == NULL)
+	if ((dirp = malloc(sizeof(*dirp))) == NULL)
 		goto error;
 	dirp->dd_buf = NULL;
 	dirp->dd_internal = NULL;

Index: src/lib/libc/gen/syslog.c
diff -u src/lib/libc/gen/syslog.c:1.48 src/lib/libc/gen/syslog.c:1.49
--- src/lib/libc/gen/syslog.c:1.48	Thu May 13 18:40:14 2010
+++ src/lib/libc/gen/syslog.c	Sat Oct 15 19:00:01 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: syslog.c,v 1.48 2010/05/13 22:40:14 christos Exp $	*/
+/*	$NetBSD: syslog.c,v 1.49 2011/10/15 23:00:01 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)syslog.c	8.5 (Berkeley) 4/29/95";
 #else
-__RCSID("$NetBSD: syslog.c,v 1.48 2010/05/13 22:40:14 christos Exp $");
+__RCSID("$NetBSD: syslog.c,v 1.49 2011/10/15 23:00:01 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -497,9 +497,9 @@ connectlog_r(struct syslog_data *data)
 	};
 
 	if (data->log_file == -1 || fcntl(data->log_file, F_GETFL, 0) == -1) {
-		if ((data->log_file = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1)
+		if ((data->log_file = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC,
+		    0)) == -1)
 			return;
-		(void)fcntl(data->log_file, F_SETFD, FD_CLOEXEC);
 		data->connected = 0;
 	}
 	if (!data->connected) {

Index: src/lib/libc/gen/utmp.c
diff -u src/lib/libc/gen/utmp.c:1.9 src/lib/libc/gen/utmp.c:1.10
--- src/lib/libc/gen/utmp.c:1.9	Thu Feb  5 18:52:55 2009
+++ src/lib/libc/gen/utmp.c	Sat Oct 15 19:00:02 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: utmp.c,v 1.9 2009/02/05 23:52:55 lukem Exp $	 */
+/*	$NetBSD: utmp.c,v 1.10 2011/10/15 23:00:02 christos Exp $	 */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 #include <sys/cdefs.h>
 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: utmp.c,v 1.9 2009/02/05 23:52:55 lukem Exp $");
+__RCSID("$NetBSD: utmp.c,v 1.10 2011/10/15 23:00:02 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -61,7 +61,7 @@ getutent(void)
 	if (ut == NULL) {
 		struct stat st;
 		off_t numentries;
-		if ((ut = fopen(utfile, "r")) == NULL)
+		if ((ut = fopen(utfile, "re")) == NULL)
 			return NULL;
 		if (fstat(fileno(ut), &st) == -1)
 			goto out;

Index: src/lib/libc/locale/localeio.c
diff -u src/lib/libc/locale/localeio.c:1.5 src/lib/libc/locale/localeio.c:1.6
--- src/lib/libc/locale/localeio.c:1.5	Sat Jun 19 09:26:52 2010
+++ src/lib/libc/locale/localeio.c	Sat Oct 15 19:00:02 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: localeio.c,v 1.5 2010/06/19 13:26:52 tnozaki Exp $	*/
+/*	$NetBSD: localeio.c,v 1.6 2011/10/15 23:00:02 christos Exp $	*/
 /*
  * Copyright (c) 2008, The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -30,7 +30,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: localeio.c,v 1.5 2010/06/19 13:26:52 tnozaki Exp $");
+__RCSID("$NetBSD: localeio.c,v 1.6 2011/10/15 23:00:02 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -64,10 +64,10 @@ _localeio_map_file(const char * __restri
 	_DIAGASSERT(pvar != NULL);
 	_DIAGASSERT(plenvar != NULL);
 
-	fd = open(path, O_RDONLY);
+	fd = open(path, O_RDONLY | O_CLOEXEC);
 	if (fd == -1)
 		return errno;
-	if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1 || fstat(fd, &st) == 1) {
+	if (fstat(fd, &st) == -1) {
 		ret = errno;
 		goto error;
 	}

Index: src/lib/libc/net/getaddrinfo.c
diff -u src/lib/libc/net/getaddrinfo.c:1.95 src/lib/libc/net/getaddrinfo.c:1.96
--- src/lib/libc/net/getaddrinfo.c:1.95	Fri Oct  2 03:41:08 2009
+++ src/lib/libc/net/getaddrinfo.c	Sat Oct 15 19:00:02 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: getaddrinfo.c,v 1.95 2009/10/02 07:41:08 wiz Exp $	*/
+/*	$NetBSD: getaddrinfo.c,v 1.96 2011/10/15 23:00:02 christos Exp $	*/
 /*	$KAME: getaddrinfo.c,v 1.29 2000/08/31 17:26:57 itojun Exp $	*/
 
 /*
@@ -55,7 +55,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: getaddrinfo.c,v 1.95 2009/10/02 07:41:08 wiz Exp $");
+__RCSID("$NetBSD: getaddrinfo.c,v 1.96 2011/10/15 23:00:02 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -1406,7 +1406,7 @@ _sethtent(FILE **hostf)
 {
 
 	if (!*hostf)
-		*hostf = fopen(_PATH_HOSTS, "r" );
+		*hostf = fopen(_PATH_HOSTS, "re");
 	else
 		rewind(*hostf);
 }
@@ -1434,7 +1434,7 @@ _gethtent(FILE **hostf, const char *name
 	_DIAGASSERT(name != NULL);
 	_DIAGASSERT(pai != NULL);
 
-	if (!*hostf && !(*hostf = fopen(_PATH_HOSTS, "r" )))
+	if (!*hostf && !(*hostf = fopen(_PATH_HOSTS, "re")))
 		return (NULL);
  again:
 	if (!(p = fgets(hostbuf, sizeof hostbuf, *hostf)))

Index: src/lib/libc/net/gethnamaddr.c
diff -u src/lib/libc/net/gethnamaddr.c:1.76 src/lib/libc/net/gethnamaddr.c:1.77
--- src/lib/libc/net/gethnamaddr.c:1.76	Sun Aug 29 11:40:35 2010
+++ src/lib/libc/net/gethnamaddr.c	Sat Oct 15 19:00:02 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: gethnamaddr.c,v 1.76 2010/08/29 15:40:35 christos Exp $	*/
+/*	$NetBSD: gethnamaddr.c,v 1.77 2011/10/15 23:00:02 christos Exp $	*/
 
 /*
  * ++Copyright++ 1985, 1988, 1993
@@ -57,7 +57,7 @@
 static char sccsid[] = "@(#)gethostnamadr.c	8.1 (Berkeley) 6/4/93";
 static char rcsid[] = "Id: gethnamaddr.c,v 8.21 1997/06/01 20:34:37 vixie Exp ";
 #else
-__RCSID("$NetBSD: gethnamaddr.c,v 1.76 2010/08/29 15:40:35 christos Exp $");
+__RCSID("$NetBSD: gethnamaddr.c,v 1.77 2011/10/15 23:00:02 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -720,7 +720,7 @@ void
 _sethtent(int f)
 {
 	if (!hostf)
-		hostf = fopen(_PATH_HOSTS, "r" );
+		hostf = fopen(_PATH_HOSTS, "re");
 	else
 		rewind(hostf);
 	stayopen = f;
@@ -742,7 +742,7 @@ _gethtent(void)
 	char *cp, **q;
 	int af, len;
 
-	if (!hostf && !(hostf = fopen(_PATH_HOSTS, "r" ))) {
+	if (!hostf && !(hostf = fopen(_PATH_HOSTS, "re"))) {
 		h_errno = NETDB_INTERNAL;
 		return NULL;
 	}

Index: src/lib/libc/net/getnetent.c
diff -u src/lib/libc/net/getnetent.c:1.18 src/lib/libc/net/getnetent.c:1.19
--- src/lib/libc/net/getnetent.c:1.18	Sat Jan 27 17:27:35 2007
+++ src/lib/libc/net/getnetent.c	Sat Oct 15 19:00:02 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: getnetent.c,v 1.18 2007/01/27 22:27:35 christos Exp $	*/
+/*	$NetBSD: getnetent.c,v 1.19 2011/10/15 23:00:02 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1993
@@ -44,7 +44,7 @@
 static char sccsid[] = "@(#)getnetent.c	8.1 (Berkeley) 6/4/93";
 static char rcsid[] = "Id: getnetent.c,v 8.4 1997/06/01 20:34:37 vixie Exp ";
 #else
-__RCSID("$NetBSD: getnetent.c,v 1.18 2007/01/27 22:27:35 christos Exp $");
+__RCSID("$NetBSD: getnetent.c,v 1.19 2011/10/15 23:00:02 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -97,7 +97,7 @@ __setnetent(f)
 {
 
 	if (netf == NULL)
-		netf = fopen(_PATH_NETWORKS, "r" );
+		netf = fopen(_PATH_NETWORKS, "re");
 	else
 		rewind(netf);
 	_net_stayopen |= f;
@@ -120,7 +120,7 @@ getnetent()
 	char *p;
 	register char *cp, **q;
 
-	if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL)
+	if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "re")) == NULL)
 		return (NULL);
 #if (defined(__sparc__) && defined(_LP64)) ||		\
     defined(__alpha__) ||				\

Index: src/lib/libc/net/getprotoent_r.c
diff -u src/lib/libc/net/getprotoent_r.c:1.5 src/lib/libc/net/getprotoent_r.c:1.6
--- src/lib/libc/net/getprotoent_r.c:1.5	Mon Apr 18 15:39:45 2005
+++ src/lib/libc/net/getprotoent_r.c	Sat Oct 15 19:00:02 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: getprotoent_r.c,v 1.5 2005/04/18 19:39:45 kleink Exp $	*/
+/*	$NetBSD: getprotoent_r.c,v 1.6 2011/10/15 23:00:02 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)getprotoent.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: getprotoent_r.c,v 1.5 2005/04/18 19:39:45 kleink Exp $");
+__RCSID("$NetBSD: getprotoent_r.c,v 1.6 2011/10/15 23:00:02 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -57,7 +57,7 @@ void
 setprotoent_r(int f, struct protoent_data *pd)
 {
 	if (pd->fp == NULL)
-		pd->fp = fopen(_PATH_PROTOCOLS, "r");
+		pd->fp = fopen(_PATH_PROTOCOLS, "re");
 	else
 		rewind(pd->fp);
 	pd->stayopen |= f;
@@ -89,7 +89,7 @@ getprotoent_r(struct protoent *pr, struc
 	size_t i = 0;
 	int oerrno;
 
-	if (pd->fp == NULL && (pd->fp = fopen(_PATH_PROTOCOLS, "r")) == NULL)
+	if (pd->fp == NULL && (pd->fp = fopen(_PATH_PROTOCOLS, "re")) == NULL)
 		return NULL;
 
 	for (;;) {

Index: src/lib/libc/net/getservent_r.c
diff -u src/lib/libc/net/getservent_r.c:1.10 src/lib/libc/net/getservent_r.c:1.11
--- src/lib/libc/net/getservent_r.c:1.10	Sat Apr 24 20:54:46 2010
+++ src/lib/libc/net/getservent_r.c	Sat Oct 15 19:00:02 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: getservent_r.c,v 1.10 2010/04/25 00:54:46 joerg Exp $	*/
+/*	$NetBSD: getservent_r.c,v 1.11 2011/10/15 23:00:02 christos Exp $	*/
 
 /*
  * Copyright (c) 1983, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)getservent.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: getservent_r.c,v 1.10 2010/04/25 00:54:46 joerg Exp $");
+__RCSID("$NetBSD: getservent_r.c,v 1.11 2011/10/15 23:00:02 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -79,7 +79,7 @@ _servent_open(struct servent_data *sd)
 		return 0;
 	}
 		
-	sd->plainfile = fopen(_PATH_SERVICES, "r");
+	sd->plainfile = fopen(_PATH_SERVICES, "re");
 	if (sd->plainfile != NULL) {
 		sd->flags |= _SV_PLAINFILE;
 		return 0;

Index: src/lib/libc/resolv/res_init.c
diff -u src/lib/libc/resolv/res_init.c:1.22 src/lib/libc/resolv/res_init.c:1.23
--- src/lib/libc/resolv/res_init.c:1.22	Sat Oct 24 13:24:01 2009
+++ src/lib/libc/resolv/res_init.c	Sat Oct 15 19:00:02 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: res_init.c,v 1.22 2009/10/24 17:24:01 christos Exp $	*/
+/*	$NetBSD: res_init.c,v 1.23 2011/10/15 23:00:02 christos Exp $	*/
 
 /*
  * Copyright (c) 1985, 1989, 1993
@@ -76,7 +76,7 @@
 static const char sccsid[] = "@(#)res_init.c	8.1 (Berkeley) 6/7/93";
 static const char rcsid[] = "Id: res_init.c,v 1.26 2008/12/11 09:59:00 marka Exp";
 #else
-__RCSID("$NetBSD: res_init.c,v 1.22 2009/10/24 17:24:01 christos Exp $");
+__RCSID("$NetBSD: res_init.c,v 1.23 2011/10/15 23:00:02 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -346,7 +346,7 @@ __res_vinit(res_state statp, int preinit
 	 line[sizeof(name) - 1] == '\t'))
 
 	nserv = 0;
-	if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) {
+	if ((fp = fopen(_PATH_RESCONF, "re")) != NULL) {
 	    struct stat st;
 	    struct kevent kc;
 
@@ -502,9 +502,7 @@ __res_vinit(res_state statp, int preinit
 	    if (fstat(statp->_u._ext.ext->resfd, &st) != -1)
 		    __res_conf_time = statp->_u._ext.ext->res_conf_time =
 			st.st_mtimespec;
-	    statp->_u._ext.ext->kq = kqueue();
-	    (void)fcntl(statp->_u._ext.ext->kq, F_SETFD, FD_CLOEXEC);
-	    (void)fcntl(statp->_u._ext.ext->resfd, F_SETFD, FD_CLOEXEC);
+	    statp->_u._ext.ext->kq = kqueue1(O_CLOEXEC);
 	    EV_SET(&kc, statp->_u._ext.ext->resfd, EVFILT_VNODE,
 		EV_ADD|EV_ENABLE|EV_CLEAR, NOTE_DELETE|NOTE_WRITE| NOTE_EXTEND|
 		NOTE_ATTRIB|NOTE_LINK|NOTE_RENAME|NOTE_REVOKE, 0, 0);

Index: src/lib/libc/rpc/getnetconfig.c
diff -u src/lib/libc/rpc/getnetconfig.c:1.18 src/lib/libc/rpc/getnetconfig.c:1.19
--- src/lib/libc/rpc/getnetconfig.c:1.18	Tue Dec  7 21:06:38 2010
+++ src/lib/libc/rpc/getnetconfig.c	Sat Oct 15 19:00:02 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: getnetconfig.c,v 1.18 2010/12/08 02:06:38 joerg Exp $	*/
+/*	$NetBSD: getnetconfig.c,v 1.19 2011/10/15 23:00:02 christos Exp $	*/
 
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
@@ -35,7 +35,7 @@
 #if 0
 static        char sccsid[] = "@(#)getnetconfig.c	1.12 91/12/19 SMI";
 #else
-__RCSID("$NetBSD: getnetconfig.c,v 1.18 2010/12/08 02:06:38 joerg Exp $");
+__RCSID("$NetBSD: getnetconfig.c,v 1.19 2011/10/15 23:00:02 christos Exp $");
 #endif
 #endif
 
@@ -220,7 +220,7 @@ setnetconfig()
 	 * handle without reopening the netconfig db.
 	 */
 	ni.ref++;
-	if ((nc_file != NULL) || (nc_file = fopen(NETCONFIG, "r")) != NULL) {
+	if ((nc_file != NULL) || (nc_file = fopen(NETCONFIG, "re")) != NULL) {
 		nc_vars->valid = NC_VALID;
 		nc_vars->flag = 0;
 		nc_vars->nc_configs = ni.head;

Index: src/lib/libc/rpc/getrpcent.c
diff -u src/lib/libc/rpc/getrpcent.c:1.21 src/lib/libc/rpc/getrpcent.c:1.22
--- src/lib/libc/rpc/getrpcent.c:1.21	Sun Aug 15 22:47:54 2004
+++ src/lib/libc/rpc/getrpcent.c	Sat Oct 15 19:00:02 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: getrpcent.c,v 1.21 2004/08/16 02:47:54 ginsbach Exp $	*/
+/*	$NetBSD: getrpcent.c,v 1.22 2011/10/15 23:00:02 christos Exp $	*/
 
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
@@ -35,7 +35,7 @@
 #if 0
 static char *sccsid = "@(#)getrpcent.c 1.14 91/03/11 Copyr 1984 Sun Micro";
 #else
-__RCSID("$NetBSD: getrpcent.c,v 1.21 2004/08/16 02:47:54 ginsbach Exp $");
+__RCSID("$NetBSD: getrpcent.c,v 1.22 2011/10/15 23:00:02 christos Exp $");
 #endif
 #endif
 
@@ -140,7 +140,7 @@ setrpcent(int f)
 	if (d == 0)
 		return;
 	if (d->rpcf == NULL)
-		d->rpcf = fopen(RPCDB, "r");
+		d->rpcf = fopen(RPCDB, "re");
 	else
 		rewind(d->rpcf);
 	d->stayopen |= f;
@@ -166,7 +166,7 @@ getrpcent(void)
 
 	if (d == 0)
 		return(NULL);
-	if (d->rpcf == NULL && (d->rpcf = fopen(RPCDB, "r")) == NULL)
+	if (d->rpcf == NULL && (d->rpcf = fopen(RPCDB, "re")) == NULL)
 		return (NULL);
 	if (fgets(d->line, BUFSIZ, d->rpcf) == NULL)
 		return (NULL);

Index: src/lib/libc/sys/adjtime.c
diff -u src/lib/libc/sys/adjtime.c:1.11 src/lib/libc/sys/adjtime.c:1.12
--- src/lib/libc/sys/adjtime.c:1.11	Sat Jan 10 21:46:30 2009
+++ src/lib/libc/sys/adjtime.c	Sat Oct 15 19:00:02 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: adjtime.c,v 1.11 2009/01/11 02:46:30 christos Exp $ */
+/*	$NetBSD: adjtime.c,v 1.12 2011/10/15 23:00:02 christos Exp $ */
 
 /*
  * Copyright (c) 2001 The NetBSD Foundation, Inc.      
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: adjtime.c,v 1.11 2009/01/11 02:46:30 christos Exp $");
+__RCSID("$NetBSD: adjtime.c,v 1.12 2011/10/15 23:00:02 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -76,14 +76,12 @@ adjtime(const struct timeval *delta, str
 		 * If this fails, it means that we are not root
 		 * and we cannot open clockctl. This is a failure.
 		 */
-		__clockctl_fd = open(_PATH_CLOCKCTL, O_WRONLY, 0);
+		__clockctl_fd = open(_PATH_CLOCKCTL, O_WRONLY | O_CLOEXEC, 0);
 		if (__clockctl_fd == -1) {
 			/* original error was EPERM - don't leak open errors */
 			errno = EPERM;
 			return -1;
 		}
-
-		(void) fcntl(__clockctl_fd, F_SETFD, FD_CLOEXEC);
 	}
 
 	/* 
Index: src/lib/libc/sys/clock_settime.c
diff -u src/lib/libc/sys/clock_settime.c:1.11 src/lib/libc/sys/clock_settime.c:1.12
--- src/lib/libc/sys/clock_settime.c:1.11	Sat Jan 10 21:46:30 2009
+++ src/lib/libc/sys/clock_settime.c	Sat Oct 15 19:00:02 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: clock_settime.c,v 1.11 2009/01/11 02:46:30 christos Exp $ */
+/*	$NetBSD: clock_settime.c,v 1.12 2011/10/15 23:00:02 christos Exp $ */
 
 /*
  * Copyright (c) 2001 The NetBSD Foundation, Inc.      
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: clock_settime.c,v 1.11 2009/01/11 02:46:30 christos Exp $");
+__RCSID("$NetBSD: clock_settime.c,v 1.12 2011/10/15 23:00:02 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -78,14 +78,12 @@ clock_settime(clockid_t clock_id, const 
 		 * If this fails, it means that we are not root
 		 * and we cannot open clockctl. This is a failure.
 		 */
-		__clockctl_fd = open(_PATH_CLOCKCTL, O_WRONLY, 0);
+		__clockctl_fd = open(_PATH_CLOCKCTL, O_WRONLY | O_CLOEXEC, 0);
 		if (__clockctl_fd == -1) {
 			/* original error was EPERM - don't leak open errors */
 			errno = EPERM;
 			return -1;
 		}
-
-		(void) fcntl(__clockctl_fd, F_SETFD, FD_CLOEXEC);
 	}
 
 	/* 
Index: src/lib/libc/sys/ntp_adjtime.c
diff -u src/lib/libc/sys/ntp_adjtime.c:1.11 src/lib/libc/sys/ntp_adjtime.c:1.12
--- src/lib/libc/sys/ntp_adjtime.c:1.11	Fri Nov 23 07:39:15 2007
+++ src/lib/libc/sys/ntp_adjtime.c	Sat Oct 15 19:00:02 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ntp_adjtime.c,v 1.11 2007/11/23 12:39:15 uebayasi Exp $ */
+/*	$NetBSD: ntp_adjtime.c,v 1.12 2011/10/15 23:00:02 christos Exp $ */
 
 /*
  * Copyright (c) 2001 The NetBSD Foundation, Inc.      
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: ntp_adjtime.c,v 1.11 2007/11/23 12:39:15 uebayasi Exp $");
+__RCSID("$NetBSD: ntp_adjtime.c,v 1.12 2011/10/15 23:00:02 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -87,14 +87,12 @@ ntp_adjtime(tp)
 		 * and we cannot open clockctl. This is a true
 		 * failure.
 		 */
-		__clockctl_fd = open(_PATH_CLOCKCTL, O_WRONLY, 0);
+		__clockctl_fd = open(_PATH_CLOCKCTL, O_WRONLY | O_CLOEXEC, 0);
 		if (__clockctl_fd == -1) {
 			/* original error was EPERM - don't leak open errors */
 			errno = EPERM;
 			return -1;
 		}
-
-		(void) fcntl(__clockctl_fd, F_SETFD, FD_CLOEXEC);
 	}
 
 	/*

Index: src/lib/libc/sys/settimeofday.c
diff -u src/lib/libc/sys/settimeofday.c:1.13 src/lib/libc/sys/settimeofday.c:1.14
--- src/lib/libc/sys/settimeofday.c:1.13	Sat Jan 10 21:46:30 2009
+++ src/lib/libc/sys/settimeofday.c	Sat Oct 15 19:00:02 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: settimeofday.c,v 1.13 2009/01/11 02:46:30 christos Exp $ */
+/*	$NetBSD: settimeofday.c,v 1.14 2011/10/15 23:00:02 christos Exp $ */
 
 /*
  * Copyright (c) 2001 The NetBSD Foundation, Inc.      
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: settimeofday.c,v 1.13 2009/01/11 02:46:30 christos Exp $");
+__RCSID("$NetBSD: settimeofday.c,v 1.14 2011/10/15 23:00:02 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -77,14 +77,12 @@ settimeofday(const struct timeval *tv, c
 		if (rv != -1 || errno != EPERM)
 			return rv;
 
-		__clockctl_fd = open(_PATH_CLOCKCTL, O_WRONLY, 0);
+		__clockctl_fd = open(_PATH_CLOCKCTL, O_WRONLY | O_CLOEXEC, 0);
 		if (__clockctl_fd == -1) {
 			/* original error was EPERM - don't leak open errors */
 			errno = EPERM;
 			return -1;
 		}
-
-		(void) fcntl(__clockctl_fd, F_SETFD, FD_CLOEXEC);
 	}
 
 	/* 

Reply via email to