packetwerk/pfsense-tools — pull request #1 by maxatome (2014-05-05 07:22:52+00:00)
Title: Monitor dhcpd.leases NOTE_LINK events too

When backuping its dhcpd.leases file, isc-dhcp first create a new file
dhcpd.leases.TIMESTAMP (with new entries), then it link() dhcpd.leases
to dhcpd.leases~, then it rename() the dhcpd.leases.TIMESTAMP to
dhcpd.leases.

In this case, the freshly added entries do not appear in the
/var/etc/hosts file until the next modification of the leases.

Before backup:
```
[2.1.2-RELEASE][admin@etoile.mobigard.com]/root(21): date ; ls -lai /var/etc/hosts /var/dhcpd/var/db/dhcpd.leases*
Fri May 2 17:24:41 CEST 2014
2449606 -rw-r--r-- 1 root _dhcp 51652 May 2 17:24 /var/dhcpd/var/db/dhcpd.leases
2449575 -rw-r--r-- 1 dhcpd _dhcp 652 Apr 11 02:08 /var/dhcpd/var/db/dhcpd.leases.old
2449607 -rw-r--r-- 1 dhcpd _dhcp 101660 May 2 16:46 /var/dhcpd/var/db/dhcpd.leases~
2449498 -rw-r--r-- 1 root wheel 6067 May 2 17:24 /var/etc/hosts
```

After backup:
```
[2.1.2-RELEASE][admin@etoile.mobigard.com]/root(22): date ; ls -lai /var/etc/hosts /var/dhcpd/var/db/dhcpd.leases*
Fri May 2 18:30:31 CEST 2014
2449608 -rw-r--r-- 1 dhcpd _dhcp 50393 May 2 18:29 /var/dhcpd/var/db/dhcpd.leases
2449575 -rw-r--r-- 1 dhcpd _dhcp 652 Apr 11 02:08 /var/dhcpd/var/db/dhcpd.leases.old
2449606 -rw-r--r-- 1 root _dhcp 59866 May 2 17:50 /var/dhcpd/var/db/dhcpd.leases~
2449498 -rw-r--r-- 1 root wheel 6067 May 2 17:50 /var/etc/hosts
```

/var/etc/hosts is not updated even though dhcpd.leases contents
changed, just because dhcpd.leases is a new file, the old is still
here link()ed as dhcpd.leases~, but not rename()d :)

So add NOTE_LINK event to watch the dhcpd.leases changes in this case,
as the NOTE_RENAME is not appropriate here, and NOTE_DELETE neither.

Perhaps a small (empirical) usleep() should be added before reopening?
Just to avoid the race condition of being called between the:
```
link(dhcpd.leases, dhcpd.leases~)
```
and the:
```
rename(dhcpd.leases.TIMESTAMP, dhcpd.leases)
```
calls of isc-dhcp...