Skip to contentSkip to conversation

Inconsistent timestamp use

PATCH Gary Thomas 3 participants 5 messages Nov 3, 2010

lore
Share & tools
lore
#0 lore raw

The Poky root file system (init scripts) has a mechanism for supporting systems without a working hardware [time of day] clock. It seems that this has suffered some rot recently and is now quite inconsistent:
* rootfs_update_timestamp() uses a different format for the time stamp
* the init scripts look for /etc/timestamp2, not /etc/timestamp which is created with the image

The attached patch makes this consistent and the system clock now works much better (about as good as a machine without a hardware clock can!)

Signature · 4 lines
------------------------------------------------------------
Gary Thomas                 |  Consulting for the
MLB Associates              |    Embedded world
------------------------------------------------------------

From 20ffc320d37895028ed5c3d2a5e13c76aba0a934 Mon Sep 17 00:00:00 2001
From: Gary Thomas <[email protected]>
Date: Wed, 3 Nov 2010 06:52:28 -0600
Subject: [PATCH] Make /etc/timestamp usage consistent (for machines without hardware clocks)

---
 meta/classes/image.bbclass                         |    4 ++--
 .../initscripts/initscripts-1.0/bootmisc.sh        |    4 ++--
 .../initscripts/initscripts-1.0/save-rtc.sh        |    2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)
meta/classes/image.bbclass +2 -2
index 3db34ac..0a6df8e 100644
@@ -183,7 +183,7 @@ zap_root_password () {
 } 
 
 create_etc_timestamp() {
-	date +%2m%2d%2H%2M%Y >${IMAGE_ROOTFS}/etc/timestamp
+	date +%Y%m%d%2H%2M >${IMAGE_ROOTFS}/etc/timestamp
 }
 
 # Turn any symbolic /sbin/init link into a file
