Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc make more descriptors that we open as close-on-exec
details: https://anonhg.NetBSD.org/src/rev/a5b8513bd139
branches: trunk
changeset: 802504:a5b8513bd139
user: christos <christos%NetBSD.org@localhost>
date: Thu Sep 18 13:58:20 2014 +0000
description:
make more descriptors that we open as close-on-exec
diffstat:
lib/libc/gen/fmtmsg.c | 6 +++---
lib/libc/gen/fts.c | 8 ++++----
lib/libc/gen/getcap.c | 10 +++++-----
lib/libc/gen/getpass.c | 7 ++++---
lib/libc/gen/nlist.c | 6 +++---
lib/libc/gen/syslog.c | 7 ++++---
lib/libc/gen/utmpx.c | 16 ++++++++--------
lib/libc/gmon/gmon.c | 9 +++++----
lib/libc/hash/hashhl.c | 4 ++--
lib/libc/md/mdXhl.c | 4 ++--
lib/libc/net/ethers.c | 8 ++++----
lib/libc/net/hesiod.c | 6 +++---
lib/libc/net/nsdispatch.c | 6 +++---
lib/libc/net/rcmd.c | 8 ++++----
lib/libc/rpc/getnetconfig.c | 6 +++---
lib/libc/stdlib/malloc.c | 6 +++---
lib/libc/time/getdate.c | 4 ++--
lib/libc/time/localtime.c | 8 ++++----
lib/libc/time/strftime.c | 8 ++++----
lib/libc/yp/yplib.c | 8 ++++----
20 files changed, 74 insertions(+), 71 deletions(-)
diffs (truncated from 616 to 300 lines):
diff -r af3fa4c09898 -r a5b8513bd139 lib/libc/gen/fmtmsg.c
--- a/lib/libc/gen/fmtmsg.c Thu Sep 18 08:06:13 2014 +0000
+++ b/lib/libc/gen/fmtmsg.c Thu Sep 18 13:58:20 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fmtmsg.c,v 1.5 2012/03/20 16:36:05 matt Exp $ */
+/* $NetBSD: fmtmsg.c,v 1.6 2014/09/18 13:58:20 christos Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: fmtmsg.c,v 1.5 2012/03/20 16:36:05 matt Exp $");
+__RCSID("$NetBSD: fmtmsg.c,v 1.6 2014/09/18 13:58:20 christos Exp $");
#endif /* LIBC_SCCS and not lint */
#include <fmtmsg.h>
@@ -213,7 +213,7 @@
}
/* Similar to MM_PRINT but ignoring $MSGVERB. */
if (classification & MM_CONSOLE) {
- if ((console = fopen(_PATH_CONSOLE, "w")) != NULL) {
+ if ((console = fopen(_PATH_CONSOLE, "we")) != NULL) {
if (writeit(console, MM_VERBALL,
label, sevstr, text, action, tag) < 0)
result |= MM_NOCON;
diff -r af3fa4c09898 -r a5b8513bd139 lib/libc/gen/fts.c
--- a/lib/libc/gen/fts.c Thu Sep 18 08:06:13 2014 +0000
+++ b/lib/libc/gen/fts.c Thu Sep 18 13:58:20 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fts.c,v 1.46 2012/09/26 15:33:43 msaitoh Exp $ */
+/* $NetBSD: fts.c,v 1.47 2014/09/18 13:58:20 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.46 2012/09/26 15:33:43 msaitoh Exp $");
+__RCSID("$NetBSD: fts.c,v 1.47 2014/09/18 13:58:20 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -601,7 +601,7 @@
ISSET(FTS_NOCHDIR))
return (sp->fts_child = fts_build(sp, instr));
- if ((fd = open(".", O_RDONLY, 0)) == -1)
+ if ((fd = open(".", O_RDONLY | O_CLOEXEC, 0)) == -1)
return (sp->fts_child = NULL);
sp->fts_child = fts_build(sp, instr);
if (fchdir(fd)) {
@@ -1211,7 +1211,7 @@
if (ISSET(FTS_NOCHDIR))
return 0;
- if (oldfd < 0 && (fd = open(path, O_RDONLY)) == -1)
+ if (oldfd < 0 && (fd = open(path, O_RDONLY | O_CLOEXEC)) == -1)
return -1;
if (fstat(fd, &sb) == -1)
diff -r af3fa4c09898 -r a5b8513bd139 lib/libc/gen/getcap.c
--- a/lib/libc/gen/getcap.c Thu Sep 18 08:06:13 2014 +0000
+++ b/lib/libc/gen/getcap.c Thu Sep 18 13:58:20 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: getcap.c,v 1.53 2014/06/26 20:14:32 christos Exp $ */
+/* $NetBSD: getcap.c,v 1.54 2014/09/18 13:58:20 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.53 2014/06/26 20:14:32 christos Exp $");
+__RCSID("$NetBSD: getcap.c,v 1.54 2014/09/18 13:58:20 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -322,8 +322,8 @@
size_t clen;
(void)snprintf(pbuf, sizeof(pbuf), "%s.db", *db_p);
- if ((capdbp = dbopen(pbuf, O_RDONLY, 0, DB_HASH, 0))
- != NULL) {
+ if ((capdbp = dbopen(pbuf, O_RDONLY | O_CLOEXEC, 0,
+ DB_HASH, 0)) != NULL) {
free(record);
retval = cdbget(capdbp, &record, name);
if (retval < 0) {
@@ -352,7 +352,7 @@
} else
#endif
{
- fd = open(*db_p, O_RDONLY, 0);
+ fd = open(*db_p, O_RDONLY | O_CLOEXEC, 0);
if (fd < 0) {
/* No error on unfound file. */
continue;
diff -r af3fa4c09898 -r a5b8513bd139 lib/libc/gen/getpass.c
--- a/lib/libc/gen/getpass.c Thu Sep 18 08:06:13 2014 +0000
+++ b/lib/libc/gen/getpass.c Thu Sep 18 13:58:20 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: getpass.c,v 1.28 2014/06/16 16:29:30 christos Exp $ */
+/* $NetBSD: getpass.c,v 1.29 2014/09/18 13:58:20 christos Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: getpass.c,v 1.28 2014/06/16 16:29:30 christos Exp $");
+__RCSID("$NetBSD: getpass.c,v 1.29 2014/09/18 13:58:20 christos Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
@@ -107,7 +107,8 @@
* and write to stderr.
*/
fd = fdc;
- if ((fd[0] = fd[1] = fd[2] = open(_PATH_TTY, O_RDWR)) == -1) {
+ if ((fd[0] = fd[1] = fd[2] = open(_PATH_TTY,
+ O_RDWR | O_CLOEXEC)) == -1) {
fd[0] = STDIN_FILENO;
fd[1] = fd[2] = STDERR_FILENO;
} else
diff -r af3fa4c09898 -r a5b8513bd139 lib/libc/gen/nlist.c
--- a/lib/libc/gen/nlist.c Thu Sep 18 08:06:13 2014 +0000
+++ b/lib/libc/gen/nlist.c Thu Sep 18 13:58:20 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nlist.c,v 1.24 2012/03/21 15:32:26 christos Exp $ */
+/* $NetBSD: nlist.c,v 1.25 2014/09/18 13:58:20 christos Exp $ */
/*
* Copyright (c) 1989, 1993
@@ -66,7 +66,7 @@
#if 0
static char sccsid[] = "@(#)nlist.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: nlist.c,v 1.24 2012/03/21 15:32:26 christos Exp $");
+__RCSID("$NetBSD: nlist.c,v 1.25 2014/09/18 13:58:20 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -119,7 +119,7 @@
_DIAGASSERT(name != NULL);
_DIAGASSERT(list != NULL);
- fd = open(name, O_RDONLY, 0);
+ fd = open(name, O_RDONLY | O_CLOEXEC, 0);
if (fd < 0)
return (-1);
n = __fdnlist(fd, list);
diff -r af3fa4c09898 -r a5b8513bd139 lib/libc/gen/syslog.c
--- a/lib/libc/gen/syslog.c Thu Sep 18 08:06:13 2014 +0000
+++ b/lib/libc/gen/syslog.c Thu Sep 18 13:58:20 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: syslog.c,v 1.53 2012/10/11 17:09:55 christos Exp $ */
+/* $NetBSD: syslog.c,v 1.54 2014/09/18 13:58:20 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.53 2012/10/11 17:09:55 christos Exp $");
+__RCSID("$NetBSD: syslog.c,v 1.54 2014/09/18 13:58:20 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -457,7 +457,8 @@
* Make sure the error reported is the one from the syslogd failure.
*/
if (tries == MAXTRIES && (data->log_stat & LOG_CONS) &&
- (fd = open(_PATH_CONSOLE, O_WRONLY|O_NONBLOCK, 0)) >= 0) {
+ (fd = open(_PATH_CONSOLE,
+ O_WRONLY | O_NONBLOCK | O_CLOEXEC, 0)) >= 0) {
iov[iovcnt].iov_base = __UNCONST(CRLF);
iov[iovcnt].iov_len = 2;
(void)writev(fd, iov, iovcnt + 1);
diff -r af3fa4c09898 -r a5b8513bd139 lib/libc/gen/utmpx.c
--- a/lib/libc/gen/utmpx.c Thu Sep 18 08:06:13 2014 +0000
+++ b/lib/libc/gen/utmpx.c Thu Sep 18 13:58:20 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: utmpx.c,v 1.31 2013/09/05 17:35:11 pooka Exp $ */
+/* $NetBSD: utmpx.c,v 1.32 2014/09/18 13:58:20 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.31 2013/09/05 17:35:11 pooka Exp $");
+__RCSID("$NetBSD: utmpx.c,v 1.32 2014/09/18 13:58:20 christos Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
@@ -122,8 +122,8 @@
struct stat st;
if ((fp = fopen(utfile, "re+")) == NULL)
- if ((fp = fopen(utfile, "w+")) == NULL) {
- if ((fp = fopen(utfile, "r")) == NULL)
+ if ((fp = fopen(utfile, "we+")) == NULL) {
+ if ((fp = fopen(utfile, "re")) == NULL)
goto fail;
else
readonly = 1;
@@ -343,10 +343,10 @@
_DIAGASSERT(file != NULL);
_DIAGASSERT(utx != NULL);
- fd = open(file, O_WRONLY|O_APPEND|O_SHLOCK);
+ fd = open(file, O_WRONLY|O_APPEND|O_SHLOCK|O_CLOEXEC);
if (fd == -1) {
- if ((fd = open(file, O_CREAT|O_WRONLY|O_EXLOCK, 0644)) == -1)
+ if ((fd = open(file, O_CREAT|O_WRONLY|O_EXLOCK|O_CLOEXEC, 0644)) == -1)
return -1;
(void)memset(&ut, 0, sizeof(ut));
ut.ut_type = SIGNATURE;
@@ -432,7 +432,7 @@
_DIAGASSERT(fname != NULL);
_DIAGASSERT(ll != NULL);
- db = dbopen(fname, O_RDONLY|O_SHLOCK, 0, DB_HASH, NULL);
+ db = dbopen(fname, O_RDONLY|O_SHLOCK|O_CLOEXEC, 0, DB_HASH, NULL);
if (db == NULL)
return NULL;
@@ -471,7 +471,7 @@
_DIAGASSERT(fname != NULL);
_DIAGASSERT(ll != NULL);
- db = dbopen(fname, O_RDWR|O_CREAT|O_EXLOCK, 0644, DB_HASH, NULL);
+ db = dbopen(fname, O_RDWR|O_CREAT|O_EXLOCK|O_CLOEXEC, 0644, DB_HASH, NULL);
if (db == NULL)
return -1;
diff -r af3fa4c09898 -r a5b8513bd139 lib/libc/gmon/gmon.c
--- a/lib/libc/gmon/gmon.c Thu Sep 18 08:06:13 2014 +0000
+++ b/lib/libc/gmon/gmon.c Thu Sep 18 13:58:20 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: gmon.c,v 1.34 2012/03/13 21:13:37 christos Exp $ */
+/* $NetBSD: gmon.c,v 1.35 2014/09/18 13:58:20 christos Exp $ */
/*
* Copyright (c) 2003, 2004 Wasabi Systems, Inc.
@@ -69,7 +69,7 @@
#if 0
static char sccsid[] = "@(#)gmon.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: gmon.c,v 1.34 2012/03/13 21:13:37 christos Exp $");
+__RCSID("$NetBSD: gmon.c,v 1.35 2014/09/18 13:58:20 christos Exp $");
#endif
#endif
@@ -432,13 +432,14 @@
proffile = "gmon.out";
}
- fd = open(proffile , O_CREAT|O_TRUNC|O_WRONLY, 0666);
+#define OPEN_FLAGS (O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC)
+ fd = open(proffile, OPEN_FLAGS, 0666);
if (fd < 0) {
warn("%s: Cannot open `%s'", __func__, proffile);
return;
}
#ifdef DEBUG
- logfd = open("gmon.log", O_CREAT|O_TRUNC|O_WRONLY, 0664);
+ logfd = open("gmon.log", OPEN_FLAGS, 0664);
if (logfd < 0) {
warn("%s: Cannot open `%s'", __func__, "gmon.log");
(void)close(fd);
diff -r af3fa4c09898 -r a5b8513bd139 lib/libc/hash/hashhl.c
--- a/lib/libc/hash/hashhl.c Thu Sep 18 08:06:13 2014 +0000
+++ b/lib/libc/hash/hashhl.c Thu Sep 18 13:58:20 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: hashhl.c,v 1.4 2010/01/17 23:10:20 wiz Exp $ */
+/* $NetBSD: hashhl.c,v 1.5 2014/09/18 13:58:20 christos Exp $ */
/*
* ----------------------------------------------------------------------------
@@ -97,7 +97,7 @@
FNPREFIX(Init)(&ctx);
- if ((fd = open(filename, O_RDONLY)) < 0)
+ if ((fd = open(filename, O_RDONLY | O_CLOEXEC)) < 0)
return (NULL);
if (len == 0) {
if (fstat(fd, &sb) == -1) {
diff -r af3fa4c09898 -r a5b8513bd139 lib/libc/md/mdXhl.c
--- a/lib/libc/md/mdXhl.c Thu Sep 18 08:06:13 2014 +0000
+++ b/lib/libc/md/mdXhl.c Thu Sep 18 13:58:20 2014 +0000
Home |
Main Index |
Thread Index |
Old Index