Hi,

A colleague of mine noticed that after a recent toybox update hwclock
now expects /etc/adjtime to be present. Previously it used to assume
UTC if /etc/adjtime is not present which is consistent with
util-linux.

I've attached patches which address this issue in hwclock and rtcwake.

Regards,

Patrick
From 963385ca53af701c20ec6b63312b96dfba917f18 Mon Sep 17 00:00:00 2001
From: Patrick Oppenlander <patrick.oppenlan...@gmail.com>
Date: Thu, 15 Oct 2020 12:51:10 +1100
Subject: [PATCH 2/2] rtcwake: default to UTC if /etc/adjtime can't be read

This is consistent with the util-linux implementation.
---
 toys/other/rtcwake.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/toys/other/rtcwake.c b/toys/other/rtcwake.c
index 161bd881..a382ee57 100644
--- a/toys/other/rtcwake.c
+++ b/toys/other/rtcwake.c
@@ -55,7 +55,7 @@ void rtcwake_main(void)
 
   if (FLAG(u)) utc = 1;
   else if (FLAG(l)) utc = 0;
-  else utc = !!strstr(xreadfile("/etc/adjtime", toybuf, 2048), "UTC");
+  else utc = !readfile("/etc/adjtime", toybuf, 2048) || !!strstr(toybuf, "UTC");
   if (FLAG(v)) xprintf("RTC time: %s\n", utc ? "UTC" : "local");
 
   if (!TT.d) TT.d = "/dev/rtc0";
-- 
2.28.0

From 85cf3b20e9706be219f0280bc40aa0da17a860e6 Mon Sep 17 00:00:00 2001
From: Patrick Oppenlander <patrick.oppenlan...@gmail.com>
Date: Thu, 15 Oct 2020 12:50:40 +1100
Subject: [PATCH 1/2] hwclock: default to UTC if /etc/adjtime can't be read

This is consistent with the util-linux implementation.
---
 toys/other/hwclock.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/toys/other/hwclock.c b/toys/other/hwclock.c
index ba28cc3d..a6db923a 100644
--- a/toys/other/hwclock.c
+++ b/toys/other/hwclock.c
@@ -40,10 +40,8 @@ void hwclock_main()
 
   if (FLAG(u)) utc = 1;
   else if (FLAG(l)) utc = 0;
-  else {
-    xreadfile("/etc/adjtime", toybuf, sizeof(toybuf));
-    utc = !!strstr(toybuf, "UTC");
-  }
+  else utc = !readfile("/etc/adjtime", toybuf, sizeof(toybuf)) ||
+    !!strstr(toybuf, "UTC");
 
   if (!FLAG(t)) {
     if (!TT.f) TT.f = "/dev/rtc0";
-- 
2.28.0

_______________________________________________
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to