All DHCP clients like to stamp their view on configuration files. After all, that is part of their job :) However, many people also have their own settings in the same configuration file. Most people don’t notice dhcpcd stamping on these files, but when they do they normally just turn that feature off.
The main culprit here is ntp.conf, as it can have quite a complex setup and dhcpcd has always imposed it’s own world view on it. However, this lead to an interesting bug being found in NetBSD rc.d script for ntpd- it requires ntp.conf to configure pidfile /var/run/ntpd.pid
. Now, dhcpcd can’t put this in as the pidfile location changes from distro to distro, so effectively dhcpcd broke the stock script. Whilst this is a NetBSD bug, some people also asked why dhcpcd could not be more intelligent about things? :?
So I’ve now added a nice framework so that dhcpcd hook scripts can trivially top/tail config files with their own data can clean up after themselves. Here’s a snippet from 50-ntp.conf
itself
do_ntp_conf()
{
local cleaned= added=1 conf= x=
clean_conf /etc/ntp.conf
cleaned=$?
if ["$1" = "add"-a-n "${new_ntp_servers}" ](); then
for x in ${new_ntp_servers}; do
conf="${conf:+\n}server ${x}"
done
append_conf /etc/ntp.conf "${conf}"
added=$?
fi
if [${cleaned}-eq 0-o ${added}-eq 0 ](); then
[-n "${ntpd_restart_cmd}" ]() && ${ntpd_restart_cmd}
fi
}
Nice and simple :D
I’m currently debating if we can use this framework to do more intelligent handling of /etc/resolv.conf
if resolvconf is not installed, but that’s not as critical.