From 16e96969c526a387985f833c9f6e8ac940c59516 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Wed, 11 Oct 2023 20:17:15 +0200 Subject: [PATCH] TimeSync: Double-check that ntpd is busybox (#10992) Kindle ships another implementation, with incompatible syntax... Regression since #10935 Thanks to @yparitcher ;). --- plugins/timesync.koplugin/main.lua | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/plugins/timesync.koplugin/main.lua b/plugins/timesync.koplugin/main.lua index ec972fdc7..f1d2006f9 100644 --- a/plugins/timesync.koplugin/main.lua +++ b/plugins/timesync.koplugin/main.lua @@ -12,8 +12,18 @@ end local ntp_cmd -- Check if we have access to ntpd or ntpdate if os.execute("command -v ntpd >/dev/null") == 0 then - ntp_cmd = "ntpd -q -n -p pool.ntp.org" -elseif os.execute("command -v ntpdate >/dev/null") == 0 then + -- Make sure it's actually busybox's implementation, as the syntax may otherwise differ... + -- (Of particular note, Kobo ships busybox ntpd, but not ntpdate; and Kindle ships ntpdate and !busybox ntpd). + local path = os.getenv("PATH") or "" + for p in path:gmatch("([^:]+)") do + local sym = lfs.symlinkattributes(p .. "/ntpd") + if sym and sym.mode == "link" and string.sub(sym.target, -7) == "busybox" then + ntp_cmd = "ntpd -q -n -p pool.ntp.org" + break + end + end +end +if not ntp_cmd and os.execute("command -v ntpdate >/dev/null") == 0 then ntp_cmd = "ntpdate pool.ntp.org" end if not ntp_cmd then