summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenning Brauer <henning@cvs.openbsd.org>2004-05-13 07:19:33 +0000
committerHenning Brauer <henning@cvs.openbsd.org>2004-05-13 07:19:33 +0000
commit65b3939ddfd72e0c8b53c12fe29b088caa3bb795 (patch)
tree3ce52a4b1b00497b467d8f6c72746f760ed21cf3
parentef40255aa9064762cdd72306c3bb0dae723f76d0 (diff)
when trying to rewrite the lease file, and if the lease file is already
opened, do not close and re-open it, which of course fails once we're chrooted and privilege revoked, but rewind the file and truncate later on as needed. makes wilfried@ and Ben Lovett happy (aka, they tested)
-rw-r--r--sbin/dhclient/dhclient.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c
index 6a960947922..cfb4bb7d888 100644
--- a/sbin/dhclient/dhclient.c
+++ b/sbin/dhclient/dhclient.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhclient.c,v 1.51 2004/05/08 16:16:33 henning Exp $ */
+/* $OpenBSD: dhclient.c,v 1.52 2004/05/13 07:19:32 henning Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -1589,11 +1589,14 @@ rewrite_client_leases(void)
{
struct client_lease *lp;
- if (leaseFile)
- fclose(leaseFile);
- leaseFile = fopen(path_dhclient_db, "w");
- if (!leaseFile)
- error("can't create %s: %m", path_dhclient_db);
+ if (!leaseFile) {
+ leaseFile = fopen(path_dhclient_db, "w");
+ if (!leaseFile)
+ error("can't create %s: %m", path_dhclient_db);
+ } else {
+ fflush(leaseFile);
+ rewind(leaseFile);
+ }
for (lp = ifi->client->leases; lp; lp = lp->next)
write_client_lease(ifi, lp, 1);
@@ -1601,6 +1604,8 @@ rewrite_client_leases(void)
write_client_lease(ifi, ifi->client->active, 1);
fflush(leaseFile);
+ ftruncate(fileno(leaseFile), ftell(leaseFile));
+ fsync(fileno(leaseFile));
}
void