[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Linux on the 750C? / time / hibernation




Eugene Fiume <elf@dgp.toronto.edu> wrote:
|> I'm running 1.3.59 or so, and am having no problems with either, except
|> that loses its sense of real-time after hibernation.

FWIW, here's a script I have as /sbin/settime (suid root) and run when I
come out of hibernation (on my 755cx). It checks to see if the clock is off
WRT the CMOS clock, and if so resets it, and also resets the keyboard
autorepeat to 30/sec (the keyboard autorepeat gets reset upon hibernation
as well, and 30/sec is what I like).

Another thought is to just put "/sbin/clock -s" into cron to run every
five minutes or so.....

	Jeffrey

---------------------------------------------------------------------------
#!/usr/local/bin/perl
## settime -- if need be, update the system time from the CMOS clock,
##            and reset the keyboard autorepeat. Must be run setuid root.

$< = $>;                 ## Make us root (must be setuid root)
$ENV{'PATH'} = '/sbin';  ## Give us a safe path (although we'll never use it)

## get the CMOS time until we see the seconds cycle
$last =           `/sbin/clock -r`;
1 while ($clock = `/sbin/clock -r`, $clock eq $last);

## now pull the date and remove the timezone
($date = `/bin/date`) =~ s/ \w\wT( \d\d\d\d)/$1/;

if ($date eq $clock) {
    print "[no clock skew]\n";
    exit 0;
}

## The kbdrate bit is unrelated to the clock,
## but usually want to update when the clock is wrong.
system "/sbin/kbdrate -r 30 > /dev/null";

$start = time;
system '/sbin/clock', '-s';
if (time - $start > 30) {
    print "[was off by ", &Time::span($start, time, 3), "]\n";
}
exit 0;

##############################################################################
##
## The following is a compressed, inlined version of "timespan.pl",
## available at http://www.wg.omron.co.jp/~jfriedl/perl/ with full
## comments and documentation.
##
package Time;sub span{local($t,$T,$places,$round)=@_;$places=10 if !defined
$places;if($t==$T){return(0) x 6 if$places==0;return "no time at all";}($t,$T)=
($T,$t)if$T>$t;local($SECOND,$MINUTE,$HOUR,$DAY,$MONTH,$YEAR)=(localtime$T);
local($second,$minute,$hour,$day,$month,$year)=(localtime$t);$year-=$YEAR;
$month-=$MONTH;$day-=$DAY;$hour-=$HOUR;$minute-=$MINUTE;$second-=$SECOND;while(
$second<0){$minute--;$second+=60;}while($minute<0){$hour--;$minute+=60;}while(
$hour<0){$day--;$hour+=24;}while($day<0){$month--;$day+=&dim(++$MONTH,$YEAR);if
($MONTH==12){$MONTH=0;$YEAR++}}while($month<0){$year--;$month+=12;}return($year
,$month,$day,$hour,$minute,$second)if$places==0;local($stop)=$places<0?-$places
:10;local(%round,@out,$value);local($toprint)=0;if($round){$round{'minute'}=60-
15 if$second>=30;$round{'hour'}=60*60-15 if$minute>=30;$round{'day'}=60*60*24-
15 if$hour>=12;$round{'month'}=60*60*24*25 if$day>=15;$round{'year'}=60*60*24*
365 if$month>=6;}foreach$UNIT('year','month','day','hour','minute','second'){if
(eval("\$value=\$$UNIT")||$toprint==1||$stop==1){if(($toprint==1||$stop==1)&&
defined$round{$UNIT}){return&span($T,$t+$round{$UNIT},$places);}push(@out,
$value eq'1'?"1$UNIT":"$value ${UNIT}s");$toprint=$places if$places>0&&@out==1;
}last if$toprint--==1||(@out&&(--$stop==0));}join(',',@out);}sub dim{local(
$month,$year)=@_;return(0,31,0,31,30,31,30,31,31,30,31,30,31)[$month] if$month
!=2;return(($year%4==0)&&($year%200!=0))?29:28;}1;

__END__