83af60
From: Robert Fairley <rfairley@redhat.com>
83af60
Date: Wed, 17 Jun 2020 10:14:19 -0400
83af60
Subject: [PATCH] examples/nm-dispatcher.dhcp: use sysconfig
83af60
83af60
Use the PEERNTP and NTPSERVERARGS environment variables from
83af60
/etc/sysconfig/network{-scripts}.
83af60
83af60
Co-Authored-By: Christian Glombek <cglombek@redhat.com>
83af60
83af60
diff --git a/examples/chrony.nm-dispatcher.dhcp b/examples/chrony.nm-dispatcher.dhcp
83af60
index 6ea4c37..a6ad35a 100644
83af60
--- a/examples/chrony.nm-dispatcher.dhcp
83af60
+++ b/examples/chrony.nm-dispatcher.dhcp
83af60
@@ -6,16 +6,24 @@
83af60
 
83af60
 chronyc=/usr/bin/chronyc
83af60
 default_server_options=iburst
83af60
-server_dir=/var/run/chrony-dhcp
83af60
+server_dir=/run/chrony-dhcp
83af60
 
83af60
 dhcp_server_file=$server_dir/$interface.sources
83af60
 # DHCP4_NTP_SERVERS is passed from DHCP options by NetworkManager.
83af60
 nm_dhcp_servers=$DHCP4_NTP_SERVERS
83af60
 
83af60
+[ -f /etc/sysconfig/network ] && . /etc/sysconfig/network
83af60
+[ -f /etc/sysconfig/network-scripts/ifcfg-"${interface}" ] && \
83af60
+    . /etc/sysconfig/network-scripts/ifcfg-"${interface}"
83af60
+
83af60
 add_servers_from_dhcp() {
83af60
     rm -f "$dhcp_server_file"
83af60
+
83af60
+    # Don't add NTP servers if PEERNTP=no specified; return early.
83af60
+    [ "$PEERNTP" = "no" ] && return
83af60
+
83af60
     for server in $nm_dhcp_servers; do
83af60
-        echo "server $server $default_server_options" >> "$dhcp_server_file"
83af60
+        echo "server $server ${NTPSERVERARGS:-$default_server_options}" >> "$dhcp_server_file"
83af60
     done
83af60
     $chronyc reload sources > /dev/null 2>&1 || :
83af60
 }
83af60
-- 
83af60
2.29.2
83af60
83af60
Use chrony-helper instead of chronyc to avoid changes in default chrony.conf
83af60
83af60
diff -up chrony-4.1/examples/chrony.nm-dispatcher.dhcp.nm-dispatcher-dhcp chrony-4.1/examples/chrony.nm-dispatcher.dhcp
83af60
--- chrony-4.1/examples/chrony.nm-dispatcher.dhcp.nm-dispatcher-dhcp	2021-06-09 11:10:30.997416152 +0200
83af60
+++ chrony-4.1/examples/chrony.nm-dispatcher.dhcp	2021-06-09 11:16:23.598381336 +0200
83af60
@@ -9,11 +9,12 @@ export LC_ALL=C
83af60
 interface=$1
83af60
 action=$2
83af60
 
83af60
-chronyc=/usr/bin/chronyc
83af60
+helper=/usr/libexec/chrony-helper
83af60
 default_server_options=iburst
83af60
-server_dir=/run/chrony-dhcp
83af60
+server_dir=/run/chrony-helper
83af60
 
83af60
-dhcp_server_file=$server_dir/$interface.sources
83af60
+dhcp_server_tmpfile=$server_dir/tmp-nm-dhcp.$interface
83af60
+dhcp_server_file=$server_dir/nm-dhcp.$interface
83af60
 # DHCP4_NTP_SERVERS is passed from DHCP options by NetworkManager.
83af60
 nm_dhcp_servers=$DHCP4_NTP_SERVERS
83af60
 
83af60
@@ -24,24 +24,30 @@ nm_dhcp_servers=$DHCP4_NTP_SERVERS
83af60
 add_servers_from_dhcp() {
83af60
     rm -f "$dhcp_server_file"
83af60
 
83af60
+    # Remove servers saved by the dhclient script before it detected NM.
83af60
+    rm -f "/var/lib/dhclient/chrony.servers.$interface"
83af60
+
83af60
     # Don't add NTP servers if PEERNTP=no specified; return early.
83af60
     [ "$PEERNTP" = "no" ] && return
83af60
 
83af60
+    # Create the directory with correct SELinux context.
83af60
+    $helper create-helper-directory > /dev/null 2>&1
83af60
+
83af60
     for server in $nm_dhcp_servers; do
83af60
-        echo "server $server ${NTPSERVERARGS:-$default_server_options}" >> "$dhcp_server_file"
83af60
+        echo "$server ${NTPSERVERARGS:-$default_server_options}" >> "$dhcp_server_tmpfile"
83af60
     done
83af60
+    [ -e "$dhcp_server_tmpfile" ] && mv "$dhcp_server_tmpfile" "$dhcp_server_file"
83af60
-    $chronyc reload sources > /dev/null 2>&1 || :
83af60
+
83af60
+    $helper update-daemon > /dev/null 2>&1 || :
83af60
 }
83af60
 
83af60
 clear_servers_from_dhcp() {
83af60
     if [ -f "$dhcp_server_file" ]; then
83af60
         rm -f "$dhcp_server_file"
83af60
-        $chronyc reload sources > /dev/null 2>&1 || :
83af60
+        $helper update-daemon > /dev/null 2>&1 || :
83af60
     fi
83af60
 }
83af60
 
83af60
-mkdir -p $server_dir
83af60
-
83af60
 if [ "$action" = "up" ] || [ "$action" = "dhcp4-change" ]; then
83af60
     add_servers_from_dhcp
83af60
 elif [ "$action" = "down" ]; then