]> xenbits.xensource.com Git - osstest.git/commitdiff
cat-dhcp-leases: new script flight-30583 flight-30597 flight-30612 flight-30626 flight-30627 flight-30628 flight-30629 flight-30630 flight-30631 flight-30632 flight-30633 flight-30634 flight-30635 flight-30636 flight-30637 flight-30639 flight-30640 flight-30641 flight-30642 flight-30644 flight-30645 flight-30647 flight-30649 flight-30650 flight-30651 flight-30652 flight-30653 flight-30654 flight-30655 flight-30656 flight-30657 flight-30658
authorIan Jackson <ian.jackson@eu.citrix.com>
Fri, 3 Oct 2014 15:02:32 +0000 (16:02 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Fri, 3 Oct 2014 15:18:26 +0000 (16:18 +0100)
ISC dhcpd treates /var/lib/dhcp3/leases as a log-structured database,
appending records to it and periodically rewriting it.  When it
decides to rewrite it it writes the new contents to a temporary file -
fine.

But rather than renaming the temporary file into place, over the top
of the old file, using rename(2), it first renames the old leases file
to leases~.  So briefly there is no leases file.

This means that the service used by Osstest/DhcpWatch/leases.pm when a
hostname and port is specified has to try various different files.

This is the appropriate shell script, which is most conveniently
maintained here in osstest.  It can be used by putting something like
this in inetd.conf:

5556 stream tcp nowait nobody /root/cat-dhcp-leases cat-dhcp-leases

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
cat-dhcp-leases [new file with mode: 0755]

diff --git a/cat-dhcp-leases b/cat-dhcp-leases
new file mode 100755 (executable)
index 0000000..6cd6d06
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+set -e
+cd /var/lib/dhcp3
+for f in dhcpd.leases dhcpd.leases~; do
+    if (exec 3>&2 2>/dev/null <$f 2>&3 3>&- cat); then exit 0; fi
+done
+echo '# CANNOT OPEN ANY LEASES FILE'