@@ -217,7 +217,7 @@ set_image_autologin () {
 # Can be use to create /etc/timestamp during image construction to give a reasonably 
 # sane default time setting
 rootfs_update_timestamp () {
-	date "+%m%d%H%M%Y" >${IMAGE_ROOTFS}/etc/timestamp
+	date "+%Y%m%d%2H%2M" >${IMAGE_ROOTFS}/etc/timestamp
 }
 
 # Prevent X from being started
meta/recipes-core/initscripts/initscripts-1.0/bootmisc.sh +2 -2
index 162df2b..41c313a 100755
@@ -65,10 +65,10 @@ fi
 # If the timestamp is 1 day or more recent than the current time,
 # use the timestamp instead.
 /etc/init.d/hwclock.sh start
-if test -e /etc/timestamp2
+if test -e /etc/timestamp
 then
 	SYSTEMDATE=`date "+%Y%m%d%2H%2M"`
-	read TIMESTAMP < /etc/timestamp2
+	read TIMESTAMP < /etc/timestamp
         NEEDUPDATE=`expr \( $TIMESTAMP \> $SYSTEMDATE + 10000 \)`
         if [ $NEEDUPDATE -eq 1 ]; then 
 		date -s $TIMESTAMP
meta/recipes-core/initscripts/initscripts-1.0/save-rtc.sh +1 -1
index 75e4300..3b95411 100644
@@ -10,4 +10,4 @@
 ### END INIT INFO
 
 # Update the timestamp
-date +%Y%m%d%2H%2M > /etc/timestamp2
+date +%Y%m%d%2H%2M > /etc/timestamp
Signature · 1 line
1.6.2.5
#1 lore raw

I was wondering why that wasn't working before.

It was also mentioned to me by someone at CELF that a lot of devices check the superblock times to set their clocks as well. I don't know if Poky has this behavior, but if it does that is not working either.

--Mark

Quoted 11 lines · Gary Thomas

The Poky root file system (init scripts) has a mechanism for supporting systems without a working hardware [time of day] clock. It seems that this has suffered some rot recently and is now quite inconsistent:
* rootfs_update_timestamp() uses a different format for the time stamp
* the init scripts look for /etc/timestamp2, not /etc/timestamp which is created with the image

The attached patch makes this consistent and the system clock now works much better (about as good as a machine without a hardware clock can!)

#2 lore raw
In reply to Gary Thomas
Quoted 11 lines · Gary Thomas

The Poky root file system (init scripts) has a mechanism for supporting systems without a working hardware [time of day] clock. It seems that this has suffered some rot recently and is now quite inconsistent:
* rootfs_update_timestamp() uses a different format for the time stamp
* the init scripts look for /etc/timestamp2, not /etc/timestamp which is created with the image

The attached patch makes this consistent and the system clock now works much better (about as good as a machine without a hardware clock can!)

Hi Gary,

This is a good change for the smaller images that use the busybox date function, but will break images that use the real date command. Unfortunately, they happen to use different formats for setting the time and date.

It may be that we need 2 timestamp files, one for a busybox system and a second for the standard date command and then extend the check in the init scripts to figure out which date we are using currently.

Sau!

#3 lore raw
Quoted 15 lines · Saul Wold
Quoted 11 lines · Gary Thomas

The Poky root file system (init scripts) has a mechanism for supporting systems without a working hardware [time of day] clock. It seems that this has suffered some rot recently and is now quite inconsistent:
* rootfs_update_timestamp() uses a different format for the time stamp
* the init scripts look for /etc/timestamp2, not /etc/timestamp which is created with the image

The attached patch makes this consistent and the system clock now works much better (about as good as a machine without a hardware clock can!)

Hi Gary,

Quoted 8 lines

This is a good change for the smaller images that use the busybox date function, but will break images that use the real date command. Unfortunately, they happen to use different formats for setting the time and date.

It may be that we need 2 timestamp files, one for a busybox system and a second for the standard date command and then extend the check in the init scripts to figure out which date we are using currently.

Fair enough. I was just trying to make what's there work consistently.

Perhaps it's good enough to remove the "-s" option from the setting function and change back to the old format (+%m%d%H%M%Y). I'm pretty sure that the full-on date program will handle that, as does busybox.

Note: I think the change 41d02d40ed83c791e7a4c1d57d829d706af42e74 was actually incorrect. The proper change would have been to fix the timestamp generation to be consistent.

Signature · 4 lines
------------------------------------------------------------
Gary Thomas                 |  Consulting for the
MLB Associates              |    Embedded world
------------------------------------------------------------
#4 lore raw
Quoted 25 lines · Gary Thomas
Quoted 15 lines · Saul Wold
Quoted 11 lines · Gary Thomas

The Poky root file system (init scripts) has a mechanism for supporting systems without a working hardware [time of day] clock. It seems that this has suffered some rot recently and is now quite inconsistent:
* rootfs_update_timestamp() uses a different format for the time stamp
* the init scripts look for /etc/timestamp2, not /etc/timestamp which is created with the image

The attached patch makes this consistent and the system clock now works much better (about as good as a machine without a hardware clock can!)

Hi Gary,

Quoted 8 lines

This is a good change for the smaller images that use the busybox date function, but will break images that use the real date command. Unfortunately, they happen to use different formats for setting the time and date.

It may be that we need 2 timestamp files, one for a busybox system and a second for the standard date command and then extend the check in the init scripts to figure out which date we are using currently.

Quoted 6 lines

Fair enough. I was just trying to make what's there work consistently.

Perhaps it's good enough to remove the "-s" option from the setting function and change back to the old format (+%m%d%H%M%Y). I'm pretty sure that the full-on date program will handle that, as does busybox.

I just verified that the +%2m%2d%2H%2M%Y format will work correctly for both version of dates, and you are correct that the -s option should go away.

The save-rtc.sh script needs to be fixed to use the correct format.

I reponed bug #265 and commented that, if you want to add yourself to that bug.

Sau!

Quoted 4 lines

Note: I think the change 41d02d40ed83c791e7a4c1d57d829d706af42e74 was actually incorrect. The proper change would have been to fix the timestamp generation to be consistent.