summaryrefslogtreecommitdiff
path: root/sbin/dhclient
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2019-07-19 14:49:44 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2019-07-19 14:49:44 +0000
commit5c6807606e22eb02b379bdd08c9b8376d0632053 (patch)
treeb48960f89994cf2e17fa7aeb7b7f75b89dc7cdbc /sbin/dhclient
parent5dec97ecbcdfeb06e91c08765ca17e236d04ef39 (diff)
Keep dhclient.leases.<if> O_EXLOCK file descriptor open for the
lifefime of the dhclient instance. Use O_NONBLOCK so RTM_* messages are seen while trying to open the O_EXLOCK file descriptor. Prevents a possible race during startup, ensuring only one dhclient instance can be configuring an interface. Improves responsiveness to interface changes during startup.
Diffstat (limited to 'sbin/dhclient')
-rw-r--r--sbin/dhclient/dhclient.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c
index dbd3cb39fa0..2d02f3bc706 100644
--- a/sbin/dhclient/dhclient.c
+++ b/sbin/dhclient/dhclient.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhclient.c,v 1.644 2019/07/16 01:42:27 krw Exp $ */
+/* $OpenBSD: dhclient.c,v 1.645 2019/07/19 14:49:43 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -595,7 +595,6 @@ main(int argc, char *argv[])
if ((leaseFile = fopen(path_lease_db, "w")) == NULL)
fatal("fopen(%s)", path_lease_db);
write_lease_db(ifi->name, &ifi->lease_db);
- close(fd);
if (path_option_db != NULL) {
/*
@@ -2485,9 +2484,9 @@ take_charge(struct interface_info *ifi, int routefd, char *leasespath)
routefd_handler(ifi, routefd);
if ((ifi->flags & IFI_IN_CHARGE) == IFI_IN_CHARGE) {
- fd = open(leasespath,
+ fd = open(leasespath, O_NONBLOCK |
O_RDONLY|O_EXLOCK|O_CREAT|O_NOFOLLOW, 0640);
- if (fd == -1)
+ if (fd == -1 && errno != EWOULDBLOCK)
fatal("open(%s)", leasespath);
}
}