summaryrefslogtreecommitdiffstats
path: root/lib/libutil
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>1997-11-17 22:46:03 +0000
committermillert <millert@openbsd.org>1997-11-17 22:46:03 +0000
commit45720f7b881e87e86d60b39ce1bd8370ef54282e (patch)
tree2db277274572836d3b6be2565ab6b075bee0b7a2 /lib/libutil
parentpw_mkdb() now returns -1 if ptmp is size 0. (diff)
downloadwireguard-openbsd-45720f7b881e87e86d60b39ce1bd8370ef54282e.tar.xz
wireguard-openbsd-45720f7b881e87e86d60b39ce1bd8370ef54282e.zip
Go back to old file locking method, O_EXLOCK method has too many problems
Diffstat (limited to 'lib/libutil')
-rw-r--r--lib/libutil/passwd.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/lib/libutil/passwd.c b/lib/libutil/passwd.c
index b1128ae3994..d01a6245a23 100644
--- a/lib/libutil/passwd.c
+++ b/lib/libutil/passwd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: passwd.c,v 1.14 1997/11/17 21:12:12 millert Exp $ */
+/* $OpenBSD: passwd.c,v 1.15 1997/11/17 22:46:03 millert Exp $ */
/*
* Copyright (c) 1987, 1993, 1994, 1995
@@ -34,7 +34,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: passwd.c,v 1.14 1997/11/17 21:12:12 millert Exp $";
+static char rcsid[] = "$OpenBSD: passwd.c,v 1.15 1997/11/17 22:46:03 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -250,16 +250,13 @@ pw_lock(retries)
if (!pw_lck)
return (-1);
- /* Acquire the lock file. */
+ /* Acquire the lock file. */
old_mode = umask(0);
- fd = open(pw_lck, O_WRONLY|O_CREAT|O_NONBLOCK|O_EXLOCK, 0600);
- for (i = 0; i < retries && fd < 0 && errno == EAGAIN; i++) {
+ fd = open(pw_lck, O_WRONLY|O_CREAT|O_EXCL, 0600);
+ for (i = 0; i < retries && fd < 0 && errno == EEXIST; i++) {
sleep(1);
- fd = open(pw_lck, O_WRONLY|O_CREAT|O_NONBLOCK|O_EXLOCK, 0600);
+ fd = open(pw_lck, O_WRONLY|O_CREAT|O_EXCL, 0600);
}
- /* Really want to use O_TRUNC above but there is a bug in open(2) */
- if (fd != -1)
- ftruncate(fd, 0);
umask(old_mode);
return (fd);
}