summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2002-05-22 18:24:36 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2002-05-22 18:24:36 +0000
commit13096a8e7dd3222590cb3328763a16e7f8143473 (patch)
tree3d207efa8090cb3bc2db603fae0b7a0ac1c3e065
parent479e29a76368102a75815e233abb4cd35f6376f5 (diff)
Use O_EXLOCK in open() instead of flock() to eliminate a potential locking
race on the pid file.
-rw-r--r--usr.sbin/lpr/lpd/lpd.c10
1 files changed, 3 insertions, 7 deletions
diff --git a/usr.sbin/lpr/lpd/lpd.c b/usr.sbin/lpr/lpd/lpd.c
index a1003852ed2..21e5e8b5fcf 100644
--- a/usr.sbin/lpr/lpd/lpd.c
+++ b/usr.sbin/lpr/lpd/lpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lpd.c,v 1.29 2002/05/20 23:13:50 millert Exp $ */
+/* $OpenBSD: lpd.c,v 1.30 2002/05/22 18:24:35 millert Exp $ */
/* $NetBSD: lpd.c,v 1.33 2002/01/21 14:42:29 wiz Exp $ */
/*
@@ -45,7 +45,7 @@ static const char copyright[] =
#if 0
static const char sccsid[] = "@(#)lpd.c 8.7 (Berkeley) 5/10/95";
#else
-static const char rcsid[] = "$OpenBSD: lpd.c,v 1.29 2002/05/20 23:13:50 millert Exp $";
+static const char rcsid[] = "$OpenBSD: lpd.c,v 1.30 2002/05/22 18:24:35 millert Exp $";
#endif
#endif /* not lint */
@@ -240,12 +240,8 @@ main(int argc, char **argv)
openlog("lpd", LOG_PID, LOG_LPR);
syslog(LOG_INFO, "restarted");
(void)umask(0);
- lfd = open(_PATH_MASTERLOCK, O_WRONLY|O_CREAT, 0644);
+ lfd = open(_PATH_MASTERLOCK, O_WRONLY|O_CREAT|O_EXLOCK|O_NONBLOCK, 0644);
if (lfd < 0) {
- syslog(LOG_ERR, "%s: %m", _PATH_MASTERLOCK);
- exit(1);
- }
- if (flock(lfd, LOCK_EX|LOCK_NB) < 0) {
if (errno == EWOULDBLOCK) /* active daemon present */
exit(0);
syslog(LOG_ERR, "%s: %m", _PATH_MASTERLOCK);