summaryrefslogtreecommitdiff
path: root/package/base-files/files/sbin
diff options
context:
space:
mode:
authorEtienne CHAMPETIER <champetier.etienne@gmail.com>2016-07-20 12:22:44 +0000
committerDaniel Golle <daniel@makrotopia.org>2016-07-27 01:24:54 +0200
commit35e423ca41d52c0415bfd2d781482d8cf2a9b067 (patch)
tree9958b484120b7acf8f63eea69920da7686456b8e /package/base-files/files/sbin
parentb8cd996d9260bd3510c9b78de77f472072202d3d (diff)
downloadmtk-20170518-35e423ca41d52c0415bfd2d781482d8cf2a9b067.zip
mtk-20170518-35e423ca41d52c0415bfd2d781482d8cf2a9b067.tar.gz
mtk-20170518-35e423ca41d52c0415bfd2d781482d8cf2a9b067.tar.bz2
base-files: use procd init for urandom_seed
Previous implementation was blocking the init and breaking halt/reboot/sysupgrade (reported by Daniel Golle) v2: use procd logging, use set -e + trap for error handling Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com> Tested-by: Daniel Golle <daniel@makrotopia.org>
Diffstat (limited to 'package/base-files/files/sbin')
-rwxr-xr-xpackage/base-files/files/sbin/urandom_seed20
1 files changed, 20 insertions, 0 deletions
diff --git a/package/base-files/files/sbin/urandom_seed b/package/base-files/files/sbin/urandom_seed
new file mode 100755
index 0000000..16d3657
--- /dev/null
+++ b/package/base-files/files/sbin/urandom_seed
@@ -0,0 +1,20 @@
+#!/bin/sh
+set -e
+
+trap '[ "$?" -eq 0 ] || echo "An error occured" >&2' EXIT
+
+save() {
+ touch "$1.tmp"
+ chown root:root "$1.tmp"
+ chmod 600 "$1.tmp"
+ getrandom 512 > "$1.tmp"
+ mv "$1.tmp" "$1"
+ echo "Seed saved ($1)"
+}
+
+SEED="$(uci -q get system.@system[0].urandom_seed || true)"
+[ "${SEED:0:1}" == "/" ] && save "$SEED"
+
+SEED=/etc/urandom.seed
+[ ! -f $SEED ] && save "$SEED"
+true