public inbox for gentoo-embedded@lists.gentoo.org
 help / color / mirror / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download: 
* [gentoo-embedded] sysvinit: sanetime for boards without an rtc?
@ 2011-07-23 17:10 99% Christopher Friedt
  0 siblings, 0 replies; 1+ results
From: Christopher Friedt @ 2011-07-23 17:10 UTC (permalink / raw
  To: gentoo-embedded

[-- Attachment #1: Type: text/plain, Size: 1580 bytes --]

Hi folks,

I have a couple of boards that ship by default without RTC devices and
boot time always incurs the following nasty messages in multiplicity.

...
 * One of the files in /etc/{conf.d,init.d} or /etc/rc.conf
 * has a modification time in the future!
 * One of the files in /etc/{conf.d,init.d} or /etc/rc.conf
 * has a modification time in the future!
...

A very simple solution was be to maintain an /etc/sanetime file that
would set a time other than the epoch at boot. Something within the
last day, month, year, or decade even ;-)

There's a fallback sanetime in /etc/init.d/sanetime just in case
/etc/sanetime doesn't exist, and it works naturally because time is
monotonically increasing (last I checked).

Also, it would seem that /etc/clock doesn't fail gracefully when there
is no rtc, even when there are provisions to 'fakeit' for other
reasons.

...
 * Cannot access the Hardware Clock via any known method.
Use the --debug option to see the details of our search for an access method.Can
not access the Hardware Clock via any known method.
Use the --debug option to see the details of our search for an access method.
 * Failed to set clock You will need to set the clock yourself

   [ !! ]
...

It was just a matter of adding an /etc/init.d/sanetime script,
slightly patching /etc/init.d/clock & /sbin/rc (AFAIK this only works
for sysvinit, not openrc).

See the attached files.

Cheers,

C

PS: I was going to file a bug report, but it seems that the
certificate for bugs.gentoo.org has become invalid ATM.

[-- Attachment #2: add-sanetime-to-sbin-rc.patch --]
[-- Type: application/octet-stream, Size: 385 bytes --]

--- /sbin/rc_orig	2011-07-23 12:52:40.908885277 -0400
+++ /sbin/rc	2011-07-23 12:52:51.276070368 -0400
@@ -166,7 +166,7 @@
 			CRITICAL_SERVICES="${CRITICAL_SERVICES} ${x##*/}"
 		done
 	else
-		CRITICAL_SERVICES="checkroot modules checkfs localmount clock bootmisc"
+		CRITICAL_SERVICES="checkroot modules checkfs localmount sanetime clock bootmisc"
 	fi
 
 	export CRITICAL_SERVICES

[-- Attachment #3: add-sanetime-to-etc-init.d-clock.patch --]
[-- Type: application/octet-stream, Size: 548 bytes --]

--- /etc/init.d/clock_orig	2011-07-23 12:58:07.447945952 -0400
+++ /etc/init.d/clock	2011-07-23 12:59:29.072944745 -0400
@@ -5,7 +5,7 @@
 opts="save"
 
 depend() {
-	need localmount
+	need sanetime localmount
 }
 
 setupopts() {
@@ -79,7 +79,8 @@
 	setupopts
 
 	if [[ ${fakeit} -ne 1 && -e /proc/modules && ! -e /dev/rtc ]] ; then
-		modprobe rtc &> /dev/null || modprobe genrtc &> /dev/null
+		modprobe rtc &> /dev/null || modprobe genrtc &> /dev/null \
+			|| fakeit=1
 	fi
 
 	ebegin "Setting system clock using the hardware clock [${TBLURB}]"

[-- Attachment #4: sanetime --]
[-- Type: application/octet-stream, Size: 878 bytes --]

#!/sbin/runscript
# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

# get this number with 'date +%s' - it's just a fallback sanetime
# but really anything is better than the epoch
SANETIME="1310410279"
SANETIME_FILE=/etc/sanetime

depend() {
	need localmount
}

write_sanetime() {
	mkdir -p $(dirname $SANETIME_FILE)
	echo "$1" > $SANETIME_FILE
}

dofunc() {
	local Now Then
	Now="$(date +%s 2>&1)"
	if [ -e $SANETIME_FILE ]; then
		Then="$(cat $SANETIME_FILE)"
	else
		Then=$SANETIME
	fi
	if [ $Now -gt $Then ]; then
		write_sanetime $Now
	else
		write_sanetime $Then
		date -s @$Then >/dev/null 2>&1
	fi
}

start() {
	ebegin "Initializing sanetime"
	(
		dofunc start
	)
	eend $? "Error initializing sanetime"
}

stop() {
	ebegin "Saving sanetime"
	(
		dofunc stop
	)
	eend $? "Failed to save sanetime"
}


# vim:ts=4

^ permalink raw reply	[relevance 99%]

Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2011-07-23 17:10 99% [gentoo-embedded] sysvinit: sanetime for boards without an rtc? Christopher Friedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox