[arch-projects] [INITSCRIPTS][PATCH 1/3] rc.d: Add started/stopped option to list
This patch allow rc.d list started and rc.d list stopped which list respectively only started and stopped daemons Signed-off-by: Sebastien Luttringer <seblu@seblu.net> --- rc.d | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) diff --git a/rc.d b/rc.d index ad0a1e9..23f89d4 100755 --- a/rc.d +++ b/rc.d @@ -23,13 +23,16 @@ case $1 in usage ;; list) + shift cd /etc/rc.d/ for d in *; do have_daemon "$d" || continue # print running / stopped satus if ! ck_daemon "$d"; then + [[ "$1" == stopped ]] && continue printf "${C_OTHER}[${C_DONE}STARTED${C_OTHER}]" else + [[ "$1" == started ]] && continue printf "${C_OTHER}[${C_FAIL}STOPPED${C_OTHER}]" fi # print auto / manual status @@ -40,7 +43,7 @@ case $1 in fi printf " ${C_CLEAR}$d\n" done - ;; + ;; *) # check min args count (( $# < 2 )) && usage @@ -62,6 +65,7 @@ case $1 in fi (( ret += !! $? )) # clamp exit value to 0/1 done + ;; esac exit $ret -- Sebastien "Seblu" Luttringer
Signed-off-by: Sebastien Luttringer <seblu@seblu.net> --- rc.d | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-) diff --git a/rc.d b/rc.d index 23f89d4..f5dd652 100755 --- a/rc.d +++ b/rc.d @@ -6,9 +6,16 @@ usage() { local name=${0##*/} cat >&2 << EOF -usage: $name action daemon ... +usage: $name <action> <daemon> [daemon] ... + $name list [started|stopped] + $name help + +<daemon> is the name of a script in /etc/rc.d +<action> can be a start, stop, restart, reload, status, ... +WARNING: initscripts are free to implement or not the above actions. e.g: $name list + $name list started $name help $name start sshd gpm EOF -- Sebastien "Seblu" Luttringer
By default all script should be run as root. If NEED_ROOT=0 is set before loading /etc/rc.d/functions in a rc.d scripts, this will not apply. This allow script with only some part which require root level to call need_root() function at beginning of those parts. Close FS#24095 Signed-off-by: Sebastien Luttringer <seblu@seblu.net> --- functions | 10 ++++++++++ rc.d | 1 + 2 files changed, 11 insertions(+), 0 deletions(-) diff --git a/functions b/functions index adf4ea9..2ee56b4 100644 --- a/functions +++ b/functions @@ -394,5 +394,15 @@ for f in /etc/rc.d/functions.d/*; do [[ -e $f ]] && . "$f" done +# Exit current shell if user is not root +need_root() { + (( $EUID != 0 )) && printf 'You need to be root.\n' && exit 1 +} + +# Quit script if it's not running by root +# This can be disabled in scripts sourcing functions by setting NEED_ROOT=0 +# A local call to need_root can be done to ensure part of script need root privilege +(( ${NEED_ROOT:-1} == 1 )) && need_root + # End of file # vim: set ts=2 sw=2 noet: diff --git a/rc.d b/rc.d index f5dd652..6d9a9f7 100755 --- a/rc.d +++ b/rc.d @@ -1,5 +1,6 @@ #!/bin/bash +NEED_ROOT=0 # this script can be run without be root . /etc/rc.conf . /etc/rc.d/functions -- Sebastien "Seblu" Luttringer
participants (1)
-
Sebastien Luttringer