From b12e3fcabc597e14ab40bf0a7bc1a9d9541def52 Mon Sep 17 00:00:00 2001 From: sindhu-krishnan <102755514+sindhu-krishnan@users.noreply.github.com> Date: Wed, 8 Jul 2026 11:49:58 +0530 Subject: [PATCH 01/33] Create 10_chronyd.c --- .../scripts/init/c_registration/10_chronyd.c | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 source/scripts/init/c_registration/10_chronyd.c diff --git a/source/scripts/init/c_registration/10_chronyd.c b/source/scripts/init/c_registration/10_chronyd.c new file mode 100644 index 00000000..e3d73928 --- /dev/null +++ b/source/scripts/init/c_registration/10_chronyd.c @@ -0,0 +1,74 @@ +/* + * If not stated otherwise in this file or this component's Licenses.txt file the + * following copyright and licenses apply: + * + * Copyright 2015 RDK Management + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +#include +#include "srvmgr.h" + +#define SERVICE_NAME "chronyd" +#define SERVICE_DEFAULT_HANDLER "/etc/utopia/service.d/service_chronyd.sh" + +/* + * Listen to the same network events as ntpd so chronyd starts when WAN comes up. + * ipv6_connection_state is registered for HUB4/SKY platforms (guarded in the + * handler script itself — no compile-time flag needed here because the RFC flag + * /nvram/chrony_enabled gates all execution in service_chronyd.sh). + */ +#ifdef _HUB4_PRODUCT_REQ_ +const char* SERVICE_CUSTOM_EVENTS[] = { + "wan-status|/etc/utopia/service.d/service_chronyd.sh", + "ipv6_connection_state|/etc/utopia/service.d/service_chronyd.sh", + NULL +}; +#else +const char* SERVICE_CUSTOM_EVENTS[] = { + "wan-status|/etc/utopia/service.d/service_chronyd.sh", + NULL +}; +#endif + +void srv_register(void) { + sm_register(SERVICE_NAME, SERVICE_DEFAULT_HANDLER, SERVICE_CUSTOM_EVENTS); +} + +void srv_unregister(void) { + sm_unregister(SERVICE_NAME); +} + +int main(int argc, char **argv) +{ + cmd_type_t choice = parse_cmd_line(argc, argv); + + switch (choice) { + case(nochoice): + case(start): + srv_register(); + break; + case(stop): + srv_unregister(); + break; + case(restart): + srv_unregister(); + srv_register(); + break; + default: + printf("%s called with invalid parameter (%s)\n", + argv[0], argc == 1 ? "" : argv[1]); + } + return 0; +} From 40bbe1e28ebd7cf8e6f2b79f576ba7a0f3d1658c Mon Sep 17 00:00:00 2001 From: sindhu-krishnan <102755514+sindhu-krishnan@users.noreply.github.com> Date: Wed, 8 Jul 2026 11:53:26 +0530 Subject: [PATCH 02/33] Create service_chronyd.sh --- .../scripts/init/service.d/service_chronyd.sh | 359 ++++++++++++++++++ 1 file changed, 359 insertions(+) create mode 100644 source/scripts/init/service.d/service_chronyd.sh diff --git a/source/scripts/init/service.d/service_chronyd.sh b/source/scripts/init/service.d/service_chronyd.sh new file mode 100644 index 00000000..31c2479c --- /dev/null +++ b/source/scripts/init/service.d/service_chronyd.sh @@ -0,0 +1,359 @@ +#!/bin/sh +########################################################################## +# If not stated otherwise in this file or this component's Licenses.txt +# file the following copyright and licenses apply: +# +# Copyright 2015 RDK Management +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +########################################################################## + +source /etc/utopia/service.d/ulog_functions.sh +source /etc/utopia/service.d/log_capture_path.sh +source /etc/log_timestamp.sh # define 'echo_t' ASAP! +source /etc/waninfo.sh +source /etc/device.properties + +SERVICE_NAME="chronyd" +SELF_NAME="`basename "$0"`" +CHRONY_CONF_TMP=/tmp/chrony.conf +CHRONY_BIN=chronyd +LOCKFILE=/var/tmp/service_chronyd.pid +RFC_FLAG=/nvram/chrony_enabled +SYNC_FILE=/tmp/clock-event +NTP_SYNCED_FILE=/tmp/.ntp_time_synced + +if [ -z "$NTPD_LOG_NAME" ]; then + NTPD_LOG_NAME=/rdklogs/logs/chrony.log +fi + +LANIPV6Support=$(sysevent get LANIPv6GUASupport) +CURRENT_WAN_STATUS=$(sysevent get wan-status) +WAN_INTERFACE=$(getWanInterfaceName) + +# ────────────────────────────────────────────────────────────────────────────── +# service_init: load syscfg NTP server values into environment +# ────────────────────────────────────────────────────────────────────────────── +service_init() { + FOO=$(utctx_cmd get ntp_server1 ntp_server2 ntp_server3 ntp_server4 ntp_server5 \ + ntp_enabled new_ntp_enabled) + eval "$FOO" +} + +# ────────────────────────────────────────────────────────────────────────────── +# wan_wait: poll WAN interface until IPv4 or IPv6 address is available +# $1 — name of variable to receive the WAN IP +# ────────────────────────────────────────────────────────────────────────────── +wan_wait() { + local WAN_UP="" + local WAN_IPv4="" + local WAN_IPv6="" + local retry=0 + local MAX_RETRY=20 + + while [ -z "$WAN_UP" ]; do + retry=$((retry + 1)) + WAN_IPv4=$(ifconfig -a "$WAN_INTERFACE" | grep inet | grep -v inet6 \ + | tr -s " " | cut -d ":" -f2 | cut -d " " -f1 | head -n1) + + if [ "$BOX_TYPE" = "HUB4" ] || [ "$BOX_TYPE" = "SR300" ] || \ + [ "$BOX_TYPE" = "SE501" ] || [ "$BOX_TYPE" = "SR213" ] || \ + [ "$BOX_TYPE" = "WNXL11BWL" ] || [ "$LANIPV6Support" = "true" ]; then + CURRENT_WAN_IPV6_STATUS=$(sysevent get ipv6_connection_state) + if [ "up" = "$CURRENT_WAN_IPV6_STATUS" ]; then + ULAprefix=$(sysevent get ula_address | cut -d ':' -f1) + if [ -z "$ULAprefix" ]; then + WAN_IPv6=$(ifconfig "$NTPD_IPV6_INTERFACE" | grep inet6 | grep Global \ + | awk '/inet6/{print $3}' | grep -v 'fdd7' \ + | cut -d '/' -f1 | head -n1) + else + WAN_IPv6=$(ifconfig "$NTPD_IPV6_INTERFACE" | grep inet6 | grep Global \ + | awk '/inet6/{print $3}' | grep -v 'fdd7' \ + | grep -v "$ULAprefix" | cut -d '/' -f1 | head -n1) + fi + fi + else + WAN_IPv6=$(ifconfig "$WAN_INTERFACE" | grep inet6 | grep Global \ + | awk '/inet6/{print $3}' | cut -d '/' -f1 | head -n1) + fi + + if [ -n "$WAN_IPv4" ] || [ -n "$WAN_IPv6" ]; then + WAN_UP="$WAN_INTERFACE" + break + fi + + sleep 6 + WAN_INTERFACE=$(getWanInterfaceName) + + if [ "$retry" -ge "$MAX_RETRY" ]; then + echo_t "SERVICE_CHRONYD : WAN IP not acquired after max retries. Exiting" >> $NTPD_LOG_NAME + break + fi + done + + eval "$1=\$WAN_UP" +} + +# ────────────────────────────────────────────────────────────────────────────── +# build_chrony_conf: construct /tmp/chrony.conf from syscfg NTP servers +# ────────────────────────────────────────────────────────────────────────────── +build_chrony_conf() { + local WAN_IP="$1" + local WAN_IPv4="" + local WAN_IPv6="" + + rm -f "$CHRONY_CONF_TMP" + + + # NTP servers from syscfg + if [ "$NTP_SERVER_URL_RESTORE" = "false" ]; then + if [ "$SYSCFG_new_ntp_enabled" = "true" ]; then + # Multi-server pool (new_ntp_enabled mode) + for srv in "$SYSCFG_ntp_server1" "$SYSCFG_ntp_server2" "$SYSCFG_ntp_server3" \ + "$SYSCFG_ntp_server4" "$SYSCFG_ntp_server5"; do + if [ -n "$srv" ] && [ "$srv" != "no_ntp_address" ]; then + echo "pool $srv iburst maxsources 3 minpoll 10 maxpoll 12" >> $CHRONY_CONF_TMP + fi + done + else + # Legacy single-server mode + local SRV="$SYSCFG_ntp_server1" + if [ -z "$SRV" ] || [ "$SRV" = "no_ntp_address" ]; then + if [ -f "/nvram/ETHWAN_ENABLE" ] || [ -z "$PARTNER_ID" ]; then + SRV="time1.google.com" + echo_t "SERVICE_CHRONYD : NTP server not configured, using default" >> $NTPD_LOG_NAME + else + echo_t "SERVICE_CHRONYD : NTP server not configured and PartnerID set — aborting" >> $NTPD_LOG_NAME + return 1 + fi + fi + echo "pool $SRV iburst maxsources 2 minpoll 10 maxpoll 12" >> $CHRONY_CONF_TMP + fi + fi + + # Fast initial step-correction + echo "makestep 1.0 3" >> $CHRONY_CONF_TMP + + # Drift file + echo "driftfile /var/lib/chrony/drift" >> $CHRONY_CONF_TMP + + # Bind acquisition (outgoing NTP client) sockets to the WAN interface by name, + # covering both IPv4 and IPv6 without needing to extract individual IPs. + if [ -n "$WAN_IP" ]; then + echo "bindacqdevice $WAN_INTERFACE" >> $CHRONY_CONF_TMP + echo_t "SERVICE_CHRONYD : binding acquisition sockets to interface $WAN_INTERFACE" >> $NTPD_LOG_NAME + fi + + if [ "$MULTI_CORE" = "yes" ] && [ "$NTPD_IMMED_PEER_SYNC" != "true" ]; then + echo "bindaddress $HOST_INTERFACE_IP" >> $CHRONY_CONF_TMP + fi + + + echo_t "SERVICE_CHRONYD : chrony.conf built at $CHRONY_CONF_TMP" >> $NTPD_LOG_NAME + return 0 +} + +# ────────────────────────────────────────────────────────────────────────────── +# set_chrony_sync_status: background monitor — polls chronyc until Leap=Normal +# ────────────────────────────────────────────────────────────────────────────── +set_chrony_sync_status() { + local retry=1 + local MAX_RETRY=12 # 12 × 10s = 120s max wait + + while true; do + if [ "$retry" -gt "$MAX_RETRY" ]; then + echo_t "SERVICE_CHRONYD : sync not confirmed within 120s — daemon still running" >> $NTPD_LOG_NAME + break + fi + + leap=$(chronyc tracking 2>/dev/null | grep "Leap status" | awk '{print $NF}') + if [ "$leap" = "Normal" ]; then + echo_t "SERVICE_CHRONYD : time sync confirmed (Leap status Normal)" >> $NTPD_LOG_NAME + syscfg set ntp_status 3 + sysevent set ntp_time_sync 1 + touch "$SYNC_FILE" + touch "$NTP_SYNCED_FILE" + DEVICEFIRSTUSEDATE=$(syscfg get device_first_use_date) + if [ -z "$DEVICEFIRSTUSEDATE" ] || [ "0" = "$DEVICEFIRSTUSEDATE" ]; then + syscfg set device_first_use_date "$(date +%Y-%m-%dT%H:%M:%S)" + fi + break + fi + + retry=$((retry + 1)) + sleep 10 + done + exit 0 +} + +# ────────────────────────────────────────────────────────────────────────────── +# service_start: main start path +# ────────────────────────────────────────────────────────────────────────────── +service_start() { + # RFC guard — only run if flag is present + if [ ! -f "$RFC_FLAG" ]; then + echo_t "SERVICE_CHRONYD : RFC flag absent — chrony path inactive" >> $NTPD_LOG_NAME + return 0 + fi + + if [ -n "$SYSCFG_ntp_enabled" ] && [ "0" = "$SYSCFG_ntp_enabled" ]; then + syscfg set ntp_status 2 + sysevent set ${SERVICE_NAME}-status "stopped" + return 0 + fi + + # Do not start a second instance if chronyd is already running + if pidof "$CHRONY_BIN" > /dev/null 2>&1; then + echo_t "SERVICE_CHRONYD : already running (pid=$(pidof $CHRONY_BIN)), skipping start" >> $NTPD_LOG_NAME + return 0 + fi + + syscfg set ntp_status 2 + sysevent set ${SERVICE_NAME}-status "starting" + + # WAN check + if [ "$BOX_TYPE" = "HUB4" ] || [ "$BOX_TYPE" = "SR300" ] || \ + [ "$BOX_TYPE" = "SE501" ] || [ "$BOX_TYPE" = "WNXL11BWL" ] || \ + [ "$BOX_TYPE" = "SR213" ] || [ "$LANIPV6Support" = "true" ]; then + WAN_IPV6_STATUS=$(sysevent get ipv6_connection_state) + if [ "started" != "$CURRENT_WAN_STATUS" ] && [ "up" != "$WAN_IPV6_STATUS" ]; then + syscfg set ntp_status 2 + sysevent set ${SERVICE_NAME}-status "wan-down" + return 0 + fi + else + if [ "started" != "$CURRENT_WAN_STATUS" ]; then + syscfg set ntp_status 2 + sysevent set ${SERVICE_NAME}-status "wan-down" + return 0 + fi + fi + + # Stop ntpd if running — mutual exclusivity with chrony + if pidof ntpd > /dev/null 2>&1; then + echo_t "SERVICE_CHRONYD : stopping ntpd for mutual exclusivity" >> $NTPD_LOG_NAME + systemctl stop ntpd + killall ntpd 2>/dev/null + sleep 2 + fi + + # Wait for WAN IP + local WAN_IP="" + wan_wait WAN_IP + + # Build chrony.conf + build_chrony_conf "$WAN_IP" + local rc=$? + if [ "$rc" -ne 0 ]; then + sysevent set ${SERVICE_NAME}-status "error" + return 1 + fi + + # Start chronyd — only reaches here when no instance is running + echo_t "SERVICE_CHRONYD : starting chronyd daemon" >> $NTPD_LOG_NAME + systemctl start chronyd + rc=$? + if [ "$rc" -ne 0 ]; then + echo_t "SERVICE_CHRONYD : systemctl start chronyd failed (rc=$rc)" >> $NTPD_LOG_NAME + sysevent set ${SERVICE_NAME}-status "error" + return 1 + fi + + sysevent set ${SERVICE_NAME}-status "started" + echo_t "SERVICE_CHRONYD : chronyd started — monitoring sync in background" >> $NTPD_LOG_NAME + + # Background sync monitor + set_chrony_sync_status & +} + +# ────────────────────────────────────────────────────────────────────────────── +# service_stop +# ────────────────────────────────────────────────────────────────────────────── +service_stop() { + echo_t "SERVICE_CHRONYD : stopping chronyd" >> $NTPD_LOG_NAME + systemctl stop chronyd 2>/dev/null + killall chronyd 2>/dev/null + sysevent set ${SERVICE_NAME}-status "stopped" +} + +# ────────────────────────────────────────────────────────────────────────────── +# Script entry point — serialise concurrent invocations via lockfile +# ────────────────────────────────────────────────────────────────────────────── +while [ -e "$LOCKFILE" ]; do + kill -0 "$(cat "$LOCKFILE")" 2>/dev/null || break + echo_t "SERVICE_CHRONYD : waiting for parallel instance to finish..." >> $NTPD_LOG_NAME + sleep 1 +done + +trap 'rm -f ${LOCKFILE}; exit' INT TERM EXIT +echo $$ > "$LOCKFILE" + +service_init +CURRENT_WAN_STATUS=$(sysevent get wan-status) + +case "$1" in + "${SERVICE_NAME}-start") + echo_t "SERVICE_CHRONYD : ${SERVICE_NAME}-start received" >> $NTPD_LOG_NAME + service_start + ;; + "${SERVICE_NAME}-stop") + echo_t "SERVICE_CHRONYD : ${SERVICE_NAME}-stop received" >> $NTPD_LOG_NAME + service_stop + ;; + "${SERVICE_NAME}-restart") + echo_t "SERVICE_CHRONYD : ${SERVICE_NAME}-restart received" >> $NTPD_LOG_NAME + service_stop + service_start + ;; + wan-status) + if [ "started" = "$CURRENT_WAN_STATUS" ]; then + # service_start() already guards against duplicate instances via pidof + echo_t "SERVICE_CHRONYD : wan-status=started, calling service_start" >> $NTPD_LOG_NAME + service_start + fi + ;; + ipv6_connection_state) + # HUB4/SKY and ntpHealthCheck-enabled platforms only + ntpHealthCheck=$(sysevent get NTPHealthCheckSupport) + if [ "$BOX_TYPE" = "HUB4" ] || [ "$BOX_TYPE" = "SR300" ] || \ + [ "$BOX_TYPE" = "SE501" ] || [ "$BOX_TYPE" = "WNXL11BWL" ] || \ + [ "$BOX_TYPE" = "SR213" ] || [ "$ntpHealthCheck" = "true" ]; then + CHRONY_PID=$(pidof $CHRONY_BIN) + NTP_STATUS=$(syscfg get ntp_status) + if [ "$NTP_STATUS" = "3" ] && [ -n "$CHRONY_PID" ]; then + # Already synced — signal chrony to re-acquire sources, no restart needed + echo_t "SERVICE_CHRONYD : IPv6 state change, running chronyc online" >> $NTPD_LOG_NAME + chronyc online > /dev/null 2>&1 + else + WAN_IPV6_STATUS=$(sysevent get ipv6_connection_state) + if [ "up" = "$WAN_IPV6_STATUS" ]; then + CURRENT_WAN_V6_PREFIX=$(syscfg get ipv6_prefix_address) + NTP_PREFIX=$(sysevent get ntp_prefix) + if [ -n "$CURRENT_WAN_V6_PREFIX" ] && [ "$NTP_PREFIX" != "$CURRENT_WAN_V6_PREFIX" ]; then + echo_t "SERVICE_CHRONYD : IPv6 prefix changed, restarting" >> $NTPD_LOG_NAME + sysevent set ntp_prefix "$CURRENT_WAN_V6_PREFIX" + service_start + fi + fi + fi + fi + ;; + *) + echo "Usage: $SELF_NAME [ ${SERVICE_NAME}-start | ${SERVICE_NAME}-stop | ${SERVICE_NAME}-restart | wan-status | ipv6_connection_state ]" >&2 + rm -f "$LOCKFILE" + exit 3 + ;; +esac + +echo_t "SERVICE_CHRONYD : end of script" >> $NTPD_LOG_NAME +rm -f "$LOCKFILE" From f4d09d4776eaa63c40d732ff11fd36d3cadd11be Mon Sep 17 00:00:00 2001 From: sindhu-krishnan <102755514+sindhu-krishnan@users.noreply.github.com> Date: Wed, 8 Jul 2026 11:55:37 +0530 Subject: [PATCH 03/33] Update Makefile.am --- source/scripts/init/c_registration/Makefile.am | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/scripts/init/c_registration/Makefile.am b/source/scripts/init/c_registration/Makefile.am index 946ca302..5253bd5b 100644 --- a/source/scripts/init/c_registration/Makefile.am +++ b/source/scripts/init/c_registration/Makefile.am @@ -51,6 +51,7 @@ bin_PROGRAMS = \ 09_xdns \ 10_firewall \ 10_ntpd \ + 10_chronyd \ 15_ccsphs \ 15_ddnsclient \ 15_dhcp_server \ @@ -103,6 +104,7 @@ endif 10_fpm_SOURCES = 10_fpm.c 10_ntpclient_SOURCES = 10_ntpclient.c 10_ntpd_SOURCES = 10_ntpd.c +10_chronyd_SOURCES = 10_chronyd.c 10_sysevent_proxy_SOURCES = 10_sysevent_proxy.c 10_time_sync_peer_SOURCES = 10_time_sync_peer.c 15_ccsphs_SOURCES = 15_ccsphs.c From 8ebfa3ddcb4ce23ab0c917ffebe9493860e04db5 Mon Sep 17 00:00:00 2001 From: sindhu-krishnan <102755514+sindhu-krishnan@users.noreply.github.com> Date: Wed, 8 Jul 2026 11:59:42 +0530 Subject: [PATCH 04/33] Update service_chronyd.sh --- source/scripts/init/service.d/service_chronyd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/scripts/init/service.d/service_chronyd.sh b/source/scripts/init/service.d/service_chronyd.sh index 31c2479c..1e1a143b 100644 --- a/source/scripts/init/service.d/service_chronyd.sh +++ b/source/scripts/init/service.d/service_chronyd.sh @@ -252,7 +252,7 @@ service_start() { wan_wait WAN_IP # Build chrony.conf - build_chrony_conf "$WAN_IP" + #build_chrony_conf "$WAN_IP" local rc=$? if [ "$rc" -ne 0 ]; then sysevent set ${SERVICE_NAME}-status "error" From ab8cc1d70cdf9dfb9ff5c4ef3b562133830f12e4 Mon Sep 17 00:00:00 2001 From: sindhu-krishnan <102755514+sindhu-krishnan@users.noreply.github.com> Date: Wed, 8 Jul 2026 12:01:22 +0530 Subject: [PATCH 05/33] Update service_chronyd.sh --- source/scripts/init/service.d/service_chronyd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/scripts/init/service.d/service_chronyd.sh b/source/scripts/init/service.d/service_chronyd.sh index 1e1a143b..fb9e2902 100644 --- a/source/scripts/init/service.d/service_chronyd.sh +++ b/source/scripts/init/service.d/service_chronyd.sh @@ -203,7 +203,7 @@ service_start() { # RFC guard — only run if flag is present if [ ! -f "$RFC_FLAG" ]; then echo_t "SERVICE_CHRONYD : RFC flag absent — chrony path inactive" >> $NTPD_LOG_NAME - return 0 + # return 0 - TBD fi if [ -n "$SYSCFG_ntp_enabled" ] && [ "0" = "$SYSCFG_ntp_enabled" ]; then From 1a4740074430e46c6088f92bd4447e1aaaea03fa Mon Sep 17 00:00:00 2001 From: sindhu-krishnan <102755514+sindhu-krishnan@users.noreply.github.com> Date: Thu, 9 Jul 2026 12:03:36 +0530 Subject: [PATCH 06/33] Update service_ntpd.sh --- source/scripts/init/service.d/service_ntpd.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/scripts/init/service.d/service_ntpd.sh b/source/scripts/init/service.d/service_ntpd.sh index edae1e55..f511d860 100644 --- a/source/scripts/init/service.d/service_ntpd.sh +++ b/source/scripts/init/service.d/service_ntpd.sh @@ -52,6 +52,7 @@ LOCKFILE=/var/tmp/service_ntpd.pid BIN=ntpd QUICK_SYNC_PID="" QUICK_SYNC_DONE=0 +RFC_FLAG=/nvram/chrony_enabled STATIC_INTERFACE=$NTPD_INTERFACE WAN_INTERFACE=$(getWanInterfaceName) @@ -332,6 +333,10 @@ set_ntp_driftsync_status () service_start () { + if [ -f "$RFC_FLAG" ]; then + echo_t "SERVICE_NTPD : RFC flag Present — chrony is the active NTP client" >> $NTPD_LOG_NAME + return 0 - TBD + fi local NTP_SERVER_URL_RESTORE="false" # Wait for connectivitycheck to complete From 82bccf3c43f5c6a2370f3b8fcee399fbb5f192d0 Mon Sep 17 00:00:00 2001 From: sindhu-krishnan <102755514+sindhu-krishnan@users.noreply.github.com> Date: Thu, 9 Jul 2026 15:02:58 +0530 Subject: [PATCH 07/33] Update service_chronyd.sh --- source/scripts/init/service.d/service_chronyd.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/source/scripts/init/service.d/service_chronyd.sh b/source/scripts/init/service.d/service_chronyd.sh index fb9e2902..7b4a8585 100644 --- a/source/scripts/init/service.d/service_chronyd.sh +++ b/source/scripts/init/service.d/service_chronyd.sh @@ -263,12 +263,19 @@ service_start() { echo_t "SERVICE_CHRONYD : starting chronyd daemon" >> $NTPD_LOG_NAME systemctl start chronyd rc=$? + if [ "$ret_val" -eq 0 ]; then + if [ -e "/usr/bin/print_uptime" ] && [ ! -f "/tmp/ntp_boot_uptime_logged" ]; then + /usr/bin/print_uptime "boot_to_chrony_uptime" + touch /tmp/ntp_boot_uptime_logged + fi + fi if [ "$rc" -ne 0 ]; then echo_t "SERVICE_CHRONYD : systemctl start chronyd failed (rc=$rc)" >> $NTPD_LOG_NAME sysevent set ${SERVICE_NAME}-status "error" return 1 fi + sysevent set ${SERVICE_NAME}-status "started" echo_t "SERVICE_CHRONYD : chronyd started — monitoring sync in background" >> $NTPD_LOG_NAME From d478b1670df6c58bde5a1d168eddce922609aa5a Mon Sep 17 00:00:00 2001 From: sindhu-krishnan <102755514+sindhu-krishnan@users.noreply.github.com> Date: Thu, 9 Jul 2026 15:11:23 +0530 Subject: [PATCH 08/33] Update service_chronyd.sh --- .../scripts/init/service.d/service_chronyd.sh | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/source/scripts/init/service.d/service_chronyd.sh b/source/scripts/init/service.d/service_chronyd.sh index 7b4a8585..558a9c55 100644 --- a/source/scripts/init/service.d/service_chronyd.sh +++ b/source/scripts/init/service.d/service_chronyd.sh @@ -37,6 +37,8 @@ if [ -z "$NTPD_LOG_NAME" ]; then NTPD_LOG_NAME=/rdklogs/logs/chrony.log fi +CONNCHECK_FILE="/tmp/connectivity_check_done" + LANIPV6Support=$(sysevent get LANIPv6GUASupport) CURRENT_WAN_STATUS=$(sysevent get wan-status) WAN_INTERFACE=$(getWanInterfaceName) @@ -196,6 +198,34 @@ set_chrony_sync_status() { exit 0 } +waitForConnChkFile() +{ + echo_t "SERVICE_NTPD CONNCHK: Waiting for connection check for completion..." >> $NTPD_LOG_NAME + TIMEOUT=120 + INTERVAL=1 + + # Get system uptime in seconds at start + START_TIME=$(cut -d. -f1 /proc/uptime) + + echo_t "SERVICE_NTPD CONNCHK: Waiting for $CONNCHECK_FILE (max ${TIMEOUT}s)..." >> $NTPD_LOG_NAME + + while true; do + if [ -f "$CONNCHECK_FILE" ]; then + echo_t "SERVICE_NTPD CONNCHK: File $CONNCHECK_FILE present" >> $NTPD_LOG_NAME + return 0 + fi + + CURRENT_TIME=$(cut -d. -f1 /proc/uptime) + ELAPSED=$((CURRENT_TIME - START_TIME)) + + if [ "$ELAPSED" -ge "$TIMEOUT" ]; then + echo_t "SERVICE_NTPD CONNCHK: Timeout ${TIMEOUT}s expired - file $CONNCHECK_FILE not found" >> $NTPD_LOG_NAME + return 1 + fi + + sleep "$INTERVAL" + done +} # ────────────────────────────────────────────────────────────────────────────── # service_start: main start path # ────────────────────────────────────────────────────────────────────────────── @@ -206,6 +236,17 @@ service_start() { # return 0 - TBD fi + # Wait for connectivitycheck to complete + if [ -f $CONNCHECK_FILE ]; then + echo_t "SERVICE_NTPD CONNCHK: connectivity success $CONNCHECK_FILE present" >> $NTPD_LOG_NAME + else + # Exclude XLE device from connectivity check. TODO + if [ "$BOX_TYPE" != "WNXL11BWL" ];then + echo_t "SERVICE_NTPD CONNCHK: start connectivity check waiting for $CONNCHECK_FILE file" >> $NTPD_LOG_NAME + waitForConnChkFile + fi + fi + if [ -n "$SYSCFG_ntp_enabled" ] && [ "0" = "$SYSCFG_ntp_enabled" ]; then syscfg set ntp_status 2 sysevent set ${SERVICE_NAME}-status "stopped" From bfed9b45ed65f9f99c70a738de4c29334afeb2e6 Mon Sep 17 00:00:00 2001 From: sindhu-krishnan <102755514+sindhu-krishnan@users.noreply.github.com> Date: Thu, 9 Jul 2026 15:29:42 +0530 Subject: [PATCH 09/33] Update service_chronyd.sh --- source/scripts/init/service.d/service_chronyd.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/scripts/init/service.d/service_chronyd.sh b/source/scripts/init/service.d/service_chronyd.sh index 558a9c55..74ac5fe4 100644 --- a/source/scripts/init/service.d/service_chronyd.sh +++ b/source/scripts/init/service.d/service_chronyd.sh @@ -328,6 +328,12 @@ service_start() { # service_stop # ────────────────────────────────────────────────────────────────────────────── service_stop() { + + # RFC guard — if chrony is not the active client, nothing to stop + if [ ! -f "$RFC_FLAG" ]; then + echo_t "SERVICE_CHRONYD : RFC flag absent — skipping chronyd stop" >> $NTPD_LOG_NAME + return 0 + fi echo_t "SERVICE_CHRONYD : stopping chronyd" >> $NTPD_LOG_NAME systemctl stop chronyd 2>/dev/null killall chronyd 2>/dev/null From a1fee04ff5a62ad24eefe068d87a5606ee75b63e Mon Sep 17 00:00:00 2001 From: sindhu-krishnan <102755514+sindhu-krishnan@users.noreply.github.com> Date: Thu, 9 Jul 2026 16:48:59 +0530 Subject: [PATCH 10/33] Update service_chronyd.sh --- source/scripts/init/service.d/service_chronyd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/scripts/init/service.d/service_chronyd.sh b/source/scripts/init/service.d/service_chronyd.sh index 74ac5fe4..e67e9ec1 100644 --- a/source/scripts/init/service.d/service_chronyd.sh +++ b/source/scripts/init/service.d/service_chronyd.sh @@ -304,7 +304,7 @@ service_start() { echo_t "SERVICE_CHRONYD : starting chronyd daemon" >> $NTPD_LOG_NAME systemctl start chronyd rc=$? - if [ "$ret_val" -eq 0 ]; then + if [ "$rc" -eq 0 ]; then if [ -e "/usr/bin/print_uptime" ] && [ ! -f "/tmp/ntp_boot_uptime_logged" ]; then /usr/bin/print_uptime "boot_to_chrony_uptime" touch /tmp/ntp_boot_uptime_logged From 9a45fad8325709bd2182083547f02d5f11426cba Mon Sep 17 00:00:00 2001 From: sindhu-krishnan <102755514+sindhu-krishnan@users.noreply.github.com> Date: Fri, 10 Jul 2026 12:09:09 +0530 Subject: [PATCH 11/33] Update service_chronyd.sh --- source/scripts/init/service.d/service_chronyd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/scripts/init/service.d/service_chronyd.sh b/source/scripts/init/service.d/service_chronyd.sh index e67e9ec1..f2aaa14c 100644 --- a/source/scripts/init/service.d/service_chronyd.sh +++ b/source/scripts/init/service.d/service_chronyd.sh @@ -243,7 +243,7 @@ service_start() { # Exclude XLE device from connectivity check. TODO if [ "$BOX_TYPE" != "WNXL11BWL" ];then echo_t "SERVICE_NTPD CONNCHK: start connectivity check waiting for $CONNCHECK_FILE file" >> $NTPD_LOG_NAME - waitForConnChkFile + #waitForConnChkFile fi fi From 91df3d5d847ec1d5c168c6b3f1d69fc138a65945 Mon Sep 17 00:00:00 2001 From: sindhu-krishnan <102755514+sindhu-krishnan@users.noreply.github.com> Date: Fri, 10 Jul 2026 16:39:09 +0530 Subject: [PATCH 12/33] Update service_chronyd.sh --- .../scripts/init/service.d/service_chronyd.sh | 31 +++++-------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/source/scripts/init/service.d/service_chronyd.sh b/source/scripts/init/service.d/service_chronyd.sh index f2aaa14c..af544808 100644 --- a/source/scripts/init/service.d/service_chronyd.sh +++ b/source/scripts/init/service.d/service_chronyd.sh @@ -26,7 +26,7 @@ source /etc/device.properties SERVICE_NAME="chronyd" SELF_NAME="`basename "$0"`" -CHRONY_CONF_TMP=/tmp/chrony.conf +CHRONY_CONF_TMP=/etc/rdk_chrony.conf CHRONY_BIN=chronyd LOCKFILE=/var/tmp/service_chronyd.pid RFC_FLAG=/nvram/chrony_enabled @@ -110,12 +110,9 @@ wan_wait() { # build_chrony_conf: construct /tmp/chrony.conf from syscfg NTP servers # ────────────────────────────────────────────────────────────────────────────── build_chrony_conf() { - local WAN_IP="$1" - local WAN_IPv4="" - local WAN_IPv6="" - - rm -f "$CHRONY_CONF_TMP" + local WAN_IFACE="$1" + rm -f "$CHRONY_CONF_TMP" # NTP servers from syscfg if [ "$NTP_SERVER_URL_RESTORE" = "false" ]; then @@ -124,7 +121,7 @@ build_chrony_conf() { for srv in "$SYSCFG_ntp_server1" "$SYSCFG_ntp_server2" "$SYSCFG_ntp_server3" \ "$SYSCFG_ntp_server4" "$SYSCFG_ntp_server5"; do if [ -n "$srv" ] && [ "$srv" != "no_ntp_address" ]; then - echo "pool $srv iburst maxsources 3 minpoll 10 maxpoll 12" >> $CHRONY_CONF_TMP + echo "pool $srv iburst maxsources 2 minpoll 10 maxpoll 12" >> $CHRONY_CONF_TMP fi done else @@ -143,24 +140,13 @@ build_chrony_conf() { fi fi - # Fast initial step-correction - echo "makestep 1.0 3" >> $CHRONY_CONF_TMP - - # Drift file - echo "driftfile /var/lib/chrony/drift" >> $CHRONY_CONF_TMP - # Bind acquisition (outgoing NTP client) sockets to the WAN interface by name, # covering both IPv4 and IPv6 without needing to extract individual IPs. - if [ -n "$WAN_IP" ]; then + if [ -n "$WAN_IFACE" ]; then echo "bindacqdevice $WAN_INTERFACE" >> $CHRONY_CONF_TMP echo_t "SERVICE_CHRONYD : binding acquisition sockets to interface $WAN_INTERFACE" >> $NTPD_LOG_NAME fi - if [ "$MULTI_CORE" = "yes" ] && [ "$NTPD_IMMED_PEER_SYNC" != "true" ]; then - echo "bindaddress $HOST_INTERFACE_IP" >> $CHRONY_CONF_TMP - fi - - echo_t "SERVICE_CHRONYD : chrony.conf built at $CHRONY_CONF_TMP" >> $NTPD_LOG_NAME return 0 } @@ -288,12 +274,11 @@ service_start() { sleep 2 fi - # Wait for WAN IP - local WAN_IP="" - wan_wait WAN_IP + # Refresh WAN interface name — guaranteed available after wait_for_connectivity + WAN_INTERFACE=$(getWanInterfaceName) # Build chrony.conf - #build_chrony_conf "$WAN_IP" + build_chrony_conf "$WAN_INTERFACE" local rc=$? if [ "$rc" -ne 0 ]; then sysevent set ${SERVICE_NAME}-status "error" From a3a8586644f4c6fc418d0281775f4082bb026aaa Mon Sep 17 00:00:00 2001 From: sindhu-krishnan <102755514+sindhu-krishnan@users.noreply.github.com> Date: Fri, 10 Jul 2026 19:22:55 +0530 Subject: [PATCH 13/33] Update service_chronyd.sh --- source/scripts/init/service.d/service_chronyd.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/source/scripts/init/service.d/service_chronyd.sh b/source/scripts/init/service.d/service_chronyd.sh index af544808..61e8b602 100644 --- a/source/scripts/init/service.d/service_chronyd.sh +++ b/source/scripts/init/service.d/service_chronyd.sh @@ -115,7 +115,6 @@ build_chrony_conf() { rm -f "$CHRONY_CONF_TMP" # NTP servers from syscfg - if [ "$NTP_SERVER_URL_RESTORE" = "false" ]; then if [ "$SYSCFG_new_ntp_enabled" = "true" ]; then # Multi-server pool (new_ntp_enabled mode) for srv in "$SYSCFG_ntp_server1" "$SYSCFG_ntp_server2" "$SYSCFG_ntp_server3" \ @@ -138,7 +137,6 @@ build_chrony_conf() { fi echo "pool $SRV iburst maxsources 2 minpoll 10 maxpoll 12" >> $CHRONY_CONF_TMP fi - fi # Bind acquisition (outgoing NTP client) sockets to the WAN interface by name, # covering both IPv4 and IPv6 without needing to extract individual IPs. From eb94280e06ae153d1b2c702017f09fd2b1c6c837 Mon Sep 17 00:00:00 2001 From: sindhu-krishnan <102755514+sindhu-krishnan@users.noreply.github.com> Date: Fri, 10 Jul 2026 22:09:14 +0530 Subject: [PATCH 14/33] Update service_chronyd.sh --- source/scripts/init/service.d/service_chronyd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/scripts/init/service.d/service_chronyd.sh b/source/scripts/init/service.d/service_chronyd.sh index 61e8b602..5e988c45 100644 --- a/source/scripts/init/service.d/service_chronyd.sh +++ b/source/scripts/init/service.d/service_chronyd.sh @@ -34,7 +34,7 @@ SYNC_FILE=/tmp/clock-event NTP_SYNCED_FILE=/tmp/.ntp_time_synced if [ -z "$NTPD_LOG_NAME" ]; then - NTPD_LOG_NAME=/rdklogs/logs/chrony.log + NTPD_LOG_NAME=/rdklogs/logs/ntpLog.log fi CONNCHECK_FILE="/tmp/connectivity_check_done" From 58566da0e93623ce976f589df7c49c243d9d5508 Mon Sep 17 00:00:00 2001 From: sindhu-krishnan <102755514+sindhu-krishnan@users.noreply.github.com> Date: Tue, 14 Jul 2026 12:17:17 +0530 Subject: [PATCH 15/33] Update service_chronyd.sh --- source/scripts/init/service.d/service_chronyd.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/scripts/init/service.d/service_chronyd.sh b/source/scripts/init/service.d/service_chronyd.sh index 5e988c45..ddbb593d 100644 --- a/source/scripts/init/service.d/service_chronyd.sh +++ b/source/scripts/init/service.d/service_chronyd.sh @@ -137,7 +137,9 @@ build_chrony_conf() { fi echo "pool $SRV iburst maxsources 2 minpoll 10 maxpoll 12" >> $CHRONY_CONF_TMP fi - + + echo "makestep 1.0 3" >> $CHRONY_CONF_TMP + # Bind acquisition (outgoing NTP client) sockets to the WAN interface by name, # covering both IPv4 and IPv6 without needing to extract individual IPs. if [ -n "$WAN_IFACE" ]; then From 8bb33ee90807cc959bc1ee7532e4aecbbdce3d2c Mon Sep 17 00:00:00 2001 From: sindhu-krishnan <102755514+sindhu-krishnan@users.noreply.github.com> Date: Tue, 14 Jul 2026 14:21:30 +0530 Subject: [PATCH 16/33] Update 10_chronyd.c --- source/scripts/init/c_registration/10_chronyd.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/scripts/init/c_registration/10_chronyd.c b/source/scripts/init/c_registration/10_chronyd.c index e3d73928..ea08f807 100644 --- a/source/scripts/init/c_registration/10_chronyd.c +++ b/source/scripts/init/c_registration/10_chronyd.c @@ -33,11 +33,17 @@ const char* SERVICE_CUSTOM_EVENTS[] = { "wan-status|/etc/utopia/service.d/service_chronyd.sh", "ipv6_connection_state|/etc/utopia/service.d/service_chronyd.sh", + "chrony-start|/etc/utopia/service.d/service_chronyd.sh", + "chrony-stop|/etc/utopia/service.d/service_chronyd.sh", + "chrony-restart|/etc/utopia/service.d/service_chronyd.sh", NULL }; #else const char* SERVICE_CUSTOM_EVENTS[] = { "wan-status|/etc/utopia/service.d/service_chronyd.sh", + "chrony-start|/etc/utopia/service.d/service_chronyd.sh", + "chrony-stop|/etc/utopia/service.d/service_chronyd.sh", + "chrony-restart|/etc/utopia/service.d/service_chronyd.sh", NULL }; #endif From e49d4bc4720877214db520dd12b7e88c48a028d5 Mon Sep 17 00:00:00 2001 From: sindhu-krishnan <102755514+sindhu-krishnan@users.noreply.github.com> Date: Tue, 14 Jul 2026 14:50:18 +0530 Subject: [PATCH 17/33] Update service_chronyd.sh --- .../scripts/init/service.d/service_chronyd.sh | 49 ++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/source/scripts/init/service.d/service_chronyd.sh b/source/scripts/init/service.d/service_chronyd.sh index ddbb593d..464f476a 100644 --- a/source/scripts/init/service.d/service_chronyd.sh +++ b/source/scripts/init/service.d/service_chronyd.sh @@ -33,6 +33,11 @@ RFC_FLAG=/nvram/chrony_enabled SYNC_FILE=/tmp/clock-event NTP_SYNCED_FILE=/tmp/.ntp_time_synced +# /rdklogs is a tmpfs that starts empty on every boot; the logs/ subdirectory +# may not exist yet when this script fires early in the boot sequence. +# Ensure it exists before any echo_t write so no log lines are silently dropped. +mkdir -p /rdklogs/logs + if [ -z "$NTPD_LOG_NAME" ]; then NTPD_LOG_NAME=/rdklogs/logs/ntpLog.log fi @@ -278,7 +283,7 @@ service_start() { WAN_INTERFACE=$(getWanInterfaceName) # Build chrony.conf - build_chrony_conf "$WAN_INTERFACE" + #build_chrony_conf "$WAN_INTERFACE" local rc=$? if [ "$rc" -ne 0 ]; then sysevent set ${SERVICE_NAME}-status "error" @@ -325,6 +330,48 @@ service_stop() { sysevent set ${SERVICE_NAME}-status "stopped" } +service_restart() { + # RFC guard — only run if chrony path is active + if [ ! -f "$RFC_FLAG" ]; then + echo_t "SERVICE_CHRONYD : chrony-restart — RFC flag absent, skipping" >> $NTPD_LOG_NAME + return 0 + fi + + # WAN gate — do not restart if WAN is down + local WAN_STATUS + WAN_STATUS=$(sysevent get wan-status) + if [ "$BOX_TYPE" = "HUB4" ] || [ "$BOX_TYPE" = "SR300" ] || \ + [ "$BOX_TYPE" = "SE501" ] || [ "$BOX_TYPE" = "WNXL11BWL" ] || \ + [ "$BOX_TYPE" = "SR213" ] || [ "$LANIPV6Support" = "true" ]; then + local WAN_IPV6_STATUS + WAN_IPV6_STATUS=$(sysevent get ipv6_connection_state) + if [ "started" != "$WAN_STATUS" ] && [ "up" != "$WAN_IPV6_STATUS" ]; then + echo_t "SERVICE_CHRONYD : chrony-restart deferred — WAN is down" >> $NTPD_LOG_NAME + return 0 + fi + else + if [ "started" != "$WAN_STATUS" ]; then + echo_t "SERVICE_CHRONYD : chrony-restart deferred — WAN is down" >> $NTPD_LOG_NAME + return 0 + fi + fi + + echo_t "SERVICE_CHRONYD : chrony-restart — stopping chronyd" >> $NTPD_LOG_NAME + systemctl stop chronyd 2>/dev/null + + # ExecStartPre in chronyd.service rebuilds rdk_chrony.conf with current RFC values + echo_t "SERVICE_CHRONYD : chrony-restart — starting chronyd (ExecStartPre rebuilds config)" >> $NTPD_LOG_NAME + systemctl start chronyd + local rc=$? + if [ "$rc" -ne 0 ]; then + echo_t "SERVICE_CHRONYD : chrony-restart — systemctl start failed (rc=$rc)" >> $NTPD_LOG_NAME + sysevent set ${SERVICE_NAME}-status "error" + return 1 + fi + sysevent set ${SERVICE_NAME}-status "started" + echo_t "SERVICE_CHRONYD : chrony-restart — chronyd restarted successfully" >> $NTPD_LOG_NAME +} + # ────────────────────────────────────────────────────────────────────────────── # Script entry point — serialise concurrent invocations via lockfile # ────────────────────────────────────────────────────────────────────────────── From 9ea7358a8066e59520021612299014dd5905f575 Mon Sep 17 00:00:00 2001 From: sindhu-krishnan <102755514+sindhu-krishnan@users.noreply.github.com> Date: Tue, 14 Jul 2026 15:09:58 +0530 Subject: [PATCH 18/33] Update service_chronyd.sh --- source/scripts/init/service.d/service_chronyd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/scripts/init/service.d/service_chronyd.sh b/source/scripts/init/service.d/service_chronyd.sh index 464f476a..3e5d7113 100644 --- a/source/scripts/init/service.d/service_chronyd.sh +++ b/source/scripts/init/service.d/service_chronyd.sh @@ -280,7 +280,7 @@ service_start() { fi # Refresh WAN interface name — guaranteed available after wait_for_connectivity - WAN_INTERFACE=$(getWanInterfaceName) + #WAN_INTERFACE=$(getWanInterfaceName) # Build chrony.conf #build_chrony_conf "$WAN_INTERFACE" From 4ace47cafd33575a242990f8b0b7a68c8a3a6508 Mon Sep 17 00:00:00 2001 From: sindhu-krishnan <102755514+sindhu-krishnan@users.noreply.github.com> Date: Fri, 17 Jul 2026 18:22:00 +0530 Subject: [PATCH 19/33] Update service_chronyd.sh --- source/scripts/init/service.d/service_chronyd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/scripts/init/service.d/service_chronyd.sh b/source/scripts/init/service.d/service_chronyd.sh index 3e5d7113..c5ab7afc 100644 --- a/source/scripts/init/service.d/service_chronyd.sh +++ b/source/scripts/init/service.d/service_chronyd.sh @@ -224,7 +224,7 @@ service_start() { # RFC guard — only run if flag is present if [ ! -f "$RFC_FLAG" ]; then echo_t "SERVICE_CHRONYD : RFC flag absent — chrony path inactive" >> $NTPD_LOG_NAME - # return 0 - TBD + return 0 fi # Wait for connectivitycheck to complete From eb8588d28e006e5f8b281bd91bc5bc752a7534d3 Mon Sep 17 00:00:00 2001 From: sindhu-krishnan <102755514+sindhu-krishnan@users.noreply.github.com> Date: Fri, 17 Jul 2026 18:25:15 +0530 Subject: [PATCH 20/33] Update 10_chronyd.c --- source/scripts/init/c_registration/10_chronyd.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/source/scripts/init/c_registration/10_chronyd.c b/source/scripts/init/c_registration/10_chronyd.c index ea08f807..e3d73928 100644 --- a/source/scripts/init/c_registration/10_chronyd.c +++ b/source/scripts/init/c_registration/10_chronyd.c @@ -33,17 +33,11 @@ const char* SERVICE_CUSTOM_EVENTS[] = { "wan-status|/etc/utopia/service.d/service_chronyd.sh", "ipv6_connection_state|/etc/utopia/service.d/service_chronyd.sh", - "chrony-start|/etc/utopia/service.d/service_chronyd.sh", - "chrony-stop|/etc/utopia/service.d/service_chronyd.sh", - "chrony-restart|/etc/utopia/service.d/service_chronyd.sh", NULL }; #else const char* SERVICE_CUSTOM_EVENTS[] = { "wan-status|/etc/utopia/service.d/service_chronyd.sh", - "chrony-start|/etc/utopia/service.d/service_chronyd.sh", - "chrony-stop|/etc/utopia/service.d/service_chronyd.sh", - "chrony-restart|/etc/utopia/service.d/service_chronyd.sh", NULL }; #endif From bcaf62fa5c52f9501ec1d757f8c0f0e79e285f45 Mon Sep 17 00:00:00 2001 From: sindhu-krishnan <102755514+sindhu-krishnan@users.noreply.github.com> Date: Fri, 17 Jul 2026 18:37:09 +0530 Subject: [PATCH 21/33] Update service_chronyd.sh --- .../scripts/init/service.d/service_chronyd.sh | 148 +----------------- 1 file changed, 1 insertion(+), 147 deletions(-) diff --git a/source/scripts/init/service.d/service_chronyd.sh b/source/scripts/init/service.d/service_chronyd.sh index c5ab7afc..15fa97c2 100644 --- a/source/scripts/init/service.d/service_chronyd.sh +++ b/source/scripts/init/service.d/service_chronyd.sh @@ -57,105 +57,6 @@ service_init() { eval "$FOO" } -# ────────────────────────────────────────────────────────────────────────────── -# wan_wait: poll WAN interface until IPv4 or IPv6 address is available -# $1 — name of variable to receive the WAN IP -# ────────────────────────────────────────────────────────────────────────────── -wan_wait() { - local WAN_UP="" - local WAN_IPv4="" - local WAN_IPv6="" - local retry=0 - local MAX_RETRY=20 - - while [ -z "$WAN_UP" ]; do - retry=$((retry + 1)) - WAN_IPv4=$(ifconfig -a "$WAN_INTERFACE" | grep inet | grep -v inet6 \ - | tr -s " " | cut -d ":" -f2 | cut -d " " -f1 | head -n1) - - if [ "$BOX_TYPE" = "HUB4" ] || [ "$BOX_TYPE" = "SR300" ] || \ - [ "$BOX_TYPE" = "SE501" ] || [ "$BOX_TYPE" = "SR213" ] || \ - [ "$BOX_TYPE" = "WNXL11BWL" ] || [ "$LANIPV6Support" = "true" ]; then - CURRENT_WAN_IPV6_STATUS=$(sysevent get ipv6_connection_state) - if [ "up" = "$CURRENT_WAN_IPV6_STATUS" ]; then - ULAprefix=$(sysevent get ula_address | cut -d ':' -f1) - if [ -z "$ULAprefix" ]; then - WAN_IPv6=$(ifconfig "$NTPD_IPV6_INTERFACE" | grep inet6 | grep Global \ - | awk '/inet6/{print $3}' | grep -v 'fdd7' \ - | cut -d '/' -f1 | head -n1) - else - WAN_IPv6=$(ifconfig "$NTPD_IPV6_INTERFACE" | grep inet6 | grep Global \ - | awk '/inet6/{print $3}' | grep -v 'fdd7' \ - | grep -v "$ULAprefix" | cut -d '/' -f1 | head -n1) - fi - fi - else - WAN_IPv6=$(ifconfig "$WAN_INTERFACE" | grep inet6 | grep Global \ - | awk '/inet6/{print $3}' | cut -d '/' -f1 | head -n1) - fi - - if [ -n "$WAN_IPv4" ] || [ -n "$WAN_IPv6" ]; then - WAN_UP="$WAN_INTERFACE" - break - fi - - sleep 6 - WAN_INTERFACE=$(getWanInterfaceName) - - if [ "$retry" -ge "$MAX_RETRY" ]; then - echo_t "SERVICE_CHRONYD : WAN IP not acquired after max retries. Exiting" >> $NTPD_LOG_NAME - break - fi - done - - eval "$1=\$WAN_UP" -} - -# ────────────────────────────────────────────────────────────────────────────── -# build_chrony_conf: construct /tmp/chrony.conf from syscfg NTP servers -# ────────────────────────────────────────────────────────────────────────────── -build_chrony_conf() { - - local WAN_IFACE="$1" - rm -f "$CHRONY_CONF_TMP" - - # NTP servers from syscfg - if [ "$SYSCFG_new_ntp_enabled" = "true" ]; then - # Multi-server pool (new_ntp_enabled mode) - for srv in "$SYSCFG_ntp_server1" "$SYSCFG_ntp_server2" "$SYSCFG_ntp_server3" \ - "$SYSCFG_ntp_server4" "$SYSCFG_ntp_server5"; do - if [ -n "$srv" ] && [ "$srv" != "no_ntp_address" ]; then - echo "pool $srv iburst maxsources 2 minpoll 10 maxpoll 12" >> $CHRONY_CONF_TMP - fi - done - else - # Legacy single-server mode - local SRV="$SYSCFG_ntp_server1" - if [ -z "$SRV" ] || [ "$SRV" = "no_ntp_address" ]; then - if [ -f "/nvram/ETHWAN_ENABLE" ] || [ -z "$PARTNER_ID" ]; then - SRV="time1.google.com" - echo_t "SERVICE_CHRONYD : NTP server not configured, using default" >> $NTPD_LOG_NAME - else - echo_t "SERVICE_CHRONYD : NTP server not configured and PartnerID set — aborting" >> $NTPD_LOG_NAME - return 1 - fi - fi - echo "pool $SRV iburst maxsources 2 minpoll 10 maxpoll 12" >> $CHRONY_CONF_TMP - fi - - echo "makestep 1.0 3" >> $CHRONY_CONF_TMP - - # Bind acquisition (outgoing NTP client) sockets to the WAN interface by name, - # covering both IPv4 and IPv6 without needing to extract individual IPs. - if [ -n "$WAN_IFACE" ]; then - echo "bindacqdevice $WAN_INTERFACE" >> $CHRONY_CONF_TMP - echo_t "SERVICE_CHRONYD : binding acquisition sockets to interface $WAN_INTERFACE" >> $NTPD_LOG_NAME - fi - - echo_t "SERVICE_CHRONYD : chrony.conf built at $CHRONY_CONF_TMP" >> $NTPD_LOG_NAME - return 0 -} - # ────────────────────────────────────────────────────────────────────────────── # set_chrony_sync_status: background monitor — polls chronyc until Leap=Normal # ────────────────────────────────────────────────────────────────────────────── @@ -278,12 +179,6 @@ service_start() { killall ntpd 2>/dev/null sleep 2 fi - - # Refresh WAN interface name — guaranteed available after wait_for_connectivity - #WAN_INTERFACE=$(getWanInterfaceName) - - # Build chrony.conf - #build_chrony_conf "$WAN_INTERFACE" local rc=$? if [ "$rc" -ne 0 ]; then sysevent set ${SERVICE_NAME}-status "error" @@ -291,6 +186,7 @@ service_start() { fi # Start chronyd — only reaches here when no instance is running + # start chronyd will populate the config based on latest RFC configuration echo_t "SERVICE_CHRONYD : starting chronyd daemon" >> $NTPD_LOG_NAME systemctl start chronyd rc=$? @@ -329,48 +225,6 @@ service_stop() { killall chronyd 2>/dev/null sysevent set ${SERVICE_NAME}-status "stopped" } - -service_restart() { - # RFC guard — only run if chrony path is active - if [ ! -f "$RFC_FLAG" ]; then - echo_t "SERVICE_CHRONYD : chrony-restart — RFC flag absent, skipping" >> $NTPD_LOG_NAME - return 0 - fi - - # WAN gate — do not restart if WAN is down - local WAN_STATUS - WAN_STATUS=$(sysevent get wan-status) - if [ "$BOX_TYPE" = "HUB4" ] || [ "$BOX_TYPE" = "SR300" ] || \ - [ "$BOX_TYPE" = "SE501" ] || [ "$BOX_TYPE" = "WNXL11BWL" ] || \ - [ "$BOX_TYPE" = "SR213" ] || [ "$LANIPV6Support" = "true" ]; then - local WAN_IPV6_STATUS - WAN_IPV6_STATUS=$(sysevent get ipv6_connection_state) - if [ "started" != "$WAN_STATUS" ] && [ "up" != "$WAN_IPV6_STATUS" ]; then - echo_t "SERVICE_CHRONYD : chrony-restart deferred — WAN is down" >> $NTPD_LOG_NAME - return 0 - fi - else - if [ "started" != "$WAN_STATUS" ]; then - echo_t "SERVICE_CHRONYD : chrony-restart deferred — WAN is down" >> $NTPD_LOG_NAME - return 0 - fi - fi - - echo_t "SERVICE_CHRONYD : chrony-restart — stopping chronyd" >> $NTPD_LOG_NAME - systemctl stop chronyd 2>/dev/null - - # ExecStartPre in chronyd.service rebuilds rdk_chrony.conf with current RFC values - echo_t "SERVICE_CHRONYD : chrony-restart — starting chronyd (ExecStartPre rebuilds config)" >> $NTPD_LOG_NAME - systemctl start chronyd - local rc=$? - if [ "$rc" -ne 0 ]; then - echo_t "SERVICE_CHRONYD : chrony-restart — systemctl start failed (rc=$rc)" >> $NTPD_LOG_NAME - sysevent set ${SERVICE_NAME}-status "error" - return 1 - fi - sysevent set ${SERVICE_NAME}-status "started" - echo_t "SERVICE_CHRONYD : chrony-restart — chronyd restarted successfully" >> $NTPD_LOG_NAME -} # ────────────────────────────────────────────────────────────────────────────── # Script entry point — serialise concurrent invocations via lockfile From 59d06911ddcda274620f9670822c85afe413c208 Mon Sep 17 00:00:00 2001 From: sindhu-krishnan <102755514+sindhu-krishnan@users.noreply.github.com> Date: Mon, 20 Jul 2026 13:04:53 +0530 Subject: [PATCH 22/33] Update service_chronyd.sh --- source/scripts/init/service.d/service_chronyd.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/scripts/init/service.d/service_chronyd.sh b/source/scripts/init/service.d/service_chronyd.sh index 15fa97c2..7d425672 100644 --- a/source/scripts/init/service.d/service_chronyd.sh +++ b/source/scripts/init/service.d/service_chronyd.sh @@ -216,8 +216,8 @@ service_start() { service_stop() { # RFC guard — if chrony is not the active client, nothing to stop - if [ ! -f "$RFC_FLAG" ]; then - echo_t "SERVICE_CHRONYD : RFC flag absent — skipping chronyd stop" >> $NTPD_LOG_NAME + if ! systemctl is-active --quiet chronyd; then + echo_t "SERVICE_CHRONYD : chronyd is not running — skipping chronyd stop" >> $NTPD_LOG_NAME return 0 fi echo_t "SERVICE_CHRONYD : stopping chronyd" >> $NTPD_LOG_NAME From bd3d63525266e7cfc4b1fe7a167055e03fc5ff71 Mon Sep 17 00:00:00 2001 From: sindhu-krishnan <102755514+sindhu-krishnan@users.noreply.github.com> Date: Thu, 23 Jul 2026 12:29:02 +0530 Subject: [PATCH 23/33] Update service_chronyd.sh --- .../scripts/init/service.d/service_chronyd.sh | 26 ------------------- 1 file changed, 26 deletions(-) diff --git a/source/scripts/init/service.d/service_chronyd.sh b/source/scripts/init/service.d/service_chronyd.sh index 7d425672..e5d060b1 100644 --- a/source/scripts/init/service.d/service_chronyd.sh +++ b/source/scripts/init/service.d/service_chronyd.sh @@ -262,32 +262,6 @@ case "$1" in service_start fi ;; - ipv6_connection_state) - # HUB4/SKY and ntpHealthCheck-enabled platforms only - ntpHealthCheck=$(sysevent get NTPHealthCheckSupport) - if [ "$BOX_TYPE" = "HUB4" ] || [ "$BOX_TYPE" = "SR300" ] || \ - [ "$BOX_TYPE" = "SE501" ] || [ "$BOX_TYPE" = "WNXL11BWL" ] || \ - [ "$BOX_TYPE" = "SR213" ] || [ "$ntpHealthCheck" = "true" ]; then - CHRONY_PID=$(pidof $CHRONY_BIN) - NTP_STATUS=$(syscfg get ntp_status) - if [ "$NTP_STATUS" = "3" ] && [ -n "$CHRONY_PID" ]; then - # Already synced — signal chrony to re-acquire sources, no restart needed - echo_t "SERVICE_CHRONYD : IPv6 state change, running chronyc online" >> $NTPD_LOG_NAME - chronyc online > /dev/null 2>&1 - else - WAN_IPV6_STATUS=$(sysevent get ipv6_connection_state) - if [ "up" = "$WAN_IPV6_STATUS" ]; then - CURRENT_WAN_V6_PREFIX=$(syscfg get ipv6_prefix_address) - NTP_PREFIX=$(sysevent get ntp_prefix) - if [ -n "$CURRENT_WAN_V6_PREFIX" ] && [ "$NTP_PREFIX" != "$CURRENT_WAN_V6_PREFIX" ]; then - echo_t "SERVICE_CHRONYD : IPv6 prefix changed, restarting" >> $NTPD_LOG_NAME - sysevent set ntp_prefix "$CURRENT_WAN_V6_PREFIX" - service_start - fi - fi - fi - fi - ;; *) echo "Usage: $SELF_NAME [ ${SERVICE_NAME}-start | ${SERVICE_NAME}-stop | ${SERVICE_NAME}-restart | wan-status | ipv6_connection_state ]" >&2 rm -f "$LOCKFILE" From 73679bec95e55101486b2989260daa587636c23e Mon Sep 17 00:00:00 2001 From: smuthu545 Date: Thu, 23 Jul 2026 08:57:18 +0000 Subject: [PATCH 24/33] chrony fast resync during network reconnection --- .../scripts/init/service.d/service_chronyd.sh | 80 ++++++++++++++++++- 1 file changed, 77 insertions(+), 3 deletions(-) diff --git a/source/scripts/init/service.d/service_chronyd.sh b/source/scripts/init/service.d/service_chronyd.sh index e5d060b1..59aa7219 100644 --- a/source/scripts/init/service.d/service_chronyd.sh +++ b/source/scripts/init/service.d/service_chronyd.sh @@ -90,6 +90,74 @@ set_chrony_sync_status() { exit 0 } +# ─────────────────────────────────────────────────────────────────────────────────────────── +# chrony_sources_reachable: return 0 if at least one chrony source is reachable +# Reachability register (reach) is a non-zero octal value once a source has +# answered at least one recent poll. +# ────────────────────────────────────────────────────────────────────────────────────────── +chrony_sources_reachable() { + chronyc -n sources 2>/dev/null | awk ' + NR>2 && NF>=7 { + if ($(NF-3) != "0" && $(NF-3) != "") { found=1 } + } + END { exit (found?0:1) } + ' +} + +# ──────────────────────────────────────────────────────────────────────────────────────────── +# chrony_offset_exceeds_threshold: return 0 if |Last offset| > 1.0s +# ────────────────────────────────────────────────────────────────────────────────────────── +chrony_offset_exceeds_threshold() { + local offset + offset=$(chronyc tracking 2>/dev/null | awk -F: '/Last offset/ {print $2}' | awk '{print $1}') + [ -n "$offset" ] || return 1 + awk -v o="$offset" 'BEGIN { if (o<0) o=-o; exit (o>1.0?0:1) }' +} + +# ────────────────────────────────────────────────────────────────────────────────────────── +# chrony_fast_resync: on network reconnect (chronyd already running and a prior +# sync happened this boot), bring the clock up to date quickly without +# restarting chronyd. Uses chronyc control commands only. +# - Sources unreachable : online -> burst -> waitsync (bounded) -> makestep +# - Sources reachable : makestep only when |offset| > 1.0s +# ────────────────────────────────────────────────────────────────────────────────────────── +chrony_fast_resync() { + # Reconnect only: require chronyd running and a prior sync this boot + if ! pidof "$CHRONY_BIN" > /dev/null 2>&1; then + return 0 + fi + if [ ! -f "$NTP_SYNCED_FILE" ]; then + # First sync has not happened this boot — let the normal start path handle it + return 0 + fi + + if chrony_sources_reachable; then + # Sources already reachable — a recent measurement exists; step only if needed + if chrony_offset_exceeds_threshold; then + echo_t "SERVICE_CHRONYD : fast-resync — sources reachable, offset > 1.0s, stepping" >> $NTPD_LOG_NAME + chronyc makestep > /dev/null 2>&1 + else + echo_t "SERVICE_CHRONYD : fast-resync — sources reachable, offset <= 1.0s, no step" >> $NTPD_LOG_NAME + fi + return 0 + fi + + # Sources unreachable — re-acquire, force a fresh measurement, then step + echo_t "SERVICE_CHRONYD : fast-resync — sources unreachable, online+burst+waitsync" >> $NTPD_LOG_NAME + chronyc online > /dev/null 2>&1 + chronyc burst 4/4 > /dev/null 2>&1 + # Bounded wait: max 10 tries, no max-correction limit (0). Backgrounded so the + # sysevent dispatcher and lockfile are not held for the wait duration. + ( + if chronyc waitsync 10 0 > /dev/null 2>&1; then + echo_t "SERVICE_CHRONYD : fast-resync — waitsync succeeded, stepping" >> $NTPD_LOG_NAME + chronyc makestep > /dev/null 2>&1 + else + echo_t "SERVICE_CHRONYD : fast-resync — waitsync timed out, no step (chronyd continues)" >> $NTPD_LOG_NAME + fi + ) & +} + waitForConnChkFile() { echo_t "SERVICE_NTPD CONNCHK: Waiting for connection check for completion..." >> $NTPD_LOG_NAME @@ -257,9 +325,15 @@ case "$1" in ;; wan-status) if [ "started" = "$CURRENT_WAN_STATUS" ]; then - # service_start() already guards against duplicate instances via pidof - echo_t "SERVICE_CHRONYD : wan-status=started, calling service_start" >> $NTPD_LOG_NAME - service_start + if pidof "$CHRONY_BIN" > /dev/null 2>&1 && [ -f "$NTP_SYNCED_FILE" ]; then + # Reconnect after a prior sync — fast-resync without restarting chronyd + echo_t "SERVICE_CHRONYD : wan-status=started (reconnect), running fast-resync" >> $NTPD_LOG_NAME + chrony_fast_resync + else + # First sync this boot — service_start() guards against duplicate instances via pidof + echo_t "SERVICE_CHRONYD : wan-status=started, calling service_start" >> $NTPD_LOG_NAME + service_start + fi fi ;; *) From 81a918af1b4e8d46ed0c4ee75a95dbde4802ec77 Mon Sep 17 00:00:00 2001 From: sindhu-krishnan <102755514+sindhu-krishnan@users.noreply.github.com> Date: Mon, 27 Jul 2026 17:03:10 +0530 Subject: [PATCH 25/33] Update service_chronyd.sh --- source/scripts/init/service.d/service_chronyd.sh | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/source/scripts/init/service.d/service_chronyd.sh b/source/scripts/init/service.d/service_chronyd.sh index 59aa7219..a4e0ba09 100644 --- a/source/scripts/init/service.d/service_chronyd.sh +++ b/source/scripts/init/service.d/service_chronyd.sh @@ -95,11 +95,9 @@ set_chrony_sync_status() { # Reachability register (reach) is a non-zero octal value once a source has # answered at least one recent poll. # ────────────────────────────────────────────────────────────────────────────────────────── -chrony_sources_reachable() { +chrony_selectable_source_available() { chronyc -n sources 2>/dev/null | awk ' - NR>2 && NF>=7 { - if ($(NF-3) != "0" && $(NF-3) != "") { found=1 } - } + /^.[*+]/ { found=1 } END { exit (found?0:1) } ' } @@ -118,8 +116,8 @@ chrony_offset_exceeds_threshold() { # chrony_fast_resync: on network reconnect (chronyd already running and a prior # sync happened this boot), bring the clock up to date quickly without # restarting chronyd. Uses chronyc control commands only. -# - Sources unreachable : online -> burst -> waitsync (bounded) -> makestep -# - Sources reachable : makestep only when |offset| > 1.0s +# - No selectable source : online -> burst -> waitsync (bounded) -> makestep +# - Selectable source : makestep only when |offset| > 1.0s # ────────────────────────────────────────────────────────────────────────────────────────── chrony_fast_resync() { # Reconnect only: require chronyd running and a prior sync this boot @@ -131,13 +129,13 @@ chrony_fast_resync() { return 0 fi - if chrony_sources_reachable; then + if chrony_selectable_source_available; then # Sources already reachable — a recent measurement exists; step only if needed if chrony_offset_exceeds_threshold; then - echo_t "SERVICE_CHRONYD : fast-resync — sources reachable, offset > 1.0s, stepping" >> $NTPD_LOG_NAME + echo_t "SERVICE_CHRONYD : fast-resync — selectable sources, offset > 1.0s, stepping" >> $NTPD_LOG_NAME chronyc makestep > /dev/null 2>&1 else - echo_t "SERVICE_CHRONYD : fast-resync — sources reachable, offset <= 1.0s, no step" >> $NTPD_LOG_NAME + echo_t "SERVICE_CHRONYD : fast-resync — selectable sources, offset <= 1.0s, no step" >> $NTPD_LOG_NAME fi return 0 fi From 8775bb62b116bde17df460a59ccf5c7d55ad64ba Mon Sep 17 00:00:00 2001 From: sindhu-krishnan <102755514+sindhu-krishnan@users.noreply.github.com> Date: Mon, 27 Jul 2026 20:24:26 +0530 Subject: [PATCH 26/33] Update service_chronyd.sh --- .../scripts/init/service.d/service_chronyd.sh | 72 ------------------- 1 file changed, 72 deletions(-) diff --git a/source/scripts/init/service.d/service_chronyd.sh b/source/scripts/init/service.d/service_chronyd.sh index a4e0ba09..147055b5 100644 --- a/source/scripts/init/service.d/service_chronyd.sh +++ b/source/scripts/init/service.d/service_chronyd.sh @@ -90,72 +90,6 @@ set_chrony_sync_status() { exit 0 } -# ─────────────────────────────────────────────────────────────────────────────────────────── -# chrony_sources_reachable: return 0 if at least one chrony source is reachable -# Reachability register (reach) is a non-zero octal value once a source has -# answered at least one recent poll. -# ────────────────────────────────────────────────────────────────────────────────────────── -chrony_selectable_source_available() { - chronyc -n sources 2>/dev/null | awk ' - /^.[*+]/ { found=1 } - END { exit (found?0:1) } - ' -} - -# ──────────────────────────────────────────────────────────────────────────────────────────── -# chrony_offset_exceeds_threshold: return 0 if |Last offset| > 1.0s -# ────────────────────────────────────────────────────────────────────────────────────────── -chrony_offset_exceeds_threshold() { - local offset - offset=$(chronyc tracking 2>/dev/null | awk -F: '/Last offset/ {print $2}' | awk '{print $1}') - [ -n "$offset" ] || return 1 - awk -v o="$offset" 'BEGIN { if (o<0) o=-o; exit (o>1.0?0:1) }' -} - -# ────────────────────────────────────────────────────────────────────────────────────────── -# chrony_fast_resync: on network reconnect (chronyd already running and a prior -# sync happened this boot), bring the clock up to date quickly without -# restarting chronyd. Uses chronyc control commands only. -# - No selectable source : online -> burst -> waitsync (bounded) -> makestep -# - Selectable source : makestep only when |offset| > 1.0s -# ────────────────────────────────────────────────────────────────────────────────────────── -chrony_fast_resync() { - # Reconnect only: require chronyd running and a prior sync this boot - if ! pidof "$CHRONY_BIN" > /dev/null 2>&1; then - return 0 - fi - if [ ! -f "$NTP_SYNCED_FILE" ]; then - # First sync has not happened this boot — let the normal start path handle it - return 0 - fi - - if chrony_selectable_source_available; then - # Sources already reachable — a recent measurement exists; step only if needed - if chrony_offset_exceeds_threshold; then - echo_t "SERVICE_CHRONYD : fast-resync — selectable sources, offset > 1.0s, stepping" >> $NTPD_LOG_NAME - chronyc makestep > /dev/null 2>&1 - else - echo_t "SERVICE_CHRONYD : fast-resync — selectable sources, offset <= 1.0s, no step" >> $NTPD_LOG_NAME - fi - return 0 - fi - - # Sources unreachable — re-acquire, force a fresh measurement, then step - echo_t "SERVICE_CHRONYD : fast-resync — sources unreachable, online+burst+waitsync" >> $NTPD_LOG_NAME - chronyc online > /dev/null 2>&1 - chronyc burst 4/4 > /dev/null 2>&1 - # Bounded wait: max 10 tries, no max-correction limit (0). Backgrounded so the - # sysevent dispatcher and lockfile are not held for the wait duration. - ( - if chronyc waitsync 10 0 > /dev/null 2>&1; then - echo_t "SERVICE_CHRONYD : fast-resync — waitsync succeeded, stepping" >> $NTPD_LOG_NAME - chronyc makestep > /dev/null 2>&1 - else - echo_t "SERVICE_CHRONYD : fast-resync — waitsync timed out, no step (chronyd continues)" >> $NTPD_LOG_NAME - fi - ) & -} - waitForConnChkFile() { echo_t "SERVICE_NTPD CONNCHK: Waiting for connection check for completion..." >> $NTPD_LOG_NAME @@ -323,15 +257,9 @@ case "$1" in ;; wan-status) if [ "started" = "$CURRENT_WAN_STATUS" ]; then - if pidof "$CHRONY_BIN" > /dev/null 2>&1 && [ -f "$NTP_SYNCED_FILE" ]; then - # Reconnect after a prior sync — fast-resync without restarting chronyd - echo_t "SERVICE_CHRONYD : wan-status=started (reconnect), running fast-resync" >> $NTPD_LOG_NAME - chrony_fast_resync - else # First sync this boot — service_start() guards against duplicate instances via pidof echo_t "SERVICE_CHRONYD : wan-status=started, calling service_start" >> $NTPD_LOG_NAME service_start - fi fi ;; *) From d890634ed4fb418b834e0dd61bdfa83c8754114d Mon Sep 17 00:00:00 2001 From: sindhu-krishnan <102755514+sindhu-krishnan@users.noreply.github.com> Date: Mon, 27 Jul 2026 20:32:31 +0530 Subject: [PATCH 27/33] Update service_ntpd.sh --- source/scripts/init/service.d/service_ntpd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/scripts/init/service.d/service_ntpd.sh b/source/scripts/init/service.d/service_ntpd.sh index f511d860..3553e3ac 100644 --- a/source/scripts/init/service.d/service_ntpd.sh +++ b/source/scripts/init/service.d/service_ntpd.sh @@ -335,7 +335,7 @@ service_start () { if [ -f "$RFC_FLAG" ]; then echo_t "SERVICE_NTPD : RFC flag Present — chrony is the active NTP client" >> $NTPD_LOG_NAME - return 0 - TBD + return 0 fi local NTP_SERVER_URL_RESTORE="false" From 50effd3d3480851edc828d77e46609c7d8bff45a Mon Sep 17 00:00:00 2001 From: sindhu-krishnan <102755514+sindhu-krishnan@users.noreply.github.com> Date: Tue, 28 Jul 2026 11:24:14 +0530 Subject: [PATCH 28/33] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- source/scripts/init/service.d/service_chronyd.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/scripts/init/service.d/service_chronyd.sh b/source/scripts/init/service.d/service_chronyd.sh index 147055b5..9ee29631 100644 --- a/source/scripts/init/service.d/service_chronyd.sh +++ b/source/scripts/init/service.d/service_chronyd.sh @@ -92,18 +92,18 @@ set_chrony_sync_status() { waitForConnChkFile() { - echo_t "SERVICE_NTPD CONNCHK: Waiting for connection check for completion..." >> $NTPD_LOG_NAME + echo_t "SERVICE_CHRONYD CONNCHK: Waiting for connection check completion..." >> $NTPD_LOG_NAME TIMEOUT=120 INTERVAL=1 # Get system uptime in seconds at start START_TIME=$(cut -d. -f1 /proc/uptime) - echo_t "SERVICE_NTPD CONNCHK: Waiting for $CONNCHECK_FILE (max ${TIMEOUT}s)..." >> $NTPD_LOG_NAME + echo_t "SERVICE_CHRONYD CONNCHK: Waiting for $CONNCHECK_FILE (max ${TIMEOUT}s)..." >> $NTPD_LOG_NAME while true; do if [ -f "$CONNCHECK_FILE" ]; then - echo_t "SERVICE_NTPD CONNCHK: File $CONNCHECK_FILE present" >> $NTPD_LOG_NAME + echo_t "SERVICE_CHRONYD CONNCHK: File $CONNCHECK_FILE present" >> $NTPD_LOG_NAME return 0 fi From eed3766a5732a35c84a0a776c7ba9e02fe904f38 Mon Sep 17 00:00:00 2001 From: sindhu-krishnan <102755514+sindhu-krishnan@users.noreply.github.com> Date: Tue, 28 Jul 2026 11:26:21 +0530 Subject: [PATCH 29/33] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- source/scripts/init/service.d/service_ntpd.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/source/scripts/init/service.d/service_ntpd.sh b/source/scripts/init/service.d/service_ntpd.sh index 3553e3ac..a4b80052 100644 --- a/source/scripts/init/service.d/service_ntpd.sh +++ b/source/scripts/init/service.d/service_ntpd.sh @@ -335,7 +335,12 @@ service_start () { if [ -f "$RFC_FLAG" ]; then echo_t "SERVICE_NTPD : RFC flag Present — chrony is the active NTP client" >> $NTPD_LOG_NAME - return 0 + sysevent set ${SERVICE_NAME}-status "stopped" + if pidof "$BIN" > /dev/null 2>&1; then + echo_t "SERVICE_NTPD : stopping ntpd because chrony is enabled" >> $NTPD_LOG_NAME + service_stop + fi + return 0 fi local NTP_SERVER_URL_RESTORE="false" From 04bfd18ff134695154b5e3d581fc27ef061aea92 Mon Sep 17 00:00:00 2001 From: sindhu-krishnan <102755514+sindhu-krishnan@users.noreply.github.com> Date: Tue, 28 Jul 2026 12:43:51 +0530 Subject: [PATCH 30/33] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- source/scripts/init/service.d/service_chronyd.sh | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/source/scripts/init/service.d/service_chronyd.sh b/source/scripts/init/service.d/service_chronyd.sh index 9ee29631..bd93343f 100644 --- a/source/scripts/init/service.d/service_chronyd.sh +++ b/source/scripts/init/service.d/service_chronyd.sh @@ -175,15 +175,10 @@ service_start() { # Stop ntpd if running — mutual exclusivity with chrony if pidof ntpd > /dev/null 2>&1; then echo_t "SERVICE_CHRONYD : stopping ntpd for mutual exclusivity" >> $NTPD_LOG_NAME - systemctl stop ntpd + systemctl stop ntpd 2>/dev/null killall ntpd 2>/dev/null sleep 2 fi - local rc=$? - if [ "$rc" -ne 0 ]; then - sysevent set ${SERVICE_NAME}-status "error" - return 1 - fi # Start chronyd — only reaches here when no instance is running # start chronyd will populate the config based on latest RFC configuration From 0af217e7221295eb3b0001cbb8c9a2351c505000 Mon Sep 17 00:00:00 2001 From: sindhu-krishnan <102755514+sindhu-krishnan@users.noreply.github.com> Date: Wed, 29 Jul 2026 17:36:02 +0530 Subject: [PATCH 31/33] Update service_chronyd.sh --- .../scripts/init/service.d/service_chronyd.sh | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/source/scripts/init/service.d/service_chronyd.sh b/source/scripts/init/service.d/service_chronyd.sh index bd93343f..3bcc3684 100644 --- a/source/scripts/init/service.d/service_chronyd.sh +++ b/source/scripts/init/service.d/service_chronyd.sh @@ -135,7 +135,7 @@ service_start() { # Exclude XLE device from connectivity check. TODO if [ "$BOX_TYPE" != "WNXL11BWL" ];then echo_t "SERVICE_NTPD CONNCHK: start connectivity check waiting for $CONNCHECK_FILE file" >> $NTPD_LOG_NAME - #waitForConnChkFile + waitForConnChkFile fi fi @@ -154,24 +154,14 @@ service_start() { syscfg set ntp_status 2 sysevent set ${SERVICE_NAME}-status "starting" - # WAN check - if [ "$BOX_TYPE" = "HUB4" ] || [ "$BOX_TYPE" = "SR300" ] || \ - [ "$BOX_TYPE" = "SE501" ] || [ "$BOX_TYPE" = "WNXL11BWL" ] || \ - [ "$BOX_TYPE" = "SR213" ] || [ "$LANIPV6Support" = "true" ]; then - WAN_IPV6_STATUS=$(sysevent get ipv6_connection_state) - if [ "started" != "$CURRENT_WAN_STATUS" ] && [ "up" != "$WAN_IPV6_STATUS" ]; then + + if [ "started" != "$CURRENT_WAN_STATUS" ]; then syscfg set ntp_status 2 sysevent set ${SERVICE_NAME}-status "wan-down" return 0 - fi - else - if [ "started" != "$CURRENT_WAN_STATUS" ]; then - syscfg set ntp_status 2 - sysevent set ${SERVICE_NAME}-status "wan-down" - return 0 - fi fi + # Stop ntpd if running — mutual exclusivity with chrony if pidof ntpd > /dev/null 2>&1; then echo_t "SERVICE_CHRONYD : stopping ntpd for mutual exclusivity" >> $NTPD_LOG_NAME From 18ef224cb5d5fc81139f4d19dba6b6b8f49edfd3 Mon Sep 17 00:00:00 2001 From: sindhu-krishnan <102755514+sindhu-krishnan@users.noreply.github.com> Date: Wed, 29 Jul 2026 17:37:16 +0530 Subject: [PATCH 32/33] Update service_chronyd.sh --- source/scripts/init/service.d/service_chronyd.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/scripts/init/service.d/service_chronyd.sh b/source/scripts/init/service.d/service_chronyd.sh index 3bcc3684..58a503a0 100644 --- a/source/scripts/init/service.d/service_chronyd.sh +++ b/source/scripts/init/service.d/service_chronyd.sh @@ -99,11 +99,11 @@ waitForConnChkFile() # Get system uptime in seconds at start START_TIME=$(cut -d. -f1 /proc/uptime) - echo_t "SERVICE_CHRONYD CONNCHK: Waiting for $CONNCHECK_FILE (max ${TIMEOUT}s)..." >> $NTPD_LOG_NAME + echo_t "SERVICE_CHRONYD : Waiting for $CONNCHECK_FILE (max ${TIMEOUT}s)..." >> $NTPD_LOG_NAME while true; do if [ -f "$CONNCHECK_FILE" ]; then - echo_t "SERVICE_CHRONYD CONNCHK: File $CONNCHECK_FILE present" >> $NTPD_LOG_NAME + echo_t "SERVICE_CHRONYD : File $CONNCHECK_FILE present" >> $NTPD_LOG_NAME return 0 fi @@ -111,7 +111,7 @@ waitForConnChkFile() ELAPSED=$((CURRENT_TIME - START_TIME)) if [ "$ELAPSED" -ge "$TIMEOUT" ]; then - echo_t "SERVICE_NTPD CONNCHK: Timeout ${TIMEOUT}s expired - file $CONNCHECK_FILE not found" >> $NTPD_LOG_NAME + echo_t "SERVICE_CHRONYD : Timeout ${TIMEOUT}s expired - file $CONNCHECK_FILE not found" >> $NTPD_LOG_NAME return 1 fi @@ -130,11 +130,11 @@ service_start() { # Wait for connectivitycheck to complete if [ -f $CONNCHECK_FILE ]; then - echo_t "SERVICE_NTPD CONNCHK: connectivity success $CONNCHECK_FILE present" >> $NTPD_LOG_NAME + echo_t "SERVICE_CHRONYD : connectivity success $CONNCHECK_FILE present" >> $NTPD_LOG_NAME else # Exclude XLE device from connectivity check. TODO if [ "$BOX_TYPE" != "WNXL11BWL" ];then - echo_t "SERVICE_NTPD CONNCHK: start connectivity check waiting for $CONNCHECK_FILE file" >> $NTPD_LOG_NAME + echo_t "SERVICE_CHRONYD : start connectivity check waiting for $CONNCHECK_FILE file" >> $NTPD_LOG_NAME waitForConnChkFile fi fi From 36b6931364813ef6053b37ef105e9061699c394d Mon Sep 17 00:00:00 2001 From: sindhu-krishnan <102755514+sindhu-krishnan@users.noreply.github.com> Date: Tue, 4 Aug 2026 15:11:21 +0530 Subject: [PATCH 33/33] Update service_chronyd.sh --- source/scripts/init/service.d/service_chronyd.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/source/scripts/init/service.d/service_chronyd.sh b/source/scripts/init/service.d/service_chronyd.sh index 58a503a0..95c5327b 100644 --- a/source/scripts/init/service.d/service_chronyd.sh +++ b/source/scripts/init/service.d/service_chronyd.sh @@ -49,11 +49,10 @@ CURRENT_WAN_STATUS=$(sysevent get wan-status) WAN_INTERFACE=$(getWanInterfaceName) # ────────────────────────────────────────────────────────────────────────────── -# service_init: load syscfg NTP server values into environment +# service_init: load syscfg ntp_enabled into environment # ────────────────────────────────────────────────────────────────────────────── service_init() { - FOO=$(utctx_cmd get ntp_server1 ntp_server2 ntp_server3 ntp_server4 ntp_server5 \ - ntp_enabled new_ntp_enabled) + FOO=$(utctx_cmd get ntp_enabled) eval "$FOO" }