From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1S3qpK-0002Bh-Us for garchives@archives.gentoo.org; Sat, 03 Mar 2012 15:24:55 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 3238AE05F2; Sat, 3 Mar 2012 15:24:48 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id DEE9AE05F2 for ; Sat, 3 Mar 2012 15:24:47 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 2951E1B402D for ; Sat, 3 Mar 2012 15:24:47 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id E01B6E542A for ; Sat, 3 Mar 2012 15:24:45 +0000 (UTC) From: "William Hubbs" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "William Hubbs" Message-ID: <1330788164.9fa54a8e8036262a7ea599d68e04fcbd8213506e.WilliamH@gentoo> Subject: [gentoo-commits] proj/openrc:master commit in: man/, sh/ X-VCS-Repository: proj/openrc X-VCS-Files: man/runscript.8 sh/runscript.sh.in X-VCS-Directories: man/ sh/ X-VCS-Committer: WilliamH X-VCS-Committer-Name: William Hubbs X-VCS-Revision: 9fa54a8e8036262a7ea599d68e04fcbd8213506e X-VCS-Branch: master Date: Sat, 3 Mar 2012 15:24:45 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: e50c9b10-bf6b-44e4-9c87-c4a556302410 X-Archives-Hash: 0665ec988ae21f9da107614695b9ae1a commit: 9fa54a8e8036262a7ea599d68e04fcbd8213506e Author: William Hubbs gentoo org> AuthorDate: Sat Mar 3 15:16:27 2012 +0000 Commit: William Hubbs gentoo org> CommitDate: Sat Mar 3 15:22:44 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/openrc.git;a=3D= commit;h=3D9fa54a8e 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 gentoo.org> X-Gentoo-Bug: 406713 X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=3D406713 --- man/runscript.8 | 3 ++- sh/runscript.sh.in | 35 +++++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/man/runscript.8 b/man/runscript.8 index 3b037ce..64f36b1 100644 --- a/man/runscript.8 +++ b/man/runscript.8 @@ -92,7 +92,8 @@ or stopping them. The following variables affect the service script: .Bl -tag -width "RC_DEFAULTLEVEL" .It Ar extra_commands -Space separated list of extra commands the service defines. +Space separated list of extra commands the service defines. These should +not depend on the service being stopped or started. .It Ar extra_started_commands Space separated list of extra commands the service defines. These only w= ork if the service has already been started. diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in index 83db42b..15cdb86 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. =20 +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" =3D "-e" ]; then @@ -24,18 +40,6 @@ if sourcex -e "/sbin/livecd-functions.sh"; then livecd_read_commandline fi =20 -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" =3D "$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" =3D "$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")" =3D "$1_pre" ] then "$1"_pre || exit $?