From 9fa54a8e8036262a7ea599d68e04fcbd8213506e Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Sat, 3 Mar 2012 09:16:27 -0600 Subject: Runscript: allow extra_commands to be run in chroots The commands defined in the extra_commands variable do not depend on whether the service is stopped or started, so it is valid to run them in chroot environments. Also, add a note to the runscript man page about the commands in extra_commands being able to run whether or not the service is started. Reported-by: Robin Johnson X-Gentoo-Bug: 406713 X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=406713 --- sh/runscript.sh.in | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) (limited to 'sh/runscript.sh.in') diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in index 83db42b1..15cdb868 100644 --- a/sh/runscript.sh.in +++ b/sh/runscript.sh.in @@ -4,6 +4,22 @@ # Copyright (c) 2007-2009 Roy Marples # Released under the 2-clause BSD license. +verify_boot() +{ + if [ ! -e ${RC_SVCDIR}/softlevel ]; then + eerror "You are attempting to run an openrc service on a" + eerror "system which openrc did not boot." + eerror "You may be inside a chroot or you may have used" + eerror "another initialization system to boot this system." + eerror "In this situation, you will get unpredictable results!" + eerror + eerror "If you really want to do this, issue the following command:" + eerror "touch ${RC_SVCDIR}/softlevel" + exit 1 + fi + return 0 +} + sourcex() { if [ "$1" = "-e" ]; then @@ -24,18 +40,6 @@ if sourcex -e "/sbin/livecd-functions.sh"; then livecd_read_commandline fi -if [ ! -e ${RC_SVCDIR}/softlevel ]; then - eerror "You are attempting to run an openrc service on a" - eerror "system which openrc did not boot." - eerror "You may be inside a chroot or you may have used" - eerror "another initialization system to boot this system." - eerror "In this situation, you will get unpredictable results!" - eerror - eerror "If you really want to do this, issue the following command:" - eerror "touch ${RC_SVCDIR}/softlevel" - exit 1 -fi - if [ -z "$1" -o -z "$2" ]; then eerror "$RC_SVCNAME: not enough arguments" exit 1 @@ -256,7 +260,7 @@ while [ -n "$1" ]; do # we can run this command for _cmd in $extra_started_commands; do if [ "$_cmd" = "$1" ]; then - if ! service_started; then + if verify_boot && ! service_started; then eerror "$RC_SVCNAME: cannot \`$1' as it has not been started" exit 1 fi @@ -266,13 +270,16 @@ while [ -n "$1" ]; do # we can run this command for _cmd in $extra_stopped_commands; do if [ "$_cmd" = "$1" ]; then - if ! service_stopped; then + if verify_boot && ! service_stopped; then eerror "$RC_SVCNAME: cannot \`$1' as it has not been stopped" exit 1 fi fi done unset _cmd + case $1 in + start|stop|status) verify_boot;; + esac if [ "$(command -v "$1_pre")" = "$1_pre" ] then "$1"_pre || exit $? -- cgit v1.2.3