Add Config -> Sync net time manual trigger
The reflashed image starts chronyd at ~27 s, before NetworkManager installs a usable resolv.conf, so pool.ntp.org stays unresolved and minpoll 12 would wait up to 4096 s. Wi-Fi came up at ~30 s but the clock was only stepped at ~112 s, when usb0 emitted another dispatcher event. - Config -> Sync net time in the built-in dmenu Config menu runs bananarchy-sync-net-time.sh, forces a burst via bananarchy-time-sync.sh sync and shows a desktop notification with the UTC date or a failure. - New sync mode reports success/failure and exit status; resolved() now requires at least one known source, DNS waits run before the flock, and network-up/force/sync get 8 retries so a slow boot retry cannot swallow network-up events. - Rebuilt dmenu.so from src/sxmo-dmenu/dmenu.c into prebuilt/ and overlay/; apply-bananarchy-overlay.sh keeps the wrapper root-owned and executable; check-rebuild.sh guards the menu entry, wrapper and sync mode. - Rebuilt and verified images/bananarchy-nokia-argon.img (all new files byte-identical to overlay, boot.img unchanged, 27 initramfs modules). Live verification on the reflashed phone: helper sync as the X session user prints "Network time synced: 2026-11-07 20:17:43 UTC", the wrapper posts a notification, a DNS-down sync fails clearly after 16 s, restoring DNS syncs again, and the rebuilt dmenu daemon was reloaded with the new Config item.
This commit is contained in:
1 parent
9ac39ce6bf
commit
85c6a7b886
12 files changed
+177
-16
No files matched your search
+23
@@ -0,0 +1,23 @@
|
||||
#!/bin/sh
|
||||
# Config -> Sync net time: force an immediate NTP sync and show the outcome.
|
||||
# Runs as the X session user; bananarchy-time-sync.sh escalates via doas.
|
||||
set -u
|
||||
|
||||
result="$(/usr/bin/bananarchy-time-sync.sh sync 2>&1)"
|
||||
[ -n "$result" ] || result="No response from chronyd"
|
||||
|
||||
case "$result" in
|
||||
"Network time synced"*)
|
||||
urgency=normal
|
||||
;;
|
||||
*)
|
||||
urgency=critical
|
||||
;;
|
||||
esac
|
||||
|
||||
if command -v notify-send >/dev/null 2>&1; then
|
||||
notify-send --urgency="$urgency" --expire-time=8000 \
|
||||
"Sync net time" "$result" >/dev/null 2>&1 || true
|
||||
else
|
||||
sxmo_notify_user.sh "Sync net time: $result" >/dev/null 2>&1 || true
|
||||
fi
|
||||
@@ -23,6 +23,12 @@ LOCK="$RUNDIR/lock"
|
||||
TRIGGER_MIN=15
|
||||
REFRESH_MIN=300
|
||||
WAIT_MAX=30
|
||||
# NetworkManager emits several up/dns events per connection. DNS resolution
|
||||
# runs before the lock is taken, so a slow boot retry cannot swallow the
|
||||
# network-up event that would otherwise sync the clock immediately.
|
||||
ATTEMPTS=8
|
||||
BOOT_ATTEMPTS=30
|
||||
SYNC_WAIT=15
|
||||
|
||||
if [ "$(id -u)" != "0" ]; then
|
||||
exec doas -n "$0" "$@"
|
||||
@@ -53,9 +59,16 @@ wait_chronyd() {
|
||||
}
|
||||
|
||||
# chronyc activity reports how many configured sources still have no address.
|
||||
# A freshly started chronyd can also report zero sources of any kind while the
|
||||
# pool name is unresolved, so require at least one known source as well.
|
||||
resolved() {
|
||||
"$CHRONYC" -h "$SOCKET" activity 2>/dev/null |
|
||||
grep -q '^0 sources with unknown address$'
|
||||
"$CHRONYC" -h "$SOCKET" activity 2>/dev/null | awk '
|
||||
/^[0-9]+ sources online$/ { on = $1 }
|
||||
/^[0-9]+ sources offline$/ { off = $1 }
|
||||
/^[0-9]+ sources doing burst/ { burst += $1 }
|
||||
/^[0-9]+ sources with unknown address$/ { unknown = $1 }
|
||||
END { exit !(unknown + 0 == 0 && on + off + burst + 0 > 0) }
|
||||
'
|
||||
}
|
||||
|
||||
synced() {
|
||||
@@ -81,26 +94,26 @@ wait_sources() {
|
||||
|
||||
trigger() {
|
||||
mode="${1:-network-up}"
|
||||
attempts=3
|
||||
[ "$mode" = "boot" ] && attempts=30
|
||||
mkdir -p "$RUNDIR" 2>/dev/null || return 1
|
||||
# NetworkManager emits several up/dns events per connection; serialise them
|
||||
# so only one helper refreshes and bursts at a time.
|
||||
exec 9>"$LOCK" || return 1
|
||||
flock -n 9 || return 0
|
||||
attempts="$ATTEMPTS"
|
||||
[ "$mode" = "boot" ] && attempts="$BOOT_ATTEMPTS"
|
||||
wait_chronyd || {
|
||||
log "chronyd command socket not available"
|
||||
return 1
|
||||
}
|
||||
if ! wait_sources "$attempts"; then
|
||||
log "NTP pool names did not resolve yet"
|
||||
return 0
|
||||
return 1
|
||||
fi
|
||||
mkdir -p "$RUNDIR" 2>/dev/null || return 1
|
||||
# Only the stamp/burst section is serialised: NetworkManager emits several
|
||||
# up/dns events per connection and a long DNS wait must not block them.
|
||||
exec 9>"$LOCK" || return 1
|
||||
flock -w 5 9 || return 1
|
||||
now="$(monotonic)"
|
||||
last=0
|
||||
[ -r "$STAMP" ] && last="$(cat "$STAMP" 2>/dev/null || echo 0)"
|
||||
case "$last" in ''|*[!0-9]*) last=0 ;; esac
|
||||
if [ "$mode" != "force" ]; then
|
||||
if [ "$mode" != "force" ] && [ "$mode" != "sync" ]; then
|
||||
if synced; then
|
||||
[ "$((now - last))" -lt "$REFRESH_MIN" ] && return 0
|
||||
else
|
||||
@@ -109,12 +122,31 @@ trigger() {
|
||||
fi
|
||||
printf '%s\n' "$now" > "$STAMP" || return 1
|
||||
chronyc_cmd online
|
||||
if ! synced || [ "$mode" = "force" ]; then
|
||||
if ! synced || [ "$mode" = "force" ] || [ "$mode" = "sync" ]; then
|
||||
chronyc_cmd burst 2/4 || log "chronyc burst failed"
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# Config -> Sync net time: force a burst and report when the clock is set.
|
||||
sync_now() {
|
||||
if ! trigger sync; then
|
||||
echo "Network time unavailable: chronyd or DNS is not ready"
|
||||
return 1
|
||||
fi
|
||||
i=0
|
||||
while [ "$i" -lt "$SYNC_WAIT" ]; do
|
||||
if synced; then
|
||||
printf 'Network time synced: %s\n' "$(date -u '+%Y-%m-%d %H:%M:%S UTC')"
|
||||
return 0
|
||||
fi
|
||||
sleep 1
|
||||
i=$((i + 1))
|
||||
done
|
||||
echo "Network time not confirmed yet; retry when the network is up"
|
||||
return 1
|
||||
}
|
||||
|
||||
case "${1:-status}" in
|
||||
boot|network-up)
|
||||
trigger "$1"
|
||||
@@ -122,6 +154,10 @@ case "${1:-status}" in
|
||||
force)
|
||||
trigger force
|
||||
;;
|
||||
sync)
|
||||
sync_now
|
||||
exit $?
|
||||
;;
|
||||
status)
|
||||
if [ ! -S "$SOCKET" ]; then
|
||||
echo "chronyd command socket absent"
|
||||
@@ -131,7 +167,7 @@ case "${1:-status}" in
|
||||
"$CHRONYC" -h "$SOCKET" sources
|
||||
;;
|
||||
*)
|
||||
echo "usage: $0 boot|network-up|force|status" >&2
|
||||
echo "usage: $0 boot|network-up|force|sync|status" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
|
||||
Reference in new issue
Block a user