Skip to contentSkip to conversation

Various fixes and improvements to initscripts

PATCH In review Ben Shelton 2 participants 8 messages Jul 17, 2014 – Jul 20, 2014

lore
Share & tools
lore
#0 lore raw

v2 cover Various fixes and improvements to initscripts

This patch series contains fixes and improvements we've made to several init scripts. These changes have been thoroughly tested on Dylan and ported to master.

Changes made in v2:
- Updated /etc/timestamp generated at build time to use seconds accuracy
- Added a patch I missed the first time to source /etc/default/urandom from /etc/init.d/urandom

The following changes since commit a449598a839e677e2a094aa4bd9a68003de6e42e:

bdwgc: Add PACKAGECONFIG for libatomic-ops (2014-07-17 15:04:07 +0100)

are available in the git repository at:

git://github.com/ni/openembedded-core dev/bshelton/upstream_initscripts
https://github.com/ni/openembedded-core/tree/dev/bshelton/upstream_initscripts

Blair Elliott (1):
initscripts: save /etc/timestamp with seconds accuracy

Ken Sharp (1):
initscripts: Use current date as an additional source of entropy

Richard Tollerton (4):
initscripts: bootmisc.sh: Make sysctl -p honor VERBOSE
initscripts: parametrize random seed file location
initscripts: make hostname.sh coreutils-compatible
initscripts: Add support for /etc/default/urandom

 meta/classes/image.bbclass                          |  2 +-
 .../initscripts/initscripts-1.0/bootmisc.sh         | 12 +++++++++---
 .../initscripts/initscripts-1.0/hostname.sh         |  2 +-
 .../initscripts/initscripts-1.0/save-rtc.sh         |  2 +-
 .../initscripts/initscripts-1.0/urandom             | 21 ++++++++++++---------
 5 files changed, 24 insertions(+), 15 deletions(-)
Signature · 1 line
2.0.2
#1 lore raw

PATCH v2 1/6 initscripts: bootmisc.sh: Make sysctl -p honor VERBOSE

From: Richard Tollerton <[email protected]>

busybox sysctl may lack the "-q" setting, so simulate it with redirects.

---
 meta/recipes-core/initscripts/initscripts-1.0/bootmisc.sh | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
meta/recipes-core/initscripts/initscripts-1.0/bootmisc.sh +6 -1
index 3b5a47f..5211824 100755
@@ -36,7 +36,12 @@ if [ -f "${SYSCTL_CONF}" ]
 then
 	if [ -x "/sbin/sysctl" ]
 	then
-		/sbin/sysctl -p "${SYSCTL_CONF}"
+		# busybox sysctl does not support -q
+		VERBOSE_REDIR="1>/dev/null"
+		if [ "${VERBOSE}" != "no" ]; then
+			VERBOSE_REDIR="1>&1"
+		fi
+		eval /sbin/sysctl -p "${SYSCTL_CONF}" $VERBOSE_REDIR
 	else
 		echo "To have ${SYSCTL_CONF} applied during boot, install package <procps>."
 	fi
Signature · 1 line
2.0.2
#2 lore raw

PATCH v2 2/6 initscripts: save /etc/timestamp with seconds accuracy

In reply to Ben Shelton

From: Blair Elliott <[email protected]>

Currently, /etc/timestamp is saved with minutes accuracy. To increase the accuracy, modify the save-rtc.sh and bootmisc.sh scripts to save and read /etc/timestamp respectively with seconds accuracy.

---
 meta/classes/image.bbclass                                | 2 +-
 meta/recipes-core/initscripts/initscripts-1.0/bootmisc.sh | 5 +++--
 meta/recipes-core/initscripts/initscripts-1.0/save-rtc.sh | 2 +-
 3 files changed, 5 insertions(+), 4 deletions(-)
meta/classes/image.bbclass +1 -1
index a03b880..772c3ed 100644
@@ -359,7 +359,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 -u +%4Y%2m%2d%2H%2M >${IMAGE_ROOTFS}/etc/timestamp
+	date -u +%4Y%2m%2d%2H%2M%2S >${IMAGE_ROOTFS}/etc/timestamp
 }
 
 # Prevent X from being started
meta/recipes-core/initscripts/initscripts-1.0/bootmisc.sh +3 -2
index 5211824..ccc7f9f 100755
@@ -66,10 +66,11 @@ fi
 test -x /etc/init.d/hwclock.sh && /etc/init.d/hwclock.sh start
 if test -e /etc/timestamp
 then
