Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion net/chrony/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk

PKG_NAME:=chrony
PKG_VERSION:=4.9
PKG_RELEASE:=2
PKG_RELEASE:=3

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://chrony-project.org/releases/
Expand Down Expand Up @@ -97,11 +97,13 @@ define Package/chrony/install
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_DIR) $(1)/etc/chrony
$(INSTALL_DIR) $(1)/etc/uci-defaults
$(INSTALL_DIR) $(1)/etc/hotplug.d/iface
$(INSTALL_BIN) ./files/chrony.hotplug $(1)/etc/hotplug.d/iface/20-chrony
$(INSTALL_BIN) ./files/chronyd.init $(1)/etc/init.d/chronyd
$(INSTALL_CONF) ./files/chrony.config $(1)/etc/config/chrony
$(INSTALL_CONF) ./files/chrony.conf $(1)/etc/chrony/chrony.conf
$(INSTALL_BIN) ./files/chrony.defaults $(1)/etc/uci-defaults/chrony
endef

Package/chrony-nts/install= $(Package/chrony/install)
Expand Down
3 changes: 0 additions & 3 deletions net/chrony/files/chrony.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,5 @@ noclientlog
# Mark the system clock as synchronized
rtcsync

# Record the clock's drift
driftfile /var/run/chrony/drift

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/etc/chrony/chrony.conf is a conffile, so if a user has modified it, the upgrade keeps their copy with this driftfile line. That line comes after confdir (line 2), so it overrides the UCI-generated directive and the new file/interval options are silently ignored. Is that acceptable, or should the upgrade path handle it (e.g. a note in the commit message, or a uci-defaults/sed migration)?


Generated by Claude Code

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's acceptable. User which modifies /etc/chrony/chrony.conf knows what he does. My patch just changes place of driftfile /var/run/chrony/drift but doesn't change behavior.


# Save NTS keys and cookies
ntsdumpdir /var/run/chrony
5 changes: 5 additions & 0 deletions net/chrony/files/chrony.config
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ config nts 'nts'
option rtccheck '1'
option systemcerts '1'

config driftfile 'driftfile'
option restore_time '0'
option file '/var/run/chrony/drift'
# option interval ''

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe path would be a better name of the file option when file is already included in driftfile?

The commented-out interval option could be setting it to 86400 as an example?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use file becouse chrony.conf manual page uses file in documentation driftfile file [interval interval]. In most cases in OpenWRT uci files used file option name not var. I ask ChatGPT to count how often meeted file.

Option name contains | Active entries | Commented examples | Total
file only | 34 | 39 | 73
path only | 8 | 4 | 12
Both | 0 | 2 | 2

I just use such values to generate the same line as deleted in net/chrony/files/chrony.conf. Chronyd by default uses 3600 as interval value. If need to use some value I think need to use default if no any reasons to use specific value.


#config smoothtime 'smoothtime'
# option maxppm '400'
# option maxwander '0.01'
Expand Down
10 changes: 10 additions & 0 deletions net/chrony/files/chrony.defaults

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this file needed? The service should start correctly even with a config that doesn't set driftfile, right?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Service will be started correctly. But in luci app section will be omitted. openwrt/luci#9139

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

uci -q get chrony.driftfile >/dev/null && exit 0

uci -q batch <<-EOF
set chrony.driftfile=driftfile
set chrony.driftfile.restore_time='0'
set chrony.driftfile.file='/var/run/chrony/drift'
commit chrony
EOF
28 changes: 27 additions & 1 deletion net/chrony/files/chronyd.init
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ HOTPLUG=/usr/sbin/chrony-hotplug
CONFIGFILE=/etc/chrony/chrony.conf
INCLUDEFILE=/var/etc/chrony.d/10-uci.conf
RTCDEVICE=/dev/rtc0
DRIFTFILE=/var/run/chrony/drift

handle_source() {
local cfg=$1 sourcetype=$2 disabled hostname minpoll maxpoll iburst nts
Expand Down Expand Up @@ -117,11 +118,36 @@ handle_logging() {
[ -n "$logchange" ] && echo logchange "$logchange"
}

handle_driftfile() {
local cfg=$1 file interval

config_get file "$cfg" file $DRIFTFILE
config_get interval "$cfg" interval

local dir=$(dirname "$file")
if [ ! -d $dir ]; then
mkdir -p "$dir"
chown chrony:chrony "$dir"
fi

if [ -n "$interval" ]; then
echo driftfile $file interval $interval
else
echo driftfile $file
fi
}

start_service() {
. /lib/functions/network.sh

config_load chrony
# Restoring time requires the -s command-line option; no configuration directive exists.
local restore_time
config_get_bool restore_time driftfile restore_time 0

procd_open_instance
procd_set_param command $PROG -n
[ "$restore_time" = "1" ] && procd_append_param command -s
procd_set_param file $CONFIGFILE
procd_set_param file $INCLUDEFILE
procd_close_instance
Expand All @@ -130,7 +156,6 @@ start_service() {
procd_set_param command $HOTPLUG
procd_close_instance

config_load chrony
mkdir -p $(dirname $INCLUDEFILE)

(
Expand All @@ -143,5 +168,6 @@ start_service() {
config_foreach handle_systemclock systemclock
config_foreach handle_nts nts
config_foreach handle_logging logging
config_foreach handle_driftfile driftfile
) > $INCLUDEFILE
}