From 7a42c5f5a4939470a5ea94ed89954c94e0ca2e4d Mon Sep 17 00:00:00 2001 From: Neil Horman Date: Fri, 27 Oct 2017 15:23:50 -0400 Subject: [PATCH] Resolves: bz 1490632 --- check-rng-entropy | 10 ++++++++++ entropy-check.service | 17 +++++++++++++++++ rng-tools.spec | 13 +++++++++++-- rngd-exit-code-for-list.patch | 21 +++++++++++++++++++++ rngd.service | 1 - 5 files changed, 59 insertions(+), 3 deletions(-) create mode 100755 check-rng-entropy create mode 100644 entropy-check.service create mode 100644 rngd-exit-code-for-list.patch diff --git a/check-rng-entropy b/check-rng-entropy new file mode 100755 index 0000000..3c29b8b --- /dev/null +++ b/check-rng-entropy @@ -0,0 +1,10 @@ +#!/bin/sh +rngd --list > /dev/null 2>&1 + +if [ $? -eq 0 ] +then + systemctl enable rngd.service + systemctl start rngd.service +fi + +exit 0 diff --git a/entropy-check.service b/entropy-check.service new file mode 100644 index 0000000..0d38976 --- /dev/null +++ b/entropy-check.service @@ -0,0 +1,17 @@ +[Unit] +Description=Checker to look for entropy sources and enable rngd +DefaultDependencies=no +Conflicts=shutdown.target +After=systemd-remount-fs.service +Before=systemd-sysusers.service sysinit.target shutdown.target +ConditionFirstBoot=yes + +[Service] +Type=oneshot +ExecStart=/usr/bin/check-rng-entropy +StandardOutput=null +StandardError=null + +[Install] +WantedBy=sysinit.target + diff --git a/rng-tools.spec b/rng-tools.spec index 52d25ee..8542fe5 100644 --- a/rng-tools.spec +++ b/rng-tools.spec @@ -4,12 +4,14 @@ Summary: Random number generator related utilities Name: rng-tools Version: 6.1 -Release: 1%{?dist} +Release: 2%{?dist} Group: System Environment/Base License: GPLv2+ URL: https://github.com/nhorman/rng-tools Source0: https://github.com/nhorman/rng-tools/archive/rng-tools-%{version}.tar.gz Source1: rngd.service +Source2: check-rng-entropy +Source3: entropy-check.service # https://sourceforge.net/p/gkernel/patches/111/ @@ -42,15 +44,19 @@ Hardware random number generation tools. # install systemd unit file install -Dt %{buildroot}%{_unitdir} -m0644 %{SOURCE1} - +install -Dt %{buildroot}%{_unitdir} -m0644 %{SOURCE2} +install -Dt %{buildroot}%{_bindir} -m0755 %{SOURCE3} %post %systemd_post rngd.service +%systemd_post entropy-check.service %preun %systemd_preun rngd.service +%systemd_preun entropy-check.service %postun %systemd_postun_with_restart rngd.service +%systemd_postun_with_restart entropy-check.service %files %{!?_licensedir:%global license %%doc} @@ -63,6 +69,9 @@ install -Dt %{buildroot}%{_unitdir} -m0644 %{SOURCE1} %attr(0644,root,root) %{_unitdir}/rngd.service %changelog +* Fri Oct 26 2017 Neil Horman - 6.1-2 +- Conditionally enable rngd on entropy src availability (bz 1490632) + * Tue Oct 10 2017 Neil Horman - 6.1-1 - update to latest upstream diff --git a/rngd-exit-code-for-list.patch b/rngd-exit-code-for-list.patch new file mode 100644 index 0000000..a79ec91 --- /dev/null +++ b/rngd-exit-code-for-list.patch @@ -0,0 +1,21 @@ +diff -up ./rngd.c.orig ./rngd.c +--- ./rngd.c.orig 2017-10-27 14:18:52.617286574 -0400 ++++ ./rngd.c 2017-10-27 14:19:34.189456107 -0400 +@@ -423,12 +423,15 @@ int main(int argc, char **argv) + } + + if (arguments->list) { ++ int rc = 1; + msg_squash = false; + printf("Available entropy sources:\n"); + for (i=0; i < ENT_MAX; i++) +- if (entropy_sources[i].init && entropy_sources[i].disabled == false) ++ if (entropy_sources[i].init && entropy_sources[i].disabled == false) { ++ rc = 0; + printf("%d: %s\n", i, entropy_sources[i].rng_name); +- return 1; ++ } ++ return rc; + } + + if (!ent_sources) { diff --git a/rngd.service b/rngd.service index 33829f6..3d9dcb5 100644 --- a/rngd.service +++ b/rngd.service @@ -3,7 +3,6 @@ Description=Hardware RNG Entropy Gatherer Daemon [Service] ExecStart=/sbin/rngd -f -SuccessExitStatus=66 [Install] WantedBy=multi-user.target