Skip to contentSkip to conversation

Various fixes and improvements to initscripts

PATCH Superseded Ben Shelton 2 participants 10 messages Jul 16, 2014 – Jul 17, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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.

The following changes since commit 846bc50fde11bbb36c8eb5b2e3ae6bb644c037f3:

ltp: use "foreign" automake strictness (2014-07-16 10:27:16 +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 (3):
initscripts: bootmisc.sh: Make sysctl -p honor VERBOSE
initscripts: parametrize random seed file location
initscripts: make hostname.sh coreutils-compatible

 .../initscripts/initscripts-1.0/bootmisc.sh          | 12 +++++++++---
 .../initscripts/initscripts-1.0/hostname.sh          |  2 +-
 .../initscripts/initscripts-1.0/save-rtc.sh          |  2 +-
 .../recipes-core/initscripts/initscripts-1.0/urandom | 20 +++++++++++---------
 4 files changed, 22 insertions(+), 14 deletions(-)
Signature · 1 line
2.0.1
#1 lore raw

PATCH 1/5 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.1
#2 lore raw

Re: [PATCH 1/5] initscripts: bootmisc.sh: Make sysctl -p honor VERBOSE

Quoted 15 lines · Ben Shelton

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 +0 -0
index 3b5a47f..5211824 100755

meta/recipes-core/initscripts/initscripts-1.0/bootmisc.sh if [ -f "${SYSCTL_CONF}" ] · line 39

Quoted 5 lines
meta/recipes-core/initscripts/initscripts-1.0/bootmisc.sh +1 -1
@@ -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

Will this work if procps's sysctl is used instead, I think it will but wanted to verify it.

Sau!

Quoted 9 lines
meta/recipes-core/initscripts/initscripts-1.0/bootmisc.sh +5 -0
+		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
#3 lore raw

Re: [PATCH 1/5] initscripts: bootmisc.sh: Make sysctl -p honor VERBOSE

Quoted 25 lines · Saul Wold
Quoted 15 lines · Ben Shelton

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 +0 -0
index 3b5a47f..5211824 100755

meta/recipes-core/initscripts/initscripts-1.0/bootmisc.sh if [ -f "${SYSCTL_CONF}" ] · line 39

Quoted 5 lines
meta/recipes-core/initscripts/initscripts-1.0/bootmisc.sh +1 -1
@@ -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

Will this work if procps's sysctl is used instead, I think it will but wanted to verify it.

Quoted 2 lines

Sau!

Yes, it will work. I just installed the procps package on an ARM target and verified that the output is as expected for both settings of VERBOSE.

Best,
Ben

Quoted 9 lines
Quoted 9 lines
meta/recipes-core/initscripts/initscripts-1.0/bootmisc.sh +5 -0
+		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
#4 lore raw

PATCH 2/5 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/recipes-core/initscripts/initscripts-1.0/bootmisc.sh | 5 +++--
 meta/recipes-core/initscripts/initscripts-1.0/save-rtc.sh | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)
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.1
#5 lore raw

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

Quoted 6 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.

We also initialize it in the image.bbclass, you may want to tweak that one.

Since we deal with readonly it's possible it won't get updated after the image creation.

Sau!

Quoted 36 lines
---
  meta/recipes-core/initscripts/initscripts-1.0/bootmisc.sh | 5 +++--
  meta/recipes-core/initscripts/initscripts-1.0/save-rtc.sh | 2 +-
  2 files changed, 4 insertions(+), 3 deletions(-)
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
#6 lore raw

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

Quoted 8 lines · Saul Wold
Quoted 6 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.

Quoted 7 lines

We also initialize it in the image.bbclass, you may want to tweak that one.

Since we deal with readonly it's possible it won't get updated after the image creation.

Sau!

Good catch -- I'll make the fix and resubmit the patchset.

Thanks,
Ben

#7 lore raw

PATCH 3/5 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.1
#8 lore raw

PATCH 4/5 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.1
#9 lore raw

PATCH 5/5 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.1