summaryrefslogtreecommitdiffstats
path: root/lib/libutil
diff options
context:
space:
mode:
authorguenther <guenther@openbsd.org>2014-08-15 03:51:40 +0000
committerguenther <guenther@openbsd.org>2014-08-15 03:51:40 +0000
commit0205f8e66ce8c2d9c439542953f237a17f23b194 (patch)
tree145b45ce27a69aca56b4834c4cd72e953fad812f /lib/libutil
parentCreate a function which loads sgd in the mfi_iop_ops struct so that skinny (diff)
downloadwireguard-openbsd-0205f8e66ce8c2d9c439542953f237a17f23b194.tar.xz
wireguard-openbsd-0205f8e66ce8c2d9c439542953f237a17f23b194.zip
Use O_CLOEXEC wherever we open a file and then call fcntl(F_SETFD, FD_CLOEXEC)
on it, simplifying error checking, reducing system calls, and improving thread-safety for libraries. ok miod@
Diffstat (limited to 'lib/libutil')
-rw-r--r--lib/libutil/passwd.c13
1 files changed, 3 insertions, 10 deletions
diff --git a/lib/libutil/passwd.c b/lib/libutil/passwd.c
index 26db941e83c..31c1ccc006a 100644
--- a/lib/libutil/passwd.c
+++ b/lib/libutil/passwd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: passwd.c,v 1.52 2013/08/17 06:54:21 guenther Exp $ */
+/* $OpenBSD: passwd.c,v 1.53 2014/08/15 03:51:40 guenther Exp $ */
/*
* Copyright (c) 1987, 1993, 1994, 1995
@@ -93,7 +93,6 @@ pw_lock(int retries)
{
int i, fd;
mode_t old_mode;
- int save_errno;
if (!pw_lck) {
errno = EINVAL;
@@ -101,18 +100,12 @@ pw_lock(int retries)
}
/* Acquire the lock file. */
old_mode = umask(0);
- fd = open(pw_lck, O_WRONLY|O_CREAT|O_EXCL, 0600);
+ fd = open(pw_lck, O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 0600);
for (i = 0; i < retries && fd < 0 && errno == EEXIST; i++) {
sleep(1);
- fd = open(pw_lck, O_WRONLY|O_CREAT|O_EXCL, 0600);
- }
- save_errno = errno;
- if (fd != -1 && fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
- close(fd);
- fd = -1;
+ fd = open(pw_lck, O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 0600);
}
(void) umask(old_mode);
- errno = save_errno;
return (fd);
}