From: Ian Jackson Subject: [OSSTEST PATCH] cat-dhcp-leases: new script Date: Fri, 3 Oct 2014 16:06:52 +0100 Message-ID: <1412348812-2850-1-git-send-email-ian.jackson@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Xa4SF-0004en-U7 for xen-devel@lists.xenproject.org; Fri, 03 Oct 2014 15:07:36 +0000 List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: Ian Jackson , Ian Campbell List-Id: xen-devel@lists.xenproject.org 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 --- cat-dhcp-leases | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100755 cat-dhcp-leases diff --git a/cat-dhcp-leases b/cat-dhcp-leases new file mode 100755 index 0000000..6cd6d06 --- /dev/null +++ b/cat-dhcp-leases @@ -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' -- 1.7.10.4