settimeofday() & reboot or power cycle

Bill Campbell linux-sxs
Wed Jan 17 13:46:28 PST 2007


On Wed, Jan 17, 2007, Susan Macchia wrote:
>Hi List,

>I have a conundrum I am trying to figure out.  I have a Mandriva 2006
>system.  The kernel is 2.6.12-12mdksmp.

>I have a process that runs (as root) that calls settimeofday().  The time
>is changed and reflected in the UI.  The problem is this:

>When the system is shutdown and restared cleanly the change in time/date
>sticks.  If instead the power cycle button is pressed (causing an "unclean"
>shutdown), the time/date DOESN'T stick (and this is the bug).  I tried
>waiting for 1/2-1 hour, executing the sync command and the time still
>doesn't stick.

>I also tested this out with the "date" command (independent of my
>application) and saw the same phenomenon.

>Does anyone know if there is a known bug in the kernel?  Does anyone know
>if there is a patch or work-around?  Iv'e scoured the kernel.org archives
>and googled, but haven' found much.

My guess is that the normal shutdown procedure does something
like ``hwclock -u -w'' to save the current time to the hardware
clock.  Of course this won't happen in the case of a catastrophic
shutdown (although I think that there are ways to trap the power
switch events interacting with the BIOS so that one might go into
a controlled shutdown).

Running ntpdate early in the boot up sequence, after networking
is started, should set the proper time.  Typically ntp start
scripts run this before starting the ntp daemon process.

Bill
--
INTERNET:   bill at Celestial.COM  Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
FAX:            (206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676

``If we got one-tenth of what was promised to us in these acceptance
speeches there wouldn't be any inducement to go to heaven.''
    Will Rogers



More information about the Linux-users mailing list