Index: usr.sbin/bsdconfig/share/sysrc.subr =================================================================== --- usr.sbin/bsdconfig/share/sysrc.subr +++ usr.sbin/bsdconfig/share/sysrc.subr @@ -1,6 +1,6 @@ if [ ! "$_SYSRC_SUBR" ]; then _SYSRC_SUBR=1 # -# Copyright (c) 2006-2012 Devin Teske +# Copyright (c) 2006-2015 Devin Teske # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -204,6 +204,95 @@ ) } +# f_sysrc_service_configs [-a] $name [$var_to_set] +# +# Get a list of optional `rc.conf.d' entries sourced by system `rc.d' script +# $name (see rc.subr(8) for additional information on `rc.conf.d'). If $name +# exists in `/etc/rc.d' or $local_startup directories and is an rc(8) script +# the result is a space separated list of `rc.conf.d' entries sourced by the +# $name `rc.d' script. Otherwise, if $name exists as a binary `rc.d' script, +# the result is ``/etc/rc.conf.d/$name /usr/local/etc/rc.conf.d/$name''. The +# result is NULL if $name does not exist. +# +# If $var_to_set is missing or NULL, output is to standard out. Returns success +# if $name was found, failure otherwise. +# +# If `-a' flag is given and $var_to_set is non-NULL, append result to value of +# $var_to_set rather than overriding current contents. +# +# If `-p' flag is given and $var_to_set is non-NULL, prepend result to value of +# $var_to_set rather than overriding current contents. +# +# NB: The `-a' and `-p' option flags are mutually exclusive. +# +f_sysrc_service_configs() +{ + local OPTIND=1 OPTARG __flag __append= __prepend= __sname= + local __local_startup __dir __spath + local __stype __name __names= + + while getopts ap __flag; do + case "$__flag" in + a) __append=1 __prepend= ;; + p) __prepend=1 __append= ;; + esac + done + shift $(( $OPTIND - 1 )) + + [ $# -gt 0 ] || return $FAILURE + local __sname="$1" __var_to_set="$2" + + __local_startup=$( f_sysrc_get local_startup ) + for __dir in /etc/rc.d $__local_startup; do + __spath="$__dir/$__sname" + [ -f "$__spath" -a -x "$__spath" ] || __spath= continue + break + done + [ "$__spath" ] || return $FAILURE + + __stype=$( file -b "$__spath" 2> /dev/null ) + case "$__stype" in + *"shell script"*) + __names=$( exec 9<&1 1>&- 2>&- + last_name= + print_name() { + local name="$1" + [ "$name" = "$last_name" ] && return + echo "$name" >&9 + last_name="$name" + } + eval "$( awk '{ + gsub(/load_rc_config /, "print_name ") + gsub(/run_rc_command /, ": ") + print + }' "$__spath" )" + ) ;; + *) + __names="$__sname" + esac + + local __configs= + for __name in $__names; do + for dir in /etc/rc.d $__local_startup; do + __configs="$__configs ${__dir%/rc.d}/rc.conf.d/$__name" + done + done + __configs="${__configs# }" + + if [ "$__var_to_set" ]; then + local __cur= + [ "$__append" -o "$__prepend" ] && + f_getvar "$__var_to_set" __cur + [ "$__append" ] && __configs="$__cur${__cur:+ }$__configs" + [ "$__prepend" ] && __configs="$__configs${__cur:+ }$__cur" + setvar "$__var_to_set" "$__configs" + else + echo "$__configs" + fi + + return $SUCCESS +} + # f_sysrc_get_default $varname # # Get a system configuration default setting from the default rc.conf(5) file Index: usr.sbin/sysrc/sysrc =================================================================== --- usr.sbin/sysrc/sysrc +++ usr.sbin/sysrc/sysrc @@ -40,18 +40,21 @@ # # Version information # -SYSRC_VERSION="6.5 Sep-1,2015" +SYSRC_VERSION="7.0 Sep-1,2015" # # Options # CHECK_ONLY= +DEFAULT= DELETE= DESCRIBE= IGNORE_UNKNOWNS= JAIL= +LIST_CONFS= QUIET= ROOTDIR= +SERVICE= SHOW_ALL= SHOW_EQUALS= SHOW_FILE= @@ -129,12 +132,18 @@ "The jid or name of the jail to operate within (overrides" f_err "$optfmt" "" \ "\`-R dir'; requires jexec(8))." + f_err "$optfmt" "-l" \ + "Print list of configuration files to stdout and exit." f_err "$optfmt" "-n" \ "Show only variable values, not their names." f_err "$optfmt" "-N" \ "Show only variable names, not their values." f_err "$optfmt" "-q" \ "Quiet. Disable verbose and hide certain errors." + f_err "$optfmt" "-s name" \ + "Process additional \`rc.conf.d' entries for service name." + f_err "$optfmt" "" \ + "Ignored if \`-f file' is given." f_err "$optfmt" "-R dir" \ "Operate within the root directory \`dir' rather than \`/'." f_err "$optfmt" "-v" \ @@ -245,27 +254,31 @@ # # Process command-line flags # -while getopts aAcdDef:Fhij:nNqR:vxX flag; do +while getopts aAcdDef:Fhij:lnNqR:s:vxX flag; do case "$flag" in a) SHOW_ALL=${SHOW_ALL:-1} ;; A) SHOW_ALL=2 ;; c) CHECK_ONLY=1 ;; d) DESCRIBE=1 ;; - D) RC_CONFS= ;; + D) DEFAULT=1 RC_CONFS= ;; e) SHOW_EQUALS=1 ;; - f) RC_CONFS="$RC_CONFS${RC_CONFS:+ }$OPTARG" ;; + f) DEFAULT= RC_CONFS="$RC_CONFS${RC_CONFS:+ }$OPTARG" ;; F) SHOW_FILE=1 ;; h) usage ;; # NOTREACHED i) IGNORE_UNKNOWNS=1 ;; j) [ "$OPTARG" ] || die \ "%s: Missing or null argument to \`-j' flag" "$pgm" JAIL="$OPTARG" ;; + l) LIST_CONFS=1 ;; n) SHOW_NAME= ;; N) SHOW_VALUE= ;; q) QUIET=1 VERBOSE= ;; R) [ "$OPTARG" ] || die \ "%s: Missing or null argument to \`-R' flag" "$pgm" ROOTDIR="$OPTARG" ;; + s) [ "$OPTARG" ] || die \ + "%s: Missing or null argument to \`-s' flag" "$pgm" + SERVICE="$OPTARG" ;; v) VERBOSE=1 QUIET= ;; x) DELETE=${DELETE:-1} ;; X) DELETE=2 ;; @@ -275,6 +288,30 @@ shift $(( $OPTIND - 1 )) # +# Process `-s name' argument +# +if [ "$DEFAULT" -o ! "${RC_CONFS+set}" ] && + f_sysrc_service_configs "$SERVICE" RC_CONFS +then + if [ "$LIST_CONFS" -a ! "$DEFAULT" ]; then + rc_conf_files=$( f_sysrc_get rc_conf_files ) + RC_CONFS="$rc_conf_files${RC_CONFS:+ }$RC_CONFS" + fi +fi + +# +# Process `-l' option flags +# +if [ "$LIST_CONFS" ]; then + if [ "${RC_CONFS+set}" ]; then + echo "$RC_CONFS" + else + f_sysrc_get rc_conf_files + fi + exit $SUCCESS +fi + +# # [More] Sanity checks (e.g., "sysrc --") # [ $# -eq 0 -a ! "$SHOW_ALL" ] && usage # NOTREACHED @@ -344,6 +381,8 @@ $( [ "$SHOW_ALL" = "1" ] && echo \ -a ) $( [ "$SHOW_ALL" = "2" ] && echo \ -A ) ${CHECK_ONLY:+-c} + ${DEFAULT:+-D} + ${LIST_CONFS:+-l} ${DESCRIBE:+-d} ${SHOW_EQUALS:+-e} ${IGNORE_UNKNOWNS:+-i} @@ -351,6 +390,11 @@ $( [ "$SHOW_VALUE" ] || echo \ -N ) $( [ "$SHOW_FILE" ] && echo \ -F ) " + if [ "$SERVICE" ]; then + escape "$SERVICE" _SERVICE + args="$args -s '$_SERVICE'" + unset _SERVICE + fi if [ "${RC_CONFS+set}" ]; then escape "$RC_CONFS" _RC_CONFS args="$args -f '$_RC_CONFS'" @@ -455,9 +499,9 @@ # IFS="$IFS|" EXCEPT="IFS|EXCEPT|PATH|RC_DEFAULTS|OPTIND|DESCRIBE|SEP" - EXCEPT="$EXCEPT|DELETE|SHOW_ALL|SHOW_EQUALS|SHOW_NAME" - EXCEPT="$EXCEPT|SHOW_VALUE|SHOW_FILE|VERBOSE|RC_CONFS" - EXCEPT="$EXCEPT|pgm|SUCCESS|FAILURE|CHECK_ONLY" + EXCEPT="$EXCEPT|DELETE|SHOW_ALL|SHOW_EQUALS|SHOW_NAME|DEFAULT" + EXCEPT="$EXCEPT|SHOW_VALUE|SHOW_FILE|VERBOSE|RC_CONFS|SERVICE" + EXCEPT="$EXCEPT|pgm|SUCCESS|FAILURE|CHECK_ONLY|LIST_CONFS" EXCEPT="$EXCEPT|f_sysrc_desc_awk|f_sysrc_delete_awk" # Index: usr.sbin/sysrc/sysrc.8 =================================================================== --- usr.sbin/sysrc/sysrc.8 +++ usr.sbin/sysrc/sysrc.8 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd March 4, 2015 +.Dd September 1, 2015 .Dt SYSRC 8 .Os .Sh NAME @@ -32,13 +32,19 @@ .Nd safely edit system rc files .Sh SYNOPSIS .Nm +.Fl l +.Op Fl s Ar name Op Fl D +.Op Fl f Ar file +.Nm .Op Fl cdDeFhinNqvx +.Op Fl s Ar name .Op Fl f Ar file .Op Fl j Ar jail | Fl R Ar dir .Ar name Ns Op Ns Oo +|- Oc Ns = Ns Ar value .Ar ... .Nm .Op Fl cdDeFhinNqvx +.Op Fl s Ar name .Op Fl f Ar file .Op Fl j Ar jail | Fl R Ar dir .Fl a | A @@ -105,6 +111,8 @@ .Ar jail to operate within .Pq overrides So Fl R Ar dir Sc ; requires Xr jexec 8 . +.It Fl l +Print the list of configuration files to stdout and exit. .It Fl n Show only variable values, not their names. .It Fl N @@ -117,6 +125,33 @@ .Sq Ar dir rather than .Sq / . +.It Fl s Ar name +If an +.Li rc.d +script of +.Ar name +exists +.Po +in +.Dq /etc/rc.d +or +.Li local_startup +directories +.Pc , +process its +.Dq rc.conf.d +entries as potential overrides to +.Sq rc_conf_files . +See +.Xr rc.subr 8 +for additional information on +.Dq rc.conf.d . +Can be combined with +.Sq Fl l Fl D +to print a list of only +.Dq rc.conf.d +entries for +.Ar name . .It Fl v Verbose. Print the pathname of the specific @@ -406,18 +441,10 @@ .Nm \&'hostname:?' .Dl returns NULL and error status 2 if $hostname is unset or NULL Pq or if set and non-NULL, returns value without error status . -.Sh LIMITATIONS -The -.Nm -utility presently does not support the -.Ql rc.conf.d -collection of system configuration files -.Pq which requires a service name to be known during execution . -.Pp -This will be corrected by a future enhancement. .Sh SEE ALSO .Xr jls 1 , .Xr rc.conf 5 , +.Xr rc.subr 8 , .Xr jail 8 , .Xr jexec 8 , .Xr rc 8 ,