[v3,repost] rng-tools: harmonise systemd and sysvinit

Submitted by nick83ola on June 12, 2019, 1 p.m. | Patch ID: 162151

Details

Message ID 20190612130004.21232-1-nick83ola@gmail.com
State Accepted
Commit 16ced1a253c74c01ca414db2f1a010c083213b91
Headers show

Commit Message

nick83ola June 12, 2019, 1 p.m.
this commit will permit to read the option from
/etc/default/rng-tools both from systemd and sysvinit unit file.

Signed-off-by: Nicola Lunghi <nick83ola@gmail.com>
---
 .../rng-tools/rng-tools/default               |  3 +--
 meta/recipes-support/rng-tools/rng-tools/init | 21 ++++++-----------
 .../rng-tools/rng-tools/rngd.service          |  4 ++--
 .../rng-tools/rng-tools_6.6.bb                | 23 ++++++++-----------
 4 files changed, 19 insertions(+), 32 deletions(-)

Patch hide | download patch | download mbox

diff --git a/meta/recipes-support/rng-tools/rng-tools/default b/meta/recipes-support/rng-tools/rng-tools/default
index ab7cd9327f..b9f8e03635 100644
--- a/meta/recipes-support/rng-tools/rng-tools/default
+++ b/meta/recipes-support/rng-tools/rng-tools/default
@@ -1,2 +1 @@ 
-# Specify rng device
-RNG_DEVICE=/dev/hwrng
+EXTRA_ARGS="-r /dev/hwrng"
diff --git a/meta/recipes-support/rng-tools/rng-tools/init b/meta/recipes-support/rng-tools/rng-tools/init
index 7cf78393a4..13f0ecd37c 100644
--- a/meta/recipes-support/rng-tools/rng-tools/init
+++ b/meta/recipes-support/rng-tools/rng-tools/init
@@ -1,26 +1,19 @@ 
-#! /bin/sh 
+#!/bin/sh
 #
 # This is an init script for openembedded
-# Copy it to /etc/init.d/rng-tools and type
+# Copy it to @SYSCONFDIR@/init.d/rng-tools and type
 # > update-rc.d rng-tools defaults 60
 #
 
-rngd=/usr/sbin/rngd
+rngd=@SBINDIR@/rngd
 test -x "$rngd" || exit 1
 
-if [ -e /etc/default/rng-tools ]; then
-    . /etc/default/rng-tools
-fi
-
-if [ -n "$RNG_DEVICE" ]; then
-    EXTRA_ARGS="-- -r $RNG_DEVICE"
-fi
-
+[ -r @SYSCONFDIR@/default/rng-tools ] && . "@SYSCONFDIR@/default/rng-tools"
 
 case "$1" in
   start)
     echo -n "Starting random number generator daemon"
-    start-stop-daemon -S -q -x $rngd $EXTRA_ARGS
+    start-stop-daemon -S -q -x $rngd -- $EXTRA_ARGS
     echo "."
     ;;
   stop)
@@ -38,11 +31,11 @@  case "$1" in
     start-stop-daemon -K -q -n rngd
     echo "."
     echo -n "Starting random number generator daemon"
-    start-stop-daemon -S -q -x $rngd $EXTRA_ARGS
+    start-stop-daemon -S -q -x $rngd -- $EXTRA_ARGS
     echo "."
     ;;
   *)
-    echo "Usage: /etc/init.d/rng-tools {start|stop|reload|restart|force-reload}"
+    echo "Usage: @SYSCONFDIR@/init.d/rng-tools {start|stop|reload|restart|force-reload}"
     exit 1
 esac
 
diff --git a/meta/recipes-support/rng-tools/rng-tools/rngd.service b/meta/recipes-support/rng-tools/rng-tools/rngd.service
index f0355db14f..b1a78527be 100644
--- a/meta/recipes-support/rng-tools/rng-tools/rngd.service
+++ b/meta/recipes-support/rng-tools/rng-tools/rngd.service
@@ -5,8 +5,8 @@  After=systemd-udev-settle.service
 Before=sysinit.target
 
 [Service]
-ExecStart=@SBINDIR@/rngd -f -r /dev/hwrng
-SuccessExitStatus=66
+EnvironmentFile=-@SYSCONFDIR@/default/rng-tools
+ExecStart=@SBINDIR@/rngd -f $EXTRA_ARGS
 
 [Install]
 WantedBy=multi-user.target
diff --git a/meta/recipes-support/rng-tools/rng-tools_6.6.bb b/meta/recipes-support/rng-tools/rng-tools_6.6.bb
index 41959a2695..b0afa4b0eb 100644
--- a/meta/recipes-support/rng-tools/rng-tools_6.6.bb
+++ b/meta/recipes-support/rng-tools/rng-tools_6.6.bb
@@ -44,18 +44,13 @@  do_configure_prepend() {
 }
 
 do_install_append() {
-    install -d "${D}${sysconfdir}/init.d"
-    install -m 0755 ${WORKDIR}/init ${D}${sysconfdir}/init.d/rng-tools
-    sed -i -e 's,/etc/,${sysconfdir}/,' -e 's,/usr/sbin/,${sbindir}/,' \
-        ${D}${sysconfdir}/init.d/rng-tools
-
-    # Only install the default script when 'sysvinit' is in DISTRO_FEATURES.
-    if ${@bb.utils.contains('DISTRO_FEATURES', 'sysvinit', 'true', 'false', d)}; then
-        install -d "${D}${sysconfdir}/default"
-        install -m 0644 ${WORKDIR}/default ${D}${sysconfdir}/default/rng-tools
-    fi
-
-    install -d ${D}${systemd_unitdir}/system
-    install -m 644 ${WORKDIR}/rngd.service ${D}${systemd_unitdir}/system
-    sed -i -e 's,@SBINDIR@,${sbindir},g' ${D}${systemd_unitdir}/system/rngd.service
+    install -Dm 0644 ${WORKDIR}/default ${D}${sysconfdir}/default/rng-tools
+    install -Dm 0755 ${WORKDIR}/init ${D}${sysconfdir}/init.d/rng-tools
+    install -Dm 0644 ${WORKDIR}/rngd.service \
+                     ${D}${systemd_system_unitdir}/rngd.service
+    sed -i \
+        -e 's,@SYSCONFDIR@,${sysconfdir},' \
+        -e 's,@SBINDIR@,${sbindir},' \
+        ${D}${sysconfdir}/init.d/rng-tools \
+        ${D}${systemd_system_unitdir}/rngd.service
 }