diff mbox

[OpenWrt-Devel,v3] base-files: For sysfixtime use hwclock if RTC available

Message ID 1453365593-4098-1-git-send-email-ynezz@true.cz
State Superseded
Headers show

Commit Message

Petr Štetiar Jan. 21, 2016, 8:39 a.m. UTC
From: Daniel Dickinson <openwrt@daniel.thecshore.com>

On systems that have an RTC prefer it to the file-based time fixup (i.e.
use hwclock when there is a permanent clock instead of the faked up time
logic that is needed when there is not RTC).

We can't rely on hctosys kernel feature either as we're usually using
RTC as kernel modules which are usually being loaded after hctosys was
run, leading in the following error:

  hctosys: unable to open rtc device (rtc0)

Signed-off-by: Daniel Dickinson <openwrt@daniel.thecshore.com>
Signed-off-by: Petr Štetiar <ynezz@true.cz>
---

Changes in v3:
 * uppercased global variables

 package/base-files/files/etc/init.d/sysfixtime |   15 +++++++++++++++
 1 file changed, 15 insertions(+)

Comments

Bastian Bittorf Jan. 21, 2016, 11:53 a.m. UTC | #1
* Petr Štetiar <ynezz@true.cz> [21.01.2016 12:22]:
>  boot() {
> +	[ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ] && $HWCLOCK -s -f $RTC_DEV && exit 0

thank you! can you please do in this line a:
&& return

and introduce a helper (maybe overengineered 8-)

deps_ok() {
	[ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ]
}

bye, bastian
John Crispin Jan. 21, 2016, 12:03 p.m. UTC | #2
On 21/01/2016 12:53, Bastian Bittorf wrote:
> * Petr Štetiar <ynezz@true.cz> [21.01.2016 12:22]:
>>  boot() {
>> +	[ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ] && $HWCLOCK -s -f $RTC_DEV && exit 0
> 
> thank you! can you please do in this line a:
> && return
> 
> and introduce a helper (maybe overengineered 8-)
> 
> deps_ok() {
> 	[ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ]
> }
> 
> bye, bastian

hang on there, this looks like bastel basti scriptowahn
Bastian Bittorf Jan. 21, 2016, 12:31 p.m. UTC | #3
* John Crispin <blogic@openwrt.org> [21.01.2016 13:30]:
> hang on there, this looks like bastel basti scriptowahn

8-) but the 'exit VS. return' is valid...

bye, bastian
Petr Štetiar Jan. 26, 2016, 8:35 p.m. UTC | #4
Bastian Bittorf <bittorf@bluebottle.com> [2016-01-21 12:53:48]:

> * Petr Štetiar <ynezz@true.cz> [21.01.2016 12:22]:
> >  boot() {
> > +	[ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ] && $HWCLOCK -s -f $RTC_DEV && exit 0
> 
> thank you! can you please do in this line a:
> && return

Like following?

	deps_ok && $HWCLOCK -s -f $RTC_DEV && exit 0 && return 

Is it really needed? I've always thought, that exit will terminate the script
so the return wouldn't be called anyway.

> and introduce a helper (maybe overengineered 8-)

Kind of, was thinking about it also so I'll change it, thanks.

> deps_ok() {
> 	[ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ]
> }

-- ynezz
John Crispin Jan. 27, 2016, 7:05 a.m. UTC | #5
On 26/01/2016 21:35, Petr Štetiar wrote:
> Bastian Bittorf <bittorf@bluebottle.com> [2016-01-21 12:53:48]:
> 
>> * Petr Štetiar <ynezz@true.cz> [21.01.2016 12:22]:
>>>  boot() {
>>> +	[ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ] && $HWCLOCK -s -f $RTC_DEV && exit 0
>>
>> thank you! can you please do in this line a:
>> && return
> 
> Like following?
> 
> 	deps_ok && $HWCLOCK -s -f $RTC_DEV && exit 0 && return 
> 
> Is it really needed? I've always thought, that exit will terminate the script
> so the return wouldn't be called anyway.
> 
>> and introduce a helper (maybe overengineered 8-)
> 
> Kind of, was thinking about it also so I'll change it, thanks.
> 
>> deps_ok() {
>> 	[ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ]
>> }
> 
> -- ynezz

please don't add a helper. instead just call start from boot, honour its
return code and then decide if you want to run the exising code.

	John

> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel@lists.openwrt.org
> https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
>
Bastian Bittorf Jan. 28, 2016, 11:15 a.m. UTC | #6
* Petr Štetiar <ynezz@true.cz> [28.01.2016 11:06]:
> Like following?
> 
> 	deps_ok && $HWCLOCK -s -f $RTC_DEV && exit 0 && return 

just:
deps_ok && $HWCLOCK -s -f $RTC_DEV && return

bye, bastian
diff mbox

Patch

diff --git a/package/base-files/files/etc/init.d/sysfixtime b/package/base-files/files/etc/init.d/sysfixtime
index 4010e06..83e9ee4 100755
--- a/package/base-files/files/etc/init.d/sysfixtime
+++ b/package/base-files/files/etc/init.d/sysfixtime
@@ -2,10 +2,25 @@ 
 # Copyright (C) 2013-2014 OpenWrt.org
 
 START=00
+STOP=90
+
+RTC_DEV=/dev/rtc0
+HWCLOCK=/sbin/hwclock
 
 boot() {
+	[ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ] && $HWCLOCK -s -f $RTC_DEV && exit 0
+
 	local curtime="$(date +%s)"
 	local maxtime="$(find /etc -type f -exec date -r {} +%s \; | sort -nr | head -n1)"
 	[ $curtime -lt $maxtime ] && date -s @$maxtime
 }
 
+start() {
+	[ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ] && $HWCLOCK -s -f $RTC_DEV
+}
+
+stop() {
+	[ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ] && \
+		$HWCLOCK -w -f $RTC_DEV && \
+		logger -t sysfixtime "saved '$(date)' to $RTC_DEV"
+}