Merge pull request #4731 from chewitt/entropy_backport

entropy: backport to 6.0 branch
This commit is contained in:
Christian Hewitt 2016-02-20 09:33:09 +04:00
commit d25db13ebd
7 changed files with 109 additions and 6 deletions

View File

@ -224,11 +224,13 @@ enable_service () {
local target_dir=$INSTALL
[ -f "$target_dir/$unit_dir/$unit" ] || exit 1
[ -z "$target" ] && target=`grep '^WantedBy' $target_dir/$unit_dir/$unit | cut -f2 -d=`
if [ -n "$target" ]; then
mkdir -p ${target_dir}/$unit_dir/${target}.wants
ln -sf ../${unit} ${target_dir}/$unit_dir/${target}.wants/
if [ -z "$target" ] ; then
for target in `grep '^WantedBy' $target_dir/$unit_dir/$unit | cut -f2 -d=` ; do
if [ -n "$target" ]; then
mkdir -p ${target_dir}/$unit_dir/${target}.wants
ln -sf ../${unit} ${target_dir}/$unit_dir/${target}.wants/
fi
done
fi
}

View File

@ -0,0 +1,50 @@
################################################################################
# This file is part of OpenELEC - http://www.openelec.tv
# Copyright (C) 2009-2016 Stephan Raue (stephan@openelec.tv)
#
# OpenELEC is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# OpenELEC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with OpenELEC. If not, see <http://www.gnu.org/licenses/>.
################################################################################
PKG_NAME="entropy"
PKG_VERSION="0"
PKG_REV="1"
PKG_ARCH="any"
PKG_LICENSE="GPL"
PKG_SITE=""
PKG_URL=""
PKG_DEPENDS_TARGET="toolchain"
PKG_PRIORITY="optional"
PKG_SECTION="system"
PKG_SHORTDESC="A simple way to add entropy at boot"
PKG_LONGDESC="A simple way to add entropy at boot"
PKG_IS_ADDON="no"
PKG_AUTORECONF="no"
make_target(){
:
}
makeinstall_target() {
mkdir -p $INSTALL/usr/lib/entropy
cp add-entropy $INSTALL/usr/lib/entropy
cp add-random-at-shutdown $INSTALL/usr/lib/entropy
chmod +x $INSTALL/usr/lib/entropy/*
}
post_install() {
enable_service add-entropy.service
enable_service add-random-at-shutdown.service
}

View File

@ -0,0 +1,24 @@
#!/usr/bin/python
import os
import struct
RNDADDENTROPY = 0x40085203
import fcntl
def add_entropy(fd, data):
add = struct.pack('ii', len(data)*8, len(data)) + data
fcntl.ioctl(fd, RNDADDENTROPY, add)
if not os.path.isfile("/storage/.cache/random.data"):
os.system("dd if=/dev/urandom of=/storage/.cache/random.data count=4 >/dev/null")
cache=os.open("/storage/.cache/random.data", os.O_RDONLY)
rnd=os.open("/dev/random", os.O_RDWR)
while True:
data=os.read(cache, 512)
if len(data) == 0:
break
add_entropy(rnd, data)

View File

@ -0,0 +1,2 @@
#!/bin/sh
dd if=/dev/urandom of=/storage/.cache/random.data count=4

View File

@ -0,0 +1,13 @@
[Unit]
Description=Add random entropy from file
DefaultDependencies=no
After=systemd-tmpfiles-setup.service
Before=systemd-udevd.service
[Service]
Type=oneshot
ExecStart=/usr/lib/entropy/add-entropy
RemainAfterExit=yes
[Install]
WantedBy=basic.target

View File

@ -0,0 +1,12 @@
[Unit]
Description=Save random entropy at shutdown
DefaultDependencies=no
Before=systemd-poweroff.service systemd-reboot.service systemd-halt.service
[Service]
Type=oneshot
ExecStart=/usr/lib/entropy/add-random-at-shutdown
RemainAfterExit=yes
[Install]
WantedBy=poweroff.target reboot.target halt.target

View File

@ -23,7 +23,7 @@ PKG_ARCH="any"
PKG_LICENSE="GPL"
PKG_SITE="http://www.freedesktop.org/wiki/Software/systemd"
PKG_URL="http://www.freedesktop.org/software/systemd/$PKG_NAME-$PKG_VERSION.tar.xz"
PKG_DEPENDS_TARGET="toolchain libcap kmod util-linux"
PKG_DEPENDS_TARGET="toolchain libcap kmod util-linux entropy"
PKG_PRIORITY="required"
PKG_SECTION="system"
PKG_SHORTDESC="systemd: a system and session manager"