Re: Bug#520763: hwclock: NVRAM flat battery sets date to 1904

2009-05-16 Thread Jörg Sommer
Hi,

Mark Purcell hat am Sat 16. May, 14:57 (+1000) geschrieben:
 This is a common problem on powerpc ibook's once the NVRAM battery goes flat.
 
 Apparently this has been discussed with upstream:
 https://bugs.launchpad.net/ubuntu/+source/gnome-session/+bug/23426/comments/18
 
 Mark
 
 
 This patch is a quick hack, but you get the idea:
 
 --- hwclockfirst.sh.orig2009-05-16 14:26:54.0 +1000
 +++ hwclockfirst.sh 2009-05-16 14:23:11.0 +1000
 @@ -38,6 +38,12 @@
  . /lib/lsb/init-functions
  verbose_log_action_msg() { [ $VERBOSE = no ] || log_action_msg $@; }
 
 +if `/sbin/hwclock | /bin/grep -q 1904`; then
 +   log_warning_msg NVRAM Battery Clock flat (date 1904)
 +   log_action_msg Setting hwclock date to 2009-5-16
 +   hwclock --set --date 2009-5-16
 +fi
 +

I would much more prefer to get prompted for the correct time, because
with a wrong time fsck fail due to the last fsck is in the future. But I
don't know how to do prompting in init scripts correctly.

And to guess if the hardware clock is wrong I think we can look at the
installation time of the module directory of the kernel.
/boot/vmlinux-$(uname -r) is possible, too.

I propose this patch:

--- /etc/init.d/hwclockfirst.sh 2009-04-18 01:03:46.0 +0200
+++ hwclockfirst.sh 2009-05-16 17:52:48.675695938 +0200
@@ -73,7 +73,17 @@
NOADJ=
fi
 
-   if [ $FIRST != yes ]; then
+   if [ $FIRST = yes ]; then
+date_of_mod_dir=$(stat --format=%X /lib/modules/$(uname -a))
+date_of_hwclock=$(date --date=$(hwclock --show $GMT \
+  $HWCLOCKPARS $BADYEAR) +%s)
+if [ $date_of_hwclock -lt $date_of_mod_dir ]; then
+log_begin_msg 'Please provide the current time as 
mmdd hhmm: '
+read time  \
+  test -n $time  \
+  hwclock --set --date=$time $GMT $HWCLOCKPARS $NOADJ
+fi
+else
# Uncomment the hwclock --adjust line below if you want
# hwclock to try to correct systematic drift errors in the
# Hardware Clock.

Bye, Jörg.
-- 
Manchmal denke ich, das sicherste Indiz dafür, daß anderswo im Universum
intelligentes Leben existiert, ist, daß niemand versucht hat, mit uns
Kontakt aufzunehmen.   (Calvin und Hobbes)


signature.asc
Description: Digital signature http://en.wikipedia.org/wiki/OpenPGP


Re: Bug#520763: hwclock: NVRAM flat battery sets date to 1904

2009-05-16 Thread Mark Purcell
On Sunday 17 May 2009 03:18:10 Jörg Sommer wrote:
 I would much more prefer to get prompted for the correct time, because
 with a wrong time fsck fail due to the last fsck is in the future. But I
 don't know how to do prompting in init scripts correctly.

I did think about this, but didn't go this way for a couple of reasons.

. I just want to get the time/date into the correct year so that things like 
kdm/ gdm will startup.  Otherwise the user is presented with a console login 
which doesn't pass the WAF. I have been asked a number of times by the other 
half over the phone what does she do when the screen is black and just says $ 
with a flashing cursor :-(

. I have ntpdate set so when the network interface is brought up, we then sync 
to exact time.  Much more precise than asking the user the time.

. I don't think you are allowed to block for input with the init.d scripts.

That said I can see merit in asking the user the time, especially if you 
aren't going to connect to the network soon..

 And to guess if the hardware clock is wrong I think we can look at the
 installation time of the module directory of the kernel.
 /boot/vmlinux-$(uname -r) is possible, too.

Yes, I'm surprised that a warning isn't set off if the time is set to the date 
before the kernel was complied.

Mark


signature.asc
Description: This is a digitally signed message part.


Re: Bug#520763: hwclock: NVRAM flat battery sets date to 1904

2009-05-16 Thread Rogério Brito
Hi, Jörg.

On May 16 2009, Jörg Sommer wrote:
 I would much more prefer to get prompted for the correct time, because
 with a wrong time fsck fail due to the last fsck is in the future.

The basic idea is sound.

 But I don't know how to do prompting in init scripts correctly.

But the problem here is that prompting in init scripts shouldn't be
done. At least, a lot of users wouldn't like to have to attend the boot
up process. Not without a timeout in the read, at least. Controlled by
the system administrator.

And, please, do remember that while we are discussing this on
debian-powerpc, other arches suffer from the very same problem too (dead
battery/lack of power leading to clock being set way before the
current date).

 And to guess if the hardware clock is wrong I think we can look at the
 installation time of the module directory of the kernel.
 /boot/vmlinux-$(uname -r) is possible, too.

I already suggested something that is slightly more general (even though
I think that it is a hack):

* save the date on every shutdown (say, somewhere under /var or a
  similar place that is guaranteed to be there when the system
  boots---we have to be sure that the place isn't mounted readonly
  when saving the date and that it will be available for reading);

* upon boot, if any saved date is used, then use it. Otherwise, set a
  dummy date (taken, say, as the most recent from the kernel, the
  filesystem being mounted or some fixed date that is known to be
  valid---the date of the release of the package, perhaps).

I do think that this is a dirty hack, but it is a bit more flexible than
just asking the user.

 I propose this patch:

And this doesn't mean that the possibility of asking the user is
completely ignored. Just put a configuration variable there defaulting
to allow unattended boots to proceed, while still providing the
opportunity for the sysadmin to do what you proposed in your patch.


Regards,

-- 
Rogério Brito : rbr...@{mackenzie,ime.usp}.br : GPG key 1024D/7C2CAEB8
http://www.ime.usp.br/~rbrito : http://meusite.mackenzie.com.br/rbrito
Projects: algorithms.berlios.de : lame.sf.net : vrms.alioth.debian.org


-- 
To UNSUBSCRIBE, email to debian-powerpc-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org