diff options
author | Roy Marples <roy@marples.name> | 2007-11-23 12:04:11 +0000 |
---|---|---|
committer | Roy Marples <roy@marples.name> | 2007-11-23 12:04:11 +0000 |
commit | d81def80b00a3dbcb4f8980f4503c4d659b48a2a (patch) | |
tree | 64a5df4281620cacbc1f03838d42e88167886fc9 | |
parent | f077f179edaeb746b267421baa29ec751c38b713 (diff) |
Move /etc/conf.d/rc to /etc/rc.conf.
Lowercase all configurable variables, non configurations remain uppercase.
Replace rc_env_bool with rc_yesno.
Split localmount info procfs (Linux) and dumpon, savecore (BSD)
64 files changed, 755 insertions, 477 deletions
diff --git a/conf.d.BSD/moused b/conf.d.BSD/moused index 2a7584ab..a9edab16 100644 --- a/conf.d.BSD/moused +++ b/conf.d.BSD/moused @@ -2,14 +2,10 @@ # Set to your mouse device psm[0-9] for PS/2 ports, ums[0-9] for USB ports # Leave blank to try to autodetect it -MOUSED_DEVICE="" +#moused_device="/dev/psm0" # Any additional arguments required -MOUSED_ARGS="" - -# If 0xd0-0xd3 default range is occupied in your language code table, specify -# alternative range start like MOUSECHAR_START="3", see vidcontrol(1) -MOUSECHAR_START="" +moused_args="" # You can also multiplex the init script for each device like so # ln -s moused /etc/init.d/moused.ums0 diff --git a/conf.d.BSD/powerd b/conf.d.BSD/powerd index ef45e5a4..df5fb700 100644 --- a/conf.d.BSD/powerd +++ b/conf.d.BSD/powerd @@ -1,7 +1,7 @@ # Mode allowed: maximum, minimum, adaptive # Default unless specified is adaptive -AC_MODE="maximum" -#BATTERY_MODE="minimum" +powerd_ac_mode="maximum" +#powerd_battery_mode="minimum" -# Addiditonal arguments for powerd -POWERD_OPTS="" +# Addiditonal arguments for powerd - see the man page for details +powerd_args="" diff --git a/conf.d.BSD/rarpd b/conf.d.BSD/rarpd index 37643f5e..60d71a45 100644 --- a/conf.d.BSD/rarpd +++ b/conf.d.BSD/rarpd @@ -1,3 +1,3 @@ # To start rarpd only for a given interface, set the # following variable. Otherwise we listen on all interfaces. -#RARPD_INTERFACE="rl0" +#rarpd_interface="rl0" diff --git a/conf.d.BSD/syscons b/conf.d.BSD/syscons index 9be8e35f..cd012df6 100644 --- a/conf.d.BSD/syscons +++ b/conf.d.BSD/syscons @@ -4,16 +4,16 @@ # NOTE:- This will blank the screen after this command is run # NOTE:- You can get more modes if you load the vesa kernel module, but this # may require the SC_PIXEL_MODE kernel option -#MODE="VGA_80x30" +#allscreen_flags="VGA_80x30" # Set the keymap to "uk.iso". -#KEYMAP="uk.iso" +#keymap="uk.iso" # Set the keyboard rate to 250ms delay, and 34 repeat rate. -#KEYRATE="250.34" +#keyrate="250.34" # Change the behaviour of F-unction keys (see kbdcontrol(1)). -#KEYCHANGE="10 'ssh myhost'" +#keychange="10 'ssh myhost'" # See vidcontrol(1) -t -#BLANKTIME="off" +#blanktime="off" diff --git a/conf.d.Linux/Makefile b/conf.d.Linux/Makefile index 40cbc172..1ba5f09a 100644 --- a/conf.d.Linux/Makefile +++ b/conf.d.Linux/Makefile @@ -1,6 +1,6 @@ -DIR = /etc/conf.d -CONF = consolefont keymaps net.example -CONF_APPEND = clock rc +DIR = /etc/conf.d +CONF = consolefont keymaps net.example +CONF_APPEND = clock TOPDIR = .. include $(TOPDIR)/default.mk diff --git a/conf.d/bootmisc b/conf.d/bootmisc index 5bf7ecf5..3da2ecac 100644 --- a/conf.d/bootmisc +++ b/conf.d/bootmisc @@ -2,11 +2,11 @@ # Put a nologin file in /etc to prevent people from logging in before # system startup is complete -DELAYLOGIN="no" +delaylogin="no" # List of /tmp directories we should clean up -WIPE_TMP_DIRS="/tmp" +wipe_tmp_dirs="/tmp" # Should we wipe the tmp paths completely or just selectively remove known # locks / files / etc... ? -WIPE_TMP="yes" +wipe_tmp="yes" diff --git a/conf.d/checkfs b/conf.d/checkfs index 6b7e06e5..351c7470 100644 --- a/conf.d/checkfs +++ b/conf.d/checkfs @@ -1,7 +1,7 @@ -# FSCK_SHUTDOWN causes checkfs to trigger during shutdown as well as startup. +# fsck_shutdown causes checkfs to trigger during shutdown as well as startup. # The end result of this is that if any periodic non-root filesystem checks are # scheduled, under normal circumstances the actual check will happen during # shutdown rather than at next boot. # This is useful when periodic filesystem checks are causing undesirable # delays at startup, but such delays at shutdown are acceptable. -FSCK_SHUTDOWN="no" +fsck_shutdown="NO" diff --git a/conf.d/clock b/conf.d/clock index 579200ce..e055474c 100644 --- a/conf.d/clock +++ b/conf.d/clock @@ -4,16 +4,9 @@ # Greenwich Mean Time). If your clock is set to the local time, then # set CLOCK to "local". Note that if you dual boot with Windows, then # you should set it to "local". -CLOCK="UTC" +clock="UTC" # If you want to set the Hardware Clock to the current System Time -# during shutdown, then say "yes" here. +# during shutdown, then say "YES" here. # You normally don't need to do this if you run a ntp daemon. -CLOCK_SYSTOHC="no" - -# Select the proper timezone. For valid values, peek inside of the -# /usr/share/zoneinfo/ directory. For example, some common values are -# "America/New_York" or "EST5EDT" or "Europe/Berlin". If you want to -# manage /etc/localtime yourself, set this to "". -TIMEZONE="Factory" - +clock_systohc="NO" diff --git a/conf.d/hostname b/conf.d/hostname index f17fabd1..ebdc8f1b 100644 --- a/conf.d/hostname +++ b/conf.d/hostname @@ -1,2 +1,2 @@ # Set to the hostname of this machine -HOSTNAME="localhost" +hostname="localhost" diff --git a/conf.d/urandom b/conf.d/urandom index 52f43430..b4e9c99e 100644 --- a/conf.d/urandom +++ b/conf.d/urandom @@ -4,4 +4,4 @@ # (say for crypt swap), so you will need to customize this # behavior. If you have /var on a separate partition, then # make sure this path lives on your root device somewhere. -URANDOM_SEED="/var/run/random-seed" +urandom_seed="/var/run/random-seed" @@ -41,6 +41,7 @@ install:: install:: $(BIN) $(CONF) $(CONF_APPEND) if test -n "$(DIR)" ; then $(INSTALL) -d $(DESTDIR)$(DIR) || exit $$?; fi if test -n "$(BIN)" ; then $(INSTALL) $(BIN) $(DESTDIR)$(DIR) || exit $$?; fi + if test -n "$(INC)" ; then $(INSTALL) -m 0644 $(INC) $(DESTDIR)$(DIR) || exit $$?; fi for x in $(CONF); do \ if ! test -e $(DESTDIR)$(DIR)/$$x; then \ $(INSTALL) -m 0644 $$x $(DESTDIR)$(DIR) || exit $$?; \ diff --git a/etc.Linux/Makefile b/etc.Linux/Makefile index 1a4aa2a3..bd853760 100644 --- a/etc.Linux/Makefile +++ b/etc.Linux/Makefile @@ -1,5 +1,6 @@ -DIR = /etc -CONF = inittab +DIR = /etc +CONF = inittab +CONF_APPEND = rc TOPDIR = .. include $(TOPDIR)/default.mk diff --git a/conf.d.Linux/rc b/etc.Linux/rc.conf index 862f78ef..72ab631a 100644 --- a/conf.d.Linux/rc +++ b/etc.Linux/rc.conf @@ -4,16 +4,7 @@ # This is the number of tty's used in most of the rc-scripts (like # consolefont, numlock, etc ...) -RC_TTY_NUMBER=12 - -# RC_DOWN_INTERFACE allows you to specify if RC will bring the interface -# completely down when it stops. The default is yes, but there are some -# instances where you may not want this to happen such as using Wake On LAN. -RC_DOWN_INTERFACE="yes" - -# RC_DOWN_HARDDISK allows you to specify if RC will put harddisks to -# standby mode when it stops. -RC_DOWN_HARDDISK="yes" +rc_tty_number=12 # Use this variable to control the /dev management behavior. # auto - let the scripts figure out what's best at boot @@ -21,7 +12,7 @@ RC_DOWN_HARDDISK="yes" # mdev - use mdev (requires sys-apps/busybox) # udev - use udev (requires sys-fs/udev) # static - let the user manage /dev (YOU need to create ALL device nodes) -RC_DEVICES="auto" +rc_devices="auto" # UDEV OPTION: # Set to "yes" if you want to save /dev to a tarball on shutdown @@ -29,7 +20,6 @@ RC_DEVICES="auto" # custom device nodes that udev does not handle/know about. RC_DEVICE_TARBALL="no" -# RC_DMESG_LEVEL sets the level at which logging of messages is done to the +# Sets the level at which logging of messages is done to the # console. See dmesg(8) for more info. -RC_DMESG_LEVEL="1" - +dmesg_level="1" diff --git a/etc/Makefile b/etc/Makefile new file mode 100644 index 00000000..0b889a9c --- /dev/null +++ b/etc/Makefile @@ -0,0 +1,5 @@ +DIR = /etc +CONF = rc.conf + +TOPDIR = .. +include $(TOPDIR)/default.mk @@ -1,68 +1,59 @@ -# /etc/conf.d/rc: Global config file for OpenRC +# /etc/rc.conf: Global OpenRC configuration settings -# Set to "yes" if you want the rc system to try and start services +# Set to "YES" if you want the rc system to try and start services # in parallel for a slight speed improvement. When running in parallel we # prefix the service output with it's name as the output will get # jumbled up. -RC_PARALLEL="no" +rc_parallel="NO" -# Set RC_INTERACTIVE to "yes" and you'll be able to press the I key during -# boot so you can choose to start specific services. Set to "no" to disable +# Set rc_interactive to "YES" and you'll be able to press the I key during +# boot so you can choose to start specific services. Set to "NO" to disable # this feature. -RC_INTERACTIVE="yes" - -# RC_VERBOSE will make init scripts more verbose and adds -# "Service FOO starting/started/stopping/stopped" messages around each -# init script. -RC_VERBOSE="no" - -# RC_QUIET on the other hand will make init scripts quiet and produce no -# output. -RC_QUIET="no" +rc_interactive="YES" # Do we allow any started service in the runlevel to satisfy the depedency # or do we want all of them regardless of state? For example, if net.eth0 -# and net.eth1 are in the default runlevel then with RC_DEPEND_STRICT="no" +# and net.eth1 are in the default runlevel then with rc_depend_strict="NO" # both will be started, but services that depend on 'net' will work if either -# one comes up. With RC_DEPEND_STRICT="yes" we would require them both to +# one comes up. With rc_depend_strict="YES" we would require them both to # come up. -RC_DEPEND_STRICT="yes" +rc_depend_strict="YES" -# Do we allow services to be hotplugged? If not, set to RC_HOTPLUG="no" +# Do we allow services to be hotplugged? If not, set to rc_hotplug="NO" # NOTE: This does not affect anything hotplug/udev/devd related, just the # starting/stopping of the init.d service triggered by it. -RC_HOTPLUG="yes" +rc_hotplug="YES" # Dynamic /dev managers can trigger coldplug events which cause services to # start before we are ready for them. If this happens, we can defer these -# services to start in the boot runlevel. Set RC_COLDPLUG="no" if you don't +# services to start in the boot runlevel. Set rc_coldplug="NO" if you don't # want this. # NOTE: This also affects module coldplugging in udev-096 and higher # If you want module coldplugging but not coldplugging of services then you -# can set RC_COLDPLUG="yes" and RC_PLUG_SERVICES="!*" -RC_COLDPLUG="yes" +# can set rc_coldplug="YES" and rc_plug_services="!*" +rc_coldplug="YES" -# Some people want a finer grain over hotplug/coldplug. RC_PLUG_SERVICES is a +# Some people want a finer grain over hotplug/coldplug. rc_plug_services is a # list of services that are matched in order, either allowing or not. By -# default we allow services through as RC_COLDPLUG/RC_HOTPLUG has to be yes +# default we allow services through as rc_coldplug/rc_hotplug has to be YES # anyway. -# Example - RC_PLUG_SERVICES="net.wlan !net.*" +# Example - rc_plug_services="net.wlan !net.*" # This allows net.wlan and any service not matching net.* to be plugged. -RC_PLUG_SERVICES="" +rc_plug_services="" # Define network fstypes. Below is the default. -#RC_NET_FS_LIST="afs cifs coda davfs fuse gfs ncpfs nfs nfs4 ocfs2 shfs smbfs" +net_fs_list="afs cifs coda davfs fuse gfs ncpfs nfs nfs4 ocfs2 shfs smbfs" -# RC_FORCE_AUTO tries its best to prevent user interaction during the boot and +# rc_force_auto tries its best to prevent user interaction during the boot and # shutdown process. For example, fsck will automatically be run or volumes # remounted to create proper directory trees. This feature can be dangerous # and is meant ONLY for headless machines where getting a physical console # hooked up is a huge pita. -RC_FORCE_AUTO="no" +rc_force_auto="NO" -# RC_LOGGER launches a logging daemon to log the entire rc process to +# rc_logger launches a logging daemon to log the entire rc process to # /var/log/rc.log -RC_LOGGER="no" +rc_logger="NO" ############################################################################## # SERVICE CONFIGURATION VARIABLES @@ -75,11 +66,11 @@ RC_LOGGER="no" #export SSD_NICELEVEL="-19" # Pass ulimit parameters -#RC_ULIMIT="-u 30" +#rc_ulimit="-u 30" # It's possible to define extra dependencies for services like so -#RC_CONFIG="/etc/foo" -#RC_NEED="openvpn" -#RC_USE="net.eth0" -#RC_AFTER="clock" -#RC_BEFORE="local" +#rc_config="/etc/foo" +#rc_need="openvpn" +#rc_use="net.eth0" +#rc_after="clock" +#rc_before="local" diff --git a/init.d.BSD/clock b/init.d.BSD/clock index 99e92733..3bb51b77 100755 --- a/init.d.BSD/clock +++ b/init.d.BSD/clock @@ -29,19 +29,24 @@ extra_commands="save" description="Sets the local clock to UTC or Local Time." description_save="Saves the current time in the BIOS." +clock=${clock:-${CLOCK:-UTC}} +if [ "${clock}" = "UTC" ]; then + utc="UTC" +else + utc="Local Time" +fi + depend() { # BSD adjkerntz needs to be able to write to /etc - if [ "${CLOCK}" = "UTC" -a -e /etc/wall_cmos_clock ] || - [ "${CLOCK}" != "UTC" -a ! -e /etc/wall_cmos_clock ] ; then + if [ "${clock}" = "UTC" -a -e /etc/wall_cmos_clock ] || + [ "${clock}" != "UTC" -a ! -e /etc/wall_cmos_clock ]; then need checkroot fi } start() { - local TBLURB="Local Time" - [ "${CLOCK}" = "UTC" ] && TBLURB="UTC" - ebegin "Starting the System Clock Adjuster [${TBLURB}]" - if [ "${CLOCK}" != "UTC" ] ; then + ebegin "Starting the System Clock Adjuster [${utc}]" + if [ "${clock}" != "UTC" ]; then echo >/etc/wall_cmos_clock start-stop-daemon --start --exec /sbin/adjkerntz -- -i else @@ -52,16 +57,16 @@ start() { } save() { - local TBLURB="Local Time" - [ "${CLOCK}" = "UTC" ] && TBLURB="UTC" - ebegin "Setting hardware clock using the system clock" "[${TBLURB}]" + ebegin "Setting hardware clock using the system clock [${utc}]" adjkerntz -a eend $? } stop() { # Don't tweak the hardware clock on LiveCD halt. - [ -z "${CDBOOT}" -a "${CLOCK_SYSTOHC}" = "yes" ] && save + if yesno "${clock_systohc:-${CLOCK_SYSTOHC}}"; then + [ -z "${CDBOOT}" ] && save + fi ebegin "Stopping the System Clock Adjuster" if start-stop-daemon --test --quiet --stop --exec /sbin/adjkerntz ; then diff --git a/init.d.BSD/dumpon b/init.d.BSD/dumpon new file mode 100755 index 00000000..1faf23b1 --- /dev/null +++ b/init.d.BSD/dumpon @@ -0,0 +1,47 @@ +#!/sbin/runscript +# Copyright 1999-2007 Gentoo Foundation +# Copyright 2007 Roy Marples +# All rights reserved + +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. + +description="Configures a specific kernel dump device." + +depend() { + need swap + before savecore +} + +start() { + # Setup any user requested dump device + if [ -n "${dump_device}" ] ; then + ebegin "Activating kernel core dump device (${dump_device})" + dumpon ${dump_device} + eend $? + fi +} + +stop() { + ebegin "Deactiving kernel core dump device" + dumpon off + eend $? +} diff --git a/init.d.BSD/ipfw b/init.d.BSD/ipfw index f5dfa775..cdddfaeb 100644 --- a/init.d.BSD/ipfw +++ b/init.d.BSD/ipfw @@ -25,9 +25,9 @@ # This is based on /etc/rc.firewall and /etc/rc.firewall6 from FreeBSD -IP_IN=${IP_IN-any} -PORTS_IN=${PORTS_IN-auth ssh} -PORTS_NOLOG=${PORTS_NOLOG-135-139,445 1026,1027 1433,1434} +ipfw_ip_in=${ipfw_ip_in-any} +ipfw_ports_in=${ipfw_ports_in-auth ssh} +ipfw_ports_nolog=${ipfw_ports_nolog-135-139,445 1026,1027 1433,1434} opts="panic showstatus" @@ -105,8 +105,8 @@ start() { # Add permits for this workstations published services below # Only IPs and nets in firewall_allowservices is allowed in. - for i in ${IP_IN}; do - for p in ${PORTS_IN}; do + for i in ${ipfw_ip_in}; do + for p in ${ipfw_ports_in}; do ipfw add pass tcp from ${i} to me ${p} done done @@ -114,14 +114,14 @@ start() { # Allow all connections from trusted IPs. # Playing with the content of firewall_trusted could seriously # degrade the level of protection provided by the firewall. - for i in ${IP_TRUST}; do + for i in ${ipfw_ip_trust}; do ipfw add pass ip from ${i} to me done ipfw add 65000 count ip from any to any # Drop packets to ports where we don't want logging - for p in ${PORTS_NOLOG}; do + for p in ${ipfw_ports_nolog}; do ipfw add deny { tcp or udp } from any to any ${p} in done @@ -138,7 +138,7 @@ start() { ipfw add deny tcp from any 80,443 to any 1024-65535 in # Deny and (if wanted) log the rest unconditionally. - if [ "${LOG_DENY}" = "yes" ]; then + if yesno ${ipfw_log_deny:-no}; then log="log" sysctl net.inet.ip.fw.verbose=1 >/dev/null fi diff --git a/init.d.BSD/moused b/init.d.BSD/moused index 2fb36261..70b0f0cf 100644 --- a/init.d.BSD/moused +++ b/init.d.BSD/moused @@ -23,14 +23,15 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. -name=${SVCNAME##*.} -if [ -n "${name}" -a "${name}" != "moused" ] ; then - device=/dev/"${name}" - pidfile=/var/run/moused-"${name}".pid +mouse=${SVCNAME##*.} +if [ -n "${name}" -a "${mouse}" != "moused" ] ; then + moused_device=/dev/"${mouse}" + pidfile=/var/run/moused-"${mouse}".pid else - name= pidfile=/var/run/moused.pid fi +name="Console Mouse Daemon" +[ -n "${moused_device}" ] && name="${name} (${moused_device})" depend() { need localmount @@ -38,45 +39,38 @@ depend() { } start() { - ebegin "Starting the Console Mouse Daemon" "${name}" + ebegin "Starting ${name}" - if [ -z "${device}" ] ; then + if [ -z "${moused_device}" ] ; then local dev= for dev in /dev/psm[0-9]* /dev/ums[0-9]* ; do [ -e "${dev}" ] || continue [ -e /var/run/moused-$(basename "${dev}").pid ] && continue - device=${dev} + moused_device=${dev} eindent - einfo "Using mouse on ${device}" + einfo "Using mouse on ${moused_device}" eoutdent break done fi - if [ -z "${device}" ] ; then + if [ -z "${moused_device}" ] ; then eend 1 "No mouse device found" return 1 fi start-stop-daemon --start --exec /usr/sbin/moused \ --pidfile "${pidfile}" \ - -- ${MOUSED_ARGS} -p "${device}" -I "${pidfile}" + -- ${moused_args} -p "${moused_device}" -I "${pidfile}" local retval=$? - [ -n "${MOUSE_CHAR_START}" ] && MOUSE_CHAR_START="-M ${MOUSE_CHAR_START}" local ttyv= for ttyv in /dev/ttyv*; do - vidcontrol < "${ttyv}" ${MOUSE_CHAR_START} -m on + vidcontrol < "${ttyv}" -m on : $((retval+= $?)) done eend ${retval} "Failed to start moused" } -stop() { - ebegin "Stopping the Console Mouse Daemon ${name}" - start-stop-daemon --quiet --stop --pidfile "${pidfile}" - eend $? "Failed to stop moused" -} - # vim: set ts=4 : diff --git a/init.d.BSD/powerd b/init.d.BSD/powerd index a97e2e02..c7886942 100644 --- a/init.d.BSD/powerd +++ b/init.d.BSD/powerd @@ -25,7 +25,7 @@ # SUCH DAMAGE. command=/usr/sbin/powerd -command_args=${POWERD_ARGS} +command_args=${powerd_args} pidfile=/var/run/powerd.pid name="Power Control Daemon" @@ -36,10 +36,19 @@ depend() { } start_pre() { - if [ -n "${BATTERY_MODE}" ]; then - command_args="${command_args} -b ${BATTERY_MODE}" + if [ -n "${powerd_battery_mode}" ]; then + command_args="${command_args} -b ${powerd_battery_mode}" fi - if [ -n "${AC_MODE}" ]; then - command_args="${command_args} -a ${AC_MODE}" + if [ -n "${powerd_ac_mode}" ]; then + command_args="${command_args} -a ${powerd_ac_mode}" + fi +} + +stop_post() +{ + local level=$(sysctl -n dev.cpu.0.freq_levels | + sed -e 's:/.*::') + if [ -n "${level}" ]; then + sysctl dev.cpu.0.freq="${level}" >/dev/null fi } diff --git a/init.d.BSD/rarpd b/init.d.BSD/rarpd index e054d56c..16ed6de6 100644 --- a/init.d.BSD/rarpd +++ b/init.d.BSD/rarpd @@ -25,14 +25,15 @@ # SUCH DAMAGE. command=/usr/sbin/rarpd -command_args="-f ${RARPD_ARGS}" +command_args="-f ${rarpd_args}" pidfile=/var/run/rarpd.pid name="Reverse ARP Daemon" +required_files="/etc/ethers" -if [ -z "${RARPD_INTERFACE}" ]; then +if [ -z "${rarpd_interface}" ]; then command_args="${command_args} -a" else - command_args="${command_args} ${RARPD_INTERFACE}" + command_args="${command_args} ${rarpd_interface}" fi command_background="YES" @@ -40,9 +41,9 @@ depend() { need localmount after bootmisc - if [ -z "${RARPD_INTERFACE}" ]; then + if [ -z "${rarpd_interface}" ]; then need net else - net net."${RARPD_INTERFACE}" + net net."${rarpd_interface}" fi } diff --git a/init.d.BSD/rc-enabled b/init.d.BSD/rc-enabled index 9ab95d5e..a43680cc 100644 --- a/init.d.BSD/rc-enabled +++ b/init.d.BSD/rc-enabled @@ -25,7 +25,8 @@ depend() { need localmount net - after $(ls -1 | grep -v local | xargs) + after * + before local } start() { diff --git a/init.d.BSD/rpcbind b/init.d.BSD/rpcbind index 403d0959..8a5299a9 100644 --- a/init.d.BSD/rpcbind +++ b/init.d.BSD/rpcbind @@ -25,7 +25,7 @@ # SUCH DAMAGE. command=/usr/sbin/rpcbind -command_args=${RPCBIND_ARGS} +command_args=${rpcbind_args} name="RPC program number mapper" depend() { diff --git a/init.d.BSD/savecore b/init.d.BSD/savecore new file mode 100755 index 00000000..8d8577f9 --- /dev/null +++ b/init.d.BSD/savecore @@ -0,0 +1,56 @@ +#!/sbin/runscript +# Copyright 1999-2007 Gentoo Foundation +# Copyright 2007 Roy Marples +# All rights reserved + +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. + +description="Saves a kernel dump." + +depend() { + need checkfs + before swap +} + +start() { + local dump_dir=${dump_dir:-/var/crash} + if ! [ -d "${dump_dir}" ]; then + mkdir -p "${dump_dir}" + chmod 700 "${dump_dir}" + fi + + if [ "${RC_UNAME}" = "FreeBSD" ] ; then + # Don't quote ${dump_device}, so that if it's unset, + # savecore will check on the partitions listed in fstab + # without errors in the output + savecore -C "${dump_dir}" ${dump_device} >/dev/null + else + ls "${dump_dir}"/bsd* > /dev/null 2>&1 + fi + [ $? = 0 ] || return 0 + + local sopts="${dump_dir} ${dump_device}" + yesno ${dump_compress} && sopts="-z ${sopts}" + ebegin "Saving kernel core dump in ${dump_dir}" + savecore ${sopts} >/dev/null + eend $? +} diff --git a/init.d.BSD/syscons b/init.d.BSD/syscons index 5fc0e7ce..ae174f3b 100644 --- a/init.d.BSD/syscons +++ b/init.d.BSD/syscons @@ -28,30 +28,29 @@ depend() { } start() { - if [ -n "${MODE}" ]; then - ebegin "Setting mode to ${MODE} for all screens" + if [ -n "${allscreen_flags}" ]; then + ebegin "Setting mode to ${allscreen_flags} for all screens" for v in /dev/ttyv*; do - [ -c "${v}" ] || continue - vidcontrol "${MODE}" <"${v}" + vidcontrol ${allscreen_flags} <"${v}" done eend $? fi - if [ -n "${KEYMAP}" ]; then - ebegin "Setting keymap to ${KEYMAP}" - kbdcontrol -l ${KEYMAP} </dev/console + if [ -n "${keymap}" ]; then + ebegin "Setting keymap to ${keymap}" + kbdcontrol -l ${keymap} </dev/console eend $? fi - if [ -n "${KEYRATE}" ]; then - ebegin "Setting keyrate to ${KEYRATE}" - kbdcontrol -r ${KEYRATE} </dev/console + if [ -n "${keyrate}" ]; then + ebegin "Setting keyrate to ${keyrate}" + kbdcontrol -r ${keyrate} </dev/console eend $? fi - if [ -n "${KEYCHANGE}" ]; then + if [ -n "${keychange}" ]; then ebegin "Changing function keys" - eval set -- "${KEYCHANGE}" + eval set -- "${keychange}" eindent while [ $# -gt 0 ] ; do veinfo "F$1 -> \`$2'" @@ -62,14 +61,14 @@ start() { eoutdent fi - if [ -n "${CURSOR}" ]; then + if [ -n "${cursor}" ]; then ebegin "Setting cursor" - vidcontrol -c ${CURSOR} + vidcontrol -c ${cursor} eend $? fi local v= f= - for v in FONT8x16 FONT8x14 FONT8x8; do + for v in font8x16 font8x14 font8x8; do f=$(eval \$"${v}") if [ -n "${f}" ]; then ebegin "Setting font ${f}" @@ -78,25 +77,24 @@ start() { fi done - if [ -n "${BLANKTIME}" ]; then + if [ -n "${blanktime}" ]; then ebegin "Setting blanktime" - vidcontrol -t ${BLANKTIME} + vidcontrol -t ${blanktime} eend $? fi - if [ -n "${SAVER}" ]; then + if [ -n "${saver}" ]; then local i= for i in $(kldstat | sed -n -e 's/.* \(splash_.*\)/\1/p'); do kldunload "${i}" done - kldstat -v | grep -q _saver || kldload ${SAVER}_saver + kldstat -v | grep -q _saver || kldload ${saver}_saver fi - if [ -n "${KBDFLAGS}" ]; then + if [ -n "${kbdflags}" ]; then ebegin "Setting keyboard flags for all screens" for v in /dev/ttyv*; do - [ -c "${v}" ] || continue - kbdcontrol ${KBDFLAGS} <"${v}" + kbdcontrol ${kbdflags} <${v} done eend $? fi diff --git a/init.d.BSD/syslogd b/init.d.BSD/syslogd index c0e57e11..d9a131ad 100644 --- a/init.d.BSD/syslogd +++ b/init.d.BSD/syslogd @@ -25,7 +25,7 @@ # SUCH DAMAGE. command=/usr/sbin/syslogd -command_args=${SYSLOGD_ARGS} +command_args=${syslogd_args} pidfile=/var/run/syslog.pid name="System Logger Daemon" diff --git a/init.d.Linux/procfs b/init.d.Linux/procfs new file mode 100644 index 00000000..95190bbd --- /dev/null +++ b/init.d.Linux/procfs @@ -0,0 +1,108 @@ +#!/sbin/runscript +# Copyright 1999-2007 Gentoo Foundation +# Copyright 2007 Roy Marples +# All rights reserved + +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. + +description="Mounts misc filesystems in /proc." + +depend() { + need checkfs +} + +start() { + # Make sure we insert usbcore if its a module + if [ -f /proc/modules -a ! -d /proc/bus/usb ]; then + modprobe -q usbcore + fi + + [ -e /proc/filesystems ] || return 0 + + # Check what USB fs the kernel support. Currently + # 2.5+ kernels, and later 2.4 kernels have 'usbfs', + # while older kernels have 'usbdevfs'. + if [ -d /proc/bus/usb -a ! -e /proc/bus/usb/devices ]; then + local usbfs=$(grep -Fow usbfs /proc/filesystems || + grep -Fow usbdevfs /proc/filesystems) + if [ -n "${usbfs}" ] ; then + ebegin "Mounting USB device filesystem (${usbfs})" + local usbgid="$(getent group usb | \ + sed -e 's/.*:.*:\(.*\):.*/\1/')" + mount -t ${usbfs} \ + -o ${usbgid:+devmode=0664,devgid=${usbgid},}noexec,nosuid \ + usbfs /proc/bus/usb + eend $? + fi + fi + + # Setup Kernel Support for the NFS daemon status + if [ -d /proc/fs/nfsd ] && ! mountinfo -q /proc/fs/nfsd ; then + if grep -qs nfsd /proc/filesystems ; then + ebegin "Mounting nfsd filesystem" + mount -t nfsd -o nodev,noexec,nosuid \ + nfsd /proc/fs/nfsd + eend $? + fi + fi + + # Setup Kernel Support for miscellaneous Binary Formats + if [ -d /proc/sys/fs/binfmt_misc ] && ! mountinfo -q /proc/sys/fs/binfmt_misc ; then + if grep -qs binfmt_misc /proc/filesystems ; then + ebegin "Mounting misc binary format filesystem" + mount -t binfmt_misc -o nodev,noexec,nosuid \ + binfmt_misc /proc/sys/fs/binfmt_misc + eend $? + fi + fi + + # Setup Kernel Support for securityfs + if [ -d /sys/kernel/security ] && ! mountinfo -q /sys/kernel/security ; then + if grep -qs securityfs /proc/filesystems ; then + ebegin "Mounting security filesystem" + mount -t securityfs securityfs /sys/kernel/security \ + -o nodev,noexec,nosuid + eend $? + fi + fi + + # Setup Kernel Support for debugfs + if [ -d /sys/kernel/debug ] && ! mountinfo -q /sys/kernel/debug ; then + if grep -qs debugfs /proc/filesystems ; then + ebegin "Mounting debug filesystem" + mount -t debugfs debugfs /sys/kernel/debug \ + -o nodev,noexec,nosuid + eend $? + fi + fi + + # Setup Kernel Support for SELinux + if [ -d /selinux ] && ! mountinfo -q /selinux ; then + if grep -qs selinuxfs /proc/filesystems ; then + ebegin "Mounting SELinux filesystem" + mount -t selinuxfs selinuxfs /selinux + eend $? + fi + fi + + return 0 +} diff --git a/init.d.misc/Makefile b/init.d.misc/Makefile new file mode 100644 index 00000000..c50e550a --- /dev/null +++ b/init.d.misc/Makefile @@ -0,0 +1,5 @@ +DIR = /etc/init.d +BIN = $(CONTENTS) + +TOPDIR = .. +include $(TOPDIR)/default.mk diff --git a/init.d.misc/named b/init.d.misc/named new file mode 100644 index 00000000..4b2a1175 --- /dev/null +++ b/init.d.misc/named @@ -0,0 +1,116 @@ +#!/sbin/runscript +# Copyright 2007 Roy Marples +# All rights reserved + +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. + +command=/usr/sbin/named +command_args=${named_args} +pidfile=/var/run/named/pid +name="Domain Name server" +extra_commands="reload" + +namedb=/etc/namedb +named_uid=${named_uid:-bind} + +depend() { + provide dns + need localmount + after bootmisc +} + +start_pre() { + if [ -n "${named_chroot}" ]; then + # Create (or update) the chroot directory structure + if [ -r /etc/mtree/BIND.chroot.dist ]; then + mtree -deU -f /etc/mtree/BIND.chroot.dist -p "${named_chroot}" + else + ewarn "/etc/mtree/BIND.chroot.dist missing," + ewarn "chroot directory structure not updated" + fi + + if [ ! -d "${named_chroot}"/. ]; then + eerror "chroot directory ${named_chroot} missing" + exit 1 + fi + + # Create /etc/namedb symlink + if [ ! -L "${namedb}" ]; then + if [ -d "${namedb}" ]; then + ewarn "named chroot: ${namedb} is a directory!" + elif [ -e "${namedb}" ]; then + ewarn "named chroot: ${namedb} exists!" + else + ln -s "${named_chroot}${namedb}" "${namedb}" + fi + else + # Make sure it points to the right place. + ln -shf "${named_chroot}${namedb}" "${namedb}" + fi + + case "${RC_UNAME}" in + *BSD|DragonFly) + # Mount a devfs in the chroot directory if needed + umount "${named_chroot}"/dev 2>/dev/null + mount -t devfs dev "${named_chroot}"/dev + devfs -m "${named_chroot}"/dev ruleset devfsrules_hide_all + devfs -m "${named_chroot}"/dev rule apply path null unhide + devfs -m "${named_chroot}"/dev rule apply path random unhide + ;; + esac + + # Copy local timezone information if it is not up to date. + if [ -r /etc/localtime ]; then + cmp -s /etc/localtime "${named_chroot}/etc/localtime" || + cp -p /etc/localtime "${named_chroot}/etc/localtime" + fi + + command_args="${command_args} -t ${named_chroot}" + + ln -fs "${named_chroot}${pidfile}" "${pidfile}" + fi + + if [ ! -s "${named_chroot}${namedb}/rndc.conf" ]; then + local confgen="${command%/named}/rndc-confgen -a -b256 -u ${named_uid} \ + -c ${named_chrootdir}/etc/namedb/rndc.key" + if [ -s "${named_chroot}${namedb}/rndc.key" ]; then + local getuser="stat -f%Su" + [ "${RC_UNAME}" = "Linux" ] && getuser="stat -c%U" + case $(${getuser} "${named_chroot}${namedb}"/rndc.key) in + root|"${named_uid}") ;; + *) ${confgen} ;; + esac + else + ${confgen} + fi + fi +} + +reload() { + rndc reload +} + +stop_post() { + if [ -n "${named_chroot}" -a -c "${named_chroot}"/dev/null ]; then + umount "${named_chroot}"/dev 2>/dev/null || true + fi +} diff --git a/init.d.misc/ntpd b/init.d.misc/ntpd new file mode 100644 index 00000000..000bf366 --- /dev/null +++ b/init.d.misc/ntpd @@ -0,0 +1,59 @@ +#!/sbin/runscript +# Copyright 2007 Roy Marples +# All rights reserved + +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. + +ntpd_config=${ntpd_config:-/etc/ntp.conf} +ntpd_drift=${ntpd_drift:-/var/db/ntpd.drift} + +command=/usr/sbin/ntpd +pidfile=/var/run/ntpd.pid +command_args="${ntpd_args} -c ${ntpd_config} -f ${ntpd_drift} -p ${pidfile}" +name="Network Time Protocol Daemon" + +depend() { + use dns + need localmount + after bootmisc ntp-client +} + +start_pre() { + if [ ! -r "${ntpd_config}" ]; then + eerror "${ntpd_config} is not readable" + exit 1 + fi + + if [ -n "${ntpd_chroot}" ]; then + case "${RC_UNAME}" in + *BSD|DragonFly) + if [ ! -c "${ntpd_chroot}/dev/clockctl" ]; then + rm -f "${ntpd_chroot}/dev/clockctl" + (cd /dev; /bin/pax -rw -pe clockctl "${ntpd_chroot}/dev") + fi + ;; + esac + ln -fs "${ntpd_chroot}${ntpd_drift}" "${ntpd_drift}" + + command_args="${command_args} -u ntpd:ntpd -i ${ntpd_chroot}" + fi +} diff --git a/init.d/bootmisc b/init.d/bootmisc index 8ea4e878..3ac53a22 100755 --- a/init.d/bootmisc +++ b/init.d/bootmisc @@ -36,7 +36,7 @@ cleanup_tmp_dir() { mkdir -p "${dir}" cd "${dir}" - if [ "${WIPE_TMP}" = "yes" ]; then + if [ "${wipe_tmp}" = "yes" ]; then ebegin "Wiping ${dir} directory" local startopts="-x . -depth" [ "${RC_UNAME}" = "Linux" ] && startopts=". -xdev -depth" @@ -116,7 +116,7 @@ start() { # Clean up /tmp directories local tmp= - for tmp in ${WIPE_TMP_DIRS-/tmp}; do + for tmp in ${wipe_tmp_dirs-/tmp}; do cleanup_tmp_dir "${tmp}" done chmod +t /tmp /var/tmp diff --git a/init.d/checkfs b/init.d/checkfs index c7cbc9c7..c5b8728c 100755 --- a/init.d/checkfs +++ b/init.d/checkfs @@ -63,7 +63,7 @@ do_checkfs() { ewend 1 "Operational error, continuing" retval=0 else - if [ "${RC_FORCE_AUTO}" = "yes" ] ; then + if yesno ${rc_force_auto:-${RC_FORCE_AUTO}}; then eend 2 "Fsck could not correct all errors, rerunning" fsck ${opts} -y ${parts} retval=$? @@ -87,7 +87,9 @@ start() { stop() { # fsck on shutdown if we need to - [ "${FSCK_SHUTDOWN}" = "yes" -a ! -f /forcefsck ] && do_checkfs + if yesno "${fsck_shutdown:-${FSCK_SHUTDOWN}}"; then + [ ! -f /forcefsck ] && do_checkfs + fi return 0 } diff --git a/init.d/checkroot b/init.d/checkroot index 3592191e..fb313b07 100755 --- a/init.d/checkroot +++ b/init.d/checkroot @@ -100,7 +100,7 @@ do_fsck() { retval=0 elif [ ${retval} -eq 2 -o ${retval} -eq 3 ] ; then ewend 1 "Filesystem repaired, but reboot needed!" - if [ "${RC_FORCE_AUTO}" != "yes" ] ; then + if ! yesno ${rc_force_auto:-${RC_FORCE_AUTO}}; then printf "\a"; sleep 1; printf "\a"; sleep 1 printf "\a"; sleep 1; printf "\a"; sleep 1 ewarn "Rebooting in 10 seconds ..." @@ -109,7 +109,7 @@ do_fsck() { einfo "Rebooting" reboot -f else - if [ "${RC_FORCE_AUTO}" = "yes" ] ; then + if yesno ${rc_force_auto:-${RC_FORCE_AUTO}}; then eend 2 "Rerunning fsck in force mode" fsck ${opts} -y "${root}" retval=$? @@ -128,7 +128,6 @@ do_fsck() { reboot -f fi fi - } start() { diff --git a/init.d/halt.sh b/init.d/halt.sh index 34e81fdb..fb82db1c 100755 --- a/init.d/halt.sh +++ b/init.d/halt.sh @@ -26,6 +26,7 @@ . /etc/init.d/functions.sh . "${RC_LIBDIR}"/sh/rc-functions.sh +[ -r /etc/rc.conf ] && . /etc/rc.conf # Support LiveCD foo if [ -r /sbin/livecd-functions.sh ] ; then @@ -43,12 +44,12 @@ if [ -x /sbin/killall5 ] ; then fi # Flush all pending disk writes now -sync ; sync +sync; sync # If we are in a VPS, we don't need anything below here, because # 1) we don't need (and by default can't) umount anything (VServer) or # 2) the host utils take care of all umounting stuff (OpenVZ) -if [ "${RC_SYS}" = "VPS" ] ; then +if [ "${RC_SYS}" = "VPS" ]; then if [ -e /etc/init.d/"$1".sh ] ; then . /etc/init.d/"$1".sh else @@ -93,7 +94,7 @@ if [ "${RC_UNAME}" = "Linux" ] ; then . "${RC_LIBDIR}"/sh/rc-mount.sh eindent fs= - for x in ${RC_NET_FS_LIST} ; do + for x in ${net_fs_list} ; do fs="${fs}${fs:+|}${x}" done [ -n "${fs}" ] && fs="^(${fs})$" diff --git a/init.d/hostname b/init.d/hostname index 3f6b0569..688c0421 100755 --- a/init.d/hostname +++ b/init.d/hostname @@ -31,13 +31,9 @@ depend() { } start() { - if [ -f /etc/hostname ] ; then - ewarn "You should stop using /etc/hostname and use /etc/conf.d/hostname" - HOSTNAME=$(cat /etc/hostname) - fi - - ebegin "Setting hostname to ${HOSTNAME}" - hostname "${HOSTNAME}" + hostname=${hostname-${HOSTNAME-localhost}} + ebegin "Setting hostname to ${hostname}" + hostname "${hostname}" eend $? "Failed to set the hostname" } diff --git a/init.d/localmount b/init.d/localmount index 3f8ce423..9823820c 100755 --- a/init.d/localmount +++ b/init.d/localmount @@ -25,8 +25,6 @@ # SUCH DAMAGE. description="Mounts disks and swap according to /etc/fstab." -[ -e /proc/filessystems ] && description="${description} Also mounts various filesystems in /proc." -[ -x /sbin/dumpon ] && description="${description} Also configures saving kernel dumps to swap." depend() { need checkfs @@ -35,7 +33,7 @@ depend() { start() { # Mount local filesystems in /etc/fstab. local types="noproc" x= - for x in ${RC_NET_FS_LIST} ; do + for x in ${net_fs_list}; do types="${types},${x}" done @@ -43,122 +41,6 @@ start() { mount -at "${types}" eend $? "Some local filesystem failed to mount" - if [ -x /sbin/savecore ] ; then - local dumpdir=${KERNEL_DUMP_DIR:-/var/crash} - if ! [ -d "${dumpdir}" ]; then - mkdir -p "${dumpdir}" - chmod 700 "${dumpdir}" - fi - - if [ "${RC_UNAME}" = "FreeBSD" ] ; then - # Don't quote ${KERNEL_DUMP_DEVICE}, so that if it's unset, - # savecore will check on the partitions listed in fstab - # without errors in the output - savecore -C "${dumpdir}" ${KERNEL_DUMP_DEVICE} >/dev/null - else - ls "${dumpdir}"/bsd* > /dev/null 2>&1 - fi - if [ $? = 0 ] ; then - local sopts="${dumpdir} ${KERNEL_DUMP_DEVICE}" - [ "${KERNEL_DUMP_COMPRESS}" = "yes" ] && sopts="-z ${sopts}" - ebegin "Saving kernel core dump in" "${dumpdir}" - savecore ${savecoreopts} >/dev/null - eend $? - fi - fi - - # Sync bootlog now as /var should be mounted - if type bootlog >/dev/null 2>/dev/null ; then - bootlog sync 2>/dev/null - fi - - # Make sure we insert usbcore if its a module - if [ -f /proc/modules -a ! -d /proc/bus/usb ] ; then - modprobe -q usbcore - fi - - if [ -e /proc/filesystems ] ; then - # Check what USB fs the kernel support. Currently - # 2.5+ kernels, and later 2.4 kernels have 'usbfs', - # while older kernels have 'usbdevfs'. - if [ -d /proc/bus/usb -a ! -e /proc/bus/usb/devices ] ; then - local usbfs=$(grep -Fow usbfs /proc/filesystems || - grep -Fow usbdevfs /proc/filesystems) - - if [ -n "${usbfs}" ] ; then - ebegin "Mounting USB device filesystem (${usbfs})" - local usbgid="$(getent group usb | \ - sed -e 's/.*:.*:\(.*\):.*/\1/')" - mount -t ${usbfs} \ - -o ${usbgid:+devmode=0664,devgid=${usbgid},}noexec,nosuid \ - usbfs /proc/bus/usb - eend $? - fi - fi - - # Setup Kernel Support for the NFS daemon status - if [ -d /proc/fs/nfsd ] && ! mountinfo -q /proc/fs/nfsd ; then - if grep -qs nfsd /proc/filesystems ; then - ebegin "Mounting nfsd filesystem" - mount -t nfsd -o nodev,noexec,nosuid \ - nfsd /proc/fs/nfsd - eend $? - fi - fi - - # Setup Kernel Support for miscellaneous Binary Formats - if [ -d /proc/sys/fs/binfmt_misc ] && ! mountinfo -q /proc/sys/fs/binfmt_misc ; then - if grep -qs binfmt_misc /proc/filesystems ; then - ebegin "Mounting misc binary format filesystem" - mount -t binfmt_misc -o nodev,noexec,nosuid \ - binfmt_misc /proc/sys/fs/binfmt_misc - eend $? - fi - fi - - # Setup Kernel Support for securityfs - if [ -d /sys/kernel/security ] && ! mountinfo -q /sys/kernel/security ; then - if grep -qs securityfs /proc/filesystems ; then - ebegin "Mounting security filesystem" - mount -t securityfs securityfs /sys/kernel/security \ - -o nodev,noexec,nosuid - eend $? - fi - fi - - # Setup Kernel Support for debugfs - if [ -d /sys/kernel/debug ] && ! mountinfo -q /sys/kernel/debug ; then - if grep -qs debugfs /proc/filesystems ; then - ebegin "Mounting debug filesystem" - mount -t debugfs debugfs /sys/kernel/debug \ - -o nodev,noexec,nosuid - eend $? - fi - fi - - # Setup Kernel Support for SELinux - if [ -d /selinux ] && ! mountinfo -q /selinux ; then - if grep -qs selinuxfs /proc/filesystems ; then - ebegin "Mounting SELinux filesystem" - mount -t selinuxfs selinuxfs /selinux - eend $? - fi - fi - fi - - # We do our swapping here instead of rc so we can get urandom started - # before us for people that like an encrypted swap. - ebegin "Activating (possible) swap" - swapon -a >/dev/null - eend 0 # If swapon has nothing todo it errors, so always return 0 - - # Setup any user requested dump device - if [ -x /sbin/dumpon -a -n "${KERNEL_DUMP_DEVICE}" ] ; then - ebegin "Activating kernel core dump device" "(${KERNEL_DUMP_DEVICE})" - dumpon "${KERNEL_DUMP_DEVICE}" - eend $? - fi - # Always return 0 - some local mounts may not be critical for boot return 0 } @@ -170,12 +52,10 @@ stop() { # We never unmount / or /dev or $RC_SVCDIR local x= no_umounts="/|/dev|/dev/.*|${RC_SVCDIR}" - # NO_UMOUNTS is taken from /etc/conf.d/localmount - # RC_NO_UMOUNTS is taken from /etc/conf.d/rc and can also be - # set by plugins + # RC_NO_UMOUNTS is an env var that can be set by plugins OIFS=${IFS} SIFS=${IFS-y} IFS=$IFS: - for x in ${NO_UMOUNTS} ${RC_NO_UMOUNTS} ; do + for x in ${no_umounts} ${RC_NO_UMOUNTS}; do no_umounts="${no_umounts}|${x}" done if [ "${SIFS}" = "y" ] ; then @@ -184,13 +64,13 @@ stop() { unset IFS fi - if [ "${RC_UNAME}" = "Linux" ] ; then + if [ "${RC_UNAME}" = "Linux" ]; then no_umounts="${no_umounts}|/proc|/proc/.*|/sys|/sys/.*" fi no_umounts="^(${no_umounts})$" # Flush all pending disk writes now - sync ; sync + sync; sync # Try to unmount all tmpfs filesystems not in use, else a deadlock may # occure, bug #13599. @@ -198,22 +78,6 @@ stop() { cd "${RC_SVCDIR}" umount -a -t tmpfs 2>/dev/null - # As we're turning off swap below, we need to disable kernel dumps - [ -x /sbin/dumpon ] && dumpon off - - local swap_list= - # Turn off swap - if [ -r /proc/swaps ] ;then - swap_list=$(sed -e '1d' /proc/swaps) - else - swap_list=$(swapctl -l 2>/dev/null | sed -e '1d') - fi - if [ -n "${swap_list}" ] ; then - ebegin "Deactivating swap" - swapoff -a >/dev/null - eend $? - fi - . "${RC_LIBDIR}"/sh/rc-mount.sh # Umount loopback devices @@ -228,7 +92,7 @@ stop() { einfo "Unmounting filesystems" eindent local fs= - for x in ${RC_NET_FS_LIST} ; do + for x in ${net_fs_list}; do fs="${fs}${fs:+|}${x}" done [ -n "${fs}" ] && fs="^(${fs})$" diff --git a/init.d/netmount b/init.d/netmount index f1603289..8742f9e0 100755 --- a/init.d/netmount +++ b/init.d/netmount @@ -59,7 +59,7 @@ start() { [ -x /etc/init.d/rpcbind ] && pmap="rpcbind" local x= fs= - for x in ${RC_NET_FS_LIST}; do + for x in ${net_fs_list}; do case "${x}" in nfs|nfs4) # If the nfsmount script took care of the nfs filesystems, @@ -89,7 +89,7 @@ stop() { ebegin "Unmounting network filesystems" . "${RC_LIBDIR}/sh/rc-mount.sh" - for x in ${RC_NET_FS_LIST} ; do + for x in ${net_fs_list} ; do fs="${fs}${fs:+,}${x}" done if [ -n "${fs}" ]; then @@ -98,7 +98,7 @@ stop() { eindent fs= - for x in ${RC_NET_FS_LIST}; do + for x in ${net_fs_list}; do fs="${fs}${fs:+|}${x}" done [ -n "${fs}" ] && fs="^(${fs})$" diff --git a/init.d/swap b/init.d/swap new file mode 100644 index 00000000..afd0bd34 --- /dev/null +++ b/init.d/swap @@ -0,0 +1,40 @@ +#!/sbin/runscript +# Copyright 2007 Roy Marples +# All rights reserved + +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. + +depend() { + need localmount +} + +start() { + ebegin "Activating swap" + swapon -a >/dev/null + eend 0 # If swapon has nothing todo it errors, so always return 0 +} + +stop() { + ebegin "Deactivating swap" + swapoff -a >/dev/null + eend 0 +} diff --git a/init.d/urandom b/init.d/urandom index c5e41d03..9a03068b 100755 --- a/init.d/urandom +++ b/init.d/urandom @@ -24,7 +24,7 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. -URANDOM_SEED=${URANDOM_SEED:-/var/run/random-seed} +urandom_seed=${urandom_seed:-${URANDOM_SEED:-/var/run/random-seed}} description="Initializes the random number generator." @@ -41,22 +41,19 @@ save_seed() { ( # sub shell to prevent umask pollution umask 077 - dd if=/dev/urandom of="${URANDOM_SEED}" count=${poolsize} 2>/dev/null + dd if=/dev/urandom of="${urandom_seed}" count=${poolsize} 2>/dev/null ) } start() { [ -c /dev/urandom ] || return - if [ -f "${URANDOM_SEED}" ] ; then - cat "${URANDOM_SEED}" > /dev/urandom + if [ -f "${urandom_seed}" ] ; then + ebegin "Initializing random number generator" + cat "${urandom_seed}" > /dev/urandom + eend $? "Error initializing random number generator" fi - if ! rm -f "${URANDOM_SEED}" ; then - ewarn "Skipping ${URANDOM_SEED} initialization (ro root?)" - return 0 - fi - ebegin "Initializing random number generator" - save_seed - eend $? "Error initializing random number generator" + rm -f "${urandom_seed}" && save_seed + return 0 } stop() { diff --git a/runlevels.BSD/Makefile b/runlevels.BSD/Makefile index 51ccbdc7..da525074 100644 --- a/runlevels.BSD/Makefile +++ b/runlevels.BSD/Makefile @@ -1,4 +1,4 @@ -BOOT = net.lo0 syscons +BOOT = dumpon net.lo0 savecore syscons DEFAULT = local.rc powerd syslogd TOPDIR = .. diff --git a/runlevels.Linux/Makefile b/runlevels.Linux/Makefile index 4a73e7b9..73a0acbe 100644 --- a/runlevels.Linux/Makefile +++ b/runlevels.Linux/Makefile @@ -1,4 +1,4 @@ -BOOT = consolefont keymaps modules net.lo +BOOT = consolefont keymaps modules net.lo procfs DEFAULT = hdparm TOPDIR = .. diff --git a/runlevels/Makefile b/runlevels/Makefile index feb7e452..f46c55da 100644 --- a/runlevels/Makefile +++ b/runlevels/Makefile @@ -1,4 +1,4 @@ -BOOT = bootmisc checkroot checkfs clock hostname localmount rmnologin sysctl urandom +BOOT = bootmisc checkroot checkfs clock hostname localmount rmnologin swap sysctl urandom DEFAULT = local netmount LEVELDIR = $(DESTDIR)/etc/runlevels diff --git a/sh.BSD/init.sh b/sh.BSD/init.sh index 090991ec..3a9ad815 100755 --- a/sh.BSD/init.sh +++ b/sh.BSD/init.sh @@ -47,7 +47,7 @@ mount_svcdir() { cp -p "${RC_SVCDIR}"/deptree "${RC_SVCDIR}"/depconfig \ "${RC_SVCDIR}"/nettree "${RC_LIBDIR}"/tmp 2>/dev/null fi - try mdconfig -a -t malloc -s "${RC_SVCSIZE:-1024}"k -u 0 + try mdconfig -a -t malloc -s "${rc_svcsize:-1024}"k -u 0 try newfs -b 4096 -i 1024 -n /dev/md0 try mount -o rw,noexec,nosuid /dev/md0 "${RC_SVCDIR}" if ${dotmp} ; then @@ -60,6 +60,7 @@ mount_svcdir() { . "${RC_LIBDIR}"/sh/init-functions.sh . "${RC_LIBDIR}"/sh/functions.sh +[ -r /etc/rc.conf ] && . /etc/rc.conf # Disable devd until we need it [ "${RC_UNAME}" = "FreeBSD" ] && sysctl hw.bus.devctl_disable=1 >/dev/null diff --git a/sh.Linux/init.sh b/sh.Linux/init.sh index 03e90386..84545b66 100755 --- a/sh.Linux/init.sh +++ b/sh.Linux/init.sh @@ -66,8 +66,8 @@ mount_svcdir() { devtmp="/dev/ram1" fs="ext2" for x in ${devdir} ${devtmp}; do - try dd if=/dev/zero of="${x}" bs=1k count="${svcsize}" - try mkfs -t "${fs}" -i 1024 -vm0 "${x}" "${svcsize}" + try dd if=/dev/zero of="${x}" bs=1k count="${rc_svcsize:-1024}" + try mkfs -t "${fs}" -i 1024 -vm0 "${x}" "${rc_svcsize:-1024}" done else echo @@ -99,12 +99,12 @@ mount_svcdir() { fi } -_RC_GET_KV_CACHE="" +_rc_get_kv_cache="" get_KV() { - [ -z "${_RC_GET_KV_CACHE}" ] \ + [ -z "${_rc_get_kv_cache}" ] \ && _RC_GET_KV_CACHE="$(uname -r)" - echo "$(KV_to_int "${_RC_GET_KV_CACHE}")" + echo "$(KV_to_int "${_rc_get_kv_cache}")" return $? } @@ -112,12 +112,13 @@ get_KV() { . /etc/init.d/functions.sh . "${RC_LIBDIR}"/sh/init-functions.sh . "${RC_LIBDIR}"/sh/rc-functions.sh +[ -r /etc/rc.conf ] && . /etc/rc.conf # Set the console loglevel to 1 for a cleaner boot # the logger should anyhow dump the ring-0 buffer at start to the # logs, and that with dmesg can be used to check for problems -if [ -n "${RC_DMESG_LEVEL}" -a "${RC_SYS}" != "VPS" ]; then - dmesg -n "${RC_DMESG_LEVEL}" +if [ -n "${dmesg_level}" -a "${RC_SYS}" != "VPS" ]; then + dmesg -n "${dmesg_level}" fi check_statedir /proc @@ -192,14 +193,14 @@ fi # - check boot parameters # - make sure the required binaries exist # - make sure the kernel has support -if [ "${RC_DEVICES}" = "static" -o "${RC_SYS}" = "VPS" ]; then +if [ "${rc_devices}" = "static" -o "${RC_SYS}" = "VPS" ]; then ebegin "Using existing device nodes in /dev" eend 0 elif [ "${RC_UNAME}" = "GNU/kFreeBSD" ]; then ebegin "Using kFreeBSD devfs in /dev" eend 0 else - case ${RC_DEVICES} in + case ${rc_devices} in devfs) managers="devfs udev mdev";; udev) managers="udev devfs mdev";; mdev) managers="mdev udev devfs";; @@ -235,7 +236,7 @@ for x in "devpts /dev/pts 0755 ,gid=5,mode=0620" "tmpfs /dev/shm 1777 ,nodev"; d mountinfo -q "$2" && continue if [ ! -d "$2" ] && \ - [ "${devfs}" = "yes" -o "${udev}" = "yes" ]; then + [ "${m}" = "devfs" -o "${m}" = "udev" ]; then mkdir -m "$3" -p "$2" >/dev/null 2>/dev/null || \ ewarn "Could not create $2!" fi diff --git a/sh/Makefile b/sh/Makefile index af610ca7..c76d622c 100644 --- a/sh/Makefile +++ b/sh/Makefile @@ -1,7 +1,7 @@ -DIR = $(RC_LIB)/sh -CONF = functions.sh init-functions.sh init-common-post.sh \ - rc-functions.sh rc-mount.sh -BIN = gendepends.sh net.sh rc-mount.sh rc-help.sh runscript.sh +DIR = $(RC_LIB)/sh +INC = functions.sh init-functions.sh init-common-post.sh \ + rc-functions.sh rc-mount.sh +BIN = gendepends.sh net.sh rc-mount.sh rc-help.sh runscript.sh TOPDIR = .. include $(TOPDIR)/default.mk diff --git a/sh/gendepends.sh b/sh/gendepends.sh index 6f93e7c3..12db5a02 100755 --- a/sh/gendepends.sh +++ b/sh/gendepends.sh @@ -77,12 +77,12 @@ for SVCNAME in * ; do depend # Add any user defined depends - config ${RC_CONFIG} - need ${RC_NEED} - use ${RC_USE} - before ${RC_BEFORE} - after ${RC_AFTER} - provide ${RC_PROVIDE} + config ${rc_config} ${RC_CONFIG} + need ${rc_need} ${RC_NEED} + use ${rc_use} ${RC_USE} + before ${rc_before} ${RC_BEFORE} + after ${rc_after} ${RC_AFTER} + provide ${rc_provide} ${RC_PROVIDE} fi ) done diff --git a/sh/init-functions.sh b/sh/init-functions.sh index ced84897..400a82b4 100644 --- a/sh/init-functions.sh +++ b/sh/init-functions.sh @@ -63,9 +63,13 @@ check_statedir() { #splash "critical" & echo eerror "To function properly, \"$1\" needs to exist." - if yesno ${RC_FORCE_AUTO}; then + if yesno ${rc_force_auto:-${RC_FORCE_AUTO}}; then eerror "Attempting to create \"$1\" for you ..." - mount -o remount,rw / + if [ "${RC_UNAME}" = "Linux" ]; then + mount -o remount,rw / + else + mount -u -o rw / + fi mkdir -p "$1" fi if [ ! -d "$1" ] ; then diff --git a/sh/rc-functions.sh b/sh/rc-functions.sh index a346796f..571a0cf1 100755 --- a/sh/rc-functions.sh +++ b/sh/rc-functions.sh @@ -45,6 +45,7 @@ stop_addon() { ( import_addon "$1-stop" ) } +net_fs_list="afs cifs coda davfs fuse gfs ncpfs nfs nfs4 ocfs2 shfs smbfs" is_net_fs() { [ -z "$1" ] && return 1 @@ -54,7 +55,7 @@ is_net_fs() { # Fall back on fs types local t=$(mountinfo --fstype "$1") - for x in ${RC_NET_FS_LIST}; do + for x in ${net_fs_list}; do [ "${x}" = "${t}" ] && return 0 done return 1 diff --git a/sh/rc-help.sh b/sh/rc-help.sh index 45f939f0..a7177485 100755 --- a/sh/rc-help.sh +++ b/sh/rc-help.sh @@ -146,7 +146,7 @@ if yesno ${BE_VERBOSE}; then printf " ${CYAN}Dependencies:${OFF} - This is the heart of the Gentoo RC-Scripts, as it determines the order + This is the heart of the OpenRC, as it determines the order in which services gets started, and also to some extend what services get started in the first place. @@ -252,9 +252,7 @@ printf " " fi -printf " /etc/conf.d/rc - /etc/conf.d/rc.\${RC_SOFTLEVEL} - /etc/conf.d/${SERVICE} +printf " /etc/conf.d/${SERVICE} /etc/conf.d/${SERVICE}.\${RC_SOFTLEVEL} /etc/rc.conf \${RC_SOFTLEVEL} denotes the name of the runlevel" @@ -263,8 +261,8 @@ if yesno ${BE_VERBOSE}; then printf " You can add extra dependencies to ${SERVICE} by adding some variables to /etc/conf.d/${SERVICE} - RC_NEED=\"openvpn ntpd\" - RC_USE=\"dns\" + rc_need=\"openvpn ntpd\" + rc_use=\"dns\" This makes ${SERVICE} need openvpn and ntpd, while it just uses dns. diff --git a/sh/runscript.sh b/sh/runscript.sh index 5ba1004d..78433e87 100755 --- a/sh/runscript.sh +++ b/sh/runscript.sh @@ -59,18 +59,18 @@ describe() { done } -yesno ${RC_DEBUG} && set -x +yesno ${rc_debug} && set -x # If we're net.eth0 or openvpn.work then load net or openvpn config -rc_c=${SVCNAME%%.*} -if [ -n "${rc_c}" -a "${rc_c}" != "${SVCNAME}" ]; then - if [ -e "/etc/conf.d/${rc_c}.${RC_SOFTLEVEL}" ]; then - . "/etc/conf.d/${rc_c}.${RC_SOFTLEVEL}" - elif [ -e "/etc/conf.d/${rc_c}" ]; then - . "/etc/conf.d/${rc_c}" +_c=${SVCNAME%%.*} +if [ -n "${_c}" -a "${_c}" != "${SVCNAME}" ]; then + if [ -e "/etc/conf.d/${_c}.${RC_SOFTLEVEL}" ]; then + . "/etc/conf.d/${_c}.${RC_SOFTLEVEL}" + elif [ -e "/etc/conf.d/${_c}" ]; then + . "/etc/conf.d/${_c}" fi fi -unset rc_c +unset _c # Overlay with our specific config if [ -e "/etc/conf.d/${SVCNAME}.${RC_SOFTLEVEL}" ]; then @@ -83,7 +83,7 @@ fi [ -e /etc/rc.conf ] && . /etc/rc.conf # Apply any ulimit defined -[ -n "${RC_ULIMIT}" ] && ulimit ${RC_ULIMIT} +[ -n "${rc_ulimit:-${RC_ULIMIT}}" ] && ulimit ${rc_ulimit:-${RC_ULIMIT}} # Load our script . $1 @@ -128,10 +128,10 @@ fi while [ -n "$1" ]; do # See if we have the required function and run it - for rc_x in describe start stop ${extra_commands:-${opts}}; do - if [ "${rc_x}" = "$1" ]; then + for _cmd in describe start stop ${extra_commands:-${opts}}; do + if [ "${_cmd}" = "$1" ]; then if type "$1" >/dev/null 2>&1; then - unset rc_x + unset _cmd if type "$1"_pre >/dev/null 2>&1; then "$1"_pre || exit $? fi @@ -142,7 +142,7 @@ while [ -n "$1" ]; do shift continue 2 else - if [ "${rc_x}" = "start" -o "${rc_x}" = "stop" ]; then + if [ "${_cmd}" = "start" -o "${_cmd}" = "stop" ]; then exit 0 else eerror "${SVCNAME}: function \`$1' defined but does not exist" diff --git a/src/fstabinfo.c b/src/fstabinfo.c index 495f311e..ffb42a1f 100644 --- a/src/fstabinfo.c +++ b/src/fstabinfo.c @@ -205,7 +205,7 @@ int fstabinfo (int argc, char **argv) } /* No point in outputting if quiet */ - if (rc_env_bool ("RC_QUIET")) + if (rc_yesno (getenv ("RC_QUIET"))) continue; switch (output) { diff --git a/src/librc-misc.c b/src/librc-misc.c index d63dc182..a8c9f33d 100644 --- a/src/librc-misc.c +++ b/src/librc-misc.c @@ -32,33 +32,28 @@ #include "librc.h" -bool rc_env_bool (const char *var) +bool rc_yesno (const char *value) { - char *v; - - if (! var) - return (false); - - if (! (v = getenv (var))) { - errno = ENOENT; + if (! value) { + errno = EINVAL; return (false); } - if (strcasecmp (v, "true") == 0 || - strcasecmp (v, "y") == 0 || - strcasecmp (v, "yes") == 0 || - strcasecmp (v, "1") == 0) + if (strcasecmp (value, "yes") == 0 || + strcasecmp (value, "y") == 0 || + strcasecmp (value, "true") == 0 || + strcasecmp (value, "1") == 0) return (true); - if (strcasecmp (v, "false") != 0 && - strcasecmp (v, "n") != 0 && - strcasecmp (v, "no") != 0 && - strcasecmp (v, "0") != 0) + if (strcasecmp (value, "no") != 0 && + strcasecmp (value, "n") != 0 && + strcasecmp (value, "false") != 0 && + strcasecmp (value, "0") != 0) errno = EINVAL; return (false); } -librc_hidden_def(rc_env_bool) +librc_hidden_def(rc_yesno) char *rc_strcatpaths (const char *path1, const char *paths, ...) { diff --git a/src/librc.h b/src/librc.h index fb37e8c0..370a1266 100644 --- a/src/librc.h +++ b/src/librc.h @@ -81,7 +81,6 @@ librc_hidden_proto(rc_deptree_load) librc_hidden_proto(rc_deptree_order) librc_hidden_proto(rc_deptree_update) librc_hidden_proto(rc_deptree_update_needed) -librc_hidden_proto(rc_env_bool) librc_hidden_proto(rc_find_pids) librc_hidden_proto(rc_runlevel_exists) librc_hidden_proto(rc_runlevel_get) @@ -123,5 +122,6 @@ librc_hidden_proto(rc_strlist_delete) librc_hidden_proto(rc_strlist_free) librc_hidden_proto(rc_strlist_join) librc_hidden_proto(rc_strlist_reverse) +librc_hidden_proto(rc_yesno) #endif diff --git a/src/mountinfo.c b/src/mountinfo.c index 22fe2c14..4fed2b1a 100644 --- a/src/mountinfo.c +++ b/src/mountinfo.c @@ -365,6 +365,7 @@ int mountinfo (int argc, char **argv) char *n; int opt; int result; + bool quiet; #define DO_REG(_var) \ if (_var) free (_var); \ @@ -442,12 +443,13 @@ int mountinfo (int argc, char **argv) rc_strlist_reverse (nodes); result = EXIT_FAILURE; + quiet = rc_yesno (getenv ("RC_QUIET")); STRLIST_FOREACH (nodes, n, i) { if (point_regex && regexec (point_regex, n, 0, NULL, 0) != 0) continue; if (skip_point_regex && regexec (skip_point_regex, n, 0, NULL, 0) == 0) continue; - if (! rc_env_bool ("RC_QUIET")) + if (! quiet) printf ("%s\n", n); result = EXIT_SUCCESS; } diff --git a/src/rc-logger.c b/src/rc-logger.c index c95b2c8f..1cab3221 100644 --- a/src/rc-logger.c +++ b/src/rc-logger.c @@ -150,7 +150,7 @@ void rc_logger_open (const char *level) if (! isatty (STDOUT_FILENO)) return; - if (! rc_env_bool ("RC_LOGGER")) + if (! rc_conf_yesno ("rc_logger")) return; if (pipe (signal_pipe) == -1) diff --git a/src/rc-misc.c b/src/rc-misc.c index 56033115..dfedbdc9 100644 --- a/src/rc-misc.c +++ b/src/rc-misc.c @@ -38,6 +38,7 @@ #endif #include <sys/utsname.h> +#include <ctype.h> #include <limits.h> #include <stdio.h> #include <stdlib.h> @@ -50,10 +51,49 @@ #define PROFILE_ENV "/etc/profile.env" #define SYS_WHITELIST RC_LIBDIR "/conf.d/env_whitelist" #define USR_WHITELIST "/etc/conf.d/env_whitelist" -#define RC_CONFIG "/etc/conf.d/rc" +#define RC_CONF "/etc/rc.conf" +#define RC_CONF_OLD "/etc/conf.d/rc" #define PATH_PREFIX RC_LIBDIR "/bin:/bin:/sbin:/usr/bin:/usr/sbin" +static char **rc_conf = NULL; + +static void _free_rc_conf (void) +{ + rc_strlist_free (rc_conf); +} + +bool rc_conf_yesno (const char *setting) +{ + if (! rc_conf) { + char *line; + int i; + + rc_conf = rc_config_load (RC_CONF); + atexit (_free_rc_conf); + + /* Support old configs */ + if (exists (RC_CONF_OLD)) { + char **old = rc_config_load (RC_CONF_OLD); + rc_strlist_join (&rc_conf, old); + rc_strlist_free (old); + } + + /* Convert old uppercase to lowercase */ + STRLIST_FOREACH (rc_conf, line, i) { + char *p = line; + while (p && *p && *p != '=') { + if (isupper (*p)) + *p = tolower (*p); + p++; + } + } + + } + + return (rc_yesno (rc_config_value (rc_conf, setting))); +} + char **env_filter (void) { char **env = NULL; @@ -64,10 +104,10 @@ char **env_filter (void) bool got_path = false; char *env_var; int env_len; - char *p; char *token; char *sep; char *e; + char *p; int pplen = strlen (PATH_PREFIX); whitelist = rc_config_list (SYS_WHITELIST); @@ -195,45 +235,14 @@ char **env_config (void) char **env = NULL; char *line; int i; - char *p; - char **config; - char *e; #ifdef __linux__ char sys[6]; #endif struct utsname uts; - bool has_net_fs_list = false; FILE *fp; char buffer[PATH_MAX]; char *runlevel = rc_runlevel_get (); - /* Don't trust environ for softlevel yet */ - snprintf (buffer, PATH_MAX, "%s.%s", RC_CONFIG, runlevel); - if (exists (buffer)) - config = rc_config_load (buffer); - else - config = rc_config_load (RC_CONFIG); - - STRLIST_FOREACH (config, line, i) { - p = strchr (line, '='); - if (! p) - continue; - - *p = 0; - e = getenv (line); - if (! e) { - *p = '='; - rc_strlist_add (&env, line); - } else { - int len = strlen (line) + strlen (e) + 2; - char *new = xmalloc (sizeof (char) * len); - snprintf (new, len, "%s=%s", line, e); - rc_strlist_add (&env, new); - free (new); - } - } - rc_strlist_free (config); - /* One char less to drop the trailing / */ i = strlen ("RC_LIBDIR=") + strlen (RC_LIBDIR) + 1; line = xmalloc (sizeof (char) * i); @@ -304,21 +313,6 @@ char **env_config (void) #endif - /* Only add a NET_FS list if not defined */ - STRLIST_FOREACH (env, line, i) - if (strncmp (line, "RC_NET_FS_LIST=", strlen ("RC_NET_FS_LIST=")) == 0) { - has_net_fs_list = true; - break; - } - - if (! has_net_fs_list) { - i = strlen ("RC_NET_FS_LIST=") + strlen (RC_NET_FS_LIST_DEFAULT) + 1; - line = xmalloc (sizeof (char) * i); - snprintf (line, i, "RC_NET_FS_LIST=%s", RC_NET_FS_LIST_DEFAULT); - rc_strlist_add (&env, line); - free (line); - } - /* Some scripts may need to take a different code path if Linux/FreeBSD, etc To save on calling uname, we store it in an environment variable */ if (uname (&uts) == 0) { diff --git a/src/rc-misc.h b/src/rc-misc.h index 01c25a6a..7e69f451 100644 --- a/src/rc-misc.h +++ b/src/rc-misc.h @@ -64,9 +64,6 @@ /* Max buffer to read a line from a file */ #define RC_LINEBUFFER 4096 -/* Good defaults just incase user has none set */ -#define RC_NET_FS_LIST_DEFAULT "afs cifs coda davfs fuse gfs ncpfs nfs nfs4 ocfs2 shfs smbfs" - #define ERRX fprintf (stderr, "out of memory\n"); exit (1) static inline void *xmalloc (size_t size) @@ -113,6 +110,7 @@ static inline bool exists (const char *pathname) return (stat (pathname, &buf) == 0); } +bool rc_conf_yesno (const char *var); char **env_filter (void); char **env_config (void); diff --git a/src/rc-status.c b/src/rc-status.c index 02368a11..3958b71a 100644 --- a/src/rc-status.c +++ b/src/rc-status.c @@ -82,7 +82,7 @@ static void print_service (char *service) } else snprintf (status, sizeof (status), " stopped "); - if (isatty (fileno (stdout)) && ! rc_env_bool ("RC_NOCOLOR")) + if (isatty (fileno (stdout)) && ! rc_yesno (getenv ("RC_NOCOLOR"))) printf ("\n"); ebracket (cols, color, status); } diff --git a/src/rc-update.c b/src/rc-update.c index f8dd6c47..02a650fe 100644 --- a/src/rc-update.c +++ b/src/rc-update.c @@ -185,7 +185,7 @@ int rc_update (int argc, char **argv) } } - verbose = rc_env_bool ("RC_VERBOSE"); + verbose = rc_yesno (getenv ("RC_VERBOSE")); if ((action & DOSHOW && action != DOSHOW) || (action & DOADD && action != DOADD) || @@ -492,6 +492,8 @@ static char read_key (bool block) static bool want_interactive (void) { char c; + static bool gotinteractive; + static bool interactive; if (PREVLEVEL && strcmp (PREVLEVEL, "N") != 0 && @@ -499,7 +501,11 @@ static bool want_interactive (void) strcmp (PREVLEVEL, "1") != 0) return (false); - if (! rc_env_bool ("RC_INTERACTIVE")) + if (! gotinteractive) { + gotinteractive = true; + interactive = rc_conf_yesno ("rc_interactive"); + } + if (! interactive) return (false); c = read_key (false); @@ -793,6 +799,7 @@ int main (int argc, char **argv) int opt; DIR *dp; struct dirent *d; + bool parallel; atexit (cleanup); if (argv[0]) @@ -982,7 +989,7 @@ int main (int argc, char **argv) ecolor (ECOLOR_GOOD), ecolor (ECOLOR_BRACKET), ecolor (ECOLOR_NORMAL)); - if (rc_env_bool ("RC_INTERACTIVE")) + if (rc_conf_yesno ("rc_interactive")) printf ("Press %sI%s to enter interactive boot mode\n\n", ecolor (ECOLOR_GOOD), ecolor (ECOLOR_NORMAL)); @@ -1156,7 +1163,7 @@ int main (int argc, char **argv) if (newlevel && strcmp (newlevel, bootlevel) == 0 && (strcmp (runlevel, RC_LEVEL_SINGLE) == 0 || strcmp (runlevel, RC_LEVEL_SYSINIT) == 0) && - rc_env_bool ("RC_COLDPLUG")) + rc_conf_yesno ("rc_coldplug")) { #if defined(__DragonFly__) || defined(__FreeBSD__) /* The net interfaces are easy - they're all in net /dev/net :) */ @@ -1263,6 +1270,8 @@ int main (int argc, char **argv) if (going_down) rc_runlevel_set (newlevel); + parallel = rc_conf_yesno ("rc_parallel"); + /* Now stop the services that shouldn't be running */ STRLIST_FOREACH (stop_services, service, i) { bool found = false; @@ -1278,7 +1287,7 @@ int main (int argc, char **argv) /* We always stop the service when in these runlevels */ if (going_down) { pid_t pid = rc_service_stop (service); - if (pid > 0 && ! rc_env_bool ("RC_PARALLEL")) + if (pid > 0 && ! parallel) rc_waitpid (pid); continue; } @@ -1348,7 +1357,7 @@ int main (int argc, char **argv) if ((pid = rc_service_stop (service)) > 0) { add_pid (pid); - if (! rc_env_bool ("RC_PARALLEL")) { + if (! parallel) { rc_waitpid (pid); remove_pid (pid); } @@ -1448,7 +1457,7 @@ interactive_option: if ((pid = rc_service_start (service)) > 0) { add_pid (pid); - if (! rc_env_bool ("RC_PARALLEL")) { + if (! parallel) { rc_waitpid (pid); remove_pid (pid); } @@ -353,12 +353,12 @@ char **rc_config_load (const char *file); /*! Return the value of the entry from a key=value list. */ char *rc_config_value (char **list, const char *entry); -/*! Check if an environment variable is a boolean and return it's value. +/*! Check if a variable is a boolean and return it's value. * If variable is not a boolean then we set errno to be ENOENT when it does * not exist or EINVAL if it's not a boolean. * @param variable to check * @return true if it matches true, yes or 1, false if otherwise. */ -bool rc_env_bool (const char *variable); +bool rc_yesno (const char *variable); /*! @name String List functions * Handy functions for dealing with string arrays of char **. @@ -9,7 +9,6 @@ global: rc_deptree_order; rc_deptree_update; rc_deptree_update_needed; - rc_env_bool; rc_environ_fd; rc_find_pids; rc_runlevel_exists; @@ -52,6 +51,7 @@ global: rc_strlist_free; rc_strlist_join; rc_strlist_reverse; + rc_yesno; local: *; diff --git a/src/runscript.c b/src/runscript.c index 6431a784..68c14f86 100644 --- a/src/runscript.c +++ b/src/runscript.c @@ -590,7 +590,7 @@ static void svc_start (bool deps) state = rc_service_state (service); - if (rc_env_bool ("IN_HOTPLUG") || in_background) { + if (rc_yesno (getenv ("IN_HOTPLUG")) || in_background) { if (! state & RC_SERVICE_INACTIVE && ! state & RC_SERVICE_STOPPED) exit (EXIT_FAILURE); @@ -615,7 +615,7 @@ static void svc_start (bool deps) hook_out = RC_HOOK_SERVICE_START_OUT; rc_plugin_run (RC_HOOK_SERVICE_START_IN, applet); - if (rc_env_bool ("RC_DEPEND_STRICT")) + if (rc_conf_yesno ("rc_depend_strict")) depoptions |= RC_DEP_STRICT; if (rc_runlevel_starting ()) @@ -651,7 +651,7 @@ static void svc_start (bool deps) STRLIST_FOREACH (use_services, svc, i) if (rc_service_state (svc) & RC_SERVICE_STOPPED) { pid_t pid = rc_service_start (svc); - if (! rc_env_bool ("RC_PARALLEL")) + if (! rc_conf_yesno ("rc_parallel")) rc_waitpid (pid); } } @@ -805,7 +805,7 @@ static void svc_stop (bool deps) state & RC_SERVICE_FAILED) exit (EXIT_FAILURE); - if (rc_env_bool ("IN_HOTPLUG") || in_background) + if (rc_yesno (getenv ("IN_HOTPLUG")) || in_background) if (! (state & RC_SERVICE_STARTED) && ! (state & RC_SERVICE_INACTIVE)) exit (EXIT_FAILURE); @@ -833,7 +833,7 @@ static void svc_stop (bool deps) char *svc; int i; - if (rc_env_bool ("RC_DEPEND_STRICT")) + if (rc_conf_yesno ("RC_DEPEND_STRICT")) depoptions |= RC_DEP_STRICT; if (rc_runlevel_stopping ()) @@ -859,7 +859,7 @@ static void svc_stop (bool deps) svcs & RC_SERVICE_INACTIVE) { pid_t pid = rc_service_stop (svc); - if (! rc_env_bool ("RC_PARALLEL")) + if (! rc_conf_yesno ("rc_parallel")) rc_waitpid (pid); rc_strlist_add (&tmplist, svc); } @@ -1087,7 +1087,7 @@ int runscript (int argc, char **argv) setenv ("RC_RUNSCRIPT_PID", pid, 1); /* eprefix is kinda klunky, but it works for our purposes */ - if (rc_env_bool ("RC_PARALLEL")) { + if (rc_conf_yesno ("rc_parallel")) { int l = 0; int ll; @@ -1137,13 +1137,13 @@ int runscript (int argc, char **argv) /* Save the IN_BACKGROUND env flag so it's ONLY passed to the service that is being called and not any dependents */ if (getenv ("IN_BACKGROUND")) { - in_background = rc_env_bool ("IN_BACKGROUND"); ibsave = xstrdup (getenv ("IN_BACKGROUND")); + in_background = rc_yesno (ibsave); unsetenv ("IN_BACKGROUND"); } - if (rc_env_bool ("IN_HOTPLUG")) { - if (! rc_env_bool ("RC_HOTPLUG") || ! rc_service_plugable (applet)) + if (rc_yesno (getenv ("IN_HOTPLUG"))) { + if (! rc_conf_yesno ("rc_hotplug") || ! rc_service_plugable (applet)) eerrorx ("%s: not allowed to be hotplugged", applet); } @@ -1197,7 +1197,7 @@ int runscript (int argc, char **argv) const char *t[] = { optarg, NULL }; const char *s[] = { applet, NULL }; - if (rc_env_bool ("RC_DEPEND_STRICT")) + if (rc_conf_yesno ("rc_depend_strict")) depoptions |= RC_DEP_STRICT; if (! deptree && ((deptree = _rc_deptree_load ()) == NULL)) diff --git a/src/start-stop-daemon.c b/src/start-stop-daemon.c index 967d4263..551bad58 100644 --- a/src/start-stop-daemon.c +++ b/src/start-stop-daemon.c @@ -708,8 +708,8 @@ int start_stop_daemon (int argc, char **argv) case_RC_COMMON_GETOPT } - quiet = rc_env_bool ("RC_QUIET"); - verbose = rc_env_bool ("RC_VERBOSE"); + quiet = rc_yesno (getenv ("RC_QUIET")); + verbose = rc_yesno (getenv ("RC_VERBOSE")); /* Allow start-stop-daemon --signal HUP --exec /usr/sbin/dnsmasq * instead of forcing --stop --oknodo as well */ |