Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc close on exec fixes:
details: https://anonhg.NetBSD.org/src/rev/14ebff5cf6b4
branches: trunk
changeset: 770411:14ebff5cf6b4
user: christos <christos%NetBSD.org@localhost>
date: Sat Oct 15 23:00:01 2011 +0000
description:
close on exec fixes:
- open + fcntl -> open O_CLOEXEC
- configuration database file descriptors that can stay open are now opened
fopen(db, "re")
diffstat:
lib/libc/citrus/citrus_mmap.c | 10 +++-------
lib/libc/gen/fstab.c | 6 +++---
lib/libc/gen/fts.c | 23 ++++++-----------------
lib/libc/gen/getcap.c | 8 ++++----
lib/libc/gen/getgrent.c | 8 ++++----
lib/libc/gen/getttyent.c | 6 +++---
lib/libc/gen/getusershell.c | 6 +++---
lib/libc/gen/initdir.c | 7 +++----
lib/libc/gen/opendir.c | 12 ++++++------
lib/libc/gen/syslog.c | 8 ++++----
lib/libc/gen/utmp.c | 6 +++---
lib/libc/gen/utmpx.c | 6 +++---
lib/libc/locale/localeio.c | 8 ++++----
lib/libc/net/getaddrinfo.c | 8 ++++----
lib/libc/net/gethnamaddr.c | 8 ++++----
lib/libc/net/getnetent.c | 8 ++++----
lib/libc/net/getprotoent_r.c | 8 ++++----
lib/libc/net/getservent_r.c | 6 +++---
lib/libc/resolv/res_init.c | 10 ++++------
lib/libc/rpc/getnetconfig.c | 6 +++---
lib/libc/rpc/getrpcent.c | 8 ++++----
lib/libc/sys/adjtime.c | 8 +++-----
lib/libc/sys/clock_settime.c | 8 +++-----
lib/libc/sys/ntp_adjtime.c | 8 +++-----
lib/libc/sys/settimeofday.c | 8 +++-----
25 files changed, 91 insertions(+), 117 deletions(-)
diffs (truncated from 850 to 300 lines):
diff -r da726aaf781a -r 14ebff5cf6b4 lib/libc/citrus/citrus_mmap.c
--- a/lib/libc/citrus/citrus_mmap.c Sat Oct 15 22:57:57 2011 +0000
+++ b/lib/libc/citrus/citrus_mmap.c Sat Oct 15 23:00:01 2011 +0000
@@ -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 @@
_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;
diff -r da726aaf781a -r 14ebff5cf6b4 lib/libc/gen/fstab.c
--- a/lib/libc/gen/fstab.c Sat Oct 15 22:57:57 2011 +0000
+++ b/lib/libc/gen/fstab.c Sat Oct 15 23:00:01 2011 +0000
@@ -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 @@
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;
}
diff -r da726aaf781a -r 14ebff5cf6b4 lib/libc/gen/fts.c
--- a/lib/libc/gen/fts.c Sat Oct 15 22:57:57 2011 +0000
+++ b/lib/libc/gen/fts.c Sat Oct 15 23:00:01 2011 +0000
@@ -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 @@
* 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 @@
(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) {
+ if ((p->fts_symfd = open(".", O_RDONLY | O_CLOEXEC, 0))
+ == -1) {
p->fts_errno = errno;
p->fts_info = FTS_ERR;
- } else if (fcntl(p->fts_symfd, F_SETFD, FD_CLOEXEC) == -1) {
- p->fts_errno = errno;
- p->fts_info = FTS_ERR;
- close(p->fts_symfd);
} else
p->fts_flags |= FTS_SYMFOLLOW;
}
@@ -446,13 +439,9 @@
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) {
+ open(".", O_RDONLY | O_CLOEXEC, 0)) == -1) {
p->fts_errno = errno;
p->fts_info = FTS_ERR;
- } else if (fcntl(p->fts_symfd, F_SETFD, FD_CLOEXEC) == -1) {
- p->fts_errno = errno;
- p->fts_info = FTS_ERR;
- close(p->fts_symfd);
} else
p->fts_flags |= FTS_SYMFOLLOW;
}
diff -r da726aaf781a -r 14ebff5cf6b4 lib/libc/gen/getcap.c
--- a/lib/libc/gen/getcap.c Sat Oct 15 22:57:57 2011 +0000
+++ b/lib/libc/gen/getcap.c Sat Oct 15 23:00:01 2011 +0000
@@ -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 @@
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 @@
(void)cgetclose();
return 0;
} else if ((pfp =
- fopen(*dbp, "r")) == NULL) {
+ fopen(*dbp, "re")) == NULL) {
(void)cgetclose();
return -1;
} else
diff -r da726aaf781a -r 14ebff5cf6b4 lib/libc/gen/getgrent.c
--- a/lib/libc/gen/getgrent.c Sat Oct 15 22:57:57 2011 +0000
+++ b/lib/libc/gen/getgrent.c Sat Oct 15 23:00:01 2011 +0000
@@ -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 @@
_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 @@
_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 {
diff -r da726aaf781a -r 14ebff5cf6b4 lib/libc/gen/getttyent.c
--- a/lib/libc/gen/getttyent.c Sat Oct 15 22:57:57 2011 +0000
+++ b/lib/libc/gen/getttyent.c Sat Oct 15 23:00:01 2011 +0000
@@ -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 @@
if (tf) {
rewind(tf);
return 1;
- } else if ((tf = fopen(path, "r")) != NULL)
+ } else if ((tf = fopen(path, "re")) != NULL)
return 1;
return 0;
}
diff -r da726aaf781a -r 14ebff5cf6b4 lib/libc/gen/getusershell.c
--- a/lib/libc/gen/getusershell.c Sat Oct 15 22:57:57 2011 +0000
+++ b/lib/libc/gen/getusershell.c Sat Oct 15 23:00:01 2011 +0000
@@ -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 @@
_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 {
diff -r da726aaf781a -r 14ebff5cf6b4 lib/libc/gen/initdir.c
--- a/lib/libc/gen/initdir.c Sat Oct 15 22:57:57 2011 +0000
+++ b/lib/libc/gen/initdir.c Sat Oct 15 23:00:01 2011 +0000
@@ -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 @@
*/
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;
}
diff -r da726aaf781a -r 14ebff5cf6b4 lib/libc/gen/opendir.c
--- a/lib/libc/gen/opendir.c Sat Oct 15 22:57:57 2011 +0000
+++ b/lib/libc/gen/opendir.c Sat Oct 15 23:00:01 2011 +0000
@@ -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 @@
{
int fd;
- if ((fd = open(name, O_RDONLY | O_NONBLOCK)) == -1)
+ if ((fd = open(name, O_RDONLY | O_NONBLOCK | O_CLOEXEC)) == -1)
Home |
Main Index |
Thread Index |
Old Index