-	SYSTEMDATE=`date -u +%4Y%2m%2d%2H%2M`
+	SYSTEMDATE=`date -u +%4Y%2m%2d%2H%2M%2S`
 	read TIMESTAMP < /etc/timestamp
 	if [ ${TIMESTAMP} -gt $SYSTEMDATE ]; then
-		date -u ${TIMESTAMP#????}${TIMESTAMP%????????}
+		# format the timestamp as date expects it (2m2d2H2M4Y.2S)
+		date -u ${TIMESTAMP:4:8}${TIMESTAMP:0:4}.${TIMESTAMP:(-2)}
 		test -x /etc/init.d/hwclock.sh && /etc/init.d/hwclock.sh stop
 	fi
 fi
meta/recipes-core/initscripts/initscripts-1.0/save-rtc.sh +1 -1
index 1f804e2..b038fc5 100644
@@ -10,4 +10,4 @@
 ### END INIT INFO
 
 # Update the timestamp
-date -u +%4Y%2m%2d%2H%2M > /etc/timestamp
+date -u +%4Y%2m%2d%2H%2M%2S > /etc/timestamp
Signature · 1 line
2.0.2
#3 lore raw

Re: [PATCH v2 2/6] initscripts: save /etc/timestamp with seconds accuracy

Quoted 35 lines · Ben Shelton

From: Blair Elliott <[email protected]>

Currently, /etc/timestamp is saved with minutes accuracy. To increase the accuracy, modify the save-rtc.sh and bootmisc.sh scripts to save and read /etc/timestamp respectively with seconds accuracy.

---
 meta/classes/image.bbclass                                | 2 +-
 meta/recipes-core/initscripts/initscripts-1.0/bootmisc.sh | 5 +++--
 meta/recipes-core/initscripts/initscripts-1.0/save-rtc.sh | 2 +-
 3 files changed, 5 insertions(+), 4 deletions(-)
meta/classes/image.bbclass +1 -1
index a03b880..772c3ed 100644
@@ -359,7 +359,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 -u +%4Y%2m%2d%2H%2M >${IMAGE_ROOTFS}/etc/timestamp
+	date -u +%4Y%2m%2d%2H%2M%2S >${IMAGE_ROOTFS}/etc/timestamp
 }
 
 # Prevent X from being started
meta/recipes-core/initscripts/initscripts-1.0/bootmisc.sh +0 -0
index 5211824..ccc7f9f 100755
@@ -66,10 +66,11 @@ fi
 test -x /etc/init.d/hwclock.sh && /etc/init.d/hwclock.sh start
 if test -e /etc/timestamp
 then

meta/recipes-core/initscripts/initscripts-1.0/bootmisc.sh fi · line 76

Quoted 10 lines
meta/recipes-core/initscripts/initscripts-1.0/bootmisc.sh +3 -2
-	SYSTEMDATE=`date -u +%4Y%2m%2d%2H%2M`
+	SYSTEMDATE=`date -u +%4Y%2m%2d%2H%2M%2S`
 	read TIMESTAMP < /etc/timestamp
 	if [ ${TIMESTAMP} -gt $SYSTEMDATE ]; then
