summaryrefslogtreecommitdiff
path: root/lib/libutil
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1997-11-17 20:56:58 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1997-11-17 20:56:58 +0000
commita2d206028623dd43603128c069c46ed0b593f91b (patch)
treecd03ff853446c86c3533695a82d0aed0757107c8 /lib/libutil
parent3c2732df213283612633ca395c5c33734acb75ff (diff)
Work around bug in open(2) wrt O_TRUNC and O_SHLOCK|O_EXLOCK.
Diffstat (limited to 'lib/libutil')
-rw-r--r--lib/libutil/passwd.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/libutil/passwd.c b/lib/libutil/passwd.c
index 7825dd99a9b..83c5c8d6614 100644
--- a/lib/libutil/passwd.c
+++ b/lib/libutil/passwd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: passwd.c,v 1.12 1997/09/29 19:18:21 deraadt Exp $ */
+/* $OpenBSD: passwd.c,v 1.13 1997/11/17 20:56:57 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.12 1997/09/29 19:18:21 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: passwd.c,v 1.13 1997/11/17 20:56:57 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -252,11 +252,14 @@ pw_lock(retries)
return (-1);
/* Acquire the lock file. */
old_mode = umask(0);
- fd = open(pw_lck, O_WRONLY|O_CREAT|O_TRUNC|O_NONBLOCK|O_EXLOCK, 0600);
+ fd = open(pw_lck, O_WRONLY|O_CREAT|O_NONBLOCK|O_EXLOCK, 0600);
for (i = 0; i < retries && fd < 0 && errno == EAGAIN; i++) {
sleep(1);
- fd = open(pw_lck, O_WRONLY|O_CREAT|O_TRUNC|O_NONBLOCK|O_EXLOCK, 0600);
+ fd = open(pw_lck, O_WRONLY|O_CREAT|O_NONBLOCK|O_EXLOCK, 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);
}