diff options
author | Philip Guenther <guenther@cvs.openbsd.org> | 2014-09-15 06:12:20 +0000 |
---|---|---|
committer | Philip Guenther <guenther@cvs.openbsd.org> | 2014-09-15 06:12:20 +0000 |
commit | 305e5c9c8be4831136878e3ee72114d74f4e1a4d (patch) | |
tree | ac00131f4fe31f6b72181a9454b32dec88707284 /lib/libc | |
parent | 6d10249b450aeaf632683794f84d99dd315ff6ec (diff) |
Pass O_CLOEXEC to open() or mkostemp() instead of setting FD_CLOEXEC afterwards
ok miod@
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/db/btree/bt_open.c | 9 | ||||
-rw-r--r-- | lib/libc/db/hash/hash_page.c | 5 |
2 files changed, 5 insertions, 9 deletions
diff --git a/lib/libc/db/btree/bt_open.c b/lib/libc/db/btree/bt_open.c index 239c2629155..b6a715cc7ef 100644 --- a/lib/libc/db/btree/bt_open.c +++ b/lib/libc/db/btree/bt_open.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bt_open.c,v 1.17 2014/05/25 17:43:03 tedu Exp $ */ +/* $OpenBSD: bt_open.c,v 1.18 2014/09/15 06:12:19 guenther Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -190,7 +190,7 @@ __bt_open(const char *fname, int flags, int mode, const BTREEINFO *openinfo, goto einval; } - if ((t->bt_fd = open(fname, flags, mode)) < 0) + if ((t->bt_fd = open(fname, flags | O_CLOEXEC, mode)) < 0) goto err; } else { @@ -201,9 +201,6 @@ __bt_open(const char *fname, int flags, int mode, const BTREEINFO *openinfo, F_SET(t, B_INMEM); } - if (fcntl(t->bt_fd, F_SETFD, FD_CLOEXEC) == -1) - goto err; - if (fstat(t->bt_fd, &sb)) goto err; if (sb.st_size) { @@ -399,7 +396,7 @@ tmp(void) (void)sigfillset(&set); (void)sigprocmask(SIG_BLOCK, &set, &oset); - if ((fd = mkstemp(path)) != -1) + if ((fd = mkostemp(path, O_CLOEXEC)) != -1) (void)unlink(path); (void)sigprocmask(SIG_SETMASK, &oset, NULL); return(fd); diff --git a/lib/libc/db/hash/hash_page.c b/lib/libc/db/hash/hash_page.c index 719a01719b4..a98df8f50e2 100644 --- a/lib/libc/db/hash/hash_page.c +++ b/lib/libc/db/hash/hash_page.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hash_page.c,v 1.21 2013/09/30 12:02:31 millert Exp $ */ +/* $OpenBSD: hash_page.c,v 1.22 2014/09/15 06:12:19 guenther Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -855,9 +855,8 @@ open_temp(HTAB *hashp) /* Block signals; make sure file goes away at process exit. */ (void)sigfillset(&set); (void)sigprocmask(SIG_BLOCK, &set, &oset); - if ((hashp->fp = mkstemp(path)) != -1) { + if ((hashp->fp = mkostemp(path, O_CLOEXEC)) != -1) { (void)unlink(path); - (void)fcntl(hashp->fp, F_SETFD, FD_CLOEXEC); } (void)sigprocmask(SIG_SETMASK, &oset, (sigset_t *)NULL); return (hashp->fp != -1 ? 0 : -1); |