dhcpcd icon indicating copy to clipboard operation
dhcpcd copied to clipboard

DHCPCD keeps deleting the /etc/ntp.conf provided by Gentoo

Open F3llFr0mTh3Sky opened this issue 2 years ago • 6 comments

Hello, I'm using netifrc+dhcpcd on gentoo. Pretty basic netifrc config file. I kept both the default dhcpcd and ntp config files. Whenever the network starts, dhcpcd keeps deleting the content of /etc/ntp.conf which prevents me to run ntpd -q -g. This shouldn't be the case because the default /etc/dhcpcd.conf file has this line commented :

# Most distributions have NTP support.
#option ntp_servers

I guess the issue is caused by the 50-ntp.conf file : https://github.com/NetworkConfiguration/dhcpcd/blob/master/hooks/50-ntp.conf

This line should be set by default in /etc/dhcpcd.conf when a /etc/ntp.conf file is provided by a Linux distribution :

env NTP_CONF=

F3llFr0mTh3Sky avatar Nov 03 '23 22:11 F3llFr0mTh3Sky

Commenting option ntp_servers just stops dhcpcd from requesting the option, not the running of the hook script.

I have seen this from time to time, but have never been able to repeat it. Mainly using OpenBSD and not Gentoo.

What the hook script does is place any config between specific markers and remove the previous config based on the markers. If you have sed installed, the command run is this: sed '/^# Generated by dhcpcd/,/^# End of dhcpcd/d' /etc/ntp.conf Which should leave your existing config alone.

Saying that, if anything outputs to stdout/stderr that isn't captured by the script then dhcpcd scripts fail with SIGPIPE which I suppose might result in an empty result. That issue was fixed in the last release of dhcpcd-10.0.4 but did introduce a new bug where dhcpcd didn't startup properly sometimes which is now fixed in the master branch.

So, is it possible for you to test the master branch of dhcpcd? Gentoo has a 9999 ebuild for this. If that doesn't work, can you put set -x and set +x in the 50-ntp.conf hook script like so:

diff --git a/hooks/50-ntp.conf b/hooks/50-ntp.conf
index cbaa3744..b9d2b001 100644
--- a/hooks/50-ntp.conf
+++ b/hooks/50-ntp.conf
@@ -84,6 +84,8 @@ build_ntp_conf()
        [ -e "$cf" ] && rm -f "$cf"
        [ -d "$ntp_conf_dir" ] || mkdir -p "$ntp_conf_dir"

+set -x
+
        if [ -n "$NTP_DHCP_CONF" ]; then
                [ -e "$ntp_conf" ] && cp "$ntp_conf" "$cf"
                ntp_conf="$NTP_DHCP_CONF"
@@ -104,6 +106,8 @@ build_ntp_conf()
        if change_file "$ntp_conf" "$cf"; then
                [ -n "$ntp_restart_cmd" ] && eval $ntp_restart_cmd
        fi
+
+set +x
 }

 add_ntp_conf()

Then run dhcpcd -dB and look at the console for something like this:

re0: executing: /usr/libexec/dhcpcd-run-hooks REBOOT
+ [ -n '' ]
+ [ -e /etc/ntp.conf ]
+ remove_markers '# Generated by dhcpcd' '# End of dhcpcd' /etc/ntp.conf
+ m1='# Generated by dhcpcd'
+ m2='# End of dhcpcd'
+ in_marker=0
+ shift
+ shift
+ command -v sed
+ sed '/^# Generated by dhcpcd/,/^# End of dhcpcd/d' /etc/ntp.conf
+ [ -n '' ]
+ [ -e /etc/ntp.conf ]
+ [ -e /var/run/dhcpcd/hook-state/ntp.conf.re0.dhcp ]
+ change_file /etc/ntp.conf /var/run/dhcpcd/hook-state/ntp.conf.re0.dhcp
+ [ -e /etc/ntp.conf ]
+ comp_file /etc/ntp.conf /var/run/dhcpcd/hook-state/ntp.conf.re0.dhcp
+ [ -e /etc/ntp.conf ]
+ [ -e /var/run/dhcpcd/hook-state/ntp.conf.re0.dhcp ]
+ command -v cmp
+ cmp -s /etc/ntp.conf /var/run/dhcpcd/hook-state/ntp.conf.re0.dhcp
+ rm -f /var/run/dhcpcd/hook-state/ntp.conf.re0.dhcp
+ return 1
+ set +x

If you can do that and repeat your ntp.conf content being deleted that would be very helpful. Or by sheer luck it's related to the SIGPIPE issue and already fixed.

Let me know!

rsmarples avatar Nov 08 '23 10:11 rsmarples

I'll do some testing and give you the feedback afterwards.

F3llFr0mTh3Sky avatar Nov 10 '23 16:11 F3llFr0mTh3Sky

As you're using Gentoo you might be affected by #262 as well.

rsmarples avatar Nov 12 '23 12:11 rsmarples

Probably, but I'm still on DHCPCD 10.0.3 and I'm only using it through netifrc.

F3llFr0mTh3Sky avatar Nov 12 '23 14:11 F3llFr0mTh3Sky

I am using this line in my conf file:

nohook resolv.conf, wpa_supplicant, hostname, ntp.conf, yp.conf

Got no problem in my Gentoo system. Maybe this helps OP.

r2ixuz avatar Dec 11 '23 08:12 r2ixuz

I already solved the issue on my side, see : https://bugs.gentoo.org/916776 but thanks anyway for the tip.

F3llFr0mTh3Sky avatar Dec 11 '23 23:12 F3llFr0mTh3Sky