From 5f15753fdefa650808b47fb8509b34e871168ace Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Tue, 22 Nov 2016 01:24:34 +0100 Subject: [PATCH] saving uncommitted changes in /etc prior to emerge run --- conf.d/net-online | 4 ++-- conf.d/swap | 13 +++++++++++++ init.d/hostname | 20 +++++++++++++++----- init.d/hwclock | 25 ++++++++++++++++++------- init.d/localmount | 4 ++-- init.d/loopback | 9 +-------- init.d/modules | 24 ++++++++++++++++++++++-- init.d/modules-load | 2 +- init.d/mount-ro | 3 +++ init.d/net-online | 4 ++-- init.d/procfs | 12 +++++++++--- init.d/runsvdir | 20 ++++++++++++++++++++ init.d/savecache | 2 +- init.d/swap | 7 ------- init.d/sysctl | 37 ++++++++++++++++++++++++++++++++++--- init.d/sysfs | 29 ++++++++++++++++++----------- local.d/README | 2 +- 17 files changed, 162 insertions(+), 55 deletions(-) create mode 100644 conf.d/swap create mode 100755 init.d/runsvdir diff --git a/conf.d/net-online b/conf.d/net-online index bf0b09a2..aa2c76ba 100644 --- a/conf.d/net-online +++ b/conf.d/net-online @@ -1,6 +1,6 @@ # The interfaces setting controls which interfaces the net-online -# service considers in deciding whether the network is active. By -# default, it is all ethernet or wireless LAN interfaces. +# service considers in deciding whether the network is active. The +# default is all interfaces that support ethernet. #interfaces="" # This setting controls whether a ping to the default gateway is diff --git a/conf.d/swap b/conf.d/swap new file mode 100644 index 00000000..17bd0341 --- /dev/null +++ b/conf.d/swap @@ -0,0 +1,13 @@ +# If you are only using local swap partitions, you should not change +# this file. Otherwise, you need to uncomment the below rc_before line +# followed by the appropriate rc_need line. +#rc_before="!localmount" +# +# If you are using swap files stored on local file systems, uncomment +# this line. +#rc_need="localmount" +# +# If you are using swap files stored on network file systems or swap +# partitions stored on network block devices such as iSCSI, uncomment +# this line. +#rc_need="netmount" diff --git a/init.d/hostname b/init.d/hostname index 614ac87e..474d75af 100755 --- a/init.d/hostname +++ b/init.d/hostname @@ -17,10 +17,20 @@ depend() { start() { - # HOSTNAME variable used to be defined in caps in conf.d/hostname. - # It is also a magic variable in bash. - hostname=${hostname-${HOSTNAME-localhost}} # checkbashisms: false positive - ebegin "Setting hostname to $hostname" - hostname "$hostname" + local h source x + if [ -s /etc/hostname ] && [ -r /etc/hostname ]; then + read h x /dev/null 2>&1; then - ewarn "Failed to remove branch $aufs_branch from aufs \ - $aufs_mount_point" + ewarn "Failed to remove branch $aufs_branch from aufs" \ + "$aufs_mount_point" fi eoutdent sync diff --git a/init.d/loopback b/init.d/loopback index 8608c857..6a0c8a14 100755 --- a/init.d/loopback +++ b/init.d/loopback @@ -21,12 +21,10 @@ start() if [ "$RC_UNAME" = Linux ]; then ebegin "Bringing up network interface lo" if command -v ip > /dev/null 2>&1; then - ip addr add 127.0.0.1/8 dev lo brd + scope host - ip route add 127.0.0.0/8 dev lo scope host + ip addr add 127.0.0.1/8 dev lo brd + ip link set lo up else ifconfig lo 127.0.0.1 netmask 255.0.0.0 - route add -net 127.0.0.0 netmask 255.0.0.0 gw 127.0.0.1 fi else ebegin "Bringing up network interface lo0" @@ -35,8 +33,3 @@ start() fi eend $? } - -stop() -{ - return 0 -} diff --git a/init.d/modules b/init.d/modules index cea19342..c97bd55d 100755 --- a/init.d/modules +++ b/init.d/modules @@ -18,7 +18,18 @@ depend() keyword -docker -lxc -openvz -prefix -systemd-nspawn -vserver } -start() +FreeBSD_modules() +{ + local cnt=0 x + for x in $modules; do + ebegin "Loading module $x" + kldload "$x" + eend $? "Failed to load $x" && : $(( cnt += 1 )) + done + einfo "Autoloaded $cnt module(s)" +} + +Linux_modules() { # Should not fail if kernel do not have module # support compiled in ... @@ -64,8 +75,17 @@ start() done [ -z "$args" ] && eval args=\$module_${aa}_args [ -z "$args" ] && eval args=\$module_${xx}_args - eval modprobe -q "$mpargs" "$x" "$args" + eval modprobe --use-blacklist -q "$mpargs" "$x" "$args" eend $? "Failed to load $x" && : $(( cnt += 1 )) done einfo "Autoloaded $cnt module(s)" } + +start() +{ + case "$RC_UNAME" in + FreeBSD|Linux) ${RC_UNAME}_modules ;; + *) ;; + esac + return 0 +} diff --git a/init.d/modules-load b/init.d/modules-load index 81c457c8..b1a010b1 100755 --- a/init.d/modules-load +++ b/init.d/modules-load @@ -54,7 +54,7 @@ load_modules() ebegin "Loading module $x" case "$RC_UNAME" in FreeBSD) kldload "$x"; rc=$? ;; - Linux) modprobe -q "$x"; rc=$? ;; + Linux) modprobe --use-blacklist -q "$x"; rc=$? ;; *) ;; esac eend $rc "Failed to load $x" diff --git a/init.d/mount-ro b/init.d/mount-ro index 6c7e70b6..3badeace 100755 --- a/init.d/mount-ro +++ b/init.d/mount-ro @@ -34,6 +34,9 @@ start() local m="/dev|/dev/.*|/proc|/proc.*|/sys|/sys/.*|/run|${rc_svcdir}" x= fs= m="$m|/bin|/sbin|/lib(32|64)?|/libexec" + if [ -e "$rc_svcdir"/usr_premounted ]; then + m="$m|/usr" + fi # RC_NO_UMOUNTS is an env var that can be set by plugins local IFS="$IFS:" for x in $no_umounts $RC_NO_UMOUNTS; do diff --git a/init.d/net-online b/init.d/net-online index c7031bbc..0a1e9977 100755 --- a/init.d/net-online +++ b/init.d/net-online @@ -42,8 +42,8 @@ get_default_gateway() start () { - local carriers configured dev gateway ifcount infinite interfaces - local rc state timeout x + local carriers configured dev gateway ifcount infinite + local rc state x ebegin "Checking to see if the network is online" rc=0 diff --git a/init.d/procfs b/init.d/procfs index 3189a37f..91be45a5 100755 --- a/init.d/procfs +++ b/init.d/procfs @@ -13,7 +13,8 @@ description="Mounts misc filesystems in /proc." depend() { - use modules devfs + use devfs + want modules need localmount keyword -docker -lxc -openvz -prefix -systemd-nspawn -vserver } @@ -21,8 +22,13 @@ depend() start() { # Setup Kernel Support for miscellaneous Binary Formats - if [ -d /proc/sys/fs/binfmt_misc -a ! -e /proc/sys/fs/binfmt_misc/register ]; then - modprobe -q binfmt-misc + if [ -d /proc/sys/fs/binfmt_misc ] && + [ ! -e /proc/sys/fs/binfmt_misc/register ]; then + if ! grep -qs binfmt_misc /proc/filesystems && + modprobe -q binfmt-misc; then + ewarn "The binfmt-misc module needs to be configured in" \ + "/etc/conf.d/modules or built in." + fi if grep -qs binfmt_misc /proc/filesystems; then ebegin "Mounting misc binary format filesystem" mount -t binfmt_misc -o nodev,noexec,nosuid \ diff --git a/init.d/runsvdir b/init.d/runsvdir new file mode 100755 index 00000000..fea196af --- /dev/null +++ b/init.d/runsvdir @@ -0,0 +1,20 @@ +#!/sbin/openrc-run +# Copyright (c) 2016 The OpenRC Authors. +# See the Authors file at the top-level directory of this distribution and +# https://github.com/OpenRC/openrc/blob/master/AUTHORS +# +# This file is part of OpenRC. It is subject to the license terms in +# the LICENSE file found in the top-level directory of this +# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE +# This file may not be copied, modified, propagated, or distributed +# except according to the terms contained in the LICENSE file. + +command=/usr/bin/runsvdir +command_background=yes +pidfile=/var/run/runsvdir.pid +command_args="-P $RC_SVCDIR/sv 'log: ...........................................................................................................................................................................................................................................................................................................................................................................................................'" + +start_pre() +{ + checkpath -m 0755 -o root:root -d ${RC_SVCDIR}/sv +} diff --git a/init.d/savecache b/init.d/savecache index f1877b2b..65bc05a8 100755 --- a/init.d/savecache +++ b/init.d/savecache @@ -49,7 +49,7 @@ start() fi ebegin "Saving dependency cache" local rc=0 save= - for x in deptree depconfig shutdowntime softlevel rc.log; do + for x in shutdowntime softlevel rc.log; do [ -e "$RC_SVCDIR/$x" ] && save="$save $RC_SVCDIR/$x" done if [ -n "$save" ]; then diff --git a/init.d/swap b/init.d/swap index 571ce2d3..0b0de870 100755 --- a/init.d/swap +++ b/init.d/swap @@ -19,7 +19,6 @@ start() { ebegin "Activating swap devices" case "$RC_UNAME" in - Linux) swapon -a -e >/dev/null;; NetBSD|OpenBSD) swapctl -A -t noblk >/dev/null;; *) swapon -a >/dev/null;; esac @@ -29,12 +28,6 @@ start() stop() { ebegin "Deactivating swap devices" - - # Try to unmount all tmpfs filesystems not in use, else a deadlock may - # occur. As $RC_SVCDIR may also be tmpfs we cd to it to lock it - cd "$RC_SVCDIR" - umount -a -t tmpfs 2>/dev/null - case "$RC_UNAME" in NetBSD|OpenBSD) swapctl -U -t noblk >/dev/null;; *) swapoff -a >/dev/null;; diff --git a/init.d/sysctl b/init.d/sysctl index a49afb51..c27248d5 100755 --- a/init.d/sysctl +++ b/init.d/sysctl @@ -15,12 +15,43 @@ depend() keyword -prefix -systemd-nspawn -vserver } -start() +BSD_sysctl() +{ + [ -e /etc/sysctl.conf ] || return 0 + local retval=0 var= comments= conf= + eindent + for conf in /etc/sysctl.conf /etc/sysctl.d/*.conf; do + if [ -r "$conf" ]; then + vebegin "applying $conf" + while read var comments; do + case "$var" in + ""|"#"*) continue;; + esac + sysctl -w "$var" >/dev/null || retval=1 + done < "$conf" + veend $retval + fi + done + eoutdent + return $retval +} + +Linux_sysctl() { local quiet yesno $rc_verbose || quiet=-q - ebegin "Configuring kernel parameters" sysctl ${quiet} --system - eend $? "Unable to configure some kernel parameters" +} + +start() +{ + local rc=0 + + ebegin "Configuring kernel parameters" + case "$RC_UNAME" in + *BSD|GNU) BSD_sysctl; rc=$? ;; + Linux) Linux_sysctl; rc=$? ;; + esac + eend $rc "Unable to configure some kernel parameters" } diff --git a/init.d/sysfs b/init.d/sysfs index ef7a388c..81b5c08a 100755 --- a/init.d/sysfs +++ b/init.d/sysfs @@ -15,6 +15,7 @@ sysfs_opts=nodev,noexec,nosuid depend() { + want modules keyword -docker -lxc -prefix -systemd-nspawn -vserver } @@ -97,17 +98,23 @@ mount_misc() fi fi - # setup up kernel support for efivarfs - # slightly complicated, as if it's build as a module but NOT yet loaded, - # it will NOT appear in /proc/filesystems yet - if [ -d /sys/firmware/efi/efivars ] \ - && ! mountinfo -q /sys/firmware/efi/efivars; then - modprobe -q efivarfs - if grep -qs efivarfs /proc/filesystems; then - ebegin "Mounting efivarfs filesystem" - mount -n -t efivarfs -o ${sysfs_opts} \ - efivarfs /sys/firmware/efi/efivars - eend $? + # set up kernel support for efivarfs + # The presence of /sys/firmware/efi indicates that the system was + # booted in efi mode. + if [ -d /sys/firmware/efi ]; then + if [ ! -d /sys/firmware/efi/efivars ] && + modprobe -q efivarfs; then + ewarn "The efivarfs module needs to be configured in " \ + "/etc/conf.d/modules or built in" + fi + if [ -d /sys/firmware/efi/efivars ] && + ! mountinfo -q /sys/firmware/efi/efivars; then + if grep -qs efivarfs /proc/filesystems; then + ebegin "Mounting efivarfs filesystem" + mount -n -t efivarfs -o ${sysfs_opts} \ + efivarfs /sys/firmware/efi/efivars + eend $? + fi fi fi } diff --git a/local.d/README b/local.d/README index 352847b4..068b7d98 100644 --- a/local.d/README +++ b/local.d/README @@ -8,7 +8,7 @@ service is stopped. All files are processed in lexical order. -Keep in mind that files in this directory are processed sequencially, +Keep in mind that files in this directory are processed sequentially, and the local service is not considered started or stopped until everything is processed, so if you have a process which takes a long time to run, it can delay your boot or shutdown processing. -- 2.39.5