-		date -u ${TIMESTAMP#????}${TIMESTAMP%????????}
+		# format the timestamp as date expects it (2m2d2H2M4Y.2S)
+		date -u ${TIMESTAMP:4:8}${TIMESTAMP:0:4}.${TIMESTAMP:(-2)}
 		test -x /etc/init.d/hwclock.sh && /etc/init.d/hwclock.sh stop
 	fi
 fi

The syntax above doesn't appear to work with busybox:

/etc/init.d/rc: /etc/rcS.d/S55bootmisc.sh: line 73: syntax error: bad substitution

:(

Cheers,

Richard

#4 lore raw

PATCH v2 3/6 initscripts: parametrize random seed file location

In reply to Ben Shelton

From: Richard Tollerton <[email protected]>

Currently, the random seed file location is hardcoded to /var/lib/urandom/random-seed. Refactor it to a parameter (RANDOM_SEED_FILE) so the file location is defined in only one place.

---
 meta/recipes-core/initscripts/initscripts-1.0/urandom | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
meta/recipes-core/initscripts/initscripts-1.0/urandom +8 -5
index eb3a7c3..a0549de 100755
@@ -12,6 +12,9 @@
 ### END INIT INFO
 
 test -c /dev/urandom || exit 0
+
+RANDOM_SEED_FILE=/var/lib/urandom/random-seed
+
 . /etc/default/rcS
 
 case "$1" in
@@ -19,13 +22,13 @@ case "$1" in
 		test "$VERBOSE" != no && echo "Initializing random number generator..."
 		# Load and then save 512 bytes,
 		# which is the size of the entropy pool
-		if test -f /var/lib/urandom/random-seed
+		if test -f "$RANDOM_SEED_FILE"
 		then
-			cat /var/lib/urandom/random-seed >/dev/urandom
+			cat "$RANDOM_SEED_FILE" >/dev/urandom
 		fi
-		rm -f /var/lib/urandom/random-seed
+		rm -f "$RANDOM_SEED_FILE"
 		umask 077
-		dd if=/dev/urandom of=/var/lib/urandom/random-seed count=1 \
+		dd if=/dev/urandom of=$RANDOM_SEED_FILE count=1 \
 			>/dev/null 2>&1 || echo "urandom start: failed."
 		umask 022
 		;;
@@ -34,7 +37,7 @@ case "$1" in
 		# see documentation in linux/drivers/char/random.c
 		test "$VERBOSE" != no && echo "Saving random seed..."
 		umask 077
-		dd if=/dev/urandom of=/var/lib/urandom/random-seed count=1 \
+		dd if=/dev/urandom of=$RANDOM_SEED_FILE count=1 \
 			>/dev/null 2>&1 || echo "urandom stop: failed."
 		;;
 	*)
Signature · 1 line
2.0.2
#5 lore raw

PATCH v2 4/6 initscripts: Use current date as an additional source of entropy

In reply to Ben Shelton

From: Ken Sharp <[email protected]>

If the seed file is empty or does not exist, the date is an extremely poor backup source of entropy, but it is better than nothing.

---
 meta/recipes-core/initscripts/initscripts-1.0/urandom | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
meta/recipes-core/initscripts/initscripts-1.0/urandom +5 -6
index a0549de..ec4ef61 100755
@@ -20,12 +20,11 @@ RANDOM_SEED_FILE=/var/lib/urandom/random-seed
 case "$1" in
 	start|"")
 		test "$VERBOSE" != no && echo "Initializing random number generator..."
-		# Load and then save 512 bytes,
-		# which is the size of the entropy pool
-		if test -f "$RANDOM_SEED_FILE"
-		then
-			cat "$RANDOM_SEED_FILE" >/dev/urandom
-		fi
+		# Load and then save 512 bytes, which is the size of the entropy
+		# pool. Also load the current date, in case the seed file is
+		# empty.
+		( date +%s.%N; [ -f "$RANDOM_SEED_FILE" ] && cat "$RANDOM_SEED_FILE" ) \
+			>/dev/urandom
 		rm -f "$RANDOM_SEED_FILE"
 		umask 077
 		dd if=/dev/urandom of=$RANDOM_SEED_FILE count=1 \
Signature · 1 line
2.0.2
#6 lore raw

PATCH v2 5/6 initscripts: make hostname.sh coreutils-compatible

In reply to Ben Shelton

From: Richard Tollerton <[email protected]>

inetutils and busybox hostname utils support hostname -F; coreutils hostname doesn't. So just use cat instead.

---
 meta/recipes-core/initscripts/initscripts-1.0/hostname.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
meta/recipes-core/initscripts/initscripts-1.0/hostname.sh +1 -1
index 78fb91c..95287cc 100755
@@ -16,7 +16,7 @@ fi
 
 # Busybox hostname doesn't support -b so we need implement it on our own
 if [ -f /etc/hostname ];then
-	hostname -F /etc/hostname
+	hostname `cat /etc/hostname`
 elif [ -z "$HOSTNAME" -o "$HOSTNAME" = "(none)" -o ! -z "`echo $HOSTNAME | sed -n '/^[0-9]*\.[0-9].*/p'`" ] ; then
 	hostname localhost
 fi
Signature · 1 line
2.0.2
#7 lore raw

PATCH v2 6/6 initscripts: Add support for /etc/default/urandom

In reply to Ben Shelton

From: Richard Tollerton <[email protected]>

Source /etc/default/urandom if present. This allows the rootfs to remain read-only while enabling the user to override the location of the random seed file.

---
 meta/recipes-core/initscripts/initscripts-1.0/urandom | 1 +
 1 file changed, 1 insertion(+)
meta/recipes-core/initscripts/initscripts-1.0/urandom +1 -0
index ec4ef61..af1625b 100755
@@ -16,6 +16,7 @@ test -c /dev/urandom || exit 0
 RANDOM_SEED_FILE=/var/lib/urandom/random-seed
 
 . /etc/default/rcS
+[ -f /etc/default/urandom ] && . /etc/default/urandom
 
 case "$1" in
 	start|"")
Signature · 1 line
2.0.2