Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F142003547
D3551.id8702.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
9 KB
Referenced Files
None
Subscribers
None
D3551.id8702.diff
View Options
Index: usr.sbin/sysrc/sysrc
===================================================================
--- usr.sbin/sysrc/sysrc
+++ usr.sbin/sysrc/sysrc
@@ -40,18 +40,23 @@
#
# Version information
#
-SYSRC_VERSION="6.5 Sep-1,2015"
+SYSRC_VERSION="7.0 Sep-12,2015"
#
# Options
#
CHECK_ONLY=
+DEFAULT=
DELETE=
DESCRIBE=
+EXISTING_ONLY=
IGNORE_UNKNOWNS=
JAIL=
+LIST_SERVICE_CONFS=
+LIST_CONFS=
QUIET=
ROOTDIR=
+SERVICE=
SHOW_ALL=
SHOW_EQUALS=
SHOW_FILE=
@@ -80,7 +85,8 @@
#
usage()
{
- f_err "Usage: %s [OPTIONS] name[[+|-]=value] ...\n" "$pgm"
+ f_err "Usage: %s [OPTIONS] %s\n" "$pgm" \
+ "{name[[+|-]=value] ... | -a | -A | -l | -L [name ...]}"
f_err "Try \`%s --help' for more information.\n" "$pgm"
die
}
@@ -95,6 +101,8 @@
local envfmt="\t%-17s%s\n"
f_err "Usage: %s [OPTIONS] name[[+|-]=value] ...\n" "$pgm"
+ f_err "Usage: %s [OPTIONS] -a | -A\n" "$pgm"
+ f_err "Usage: %s [OPTIONS] -l | -L [name ...]\n" "$pgm"
f_err "OPTIONS:\n"
f_err "$optfmt" "-a" \
@@ -113,6 +121,8 @@
"Print query results as \`var=value' (useful for producing"
f_err "$optfmt" "" \
"output to be fed back in). Ignored if \`-n' is specified."
+ f_err "$optfmt" "-E" \
+ "Existing files only with \`-[lL]' or when changing a setting."
f_err "$optfmt" "-f file" \
"Operate on the specified file(s) instead of rc_conf_files."
f_err "$optfmt" "" \
@@ -129,12 +139,20 @@
"The jid or name of the jail to operate within (overrides"
f_err "$optfmt" "" \
"\`-R dir'; requires jexec(8))."
+ f_err "$optfmt" "-l" \
+ "List configuration files used at startup on stdout and exit."
+ f_err "$optfmt" "-L" \
+ "List all configuration files including rc.conf.d entries."
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 +263,33 @@
#
# Process command-line flags
#
-while getopts aAcdDef:Fhij:nNqR:vxX flag; do
+while getopts aAcdDeEf:Fhij:lLnNqR: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" ;;
+ E) EXISTING_ONLY=1 ;;
+ 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 ;;
+ L) LIST_SERVICE_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 +299,127 @@
shift $(( $OPTIND - 1 ))
#
+# Process `-L' flag
+#
+if [ "$LIST_SERVICE_CONFS" ]; then
+ list=
+
+ #
+ # List rc_conf_files if no service names given
+ #
+ files=
+ [ $# -eq 0 ] && files=$( f_sysrc_get rc_conf_files )
+ for file in $files; do
+ if [ "$EXISTING_ONLY" ]; then
+ [ -e "$file" -a ! -d "$file" ] || continue
+ fi
+ case "$list" in
+ "$file"|*" $file"|"$file "*|*" $file "*) continue ;;
+ esac
+ list="$list $file"
+ done
+ list="${list# }"
+ if [ $# -eq 0 ]; then
+ if [ "$VERBOSE" ]; then
+ echo rc_conf_files: $list
+ elif [ "$SHOW_EQUALS" ]; then
+ echo "rc_conf_files=\"$list\""
+ fi
+ fi
+
+ #
+ # List rc.conf.d entries
+ #
+ retval=$SUCCESS
+ for service in ${*:-$( service -l )}; do
+ slist=
+ f_sysrc_service_configs $service files || retval=$? continue
+ for file in $files; do
+ if [ "$EXISTING_ONLY" ]; then
+ [ -e "$file" -a ! -d "$file" ] || continue
+ fi
+ if [ ! "$VERBOSE" -a ! "$SHOW_EQUALS" ]; then
+ case "$list" in
+ "$file"|*" $file"|"$file "*|*" $file "*)
+ continue ;;
+ esac
+ fi
+ slist="$slist $file"
+ done
+ slist="${slist# }"
+ if [ $# -gt 0 ]; then
+ [ "$slist" ] || retval=$?
+ fi
+ if [ "$VERBOSE" ]; then
+ [ "$slist" ] && echo "$service: $slist"
+ continue
+ elif [ "$SHOW_EQUALS" ]; then
+ [ "$slist" ] && echo "$service=\"$slist\""
+ continue
+ fi
+ list="$list${slist:+ }$slist"
+ done
+ if [ ! "$VERBOSE" -a ! "$SHOW_EQUALS" ]; then
+ list="${list# }"
+ [ "$list" ] && echo $list
+ fi
+
+ exit $retval
+fi
+
+#
+# Process `-s name' argument
+#
+if [ "$SERVICE" -a ! "${RC_CONFS+set}" ]; then
+ if f_sysrc_service_configs "$SERVICE" RC_CONFS; then
+ rc_conf_files=$( f_sysrc_get rc_conf_files )
+ RC_CONFS="$rc_conf_files${RC_CONFS:+ }$RC_CONFS"
+ unset rc_conf_files
+ else
+ unset RC_CONFS
+ fi
+fi
+
+#
+# Process `-E' option flag
+#
+if [ "$EXISTING_ONLY" ]; then
+ #
+ # To get f_sysrc_*() to ignore missing rc_conf_files, we have to use
+ # RC_CONFS to override the unpreened value. If RC_CONFS already has a
+ # value (`-D', `-f file', `-s name', or inherited from parent), use it.
+ # Otherwise, include filtered contents of rc_conf_files.
+ #
+ RC_CONFS=$(
+ if [ "${RC_CONFS+set}" ]; then
+ set -- $RC_CONFS
+ else
+ set -- $( f_sysrc_get rc_conf_files )
+ fi
+ while [ $# -gt 0 ]; do
+ [ -f "$1" ] && echo -n " $1"
+ shift
+ done
+ )
+ RC_CONFS="${RC_CONFS# }"
+fi
+
+#
+# Process `-l' option flag
+#
+if [ "$LIST_CONFS" ]; then
+ [ $# -eq 0 ] || usage
+ if [ "$DEFAULT" ]; then
+ echo "$RC_DEFAULTS"
+ elif [ "${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 +489,10 @@
$( [ "$SHOW_ALL" = "1" ] && echo \ -a )
$( [ "$SHOW_ALL" = "2" ] && echo \ -A )
${CHECK_ONLY:+-c}
+ ${DEFAULT:+-D}
+ ${EXISTING_ONLY:+-E}
+ ${LIST_CONFS:+-l}
+ ${LIST_SERVICE_CONFS:+-L}
${DESCRIBE:+-d}
${SHOW_EQUALS:+-e}
${IGNORE_UNKNOWNS:+-i}
@@ -351,6 +500,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'"
@@ -454,9 +608,10 @@
#
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|EXISTING_ONLY"
+ EXCEPT="$EXCEPT|LIST_CONFS|LIST_SERVICE_CONFS"
EXCEPT="$EXCEPT|f_sysrc_desc_awk|f_sysrc_delete_awk"
#
@@ -479,7 +634,13 @@
# explicit value, modifying the default behavior of
# source_rc_confs().
#
- [ "${RC_CONFS+set}" ] && rc_conf_files="$RC_CONFS"
+ if [ "${RC_CONFS+set}" ]; then
+ [ "$SHOW_ALL" = "1" -a "$SERVICE" -a \
+ ! "$DEFAULT" ] || rc_conf_files=
+ rc_conf_files="$rc_conf_files $RC_CONFS"
+ rc_conf_files="${rc_conf_files# }"
+ rc_conf_files="${rc_conf_files% }"
+ fi
source_rc_confs
Index: usr.sbin/sysrc/sysrc.8
===================================================================
--- usr.sbin/sysrc/sysrc.8
+++ usr.sbin/sysrc/sysrc.8
@@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd September 2, 2015
+.Dd September 12, 2015
.Dt SYSRC 8
.Os
.Sh NAME
@@ -32,16 +32,27 @@
.Nd safely edit system rc files
.Sh SYNOPSIS
.Nm
-.Op Fl cdDeFhinNqvx
+.Op Fl cdDeEFhinNqvx
+.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 cdDeEFhinNqvx
+.Op Fl s Ar name
.Op Fl f Ar file
.Op Fl j Ar jail | Fl R Ar dir
.Fl a | A
+.Nm
+.Op Fl E
+.Op Fl s Ar name
+.Op Fl f Ar file
+.Fl l
+.Nm
+.Op Fl eEv
+.Fl L
+.Op Ar name ...
.Sh DESCRIPTION
The
.Nm
@@ -81,6 +92,13 @@
or
.Ql Fl F
is specified.
+.It Fl E
+When given
+.Sq Fl l
+or
+.Sq Fl L
+to list configuration files, only list those that exist.
+When changing a setting, prefer to modify existing files.
.It Fl f Ar file
Operate on the specified file(s) instead of the files obtained by reading the
.Sq rc_conf_files
@@ -105,6 +123,15 @@
.Ar jail
to operate within
.Pq overrides So Fl R Ar dir Sc ; requires Xr jexec 8 .
+.It Fl l
+List configuration files used at startup on stdout and exit.
+.It Fl L
+List all configuration files including rc.conf.d entries on stdout and exit.
+Can be combined with
+.Sq Fl v
+or
+.Sq Fl e
+to show service names.
.It Fl n
Show only variable values, not their names.
.It Fl N
@@ -117,6 +144,30 @@
.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
+to list configuration files used by service at startup.
.It Fl v
Verbose.
Print the pathname of the specific
@@ -336,6 +387,10 @@
.It Pa /etc/defaults/rc.conf
.It Pa /etc/rc.conf
.It Pa /etc/rc.conf.local
+.It Pa /etc/rc.conf.d/name
+.It Pa /etc/rc.conf.d/name/*
+.It Pa /usr/local/etc/rc.conf.d/name
+.It Pa /usr/local/etc/rc.conf.d/name/*
.El
.Sh EXAMPLES
Below are some simple examples of how
@@ -397,6 +452,7 @@
.Sh SEE ALSO
.Xr jls 1 ,
.Xr rc.conf 5 ,
+.Xr rc.subr 8 ,
.Xr jail 8 ,
.Xr jexec 8 ,
.Xr rc 8 ,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Jan 15, 6:48 PM (52 m, 10 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
27653972
Default Alt Text
D3551.id8702.diff (9 KB)
Attached To
Mode
D3551: sysrc: Add support for ``rc.conf.d'' service(8) configuration file(s)
Attached
Detach File
Event Timeline
Log In to Comment