Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 272073 - simple swclock init.d script to save/restore time in place of broken hwclock
Summary: simple swclock init.d script to save/restore time in place of broken hwclock
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] baselayout (show other bugs)
Hardware: All Linux
: High enhancement (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-06-01 11:21 UTC by michael@smith-li.com
Modified: 2009-10-13 20:16 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
setsystimefromfile.c (setsystimefromfile.c,422 bytes, text/plain)
2009-06-01 11:21 UTC, michael@smith-li.com
Details
clock.init_settimefromfile.patch (clock.init_settimefromfile.patch,1.72 KB, patch)
2009-06-01 11:23 UTC, michael@smith-li.com
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description michael@smith-li.com 2009-06-01 11:21:01 UTC
For machines with broken rtcs and dead mobo batteries booting is a chore -- if the clock appears to be set to a ridiculous time, (in my case, 1988), it results in lots of filesystem checks and superfluous warnings.

This set of tweaks for both baselayout 1 and 2 writes to a file called /etc/SHUTDOWNTIME at /etc/init.d/(hw)clock stop time, and then on reboot uses that file's mtime to set the system time, bypassing the broken hwclock.

This tool should work for both openrc and bl1. I haven't quite worked out all the kinks, but here it is for now...

Reproducible: Always

Steps to Reproduce:
Comment 1 michael@smith-li.com 2009-06-01 11:21:45 UTC
Created attachment 193125 [details]
setsystimefromfile.c

This is the core program -- it just grabs the mtime of /etc/SHUTDOWNTIME
Comment 2 michael@smith-li.com 2009-06-01 11:23:19 UTC
Created attachment 193126 [details, diff]
clock.init_settimefromfile.patch

This is a patch for bl1's clock initscript. It should be set to run before * to prevent unnecessary fscks, but so far I can't get the rc dependency resolution to do that. Still working on it...
Comment 3 michael@smith-li.com 2009-06-01 11:25:17 UTC
/etc/conf.d/clock just needs an additional line added to turn the other two programs on:

# If your Hardware Clock resets during reboots
# set this to "yes" to use the mtime of a file
# to set your System Clock and prevent warnings.
# (It will cause CLOCK_SYSTOHC to be ignored.)
SETTIMEFROMFILE="yes"

(Oh, and finally, I forgot to mention I put the compiled C program in /sbin/settimefromfile. Obviously, if you change that you'd have to change the initscript to suit.)
Comment 4 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2009-06-01 17:06:39 UTC
kojiro:
For bl2, as I described, make an init script using hwclock as a template, but give it a new name.
Comment 5 SpanKY gentoo-dev 2009-06-01 22:45:01 UTC
yes, please create a new init.d script (i'd suggest "swclock") that only operates on this file and use /var/lib/swclock as the default location
Comment 6 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2009-06-01 23:50:17 UTC
vapier: I was suggesting /.clock or something in /etc/ as /var might not be available.
Comment 7 michael@smith-li.com 2009-06-02 11:13:50 UTC
hmm, is it safe for the default location to be in /var? FHS aside, this should run before localmount (or its openrc equivalent, if different), so /var might not be available, right? That's why I chose /etc...
Comment 8 SpanKY gentoo-dev 2009-06-02 19:27:42 UTC
/var/lib/ makes more sense, but it has the problems you guys highlight.  so a default path of /etc/ is fine.
Comment 9 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2009-09-14 09:40:08 UTC
Michael A. Smith:
Did you implement this as a new swclock package?
Comment 10 Roy Marples 2009-10-11 15:37:04 UTC
I can roll this directly into OpenRC and store the file in the same place as the depcache if there's any interest.
Comment 11 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2009-10-11 16:51:28 UTC
roy: yes please, there's a bunch of embedded gear coming up without RTC chips where it would be really handy.

(re)boot with stored timestamp, then hit NTP as soon as possible.

should prevent the backwards time "jump" appearance.
Comment 12 Roy Marples 2009-10-13 07:12:03 UTC
http://roy.marples.name/projects/openrc/changeset/a8f6a9b6540ca301af625b4767df53860511a6dc

It's up to the user to remove hwclock and add swclock to the runlevel of choice - maybe even to the sysinit runlevel?
Comment 13 SpanKY gentoo-dev 2009-10-13 07:22:21 UTC
forcing users to change the init scripts is fine by me
Comment 14 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2009-10-13 19:58:12 UTC
roy:
why did you drop 'provide clock' from swclock compared to hwclock.in?
I'm fine with making user add it to the sysinit runlevel themselves.
Comment 15 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2009-10-13 19:58:51 UTC
Reopening because 'provide clock' is critical so that scripts with 'need clock' are happy and don't try to start hwclock.
Comment 16 Roy Marples 2009-10-13 20:07:18 UTC
(In reply to comment #14)
> roy:
> why did you drop 'provide clock' from swclock compared to hwclock.in?
> I'm fine with making user add it to the sysinit runlevel themselves.

Honest answer - I cut one line too many!
It's been added back now.
Comment 17 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2009-10-13 20:16:16 UTC
Thanks, closing (and looking forward to this in the next release for some embedded hardware myself).