From ba7e409249ade51a2686295e03bf5b068665fe0f Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Thu, 22 Apr 2021 12:32:13 +0200 Subject: [PATCH] rework NM-dispatcher/dhclient detection The packaged NM dispatcher and dhclient scripts provide the same functionality. Only one should be active depending on the system configuration. Instead of guessing in the NM dispatcher script whether the dhclient script is executed, check in the dhclient script whether it is called from a NM dispatcher script (the 11-dhclient script included in the dhcp-client package). This is simpler and it removes dependency on the 11-dhclient script. --- chrony-nm-dispatcher-dhcp.patch | 27 +++------------------------ chrony.dhclient | 5 +++++ chrony.spec | 2 +- 3 files changed, 9 insertions(+), 25 deletions(-) diff --git a/chrony-nm-dispatcher-dhcp.patch b/chrony-nm-dispatcher-dhcp.patch index bdd199d..23087d6 100644 --- a/chrony-nm-dispatcher-dhcp.patch +++ b/chrony-nm-dispatcher-dhcp.patch @@ -1,38 +1,17 @@ -From 1b29e43133d992e735ffbf87d79f008994479036 Mon Sep 17 00:00:00 2001 From: Robert Fairley Date: Wed, 17 Jun 2020 10:14:19 -0400 -Subject: [PATCH] examples/nm-dispatcher.dhcp: use sysconfig, detect dhclient +Subject: [PATCH] examples/nm-dispatcher.dhcp: use sysconfig Use the PEERNTP and NTPSERVERARGS environment variables from -/etc/sysconfig/network{-scripts}. Detect a dhclient install to avoid a -redundant operation with the 11-dhclient NM dispatcher in the -dhcp-client package. +/etc/sysconfig/network{-scripts}. Co-Authored-By: Christian Glombek ---- - examples/chrony.nm-dispatcher.dhcp | 21 +++++++++++++++++++-- - 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/examples/chrony.nm-dispatcher.dhcp b/examples/chrony.nm-dispatcher.dhcp index 6ea4c37..a6ad35a 100644 --- a/examples/chrony.nm-dispatcher.dhcp +++ b/examples/chrony.nm-dispatcher.dhcp -@@ -6,21 +6,39 @@ - - export LC_ALL=C - -+# If a dhclient installation is present, avoid a redundant operation -+# in case dhclient handles NTP server config through its own chrony config script, -+# exec'ed by NetworkManager's 11-dhclient dispatcher script. -+# In RHCOS, 11-dhclient is excluded and not shipped with base image. -+[ -e /usr/sbin/dhclient ] && \ -+ [ -e /etc/dhcp/dhclient.d/chrony.sh ] && \ -+ [ -e /etc/NetworkManager/dispatcher.d/11-dhclient -o \ -+ -e /usr/lib/NetworkManager/dispatcher.d/11-dhclient ] && \ -+ exit 0 -+ - interface=$1 - action=$2 +@@ -6,16 +6,24 @@ chronyc=/usr/bin/chronyc default_server_options=iburst diff --git a/chrony.dhclient b/chrony.dhclient index 92fa4fa..3fe9e92 100644 --- a/chrony.dhclient +++ b/chrony.dhclient @@ -4,6 +4,9 @@ CHRONY_SOURCEDIR=/run/chrony-dhcp SERVERFILE=$CHRONY_SOURCEDIR/$interface.sources chrony_config() { + # Disable modifications if called from a NM dispatcher script + [ -n "$NM_DISPATCHER_ACTION" ] && return 0 + rm -f "$SERVERFILE" if [ "$PEERNTP" != "no" ]; then mkdir -p $CHRONY_SOURCEDIR @@ -15,6 +18,8 @@ chrony_config() { } chrony_restore() { + [ -n "$NM_DISPATCHER_ACTION" ] && return 0 + if [ -f "$SERVERFILE" ]; then rm -f "$SERVERFILE" /usr/bin/chronyc reload sources > /dev/null 2>&1 || : diff --git a/chrony.spec b/chrony.spec index e26f14e..2fc3452 100644 --- a/chrony.spec +++ b/chrony.spec @@ -63,7 +63,7 @@ md5sum -c <<-EOF | (! grep -v 'OK$') 2d01b94bc1a7b7fb70cbee831488d121 examples/chrony.conf.example2 96999221eeef476bd49fe97b97503126 examples/chrony.keys.example 6a3178c4670de7de393d9365e2793740 examples/chrony.logrotate - 2da011da89727ef009799502d84e7cd0 examples/chrony.nm-dispatcher.dhcp + a7054c9352c07384bd7ea0477e6e8a8c examples/chrony.nm-dispatcher.dhcp 8f5a98fcb400a482d355b929d04b5518 examples/chrony.nm-dispatcher.onoffline 32c34c995c59fd1c3ad1616d063ae4a0 examples/chronyd.service EOF