Initial import of NetBSD rc system

IMPORTANT: this change has a docs/UPDATING entry!

This patch performs an initial import of the infrastructure and a
subset of the NetBSD set of rc startup and shutdown scripts.  The
"initial" refers to the fact that this is not yet a full switch to the
NetBSD rc system: the MINIX ramdisk rc script, which (typically) runs
as the first thing, is kept as is.  After mounting the root file
system, the ramdisk rc script will start the NetBSD rc infrastructure
by invoking /etc/rc, however.  The regular MINIX startup-and-shutdown
script has been moved from /etc/rc to /etc/rc.minix, and is now
invoked as part of the NetBSD rc infrastructure through a bridge rc
script /etc/rc.d/minixrc.  /etc/rc.minix invokes /usr/etc/rc as before.

Switching over the ramdisk to the NetBSD system and decomposing the
MINIX rc.minix script into smaller components are left to future work.
Also, the current pkgsrc etc/rc.d auto-start functionality is left as
is, even though it should be removed (see the etc/usr/rc comment).

Change-Id: Ia96cae7c426e94b85c67978dc1307dacc4b09fc5
This commit is contained in:
David van Moolenbroek 2017-02-13 13:35:23 +00:00
parent 2109df2759
commit 325ce30bcc
45 changed files with 5123 additions and 299 deletions

1
.gitignore vendored
View File

@ -15,6 +15,7 @@ lib*.so*
*.a
*.so.*
*.d
!etc/*.d
.depend
*.gcno
*.gcda

View File

@ -124,8 +124,32 @@
./etc/rc.cd minix-base
./etc/rc.conf minix-base
./etc/rc.d minix-base
./etc/rc.d/DAEMON minix-base
./etc/rc.d/DISKS minix-base
./etc/rc.d/LOGIN minix-base
./etc/rc.d/NETWORKING minix-base
./etc/rc.d/SERVERS minix-base
./etc/rc.d/blacklistd minix-base
./etc/rc.d/bootconf.sh minix-base
./etc/rc.d/fsck minix-base
./etc/rc.d/ftpd minix-base
./etc/rc.d/ipfilter minix-base
./etc/rc.d/ipsec minix-base
./etc/rc.d/local minix-base
./etc/rc.d/minixrc minix-base
./etc/rc.d/mountcritlocal minix-base
./etc/rc.d/mountcritremote minix-base
./etc/rc.d/network minix-base
./etc/rc.d/npf minix-base
./etc/rc.d/pwcheck minix-base
./etc/rc.d/root minix-base
./etc/rc.d/sysctl minix-base
./etc/rc.d/sysdb minix-base
./etc/rc.d/syslogd minix-base
./etc/rc.d/ttys minix-base
./etc/rc.d/wscons minix-base
./etc/rc.daemons.dist minix-base
./etc/rc.minix minix-base
./etc/rc.shutdown minix-base
./etc/rc.subr minix-base
./etc/release minix-base

View File

@ -3299,6 +3299,7 @@
./usr/man/man5/passwd.5 minix-man
./usr/man/man5/pkg_install.conf.5 minix-man
./usr/man/man5/pkg_summary.5 minix-man
./usr/man/man5/rc.conf.5 minix-man
./usr/man/man5/resolv.conf.5 minix-man
./usr/man/man5/resolver.5 minix-man
./usr/man/man5/rhosts.5 minix-man
@ -3429,6 +3430,11 @@
./usr/man/man8/pwdauth.8 minix-man obsolete
./usr/man/man8/rarpd.8 minix-man
./usr/man/man8/rawspeed.8 minix-man
./usr/man/man8/rc.8 minix-man
./usr/man/man8/rc.d.8 minix-man
./usr/man/man8/rc.local.8 minix-man
./usr/man/man8/rc.shutdown.8 minix-man
./usr/man/man8/rc.subr.8 minix-man
./usr/man/man8/rcorder.8 minix-man
./usr/man/man8/rdate.8 minix-man
./usr/man/man8/readclock.8 minix-man

View File

@ -1,3 +1,9 @@
20170223:
Edit your /etc/rc.conf to set rc_configured to YES. If you do not,
your system will refuse to enter multi-user mode after the next reboot.
You can then still make the same edit from single user mode, but that
is not as easy.
20170222:
Because of naming conflicts, the MINIX 3 service(8) utility has been
renamed to "minix-service". After successfully rebuilding the system

View File

@ -94,12 +94,18 @@ BINOWN= root
BINGRP= wheel
UTMPGRP= utmp
.if defined(__MINIX)
BIN1+= boot.cfg.default \
BIN1+= \
\
gettytab \
man.conf \
passwd.conf protocols rc rc.cd rc.subr \
rc.daemons.dist rs.inet rs.single \
services shells syslog.conf \
termcap utmp gettytab rc.shutdown
\
passwd.conf \
protocols rc rc.cd rc.subr \
rc.shutdown services shells \
syslog.conf
# MINIX-only files:
BIN1+= boot.cfg.default rc.daemons.dist rc.minix \
rs.inet rs.single termcap utmp
.else
BIN1+= bootptab changelist csh.cshrc csh.login \
csh.logout daily daily.conf dm.conf envsys.conf floppytab ftpchroot \
@ -476,7 +482,7 @@ install-etc-files-safe: .PHONY .MAKE check_DESTDIR MAKEDEV
${INSTALL_FILE} -m ${BINMODE} -o ${BINOWN} -g ${BINGRP} ${NETBSDSRCDIR}/etc/rc.capes/* ${DESTDIR}/etc/rc.capes
${INSTALL_FILE} -m ${BINMODE} -o ${BINOWN} -g ${BINGRP} ${NETBSDSRCDIR}/minix/drivers/usb/usbd/usbd.conf ${DESTDIR}/etc/system.conf.d/usbd
.endif # Minix/earm specific
.for subdir in . defaults mtree root skel
.for subdir in . defaults mtree rc.d root skel
${MAKEDIRTARGET} ${subdir} configinstall
.endfor
${_MKMSG_INSTALL} ${DESTDIR}/usr/lib/fonts

View File

@ -1,5 +1,9 @@
# Minix-specific rc.conf default values
# Override settings in NetBSD's default rc.conf with different default settings
# for MINIX here, typically to disable scripts that NetBSD enables by default.
#(nothing yet)
# Where to find servers/drivers binaries
PKG_SERVICE_DIR=/usr/pkg/service
SERVICES_DIRS="/service $PKG_SERVICE_DIR"

View File

@ -1,4 +1,382 @@
# $NetBSD: rc.conf,v 1.133 2015/03/30 10:58:37 chopps Exp $
#
# /etc/defaults/rc.conf --
# default configuration of /etc/rc.conf
#
# see rc.conf(5) for more information.
#
# DO NOT EDIT THIS FILE DIRECTLY; IT MAY BE REPLACED DURING A SYSTEM UPGRADE.
# EDIT /etc/rc.conf INSTEAD.
#
#
# Use program=YES to enable program, NO to disable it. program_flags are
# passed to the program on the command line.
#
# Uncomment this if you want to use local paths in rc.
#
#export PATH=$PATH:/usr/pkg/sbin:/usr/pkg/bin:/usr/local/sbin:/usr/local/bin
# Uncomment the following to execute each /etc/rc.d script in
# the current shell rather than in a subshell. This may be
# faster on very slow machines that have an expensive fork(2).
# NOTE: USE THIS AT YOUR OWN RISK; A ROGUE COMMAND
# MAY INADVERTENTLY PREVENT BOOT TO MULTIUSER.
#
#rc_fast_and_loose=YES
# If rc_silent is true then /etc/rc will suppress most output to
# the console. The default is taken from the AB_SILENT flag passed
# from the boot loader to the kernel in the boothowto(9) variable.
#
# rc_silent_cmd is executed once for each suppressed line of output.
# Useful values are ":" and "twiddle".
#
rc_silent=$( [ "$(( $(/sbin/sysctl -n kern.boothowto 2>/dev/null || echo 0) \
& 0x40000 ))" != 0 ] && echo true || echo false )
rc_silent_cmd=twiddle
# Additional flags to the rcorder(8) that's run by /etc/rc.
#
rc_rcorder_flags=""
# The directories searched for rc scripts.
# These directories must be part of the root file system.
rc_directories=/etc/rc.d
# If this is set to NO, shutdown(8) will not run /etc/rc.shutdown.
#
do_rcshutdown=YES
# Additional flags to the rcorder(8) that's run by /etc/rc.shutdown.
#
rcshutdown_rcorder_flags=""
# If this is non-blank, use as the number of seconds to run a watchdog
# timer which will terminate /etc/rc.shutdown if the timeout expires.
#
rcshutdown_timeout=""
# Basic network configuration
#
# Fully Qualified Internet Domain Name (a.k.a. hostname, e.g. foo.baz.edu).
# If blank, use /etc/myname.
#
hostname=""
# If there's only one way out of your IPv4 network, set this to the hostname
# or the IPv4 address of the router that will get your packets off the LAN.
# If blank, use /etc/mygate.
#
defaultroute=""
# Same thing for IPv6. If blank, use /etc/mygate6.
#
defaultroute6=""
# The NIS domain name (formerly known as Yellow Pages); not in any way
# related to Internet domain names.
# If blank, use /etc/defaultdomain.
#
domainname=""
# Filesystems to mount early in boot-up.
# Note that `/var' is needed in $critical_filesystems_local (or
# implied as part of `/') as certain services that need /var (such as
# dhclient) may be needed to get the network operational enough to mount
# the $critical_filesystems_remote. Prepending "OPTIONAL:" means it
# will not be an error if that file system is not present in fstab(5).
#
critical_filesystems_local="OPTIONAL:/var"
critical_filesystems_remote="OPTIONAL:/usr"
# Swap device controls.
#
no_swap=NO # Set to YES if you have purposefully setup no swap
# partitions and don't want to be warned about it.
swapoff=YES # Remove block-type swap partitions upon shutdown
# This defaults to yes, so that raids shutdown cleanly
# Concatenated disk driver.
#
ccd=YES
# RAIDframe driver (manually configured devices).
#
raidframe=YES
# Crypto file system.
#
cgd=YES
# Logical Volume Manager
#
lvm=NO
# One-time actions and programs on boot-up.
#
savecore=YES savecore_flags="-z"
savecore_dir="/var/crash"
resize_root=NO # resize root to fill partition
per_user_tmp=NO # per-user /tmp directories
per_user_tmp_dir="/private/tmp" # real storage for /tmp
clear_tmp=YES # clear /tmp after reboot
update_motd=YES # updates /etc/motd
dmesg=YES dmesg_flags="" # write /var/run/dmesg.boot
accounting=NO # uses /var/account/acct
newsyslog=NO newsyslog_flags="" # trim log files
quota=YES # check and enable quotas
ldconfig=YES # rebuild a.out ldconfig cache
sysdb=YES # build system databases
rndctl=NO rndctl_flags="" # configure rndctl(8)
gpio=NO # configure GPIO devices
modules=YES # process /etc/modules.conf
# cope with other OSes using the real time clock at localtime on this
# machine (by adjusting kern.rtc_offset at boot)
rtclocaltime=NO
# NOTE: default coredump name now set in /etc/sysctl.conf
#
# File system check flags; default to preen mode, checking file systems
# that are listed in /etc/fstab in parallel as the fsck pass number
# permits. Fix minor faults automatically, and exit with non 0 only
# when major errors occur.
#
fsck_flags=-p
# Security setting. If $securelevel is non-empty, the system securelevel
# is set to this value early in the boot sequence. Otherwise the default
# action is taken (see init(8)).
#
securelevel="" # securelevel to set to
# To set the IP address of an interface either use
# ifconfig_xxN="IP-NO"
# where xxN is the interface. If this variable is not set then
# contents of the file /etc/ifconfig.xxN is used.
# Networking startup.
#
mdnsd=NO
npf=NO
ipfilter=NO ipfilter_flags="" # uses /etc/ipf.conf
ipnat=NO # uses /etc/ipnat.conf
ipfs=NO ipfs_flags="" # save/load ipnat and ipf states
ipsec=NO # uses /etc/ipsec.conf
ipmon=NO ipmon_flags="-Dns" # syslog ipfilter messages
pf=NO pf_rules="/etc/pf.conf" pf_flags=""
pflogd=NO
ftp_proxy=NO
racoon=NO # IKE daemon
auto_ifconfig=YES # config all avail. interfaces
net_interfaces="" # used only if above is NO
flushroutes=YES # flush routes in netstart
dhcpcd=NO
dhcpcd_flags="-qM" # For ifconfig_XXX=dhcp.
dhclient=NO # behave as a DHCP client
dhclient_flags="" # blank: config all interfaces
ntpdate=NO ntpdate_flags="-b -s" # May need '-u' thru firewall
ppp=YES ppp_peers="" # /etc/ppp/peers to call
ip6mode=host # host, autohost or router
ip6uniquelocal=NO # IPv6 unique-local forwarding
# Special treatment for interfaces that need to be downed on
# shutdown (because they might cause unnecessary costs or block resources
# on the peer). All pppoe* interfaces are automatically included in this
# list, add others here manually.
#force_down_interfaces=""
ifwatchd=NO # execute up/down scripts for in-kernel PPPoE interfaces
ifwatchd_flags="-u /etc/ppp/ip-up -d /etc/ppp/ip-down pppoe0"
# ALTQ configuration/monitoring daemon
altqd=NO altqd_flags=""
# Daemons required by servers. These are not needed for strictly client use.
#
# inetd is used to start the IP-based services enabled in /etc/inetd.conf
#
inetd=YES inetd_flags="-l" # -l logs libwrap
# identd
#
identd=NO identd_flags="-b -l -u nobody"
# rpcbind (formerly known as 'portmap') is used to look up RPC-based services.
#
rpcbind=NO rpcbind_flags="-l" # -l logs libwrap
# Commonly used daemons.
#
syslogd=YES syslogd_flags="-s" # -s "secure" unix domain only
cron=YES
named=NO named_flags="" # see below for named_chrootdir
timed=NO timed_flags=""
ntpd=NO ntpd_flags="" # see below for ntpd_chrootdir
# The default setting for postfix here is YES, but gets re-examined by
# the rc.d/postfix startup script when it runs. The script sets
# _rc_d_postfix to "check", and then causes all rc.conf settings to
# be re-evaluated. If the value of $postfix after this is "check",
# the script then checks to see if /etc/mailer.conf selects the system
# postfix. If not, it does print a warning and does not start postfix
# to avoid conflict with a different MTA.
postfix=${_rc_d_postfix:-YES}
lpd=NO lpd_flags="-s" # -s "secure" unix domain only
sshd=NO sshd_flags=""
ssh_keygen_flags=""
ftpd=NO ftpd_flags="-ll"
httpd=NO httpd_flags=""
httpd_wwwdir="/var/www"
httpd_wwwuser="_httpd"
# To run the named(8) DNS server as an unprivileged user under a
# chroot(2) cage, uncomment the following after migrating the contents
# of /etc/namedb to /var/chroot/named/etc/namedb
#
#named_chrootdir="/var/chroot/named"
# To run the ntpd(8) NTP server as an unprivileged user under a
# chroot(2) cage, uncomment the following, after ensuring that:
# - The kernel has "pseudo-device clockctl" compiled in
# - /dev/clockctl is present
#
#ntpd_chrootdir="/var/chroot/ntpd"
# Routing daemons.
#
routed=NO routed_flags="-q"
gated=NO
mrouted=NO mrouted_flags=""
route6d=NO route6d_flags=""
ldpd=NO
# Daemons used to boot other hosts over a network.
#
rarpd=NO rarpd_flags="-a"
bootparamd=NO bootparamd_flags=""
dhcpd=NO dhcpd_flags="-q"
dhcrelay=NO dhcrelay_flags=""
rbootd=NO rbootd_flags=""
mopd=NO mopd_flags="-a"
ndbootd=NO ndbootd_flags="-s /tftpboot /tftpboot/bootyy"
rtadvd=NO rtadvd_flags=""
isibootd=NO isibootd_flags=""
# X11 daemons.
#
xfs=NO xfs_flags="" # X11 font server
xdm=NO xdm_flags="" # X11 display manager; needs
# wscons=YES for local displays.
# Update fontconfig cache at boot
fccache=YES
# YP (NIS) daemons.
#
ypbind=NO ypbind_flags=""
ypserv=NO ypserv_flags="-d"
yppasswdd=NO yppasswdd_flags=""
# NFS daemons and parameters.
#
mountd=NO mountd_flags="" # NFS mount requests daemon
nfs_client=NO # enable client daemons
nfs_server=NO # enable server daemons
nfsd_flags=""
lockd=NO lockd_flags=""
statd=NO statd_flags=""
amd=NO amd_flags="-l syslog -x error,noinfo,nostats"
amd_dir=/amd # mount dir
# Heimdal Kerberos 5 KDC (with Kerberos IV compatibility)
kdc=NO kdc_flags="--detach"
# iSCSI target
iscsi_target=NO iscsi_target_flags=""
# iSCSI kernel initiator
iscsid=NO
# WPA daemons.
hostapd=NO hostapd_flags="-B /etc/hostapd.conf"
wpa_supplicant=NO wpa_supplicant_flags="" # -i<if> -c<file>
# ISDN daemon
isdnd=NO isdnd_flags=""
# Bluetooth configuration
bluetooth=NO
# and the following are used when bluetooth=YES
btconfig_devices="" # all
bthcid=YES bthcid_flags=""
sdpd=YES sdpd_flags=""
# Other daemons.
#
rwhod=NO rwhod_flags="-u _rwhod"
devpubd=NO devpubd_flags="" # autocreate nodes for new devs
envsys=NO # Set /etc/envsys.conf preferences
# Hardware daemons.
#
apmd=NO apmd_flags="" # APM power management daemon.
powerd=NO powerd_flags="" # power management daemon
screenblank=NO screenblank_flags="" # wscons and FBIO screenblanker
moused=NO # serial mouse handler
moused_flags="-p /dev/tty00"
wdogctl=NO # watchdog timer control
# wdogctl_flags="-k devicename"
irdaattach=NO # attach serial lines to IrDA
irdaattach_flags="tty00"
# Configuration of "wscons" console driver virtual screens.
#
wscons=NO wscons_flags="" # setup wscons from wscons.conf
# Configuration of "wsmoused" console driver cut-n-paste support
#
wsmoused=NO wsmoused_flags=""
# Configuration of "tpctl" touch panel calibration utility
#
tpctl=NO tpctl_flags=""
# Mixer setting
#
mixerctl=NO mixerctl_mixers="" # "mixer0 mixer1" means saving
# and restoring their settings
# Vi recovery notification. Vi(1)'s -r option can recover files which were
# accidentally closed. See vi(1) for more details.
#
virecover=YES
# Veriexec signature loading.
#
veriexec=NO
veriexec_strict=0
veriexec_verbose=0
veriexec_flags="-k"
# Entropy load/save to/from /dev/random at startup/shutdown
#
random_seed=YES
# Creating / updating of man page index on boot
makemandb=YES
# blacklist daemon, needs npf
blacklistd=NO
# Start of MINIX 3 specific settings block
if [ -r /etc/defaults/minix.rc.conf ]; then
. /etc/defaults/minix.rc.conf
fi
# End of MINIX 3 specific settings block

696
etc/rc Executable file → Normal file
View File

@ -1,246 +1,468 @@
# /etc/rc - System startup script run by init before going multiuser.
#!/bin/sh
#
# $NetBSD: rc,v 1.170 2014/07/29 20:39:16 apb Exp $
#
# rc --
# Run the scripts in /etc/rc.d with rcorder, and log output
# to /var/run/rc.log.
if sysenv bootramdisk >/dev/null
then
/bin/sh /etc/rc.ramdisk
fi
# Are we booting from CD?
bootcd="`/bin/sysenv bootcd`"
exec >/dev/log
exec 2>/dev/log
exec </dev/null
# System startup script run by init(8) on autoboot or after single-user.
# Output and error are redirected to console by init, and the console
# is the controlling terminal.
export HOME=/
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
umask 022
# Same settings as in the default /etc/profile. We do not source this file
# as the system administrator may decide to change those values for his users.
RC_TZ=/etc/rc.timezone
PATH=/usr/local/sbin:/usr/pkg/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/pkg/bin:/usr/bin:/bin
if [ -e ./rc.subr ] ; then
. ./rc.subr # for testing
else
. /etc/rc.subr
fi
. /etc/rc.conf
_rc_conf_loaded=true
# Set TERM to minix if not present.
TERM="${TERM-minix}"
: ${RC_LOG_FILE:="/var/run/rc.log"}
export TERM PATH
# rc.subr redefines echo and printf. Undo that here.
unset echo ; unalias echo
unset printf ; unalias printf
# Local variables
ARCH="`sysenv arch`"
usage()
{
echo >&2 "Usage: $0 [-saf] autoboot|start|stop|down"
exec intr sh
}
up()
{
# Function to dynamically start a system service
opt=""
prefix=$(expr "$1 " : '\(-\)')
if [ "$prefix" = "-" ];
then
opt=$1
shift
fi
service=$1
shift
minix-service $opt up /service/$service "$@"
}
edit()
{
# Function to dynamically edit system service settings
opt=""
prefix=$(expr "$1 " : '\(-\)')
if [ "$prefix" = "-" ];
then
opt=$1
shift
fi
service=$1
shift
# Assume binaries are always in /service or /usr/pkg/service
binlocation=/service/$service
if [ ! -x $binlocation ]
then binlocation=/usr/pkg/service/$service
fi
# Mostly to find init...
if [ ! -x $binlocation ]
then binlocation=/sbin/$service
fi
minix-service $opt edit $binlocation -label $service "$@"
}
while getopts 'saf' opt
do
case $opt in
s) sflag=t ;; # Single user
a) aflag=t ;; # Ask for /usr
f) fflag=-f ;; # Force a full file system check
*) usage
esac
done
shift `expr $OPTIND - 1`
case "$#:$1" in
1:start|1:stop|1:down|1:autoboot)
action=$1
;;
*) usage
esac
case $action in
autoboot|start)
# If booting from CD, we want some directories to be ramdisks
if [ ! -z "$bootcd" ]
then
. /etc/rc.cd
fi
# National keyboard?
test -f /etc/keymap && loadkeys /etc/keymap
# options for fsck. default is -r, which prompts the user for repairs.
optname=fsckopts
fsckopts=-p
if sysenv $optname >/dev/null
then fsckopts="`sysenv $optname`"
fi
if [ "`sysenv debug_fkeys`" != 0 ]
then
up -n is -period 5HZ
fi
# Set timezone.
export TZ=GMT0
if [ -f "$RC_TZ" ]
then
. "$RC_TZ"
fi
# Start real time clock driver & set system time, otherwise default date.
up readclock.drv
readclock -q || date 201301010000
# We are not shutting down.
if [ -f /etc/nologin ]
then
rm -f /etc/nologin
fi
# Use MFS binary only from kernel image?
if [ "`sysenv bin_img`" = 1 ]
then
bin_img="-i "
fi
# fsck + mount using /etc/fstab.
fsck -x / $fflag $fsckopts
mount -a
if [ -z "`sysenv bootramdisk`" ]
then
# Unmount and free now defunct ramdisk
umount /dev/imgrd > /dev/null || echo "Failed to unmount boot ramdisk"
ramdisk 0 /dev/imgrd || echo "Failed to free boot ramdisk"
fi
# Initialize files.
>/var/run/utmp # /etc/utmp keeps track of logins
>/var/run/utmpx # /etc/utmpx keeps track of logins
# Edit settings for boot system services
if [ "`sysenv skip_boot_config`" != 1 ]
then
edit rs
edit vm
edit pm
edit sched
edit vfs
edit ds
edit tty
edit memory
edit mib
edit pfs
edit init
#
# Keep a copy around to recover the root FS from crashes
#
rootline=`cat /etc/mtab | grep "on / "`
rootfs=fs_`echo "$rootline" | cut -d' ' -f1 | cut -d'/' -f3`
roottype=`echo "$rootline" | cut -d' ' -f5`
minix-service -c edit /service/$roottype -label $rootfs
fi
if [ "$sflag" ]
then
echo "Single user. Press ^D to resume multiuser startup."
intr sh
echo
fi
echo "Multiuser startup in progress ..."
case "`printroot -r`":$bootcd in
/dev/ram:)
# Remove boot-only things to make space,
# unless booting from CD, in which case we need them.
rm -rf /boot
# put the compiler on ram
cp /usr/lib/em* /usr/lib/cpp* /lib
esac
echo -n "Starting hotplugging infrastructure... "
rm -f /var/run/devmand.pid
devmand -d /etc/devmand -d /usr/pkg/etc/devmand &
echo "done."
# Things should be alright now.
;;
down|stop)
sync
if [ -f /var/run/devmand.pid ]
then
kill -INT `cat /var/run/devmand.pid`
# without this delay the following will
# be printed in the console
# RS: devman not running?
sleep 1
fi
#
# usbd needs to be stopped exactly
# at this stage(before stopping devman
# and after stopping the services
# stated by devmand)
if [ -x /usr/pkg/etc/rc.d/usbd ]
then
/usr/pkg/etc/rc.d/usbd stop
fi
if [ -x /service/usbd ]
then
minix-service down usbd
fi
# Tell RS server we're going down.
minix-service shutdown
;;
esac
# Further initialization.
test -f /usr/etc/rc && sh /usr/etc/rc $action
test -f /usr/local/etc/rc && sh /usr/local/etc/rc $action
# Any messages?
if [ "$action" = start -o "$action" = autoboot ]
then if [ -f /etc/issue ]
then cat /etc/issue
fi
if ! checkyesno rc_configured; then
echo "/etc/rc.conf is not configured. Multiuser boot aborted."
exit 1
fi
exit 0
if [ "$1" = autoboot ]; then
autoboot=yes
rc_fast=yes # run_rc_command(): do fast booting
fi
#
# Completely ignore INT and QUIT at the outer level. The rc_real_work()
# function should do something different.
#
trap '' INT QUIT
#
# This string will be used to mark lines of meta-data sent over the pipe
# from the rc_real_work() function to the rc_postprocess() function. Lines
# not so marked are assumed to be output from rc.d scripts.
#
# This string is long and unique to ensure that it does not accidentally
# appear in output from any rc.d script. It must not contain any
# characters that are special to glob expansion ('*', '?', '[', or ']').
#
rc_metadata_prefix="$0:$$:metadata:";
# Child scripts may sometimes want to print directly to the original
# stdout and stderr, bypassing the pipe to the postprocessor. These
# _rc_*_fd variables are private, shared with /etc/rc.subr, but not
# intended to be used directly by child scripts. (Child scripts
# may use rc.subr's no_rc_postprocess function.)
#
_rc_original_stdout_fd=7; export _rc_original_stdout_fd
_rc_original_stderr_fd=8; export _rc_original_stderr_fd
eval "exec ${_rc_original_stdout_fd}>&1"
eval "exec ${_rc_original_stderr_fd}>&2"
#
# rc_real_work
# Do the real work. Output from this function will be piped into
# rc_postprocess(), and some of the output will be marked as
# metadata.
#
# The body of this function is defined using (...), not {...}, to force
# it to run in a subshell.
#
rc_real_work()
(
stty status '^T'
# print_rc_metadata() wants to be able to print to the pipe
# that goes to our postprocessor, even if its in a context
# with redirected output.
#
_rc_postprocessor_fd=9 ; export _rc_postprocessor_fd
_rc_pid=$$ ; export _rc_pid
eval "exec ${_rc_postprocessor_fd}>&1"
# Print a metadata line when we exit
#
trap 'es=$?; print_rc_metadata "exit:$es"; trap "" 0; exit $es' 0
# Set shell to ignore SIGINT, but children will not ignore it.
# Shell catches SIGQUIT and returns to single user.
#
trap : INT
trap '_msg="Boot interrupted at $(date)";
print_rc_metadata "interrupted:${_msg}";
exit 1' QUIT
print_rc_metadata "start:$(date)"
#
# The stop_boot() function in rc.subr may kill $RC_PID. We want
# it to kill the subshell running this rc_real_work() function,
# rather than killing the parent shell, because we want the
# rc_postprocess() function to be able to log the error
# without being killed itself.
#
# "$$" is the pid of the top-level shell, not the pid of the
# subshell that's executing this function. The command below
# tentatively assumes that the parent of the "/bin/sh -c ..."
# process will be the current subshell, and then uses "kill -0
# ..." to check the result. If the "/bin/sh -c ..." process
# fails, or returns the pid of an ephemeral process that exits
# before the "kill" command, then we fall back to using "$$".
#
RC_PID=$(/bin/sh -c 'ps -p $$ -o ppid=') || RC_PID=$$
kill -0 $RC_PID >/dev/null 2>&1 || RC_PID=$$
#
# As long as process $RC_PID is still running, send a "nop"
# metadata message to the postprocessor every few seconds.
# This should help flush partial lines that may appear when
# rc.d scripts that are NOT marked with "KEYWORD: interactive"
# nevertheless attempt to print prompts and wait for input.
#
(
# First detach from tty, to avoid intercepting SIGINFO.
eval "exec ${_rc_original_stdout_fd}<&-"
eval "exec ${_rc_original_stderr_fd}<&-"
exec </dev/null >/dev/null 2>&1
while kill -0 $RC_PID ; do
print_rc_metadata "nop"
sleep 3
done
) &
#
# Get a list of all rc.d scripts, and use rcorder to choose
# what order to execute them.
#
# For testing, allow RC_FILES_OVERRIDE from the environment to
# override this.
#
print_rc_metadata "cmd-name:rcorder"
scripts=$(for rcd in ${rc_directories:-/etc/rc.d}; do
test -d ${rcd} && echo ${rcd}/*;
done)
files=$(rcorder -s nostart ${rc_rcorder_flags} ${scripts})
print_rc_metadata "cmd-status:rcorder:$?"
if [ -n "${RC_FILES_OVERRIDE}" ]; then
files="${RC_FILES_OVERRIDE}"
fi
#
# Run the scripts in order.
#
for _rc_elem in $files; do
print_rc_metadata "cmd-name:$_rc_elem"
run_rc_script $_rc_elem start
print_rc_metadata "cmd-status:$_rc_elem:$?"
done
print_rc_metadata "end:$(date)"
exit 0
)
#
# rc_postprocess
# Post-process the output from the rc_real_work() function. For
# each line of input, we have to decide whether to print the line
# to the console, print a twiddle on the console, print a line to
# the log, or some combination of these.
#
# If rc_silent is true, then suppress most output, instead running
# rc_silent_cmd (typically "twiddle") for each line.
#
# The body of this function is defined using (...), not {...}, to force
# it to run in a subshell.
#
# We have to deal with the following constraints:
#
# * There may be no writable file systems early in the boot, so
# any use of temporary files would be problematic.
#
# * Scripts run during the boot may clear /tmp and/var/run, so even
# if they are writable, using those directories too early may be
# problematic. We assume that it's safe to write to our log file
# after the mountcritlocal script has run.
#
# * /usr/bin/tee cannot be used because the /usr file system may not
# be mounted early in the boot.
#
# * All calls to the rc_log_message and rc_log_flush functions must be
# from the same subshell, otherwise the use of a shell variable to
# buffer log messages will fail.
#
rc_postprocess()
(
local line
local before after
local IFS=''
# Try quite hard to flush the log to disk when we exit.
trap 'es=$?; rc_log_flush FORCE; trap "" 0; exit $es' 0
yesno_to_truefalse rc_silent 2>/dev/null
while read -r line ; do
case "$line" in
"${rc_metadata_prefix}"*)
after="${line#*"${rc_metadata_prefix}"}"
rc_postprocess_metadata "${after}"
;;
*"${rc_metadata_prefix}"*)
# magic string is present, but not at the start of
# the line. Treat it as a partial line of
# ordinary data, followed by a line of metadata.
before="${line%"${rc_metadata_prefix}"*}"
rc_postprocess_partial_line "${before}"
after="${line#*"${rc_metadata_prefix}"}"
rc_postprocess_metadata "${after}"
;;
*)
rc_postprocess_plain_line "${line}"
;;
esac
done
# If we get here, then the rc_real_work() function must have
# exited uncleanly. A clean exit would have been accompanied by
# a line of metadata that would have prevented us from getting
# here.
#
exit 1
)
#
# rc_postprocess_plain_line string
# $1 is a string representing a line of output from one of the
# rc.d scripts. Append the line to the log, and also either
# display the line on the console, or run $rc_silent_cmd,
# depending on the value of $rc_silent.
#
rc_postprocess_plain_line()
{
local line="$1"
rc_log_message "${line}"
if $rc_silent; then
eval "$rc_silent_cmd"
else
printf "%s\n" "${line}"
fi
}
#
# rc_postprocess_partial_line string
# This is just like rc_postprocess_plain_line, except that
# a newline is not appended to the string.
#
rc_postprocess_partial_line()
{
local line="$1"
rc_log_message_n "${line}"
if $rc_silent; then
eval "$rc_silent_cmd"
else
printf "%s" "${line}"
fi
}
#
# rc_postprocess_metadata string
# $1 is a string containing metadata from the rc_real_work()
# function. The rc_metadata_prefix marker should already
# have been removed before the string is passed to this function.
# Take appropriate action depending on the content of the string.
#
rc_postprocess_metadata()
{
local metadata="$1"
local keyword args
local msg
local IFS=':'
# given metadata="bleep:foo bar:baz",
# set keyword="bleep", args="foo bar:baz",
# $1="foo bar", $2="baz"
#
keyword="${metadata%%:*}"
args="${metadata#*:}"
set -- $args
case "$keyword" in
start)
# Marks the start of the entire /etc/rc script.
# $args contains a date/time.
rc_log_message "[$0 starting at $args]"
if ! $rc_silent; then
# MINIX 3: the clock has not been set yet!
#printf "%s\n" "$args"
# MINIX 3: end
fi
;;
cmd-name)
# Marks the start of a child script (usually one of
# the /etc/rc.d/* scripts).
rc_log_message "[running $1]"
;;
cmd-status)
# Marks the end of a child script.
# $1 is a command name, $2 is the command's exit status.
# If the command failed, report it, and add it to a list.
if [ "$2" != 0 ]; then
rc_failures="${rc_failures}${rc_failures:+ }$1"
msg="$1 $(human_exit_code $2)"
rc_log_message "$msg"
if ! $rc_silent; then
printf "%s\n" "$msg"
fi
fi
# After the mountcritlocal script has finished, it's
# OK to flush the log to disk
case "$1" in
*/mountcritlocal)
rc_log_flush OK
;;
esac
;;
nop)
# Do nothing.
# This has the side effect of flushing partial lines,
# and the echo() and printf() functions in rc.subr take
# advantage of this.
;;
note)
# Unlike most metadata messages, which should be used
# only by /etc/rc and rc.subr, the "note" message may be
# used directly by /etc.rc.d/* and similar scripts.
# It adds a note to the log file, without displaying
# it to stdout.
rc_log_message "[NOTE: $args]"
;;
end)
# Marks the end of processing, after the last child script.
# If any child scripts (or other commands) failed, report them.
#
if [ -n "$rc_failures" ]; then
rc_log_message "[failures]"
msg="The following components reported failures:"
msg="${msg}${nl}$( echo " ${rc_failures}" | fmt )"
msg="${msg}${nl}See ${RC_LOG_FILE} for more information."
rc_log_message "${msg}"
printf "%s\n" "${msg}"
fi
#
# Report the end date/time, even in silent mode
#
rc_log_message "[$0 finished at $args]"
printf "%s\n" "$args"
;;
exit)
# Marks an exit from the rc_real_work() function.
# This may be a normal or abnormal exit.
#
rc_log_message "[$0 exiting with status $1]"
exit $1
;;
interrupted)
# Marks an interrupt trapped by the rc_real_work() function.
# $args is a human-readable message.
rc_log_message "$args"
printf "%s\n" "$args"
;;
*)
# an unrecognised line of metadata
rc_log_message "[metadata:${metadata}]"
;;
esac
}
#
# rc_log_message string [...]
# Write a message to the log file, or buffer it for later.
# This function appends a newline to the message.
#
rc_log_message()
{
_rc_log_buffer="${_rc_log_buffer}${*}${nl}"
rc_log_flush
}
#
# rc_log_message_n string [...]
# Just like rc_log_message, except without appending a newline.
#
rc_log_message_n()
{
_rc_log_buffer="${_rc_log_buffer}${*}"
rc_log_flush
}
#
# rc_log_flush [OK|FORCE]
# save outstanding messages from $_rc_log_buffer to $RC_LOG_FILE.
#
# The log file is expected to reside in the /var/run directory, which
# may not be writable very early in the boot sequence, and which is
# erased a little later in the boot sequence. We therefore avoid
# writing to the file until we believe it's safe to do so. We also
# assume that it's reasonable to always append to the file, never
# truncating it.
#
# Optional argument $1 may be "OK" to report that writing to the log
# file is expected to be safe from now on, or "FORCE" to force writing
# to the log file even if it may be unsafe.
#
# Returns a non-zero status if messages could not be written to the
# file.
#
rc_log_flush()
{
#
# If $_rc_log_flush_ok is false, then it's probably too early to
# write to the log file, so don't do it, unless $1 is "FORCE".
#
: ${_rc_log_flush_ok=false}
case "$1:$_rc_log_flush_ok" in
OK:*)
_rc_log_flush_ok=true
;;
FORCE:*)
: OK just this once
;;
*:true)
: OK
;;
*)
# it's too early in the boot sequence, so don't flush
return 1
;;
esac
#
# Now append the buffer to the file. The buffer should already
# contain a trailing newline, so don't add an extra newline.
#
if [ -n "$_rc_log_buffer" ]; then
if { printf "%s" "${_rc_log_buffer}" >>"${RC_LOG_FILE}" ; } \
2>/dev/null
then
_rc_log_buffer=""
else
return 1
fi
fi
return 0
}
#
# Most of the action is in the rc_real_work() and rc_postprocess()
# functions.
#
rc_real_work "$@" 2>&1 | rc_postprocess
exit $?

View File

@ -23,7 +23,7 @@ create_ramdisk()
}
# Create /var ramdisk
create_ramdisk ram0 /var 256
create_ramdisk ram0 /var 512
create_ramdisk ram1 /tmp 128
create_ramdisk ram2 /usr/run 64
create_ramdisk ram3 /root 512

View File

@ -14,8 +14,9 @@ if [ -r /etc/defaults/rc.conf ]; then
fi
# If this is not set to YES, the system will drop into single-user mode.
# MINIX 3: for now, this setting is enabled by default.
#
rc_configured=NO
rc_configured=YES
# Add local overrides below.
#

10
etc/rc.d/DAEMON Executable file
View File

@ -0,0 +1,10 @@
#!/bin/sh
#
# $NetBSD: DAEMON,v 1.8 2002/03/22 04:33:57 thorpej Exp $
#
# PROVIDE: DAEMON
# REQUIRE: NETWORKING SERVERS
# This is a dummy dependency, to ensure that general purpose daemons
# are run _after_ the above are.

11
etc/rc.d/DISKS Normal file
View File

@ -0,0 +1,11 @@
#!/bin/sh
#
# $NetBSD: DISKS,v 1.1 2009/04/21 16:08:57 joerg Exp $
#
# PROVIDE: DISKS
#
# This is a dummy dependency, to ensure that all disk devices are
# accessible for fsck and mountcritlocal.
#

13
etc/rc.d/LOGIN Executable file
View File

@ -0,0 +1,13 @@
#!/bin/sh
#
# $NetBSD: LOGIN,v 1.7 2002/03/22 04:33:57 thorpej Exp $
#
# PROVIDE: LOGIN
# REQUIRE: DAEMON
# This is a dummy dependency to ensure user services such as xdm,
# inetd, cron and kerberos are started after everything else, incase
# the administrator has increased the system security level and
# wants to delay user logins until the system is (almost) fully
# operational.

79
etc/rc.d/Makefile Executable file
View File

@ -0,0 +1,79 @@
# $NetBSD: Makefile,v 1.93 2015/03/30 10:58:37 chopps Exp $
.include <bsd.own.mk>
#
# NOTE:
#
# If you're adding new scripts, don't forget to update following:
# src/distrib/sets/lists/etc/mi
# src/etc/mtree/special
# src/usr.sbin/postinstall/postinstall
#
# You can find a script to visualize the dependency graph in
# src/sbin/rcorder.
# MINIX: the idea for importing rc.d scripts is basically:
# - in principle, import only the scripts for functionality that we support;
# - do not change dependencies ("REQUIRE", "BEFORE") in such scripts; rather,
# satisfy the dependencies, recursively, with the following rules;
# - for each such dependency, if it can be disabled (= it has a "rcvar"), then
# import its script as is, even if we do not support its functionality;
# - if such an unsupported dependency is enabled by default as per
# etc/defaults/rc.conf, then disable it by overriding it explicitly in
# etc/defaults/minix.rc.conf;
# - for unsupported dependencies that can not be disabled, create a stub for it
# (examples: fsck, root, mountcritlocal) but whenever relevant do try to keep
# its dependency listing intact so as not to disturb the regular ordering.
CONFIGFILES=\
DAEMON DISKS LOGIN NETWORKING SERVERS \
\
bootconf.sh \
\
\
fsck ftpd \
\
\
ipfilter ipsec \
\
\
local \
\
mountcritlocal mountcritremote \
network npf \
\
pwcheck \
\
\
root \
\
\
sysctl sysdb syslogd \
ttys \
wscons \
.if defined(__MINIX)
# MINIX: we will gradually switch over to the NetBSD rc system. For conflict
# avoidance, all MINIX-specific scripts should have "minix" in their name.
CONFIGFILES+= minixrc
.endif
FILESDIR= /etc/rc.d
FILESMODE= ${BINMODE}
.if !defined(__MINIX) # XXX needs testing first
.if ${MKX11} != "no"
CONFIGFILES+= xdm xfs fccache
FILESBUILD_xdm= yes
FILESBUILD_xfs= yes
FILESBUILD_fccache= yes
.endif # !defined(__MINIX)
.SUFFIXES: .in
.in:
${_MKTARGET_CREATE}
${TOOL_SED} -e 's,@X11ROOTDIR@,${X11ROOTDIR},g' < ${.IMPSRC} > ${.TARGET}
.endif
.include <bsd.prog.mk>

9
etc/rc.d/NETWORKING Executable file
View File

@ -0,0 +1,9 @@
#!/bin/sh
#
# $NetBSD: NETWORKING,v 1.2 2002/03/22 04:33:57 thorpej Exp $
#
# PROVIDE: NETWORKING NETWORK
# This is a dummy dependency, for services which require networking
# to be operational before starting.

10
etc/rc.d/SERVERS Executable file
View File

@ -0,0 +1,10 @@
#!/bin/sh
#
# $NetBSD: SERVERS,v 1.9 2002/03/22 04:33:57 thorpej Exp $
#
# PROVIDE: SERVERS
# REQUIRE: mountcritremote
# This is a dummy dependency, for early-start servers relying on
# some basic configuration.

87
etc/rc.d/bootconf.sh Executable file
View File

@ -0,0 +1,87 @@
#!/bin/sh
#
# $NetBSD: bootconf.sh,v 1.15 2012/12/31 23:21:27 christos Exp $
#
# PROVIDE: bootconf
# REQUIRE: mountcritlocal
# KEYWORD: interactive
$_rc_subr_loaded . /etc/rc.subr
name="bootconf"
start_cmd="bootconf_start"
stop_cmd=":"
bootconf_start()
{
# Refer to newbtconf(8) for more information
#
if [ ! -e /etc/etc.current ]; then
return 0
fi
if [ -h /etc/etc.default ]; then
def=$(ls -ld /etc/etc.default 2>&1)
default="${def##*-> *etc.}"
else
default=current
fi
if [ "$default" = "current" ]; then
def=$(ls -ld /etc/etc.current 2>&1)
default="${def##*-> *etc.}"
fi
spc=""
for i in /etc/etc.*; do
name="${i##/etc/etc.}"
case $name in
current|default|\*)
continue
;;
*)
if [ "$name" = "$default" ]; then
echo -n "${spc}[${name}]"
else
echo -n "${spc}${name}"
fi
spc=" "
;;
esac
done
echo
_DUMMY=/etc/passwd
conf=${_DUMMY}
while [ ! -d /etc/etc.$conf/. ]; do
trap "conf=$default; echo; echo Using default of $default" ALRM
echo -n "Which configuration [$default] ? "
(sleep 30 && kill -ALRM $RC_PID) >/dev/null 2>&1 &
read conf
trap : ALRM
if [ -z $conf ] ; then
conf=$default
fi
if [ ! -d /etc/etc.$conf/. ]; then
conf=${_DUMMY}
fi
done
print_rc_metadata "note:Using configuration \"${conf}\""
case $conf in
current|default)
;;
*)
rm -f /etc/etc.current
ln -s etc.$conf /etc/etc.current
sync
;;
esac
if [ -f /etc/rc.conf ] ; then
. /etc/rc.conf
fi
}
load_rc_config $name
run_rc_command "$1"

5
etc/rc.d/fsck Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
# MINIX 3 stub.
# PROVIDE: fsck
# REQUIRE: DISKS

19
etc/rc.d/ftpd Executable file
View File

@ -0,0 +1,19 @@
#!/bin/sh
#
# $NetBSD: ftpd,v 1.3 2005/08/09 14:59:33 peter Exp $
#
# PROVIDE: ftpd
# REQUIRE: LOGIN
# KEYWORD: shutdown
$_rc_subr_loaded . /etc/rc.subr
name="ftpd"
rcvar=$name
command="/usr/libexec/${name}"
command_args="-D"
pidfile="/var/run/${name}.pid"
load_rc_config $name
run_rc_command "$1"

104
etc/rc.d/ipfilter Executable file
View File

@ -0,0 +1,104 @@
#!/bin/sh
#
# $NetBSD: ipfilter,v 1.18 2009/03/23 18:52:02 hannken Exp $
#
# PROVIDE: ipfilter
# REQUIRE: root bootconf mountcritlocal tty
$_rc_subr_loaded . /etc/rc.subr
name="ipfilter"
rcvar=$name
start_precmd="ipfilter_prestart"
start_cmd="ipfilter_start"
stop_precmd="test -f /etc/ipf.conf -o -f /etc/ipf6.conf"
stop_cmd="ipfilter_stop"
reload_precmd="$stop_precmd"
reload_cmd="ipfilter_reload"
resync_precmd="$stop_precmd"
resync_cmd="ipfilter_resync"
status_precmd="$stop_precmd"
status_cmd="ipfilter_status"
extra_commands="reload resync status"
ipfilter_prestart()
{
if [ ! -f /etc/ipf.conf ] && [ ! -f /etc/ipf6.conf ]; then
warn "/etc/ipf*.conf not readable; ipfilter start aborted."
stop_boot
return 1
fi
return 0
}
ipfilter_start()
{
echo "Enabling ipfilter."
/sbin/ipf ${rc_flags} -E
# Do the flush first; since older ipf has different semantics.
#
if [ -f /etc/ipf.conf ]; then
/sbin/ipf -Fa
fi
if [ -f /etc/ipf6.conf ]; then
/sbin/ipf -6 -Fa
fi
# Now load the config files
#
if [ -f /etc/ipf.conf ]; then
/sbin/ipf -f /etc/ipf.conf
fi
if [ -f /etc/ipf6.conf ]; then
/sbin/ipf -6 -f /etc/ipf6.conf
fi
}
ipfilter_stop()
{
echo "Disabling ipfilter."
/sbin/ipf -D
}
ipfilter_reload()
{
echo "Reloading ipfilter rules."
# Do the flush first; since older ipf has different semantics.
#
if [ -f /etc/ipf.conf ]; then
/sbin/ipf -I -Fa
fi
if [ -f /etc/ipf6.conf ]; then
/sbin/ipf -6 -I -Fa
fi
# Now load the config files into the Inactive set
#
if [ -f /etc/ipf.conf ] && ! /sbin/ipf -I -f /etc/ipf.conf; then
err 1 "reload of ipf.conf failed; not swapping to new ruleset."
fi
if [ -f /etc/ipf6.conf ] && ! /sbin/ipf -I -6 -f /etc/ipf6.conf; then
err 1 "reload of ipf6.conf failed; not swapping to new ruleset."
fi
# Swap in the new rules
#
/sbin/ipf -s
}
ipfilter_resync()
{
/sbin/ipf -y
}
ipfilter_status()
{
/sbin/ipf -V
}
load_rc_config $name
run_rc_command "$1"

90
etc/rc.d/ipsec Executable file
View File

@ -0,0 +1,90 @@
#!/bin/sh
#
# $NetBSD: ipsec,v 1.13 2013/09/12 19:52:50 christos Exp $
#
# PROVIDE: ipsec
# REQUIRE: root bootconf mountcritlocal tty
# BEFORE: DAEMON
$_rc_subr_loaded . /etc/rc.subr
name="ipsec"
rcvar=$name
start_precmd="ipsec_prestart"
start_cmd="ipsec_start"
stop_precmd="test -f /etc/ipsec.conf"
stop_cmd="ipsec_stop"
reload_cmd="ipsec_reload"
extra_commands="reload"
ipsec_prestart()
{
if [ ! -f /etc/ipsec.conf ]; then
warn "/etc/ipsec.conf not readable; ipsec start aborted."
stop_boot
return 1
fi
return 0
}
ipsec_getip() {
ifconfig $1 | while read what address rest; do
case "$what" in
inet) echo "$address";;
esac
done
}
ipsec_load() {
if [ -z "$1" ]; then
/sbin/setkey -f /etc/ipsec.conf
else
sed -e "s/@LOCAL_ADDR@/$1/" < /etc/ipsec.conf | \
/sbin/setkey -f -
fi
}
ipsec_configure() {
while true; do
local addr="$(ipsec_getip "$ipsec_flags")"
case "$addr" in
'') sleep 1;;
"0.0.0.0") sleep 1;;
*) ipsec_load "$addr"; return;;
esac
done &
}
ipsec_start()
{
echo "Installing ipsec manual keys/policies."
if [ -n "$ipsec_flags" ]; then
ipsec_configure
else
ipsec_load
fi
}
ipsec_stop()
{
echo "Clearing ipsec manual keys/policies."
# still not 100% sure if we would like to do this.
# it is very questionable to do this during shutdown session, since
# it can hang any of remaining IPv4/v6 session.
#
/sbin/setkey -F
/sbin/setkey -FP
}
ipsec_reload()
{
echo "Reloading ipsec manual keys/policies."
ipsec_stop
ipsec_start
}
load_rc_config $name
run_rc_command "$1"

32
etc/rc.d/local Executable file
View File

@ -0,0 +1,32 @@
#!/bin/sh
#
# $NetBSD: local,v 1.7 2004/08/13 18:08:03 mycroft Exp $
#
# REQUIRE: DAEMON
# PROVIDE: local
# BEFORE: LOGIN
# KEYWORD: shutdown
$_rc_subr_loaded . /etc/rc.subr
name="local"
start_cmd="local_start"
stop_cmd="local_stop"
local_start()
{
if [ -f /etc/rc.local ]; then
. /etc/rc.local
fi
}
local_stop()
{
if [ -f /etc/rc.shutdown.local ]; then
. /etc/rc.shutdown.local
fi
}
load_rc_config $name
run_rc_command "$1"

17
etc/rc.d/minixrc Executable file
View File

@ -0,0 +1,17 @@
#!/bin/sh
# MINIX 3 bridge from NetBSD rc to MINIX rc. Must be called as the very first
# script at startup (hence the current 'before'). Ideally the MINIX rc would
# be decomposed into a number of small rc scripts, though.
# PROVIDE: minixrc
# BEFORE: DISKS
# KEYWORD: shutdown
$_rc_subr_loaded . /etc/rc.subr
name="minixrc"
start_cmd="sh /etc/rc.minix start"
stop_cmd="sh /etc/rc.minix stop"
load_rc_config $name
run_rc_command "$1"

5
etc/rc.d/mountcritlocal Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
# MINIX 3 stub.
# PROVIDE: mountcritlocal
# REQUIRE: fsck

7
etc/rc.d/mountcritremote Executable file
View File

@ -0,0 +1,7 @@
#!/bin/sh
# MINIX 3 stub.
# Even though this script does not appear to do much, it will in some cases
# invoke the mount command with a syntax that we do not support.
# PROVIDE: mountcritremote
# REQUIRE: NETWORKING root mountcritlocal

6
etc/rc.d/network Executable file
View File

@ -0,0 +1,6 @@
#!/bin/sh
# MINIX 3 stub (for now!).
# PROVIDE: network
# REQUIRE: ipfilter ipsec mountcritlocal root tty sysctl
# BEFORE: NETWORKING

62
etc/rc.d/npf Normal file
View File

@ -0,0 +1,62 @@
#!/bin/sh
#
# $NetBSD: npf,v 1.3 2012/11/01 06:06:14 mrg Exp $
#
# Public Domain.
#
# PROVIDE: npf
# REQUIRE: root bootconf mountcritlocal tty network
# BEFORE: NETWORKING
$_rc_subr_loaded . /etc/rc.subr
name="npf"
rcvar=$name
config="/etc/npf.conf"
start_cmd="npf_start"
stop_cmd="npf_stop"
reload_cmd="npf_reload"
status_cmd="npf_status"
extra_commands="reload status"
npf_cfg_check()
{
if [ ! -f ${config} ]; then
warn "${config} is not readable; failed."
exit 1
fi
}
npf_start()
{
echo "Enabling NPF."
npf_cfg_check
/sbin/npfctl reload
/sbin/npfctl start
}
npf_stop()
{
echo "Disabling NPF."
/sbin/npfctl stop
/sbin/npfctl flush
}
npf_reload()
{
echo "Reloading NPF ruleset."
npf_cfg_check
/sbin/npfctl reload
}
npf_status()
{
:
}
load_rc_config $name
run_rc_command "$1"

27
etc/rc.d/pwcheck Executable file
View File

@ -0,0 +1,27 @@
#!/bin/sh
#
# $NetBSD: pwcheck,v 1.5 2004/08/13 18:08:03 mycroft Exp $
#
# PROVIDE: pwcheck
# REQUIRE: mountcritremote syslogd
# BEFORE: DAEMON
$_rc_subr_loaded . /etc/rc.subr
name="pwcheck"
start_cmd="pwcheck_start"
stop_cmd=":"
pwcheck_start()
{
# check the password temp/lock file
#
if [ -f /etc/ptmp ]; then
logger -s -p auth.err \
"password file may be incorrect -- /etc/ptmp exists"
fi
}
load_rc_config $name
run_rc_command "$1"

4
etc/rc.d/root Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
# MINIX 3 stub.
# PROVIDE: root

25
etc/rc.d/sysctl Executable file
View File

@ -0,0 +1,25 @@
#!/bin/sh
#
# $NetBSD: sysctl,v 1.13 2004/08/13 18:08:03 mycroft Exp $
#
# PROVIDE: sysctl
# REQUIRE: root ipfilter ipsec
# BEFORE: DAEMON
$_rc_subr_loaded . /etc/rc.subr
name="sysctl"
start_cmd="sysctl_start"
stop_cmd=":"
sysctl_start()
{
if [ -r /etc/sysctl.conf ]; then
echo "Setting sysctl variables:"
sysctl -f /etc/sysctl.conf
fi
}
load_rc_config $name
run_rc_command "$1"

93
etc/rc.d/sysdb Executable file
View File

@ -0,0 +1,93 @@
#!/bin/sh
#
# $NetBSD: sysdb,v 1.24 2012/06/03 21:42:45 joerg Exp $
#
# PROVIDE: sysdb
# REQUIRE: mountcritremote
# BEFORE: DAEMON
$_rc_subr_loaded . /etc/rc.subr
name="sysdb"
rcvar=$name
start_cmd="sysdb_start"
stop_cmd=":"
extra_commands="devdb utmp services netgroup password"
devdb_cmd="build_devdb"
utmp_cmd="build_utmp"
services_cmd="build_services"
netgroup_cmd="build_netgroup"
password_cmd="build_password"
echo=:
sysdb_start()
{
echo -n "Building databases:"
echo=echo
comma=" "
$devdb_cmd
$utmp_cmd
$services_cmd
$netgroup_cmd
$password_cmd
echo "."
}
check_file()
{
local src="$1"
local db="$2"
shift 2
if [ ! -e "$src" ]; then
return
fi
if [ \( ! -f "$db" \) -o \( "$src" -nt "$db" \) ]; then
$echo -n "$comma$(basename "$src")"
comma=", "
"$@"
fi
}
build_services()
{
check_file /etc/services /var/db/services.cdb services_mkdb -q
}
build_netgroup()
{
check_file /etc/netgroup /var/db/netgroup.db netgroup_mkdb
}
build_devdb()
{
check_file /dev /var/run/dev.db dev_mkdb
check_file /dev /var/run/dev.cdb dev_mkdb
}
build_password()
{
local p=/etc/master.passwd
check_file $p /etc/spwd.db pwd_mkdb -w $p
}
build_utmp()
{
# Re-create /var/run/utmp and /var/run/utmpx, which are
# deleted by mountcritlocal but can't be recreated by it
# because install and chown may not be available then
# (possibly no /usr).
#
local i
for i in "" x; do
if [ ! -f /var/run/utmp$i ]; then
$echo -n "${comma}utmp$i"
comma=", "
install -c -m 664 -g utmp /dev/null /var/run/utmp$i
fi
done
}
load_rc_config $name
run_rc_command "$1"

64
etc/rc.d/syslogd Executable file
View File

@ -0,0 +1,64 @@
#!/bin/sh
#
# $NetBSD: syslogd,v 1.15 2004/10/11 13:29:52 lukem Exp $
#
# PROVIDE: syslogd
# REQUIRE: mountcritremote sysdb wscons
# BEFORE: SERVERS
$_rc_subr_loaded . /etc/rc.subr
name="syslogd"
rcvar=$name
command="/usr/sbin/${name}"
pidfile="/var/run/${name}.pid"
required_files="/etc/syslog.conf"
start_precmd="syslogd_precmd"
extra_commands="reload"
_sockfile="/var/run/syslogd.sockets"
syslogd_precmd()
{
# Transitional symlink for old binaries
#
# MINIX 3: unsupported, disabled
#if [ ! -h /dev/log ]; then
# ln -sf /var/run/log /dev/log
#fi
# MINIX 3: end
# Create default list of syslog sockets to watch
#
( umask 022 ; > $_sockfile )
# Find /etc/rc.d scripts with "chrootdir" rcorder(8) keyword,
# and if $${app}_chrootdir is a directory, add appropriate
# syslog socket to list of sockets to watch.
#
for _lr in $(rcorder -k chrootdir /etc/rc.d/*); do
(
_l=${_lr##*/}
load_rc_config ${_l}
eval _ldir=\$${_l}_chrootdir
if checkyesno $_l && [ -n "$_ldir" ]; then
echo "${_ldir}/var/run/log" >> $_sockfile
fi
)
done
# If other sockets have been provided, change run_rc_command()'s
# internal copy of $syslogd_flags to force use of specific
# syslogd sockets.
#
if [ -s $_sockfile ]; then
echo "/var/run/log" >> $_sockfile
rc_flags="-P $_sockfile $rc_flags"
fi
return 0
}
load_rc_config $name
run_rc_command "$1"

8
etc/rc.d/ttys Executable file
View File

@ -0,0 +1,8 @@
#!/bin/sh
# MINIX 3 stub.
# There is currently nothing in the NetBSD script that we want: setting tty
# flags is not yet a supported concept, and changing /dev/tty permissions does
# not work from the installation CD with its read-only /dev directory.
# PROVIDE: tty
# REQUIRE: root bootconf

186
etc/rc.d/wscons Executable file
View File

@ -0,0 +1,186 @@
#!/bin/sh
#
# $NetBSD: wscons,v 1.13 2011/08/09 08:08:10 mbalmer Exp $
#
# PROVIDE: wscons
# REQUIRE: mountcritremote
# BEFORE: LOGIN
$_rc_subr_loaded . /etc/rc.subr
name="wscons"
rcvar=$name
start_cmd="wscons_start"
stop_cmd=":"
wscons_start()
{
wscfg=/usr/sbin/wsconscfg
wsfld=/usr/sbin/wsfontload
wsctl=/sbin/wsconsctl
config=/etc/wscons.conf
usage="Usage: wsconfig [-n] [-f configfile] [-font fontpgm] [-screen screenpgm]"
DOIT=
while [ $# -gt 0 ]; do
case $1 in
-n)
DOIT=echo
;;
-f)
config=$2
shift
;;
-font)
wsfld=$2
shift
;;
-screen)
wscfg=$2
shift
;;
*)
echo $usage
exit 1
;;
esac
shift
done
# args mean:
# screen idx scr emul
# font name width height enc file
( while read type arg1 arg2 arg3 arg4 arg5; do
case "$type" in
\#*|"")
continue
;;
font)
name=$arg1
width=$arg2
height=$arg3
enc=$arg4
file=$arg5
cmd=$wsfld
case $width in
-)
;;
*)
cmd="$cmd -w $width"
;;
esac
case $height in
-)
;;
*)
cmd="$cmd -h $height"
;;
esac
case $enc in
-)
;;
*)
cmd="$cmd -e $enc"
;;
esac
cmd="$cmd -N $name $file"
eval $DOIT $cmd
;;
screen)
idx=$arg1
scr=$arg2
emul=$arg3
cmd=$wscfg
case $scr in
-)
;;
*)
cmd="$cmd -t $scr"
;;
esac
case $emul in
-)
;;
*)
cmd="$cmd -e $emul"
;;
esac
cmd="$cmd $idx"
eval $DOIT $cmd
;;
keyboard)
kbd=$arg1
cmd=$wscfg
case $kbd in
-|auto)
cmd="$cmd -k"
;;
*)
cmd="$cmd -k $kbd"
;;
esac
eval $DOIT $cmd
;;
encoding)
map=$arg1
cmd="$wsctl -w \"encoding=$map\""
echo -n 'Keyboard '
eval $DOIT $cmd
;;
mapfile)
mapfile=$arg1
( while read entry; do
case "$entry" in
\#*|"")
continue
;;
*)
cmd="$wsctl -w \"map+=$entry\""
cmd="$cmd >/dev/null"
eval $DOIT $cmd
;;
esac
done ) < $mapfile
;;
mux)
cmd="$wscfg -m $arg1"
eval $DOIT $cmd
;;
setvar)
dev=$arg1
var=$arg2
val=$arg3
case $dev in
ttyE*)
cmdmod="-d"
;;
wskbd*)
cmdmod="-k"
;;
wsmouse*)
cmdmod="-m"
;;
esac
echo -n "$dev: "
cmd="$wsctl -f /dev/$dev $cmdmod -w $var=$val"
eval $DOIT $cmd
;;
esac
done ) < $config
}
load_rc_config $name
run_rc_command "$1"

248
etc/rc.minix Executable file
View File

@ -0,0 +1,248 @@
# /etc/rc.minix - MINIX system startup script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
# The normal system boot situation is that init(8) invokes the ramdisk RC
# script, which invokes the NetBSD rc infrastructure, which in turn calls this
# script through /etc/rc.d/minixrc. With a boot ramdisk (x86_ramimage), the
# ramdisk RC is bypassed altogether, but stored as /etc/rc.ramdisk. We then
# have to invoke it here (for startup only!) to let it perform its tasks first.
if sysenv bootramdisk >/dev/null
then
[ "$1" = "start" ] && sh /etc/rc.ramdisk "$@"
fi
# Same settings as in the default /etc/profile. We do not source this file
# as the system administrator may decide to change those values for his users.
RC_TZ=/etc/rc.timezone
# Are we booting from CD?
bootcd="`/bin/sysenv bootcd`"
# Set TERM to minix if not present.
TERM="${TERM-minix}"
export TERM PATH
# Local variables
ARCH="`sysenv arch`"
usage()
{
echo >&2 "Usage: $0 [-saf] [start|stop]"
exec intr sh
}
up()
{
# Function to dynamically start a system service
opt=""
prefix=$(expr "$1 " : '\(-\)')
if [ "$prefix" = "-" ];
then
opt=$1
shift
fi
service=$1
shift
minix-service $opt up /service/$service "$@"
}
edit()
{
# Function to dynamically edit system service settings
opt=""
prefix=$(expr "$1 " : '\(-\)')
if [ "$prefix" = "-" ];
then
opt=$1
shift
fi
service=$1
shift
# Assume binaries are always in /service or /usr/pkg/service
binlocation=/service/$service
if [ ! -x $binlocation ]
then binlocation=/usr/pkg/service/$service
fi
# Mostly to find init...
if [ ! -x $binlocation ]
then binlocation=/sbin/$service
fi
minix-service $opt edit $binlocation -label $service "$@"
}
set -- `sysenv bootopt` "$@"
while getopts 'saf' opt
do
case $opt in
s) sflag=t ;; # Single user
a) aflag=t ;; # Ask for /usr
f) fflag=-f ;; # Force a full file system check
*) usage
esac
done
shift `expr $OPTIND - 1`
case "$#:$1" in
1:start|1:stop)
action=$1
;;
*) usage
esac
case $action in
start)
# If booting from CD, we want some directories to be ramdisks
if [ ! -z "$bootcd" ]
then
. /etc/rc.cd
fi
# National keyboard?
test -f /etc/keymap && loadkeys /etc/keymap
# options for fsck. default is -r, which prompts the user for repairs.
optname=fsckopts
fsckopts=-p
if sysenv $optname >/dev/null
then fsckopts="`sysenv $optname`"
fi
if [ "`sysenv debug_fkeys`" != 0 ]
then
up -n is -period 5HZ
fi
# Set timezone.
export TZ=GMT0
if [ -f "$RC_TZ" ]
then
. "$RC_TZ"
fi
# Start real time clock driver & set system time, otherwise default date.
up readclock.drv
readclock -q || date 201301010000
# We are not shutting down.
if [ -f /etc/nologin ]
then
rm -f /etc/nologin
fi
# Use MFS binary only from kernel image?
if [ "`sysenv bin_img`" = 1 ]
then
bin_img="-i "
fi
# fsck + mount using /etc/fstab.
fsck -x / $fflag $fsckopts
mount -a
if [ -z "`sysenv bootramdisk`" ]
then
# Unmount and free now defunct ramdisk
umount /dev/imgrd > /dev/null || echo "Failed to unmount boot ramdisk"
ramdisk 0 /dev/imgrd || echo "Failed to free boot ramdisk"
fi
# Initialize files.
>/var/run/utmp # /etc/utmp keeps track of logins
>/var/run/utmpx # /etc/utmpx keeps track of logins
# Edit settings for boot system services
if [ "`sysenv skip_boot_config`" != 1 ]
then
edit rs
edit vm
edit pm
edit sched
edit vfs
edit ds
edit tty
edit memory
edit mib
edit pfs
edit init
#
# Keep a copy around to recover the root FS from crashes
#
rootline=`cat /etc/mtab | grep "on / "`
rootfs=fs_`echo "$rootline" | cut -d' ' -f1 | cut -d'/' -f3`
[ "$rootfs" = "fs_bootramdisk" ] && rootfs=fs_imgrd
roottype=`echo "$rootline" | cut -d' ' -f5`
minix-service -c edit /service/$roottype -label $rootfs
fi
if [ "$sflag" ]
then
echo "Single user. Press ^D to resume multiuser startup."
intr sh
echo
fi
echo "Multiuser startup in progress ..."
case "`printroot -r`":$bootcd in
/dev/ram:)
# Remove boot-only things to make space,
# unless booting from CD, in which case we need them.
rm -rf /boot
# put the compiler on ram
cp /usr/lib/em* /usr/lib/cpp* /lib
esac
echo -n "Starting hotplugging infrastructure... "
rm -f /var/run/devmand.pid
devmand -d /etc/devmand -d /usr/pkg/etc/devmand &
echo "done."
# Things should be alright now.
;;
stop)
sync
if [ -f /var/run/devmand.pid ]
then
kill -INT `cat /var/run/devmand.pid`
# without this delay the following will
# be printed in the console
# RS: devman not running?
sleep 1
fi
#
# usbd needs to be stopped exactly
# at this stage(before stopping devman
# and after stopping the services
# stated by devmand)
if [ -x /usr/pkg/etc/rc.d/usbd ]
then
/usr/pkg/etc/rc.d/usbd stop
fi
if [ -x /service/usbd ]
then
minix-service down usbd
fi
# Tell RS server we're going down.
minix-service shutdown
;;
esac
# Further initialization.
test -f /usr/etc/rc && sh /usr/etc/rc $action
test -f /usr/local/etc/rc && sh /usr/local/etc/rc $action
# Any messages?
if [ "$action" = start ]
then if [ -f /etc/issue ]
then cat /etc/issue
fi
fi
exit 0

View File

@ -1,3 +1,66 @@
#!/bin/sh
#
# $NetBSD: rc.shutdown,v 1.9 2012/06/25 07:22:45 jnemeth Exp $
#
# rc.shutdown --
# Run the scripts in /etc/rc.d with reverse rcorder.
sh /etc/rc stop
# System shutdown script run by shutdown(8) at system shutdown time.
# Note that halt(8) and reboot(8) do NOT invoke this script.
export HOME=/
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
. /etc/rc.subr
. /etc/rc.conf
if ! checkyesno do_rcshutdown; then
echo "Skipping shutdown hooks."
exit 0
fi
stty status '^T'
# Set shell to ignore SIGINT, but not children;
# shell catches SIGQUIT and returns to single user.
#
trap : INT
trap "echo 'Shutdown interrupted.'; exit 1" QUIT
# If requested, start a watchdog timer in the background which
# will terminate rc.shutdown if rc.shutdown doesn't complete
# within the specified time.
#
_rcshutdown_watchdog=
if [ -n "$rcshutdown_timeout" ]; then
sleep $rcshutdown_timeout && (
_msg="$rcshutdown_timeout second watchdog timeout expired. Shutdown terminated."
logger -t rc.shutdown "$_msg"
echo "$_msg"
date
kill -KILL $$ >/dev/null 2>&1
) &
_rcshutdown_watchdog=$!
fi
# Determine the shutdown order of the rc.d scripts,
# and perform the operation
#
scripts=$(for rcd in ${rc_directories:-/etc/rc.d}; do
test -d ${rcd} && echo ${rcd}/*; done)
files=$(rcorder -k shutdown ${rcshutdown_rcorder_flags} ${scripts})
for _rc_elem in $(reverse_list $files); do
run_rc_script $_rc_elem stop
done
# Terminate the background watchdog timer (if it is running)
#
if [ -n "$_rcshutdown_watchdog" ]; then
kill -TERM $_rcshutdown_watchdog >/dev/null 2>&1
fi
date
exit 0

View File

@ -25,13 +25,10 @@ fi
bootcd="`/bin/sysenv bootcd`"
case "$#:$1" in
1:autoboot)
action=start
;;
1:start|1:stop|1:down)
1:start|1:stop)
action=$1
;;
*) echo >&2 "Usage: $0 autoboot|start|stop|down"
*) echo >&2 "Usage: $0 [start|stop]"
exit 1
esac
@ -161,7 +158,7 @@ capemgr() {
DAEMONS=/etc/rc.daemons
case $action in
start|autoboot)
start)
# Select console font.
test -f /etc/font && loadfont /etc/font </dev/console
@ -236,9 +233,7 @@ start|autoboot)
ln -s /tmp/log /var/log || true
. /etc/rc.cd
fi
# syslogd has not been started yet
rm -f /var/run/syslogd.pid
daemonize syslogd -s
echo .
# i2c only supported on ARM at the moment
@ -393,23 +388,6 @@ start|autoboot)
fi
fi
# Now that all device files should be created, see if we need to update the
# device file database. This code is butchered from NetBSD etc/rc.d/sysdb.
DEVDIR=/dev
DEVDB=/var/run/dev.cdb
if [ ! -f "$DEVDB" -o "$DEVDIR" -nt "$DEVDB" ]
then
dev_mkdb
fi
# Same for /etc/services.
SERVICESFILE=/etc/services
SERVICESDB=/var/db/services.cdb
if [ ! -f "$SERVICESDB" -o "$SERVICESFILE" -nt "$SERVICESDB" ]
then
services_mkdb -q
fi
if [ "$net" ]
then
# Get the nodename from the DNS and set it.
@ -427,7 +405,7 @@ start|autoboot)
# Run the daily cleanup on systems that are not on at night.
test -f /usr/etc/daily && sh /usr/etc/daily boot &
;;
stop|down)
stop)
# Save random data, if /usr is mounted rw.
if grep ' \/usr .*rw.*' /etc/mtab >/dev/null
then
@ -440,8 +418,10 @@ stop|down)
fi
esac
d=
# Let packages run their own scripts
# FIXME: this should be removed altogether: pkgsrc is not supposed to be used
# this way. Instead, the user should copy over scripts from /usr/pkg/etc/rc.d
# to /etc/rc.d as desired, and configure them in /etc/rc.conf as appropriate.
for d in /usr/local/etc/rc.d /usr/pkg/etc/rc.d
do
if [ -d "$d" -a -z "$bootcd" ]

View File

@ -1,16 +1,12 @@
#!/bin/sh
set -e
exec >/dev/log
exec 2>/dev/log
exec </dev/null
PATH=/sbin:/usr/sbin:/bin:/usr/bin
FSCK=/bin/fsck_mfs
ACPI=/service/acpi
if [ X`/bin/sysenv arch` = Xi386 ]
if [ X`sysenv arch` = Xi386 ]
then if [ -e $ACPI -a -n "`sysenv acpi`" ]
then
minix-service -c up $ACPI
@ -25,15 +21,15 @@ then if [ -e $ACPI -a -n "`sysenv acpi`" ]
# Do we want to use the virtio block device?
# If not specified, default to yes if the device is found.
if /bin/sysenv virtio_blk >/dev/null
then virtio_blk="`/bin/sysenv virtio_blk`"
if sysenv virtio_blk >/dev/null
then virtio_blk="`sysenv virtio_blk`"
elif grep '^[^ ]* [^ ]* 1AF4:1001[^ ]* ' /proc/pci >/dev/null
then echo "virtio_blk not set, defaulting to using found virtio device."
virtio_blk=yes
fi
minix-service -cn up /service/floppy -dev /dev/fd0
if [ X`/bin/sysenv ahci` = Xyes ]
if [ X`sysenv ahci` = Xyes ]
then
# this is here temporarily, for testing purposes
minix-service -c up /service/ahci -dev /dev/c0d0 -label ahci_0 -args instance=0
@ -44,18 +40,21 @@ then if [ -e $ACPI -a -n "`sysenv acpi`" ]
minix-service -c up /service/at_wini -dev /dev/c0d0 -label at_wini_0
minix-service -cr up /service/at_wini -dev /dev/c1d0 -label at_wini_1 -args instance=1 2>/dev/null || :
fi
/bin/umount /proc >/dev/null
umount /proc >/dev/null
fi
if [ X`/bin/sysenv arch` = Xearm ]
if [ X`sysenv arch` = Xearm ]
then echo Starting the mmc driver
minix-service -c up /service/mmc -dev /dev/c0d0
fi
# Load ProcFS from the ramdisk to minimize the chance of a desync with the boot
# image services from which it obtains data structures directly. As we move to
# the MIB service, this will eventually become obsolete.
minix-service up /service/procfs || echo "WARNING: couldn't start procfs"
if /bin/sysenv rootdevname >/dev/null
then rootdevname=/dev/`/bin/sysenv rootdevname`
if sysenv rootdevname >/dev/null
then rootdevname=/dev/`sysenv rootdevname`
else
if (! sysenv cdproberoot) && (! sysenv bootramdisk) >/dev/null
then echo "rootdevname not set"
@ -78,7 +77,7 @@ then
export rootdevname
elif [ "$rootdevname" = "/dev/ram" ]
then
ramimagename=/dev/`/bin/sysenv ramimagename`
ramimagename=/dev/`sysenv ramimagename`
echo "Loading ramdisk from $ramimagename"
loadramdisk "$ramimagename" || echo "WARNING: loadramdisk failed"
fi
@ -97,16 +96,21 @@ then
fi
fi
# Change root from temporary boot ramdisk to the configure
# root device
if ! sysenv bootramdisk >/dev/null
then
/bin/mount -n $bin_img"$rootdevname" /
# Change root from temporary boot ramdisk to the configure root device
if ! sysenv bootramdisk >/dev/null; then
mount -n $bin_img"$rootdevname" /
# Reopen standard file descriptors, so that we can unmount the ramdisk.
# That is essentially a VFS shortcoming that should be fixed, though..
exec >/dev/log
exec 2>/dev/log
exec </dev/console
fi
/bin/mount -e -n -t procfs none /proc || echo "WARNING: couldn't mount procfs"
# Mount the ProcFS instance that was loaded from the ramdisk, on the root FS.
mount -e -n -t procfs none /proc || echo "WARNING: couldn't mount procfs"
if ! sysenv bootramdisk >/dev/null
then
exec /bin/sh /etc/rc `sysenv bootopts` "$@"
# Start the NetBSD rc infrastructure
if ! sysenv bootramdisk >/dev/null; then
exec sh /etc/rc "$@"
fi

View File

@ -4,12 +4,12 @@
# Missing: ms
.include <bsd.own.mk>
#__MINIX: dict doc examples man me \
#__MINIX: dict doc examples me \
# tabset tmac wscons xml
.if ${MKSHARE} != "no" || \
make(clean) || make(cleandir) || make(distclean) || make(obj)
SUBDIR= legal misc mk \
SUBDIR= legal man misc mk \
terminfo
.if ${MKNLS} != "no"
SUBDIR+=i18n locale nls

34
share/man/Makefile Normal file
View File

@ -0,0 +1,34 @@
# $NetBSD: Makefile,v 1.34 2014/12/13 14:16:48 christos Exp $
# from: @(#)Makefile 8.2 (Berkeley) 4/16/94
.include <bsd.own.mk>
.if ${MKSHARE} != "no"
# MINIX 3: XXX FIXME
#SUBDIR= man0 man1 man2 man3 man3lua man4 man5 man6 man7 man8 man9 man9lua
SUBDIR= man5 man8
.if !defined(__MINIX) # XXX FIXME
.if ${MKRUMP} != "no"
SUBDIR+=${.CURDIR}/../../sys/rump/share/man
.endif
WHATISDBDIR?= /usr/share/man
.if ${MKMAKEMANDB} == "no"
makedb:
${TOOL_MAKEWHATIS} ${DESTDIR}${WHATISDBDIR}
.if ${MKUNPRIVED} != "no"
echo ".${WHATISDBDIR}/whatis.db type=file mode=0444 uname=${BINOWN} gname=${BINGRP}" \
| ${METALOG.add}
.endif
.else
makedb:
.endif
.else
.endif # !defined(__MINIX)
makedb:
.endif
.include <bsd.subdir.mk>

33
share/man/man5/Makefile Normal file
View File

@ -0,0 +1,33 @@
# $NetBSD: Makefile,v 1.71 2015/03/21 19:10:43 jmcneill Exp $
# @(#)Makefile 8.1 (Berkeley) 6/5/93
# missing: dump.5 plot.5
# MINIX:
MAN= \
\
\
\
\
\
\
\
\
rc.conf.5 \
\
\
\
#MLINKS+=capfile.5 termcap.5
#MLINKS+=daily.5 daily.conf.5
#MLINKS+=fs.5 inode.5
#MLINKS+=hosts.equiv.5 rhosts.5
#MLINKS+=monthly.5 monthly.conf.5
#MLINKS+=resolv.conf.5 resolver.5
#MLINKS+=utmp.5 wtmp.5 utmp.5 lastlog.5 passwd.5 master.passwd.5
#MLINKS+=utmpx.5 wtmpx.5 utmpx.5 lastlogx.5
#MLINKS+=weekly.5 weekly.conf.5
.include <bsd.man.mk>
.include <bsd.subdir.mk>

1556
share/man/man5/rc.conf.5 Normal file

File diff suppressed because it is too large Load Diff

39
share/man/man8/Makefile Normal file
View File

@ -0,0 +1,39 @@
# $NetBSD: Makefile,v 1.104 2014/02/24 07:23:41 skrll Exp $
# from: @(#)Makefile 8.1 (Berkeley) 6/5/93
# MINIX:
MAN= \
\
\
\
rc.8 rc.subr.8 \
\
#MLINKS+=MAKEDEV.8 makedev.8
#MLINKS+=MAKEDEV.local.8 makedev.local.8
#MLINKS+=compat_svr4.8 compat_sco.8
#MLINKS+=compat_svr4.8 compat_solaris.8
#MLINKS+=compat_svr4.8 compat_svr4_32.8
#MLINKS+=compat_svr4.8 compat_xenix.8
#MLINKS+=compat_netbsd32.8 netbsd32.8
#MLINKS+=nis.8 yp.8
MLINKS+=rc.8 rc.d.8
MLINKS+=rc.8 rc.local.8
MLINKS+=rc.8 rc.shutdown.8
.if !defined(__MINIX)
SUBDIR= man8.acorn26 man8.acorn32 man8.alpha man8.amiga man8.atari \
man8.cobalt man8.dreamcast man8.emips man8.evbarm \
man8.hp300 man8.hpcarm man8.hpcmips man8.hpcsh man8.hppa \
man8.mac68k man8.macppc \
man8.mvme68k man8.next68k man8.pmax man8.prep man8.sandpoint \
man8.sgimips man8.sparc man8.sparc64 man8.sun2 man8.sun3 \
man8.vax man8.x68k man8.x86
# create MAKEDEV.8 from ../../etc/MAKEDEV.tmpl
makedevs:
cd ${.CURDIR} && ${HOST_SH} MAKEDEV2manpage.sh
.endif # !defined(__MINIX)
.include <bsd.man.mk>
.include <bsd.subdir.mk>

381
share/man/man8/rc.8 Normal file
View File

@ -0,0 +1,381 @@
.\" $NetBSD: rc.8,v 1.36 2010/05/14 16:19:58 jruoho Exp $
.\"
.\" Copyright (c) 2000-2004 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Luke Mewburn.
.\"
.\" 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
.\"
.Dd May 14, 2010
.Dt RC 8
.Os
.Sh NAME
.Nm rc ,
.Nm rc.local ,
.Nm rc.shutdown ,
.Nm rc.d/
.Nd startup and shutdown scripts
.Sh SYNOPSIS
.Nm rc
.Nm rc.local
.Nm rc.shutdown
.Nm rc.d/
.Sh DESCRIPTION
.Nm
is the command script which controls the startup of various services,
and is invoked by
.Xr init 8
as part of the process of entering the automatic reboot to multi-user startup,
or after the single user mode shell has exited.
If
.Xr init 8
is starting the automatic reboot process,
.Nm
is invoked with the argument of
.Sq autoboot .
.Pp
.Nm rc.local
is a command script to which local boot-time actions can be added.
It is (nearly) the last thing invoked by
.Nm rc
during a normal boot.
.Pp
.Nm rc.shutdown
is the command script which shuts down various services, and is invoked by
.Xr shutdown 8
as part of the process of shutting down the system.
.Pp
.Nm rc.d/
is the directory which contains various
.Xr sh 1
scripts, one for each service,
which are called by
.Nm
at startup,
.Nm rc.shutdown
at shutdown,
and as necessary during system operation to stop, start, restart, reload,
or otherwise control the service.
.Ss Operation of rc
.Bl -enum
.It
Source
.Pa /etc/rc.subr
to load various
.Xr rc.subr 8
shell functions to use.
.It
If autobooting, set
.Sy autoboot=yes
and enable a flag
.Sy ( rc_fast=yes ) ,
which prevents the
.Nm rc.d
scripts from performing the check for already running processes
(thus speeding up the boot process).
This
.Sy rc_fast=yes
speedup won't occur when
.Nm
is started up after exiting the single-user shell.
.It
Invoke
.Xr rcorder 8
to order the files in
.Pa /etc/rc.d/
that do not have a
.Dq nostart
keyword (refer to
.Xr rcorder 8 Ns 's
.Fl s
flag),
and assigns the result to a variable.
.It
Calls each script in turn using
.Fn run_rc_script
(from
.Xr rc.subr 8 ) ,
which sets
.Dv $1
to
.Sq start ,
and sources the script in a subshell.
If the script has a
.Sq .sh
suffix then it is sourced directly into the current shell.
.It
The output from the above steps is sent to a post-processor.
If
.Sy rc_silent
is false, then the post-processor displays the output.
If
.Sy rc_silent
is true, then the post-processor invokes the command specified in
.Va rc_silent_cmd
once for each line, without otherwise displaying the output.
Useful values for
.Va rc_silent_cmd
include
.Dq \&:
to display nothing at all, and
.Dq twiddle
to display a spinning symbol on the console.
Regardless of the value of
.Sy rc_silent ,
the post-processor saves the output in
.Pa /var/run/rc.log .
.El
.Ss Operation of rc.shutdown
.Bl -enum
.It
Source
.Pa /etc/rc.subr
to load various
.Xr rc.subr 8
shell functions to use.
.It
Invoke
.Xr rcorder 8
to order the files in
.Pa /etc/rc.d/
that have a
.Dq shutdown
keyword (refer to
.Xr rcorder 8 Ns 's
.Fl k
flag),
reverses that order, and assigns the result to a variable.
.It
Calls each script in turn using
.Fn run_rc_script
(from
.Xr rc.subr 8 ) ,
which sets
.Dv $1
to
.Sq stop ,
and sources the script in a subshell.
If the script has a
.Sq .sh
suffix then it is sourced directly into the current shell.
.El
.Ss Contents of rc.d/
.Nm rc.d/
is located in
.Pa /etc/rc.d .
The following file naming conventions are currently used in
.Nm rc.d/ :
.Bl -tag -width ALLUPPERCASExx -offset indent
.It Pa ALLUPPERCASE
Scripts that are
.Sq placeholders
to ensure that certain operations are performed before others.
In order of startup, these are:
.Bl -tag -width NETWORKINGxx
.It Pa NETWORKING
Ensure basic network services are running, including general
network configuration
.Pq Pa network
and
.Pa dhclient .
.It Pa SERVERS
Ensure basic services (such as
.Pa NETWORKING ,
.Pa ppp ,
.Pa syslogd ,
and
.Pa kdc )
exist for services that start early (such as
.Pa named ) ,
because they're required by
.Pa DAEMON
below.
.It Pa DAEMON
Before all general purpose daemons such as
.Pa dhcpd ,
.Pa lpd ,
and
.Pa ntpd .
.It Pa LOGIN
Before user login services
.Pa ( inetd ,
.Pa telnetd ,
.Pa rshd ,
.Pa sshd ,
and
.Pa xdm ) ,
as well as before services which might run commands as users
.Pa ( cron ,
.Pa postfix ,
and
.Pa sendmail ) .
.El
.It Pa foo.sh
Scripts that are to be sourced into the current shell rather than a subshell
have a
.Sq Pa .sh
suffix.
Extreme care must be taken in using this, as the startup sequence will
terminate if the script does.
.Pa /etc/rc.d/bootconf.sh
uses this behaviour to allow the user to select a different
configuration (including
.Pa /etc/rc.conf )
early in the boot.
.It Pa bar
Scripts that are sourced in a subshell.
The boot does not stop if such a script terminates with a non-zero status,
but a script can stop the boot if necessary by invoking the
.Fn stop_boot
function (from
.Xr rc.subr 8 ) .
.El
.Pp
Each script should contain
.Xr rcorder 8
keywords, especially an appropriate
.Dq PROVIDE
entry.
.Pp
The scripts are expected to support at least the following arguments:
.Bl -tag -width restart -offset indent
.It Sy start
Start the service.
This should check that the service is to be started as specified by
.Xr rc.conf 5 .
Also checks if the service is already running and refuses to start if
it is.
This latter check is not performed by standard
.Nx
scripts if the system is starting directly to multi-user mode, to
speed up the boot process.
.It Sy stop
If the service is to be started as specified by
.Xr rc.conf 5 ,
stop the service.
This should check that the service is running and complain if it's not.
.It Sy restart
Perform a
.Sy stop
then a
.Sy start .
.It Sy status
If the script starts a process (rather than performing a one-off
operation), show the status of the process.
Otherwise it's not necessary to support this argument.
Defaults to displaying the process ID of the program (if running).
.It Sy poll
If the script starts a process (rather than performing a one-off
operation), wait for the command to exit.
Otherwise it's not necessary to support this argument.
.It Sy rcvar
Display which
.Xr rc.conf 5
variables are used to control the startup of the service (if any).
.El
.Pp
Other arguments (such as
.Sq reload ,
.Sq dumpdb ,
etc) can be added if necessary.
.Pp
The argument may have one of the following prefixes to alter its operation:
.Bl -tag -width "force" -offset indent
.It Sy fast
Skip the check for an existing running process.
Sets
.Sy rc_fast=yes .
.It Sy force
Skips the
.Xr rc.conf 5
check, ignores a failure result from any of the prerequisite checks,
executes the command, and always returns a zero exit status.
Sets
.Sy rc_force=yes .
.It Sy one
Skips the
.Xr rc.conf 5
check, but performs all other prerequisite tests.
.El
.Pp
In order to simplify scripts, the
.Fn run_rc_command
function from
.Xr rc.subr 8
may be used.
.Sh FILES
.Bl -tag -width /etc/rc.shutdown -compact
.It Pa /etc/rc
Startup script called by
.Xr init 8 .
.It Pa /etc/rc.d/
Directory containing control scripts for each service.
.It Pa /etc/rc.local
Local startup script.
.It Pa /etc/rc.shutdown
Shutdown script called by
.Xr shutdown 8 .
.It Pa /etc/rc.subr
Contains
.Xr rc.subr 8
functions used by various scripts.
.It Pa /etc/rc.conf
System startup configuration file.
.It Pa /var/run/rc.log
Log file created by
.Nm .
.El
.Sh SEE ALSO
.Xr rc.conf 5 ,
.Xr init 8 ,
.Xr rc.subr 8 ,
.Xr rcorder 8 ,
.Xr reboot 8 ,
.Xr shutdown 8
.Rs
.%A Luke Mewburn
.%T The Design and Implementation of the NetBSD rc.d system
.%I USENIX Association
.%B Proceedings of the FREENIX Track: 2001 USENIX Annual Technical Conference
.%D June 25-30, 2001
.%U http://www.usenix.org/publications/library/proceedings/usenix01/freenix01/full_papers/mewburn/mewburn.pdf
.Re
.Sh HISTORY
The
.Nm
command appeared in
.Bx 4.0 .
The
.Pa /etc/rc.d
support was implemented in
.Nx 1.5
by
.An Luke Mewburn
.Aq lukem@NetBSD.org .
The post-processor, support for
.Va rc_silent ,
and saving output to a file, was implemented in
.Nx 6.0
by
.An Alan Barrett .

865
share/man/man8/rc.subr.8 Normal file
View File

@ -0,0 +1,865 @@
.\" $NetBSD: rc.subr.8,v 1.31 2012/12/18 13:14:34 wiz Exp $
.\"
.\" Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Luke Mewburn.
.\"
.\" 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
.\"
.Dd December 17, 2012
.Dt RC.SUBR 8
.Os
.Sh NAME
.Nm rc.subr
.Nd functions used by system shell scripts
.Sh SYNOPSIS
.Bl -item
.It
.Li . /etc/rc.subr
.It
.Ic backup_file Ar action Ar file Ar current Ar backup
.It
.Ic basename Ar file Op Ar suffix
.It
.Ic checkyesno Ar var
.It
.Ic check_pidfile Ar pidfile Ar procname Op Ar interpreter
.It
.Ic check_process Ar procname Op Ar interpreter
.It
.Ic collapse_backslash_newline
.It
.Ic dirname Ar file
.It
.Ic err Ar exitval Ar message
.It
.Ic load_rc_config Ar command
.It
.Ic load_rc_config_var Ar command Ar var
.It
.Ic mount_critical_filesystems Ar type
.It
.Ic no_rc_postprocess Ar command Op Ar arguments
.It
.Ic print_rc_metadata Ar string
.It
.Ic print_rc_normal Oo Fl n Oc Ar string
.It
.Ic rc_usage Ar command Op Ar ...
.It
.Ic reverse_list Ar item Op Ar ...
.It
.Ic run_rc_command Ar argument [parameters]
.It
.Ic run_rc_script Ar file Ar argument
.It
.Ic stop_boot
.It
.Ic twiddle
.It
.Ic wait_for_pids Op Ar pid Op Ar ...
.It
.Ic warn Ar message
.It
.Ic yesno_to_truefalse Ar var
.El
.Sh DESCRIPTION
.Nm
contains commonly used shell script functions which are used by
various scripts such as
.Xr rc 8 ,
and the periodic system services which are controlled by
.Xr daily.conf 5 ,
.Xr monthly.conf 5 ,
.Xr security.conf 5 ,
and
.Xr weekly.conf 5 .
.Pp
The
.Nm
functions are accessed by sourcing
.Pa /etc/rc.subr
into the current shell.
.Pp
The following shell functions are available:
.Bl -tag -width 4n
.It Ic backup_file Ar action Ar file Ar current Ar backup
Make a backup copy of
.Ar file
into
.Ar current .
If the
.Xr rc.conf 5
variable
.Sy backup_uses_rcs
is
.Sq YES ,
use
.Xr rcs 1
to archive the previous version of
.Ar current ,
otherwise save the previous version of
.Ar current
as
.Ar backup .
.Pp
.Ar action
may be one of the following:
.Bl -tag -width remove
.It Sy add
.Ar file
is now being backed up by or possibly re-entered into this backup mechanism.
.Ar current
is created, and if necessary, the
.Xr rcs 1
files are created as well.
.It Sy update
.Ar file
has changed and needs to be backed up.
If
.Ar current
exists, it is copied to
.Ar backup
or checked into
.Xr rcs 1
(if the repository file is old),
and then
.Ar file
is copied to
.Ar current .
.It Sy remove
.Ar file
is no longer being tracked by this backup mechanism.
If
.Xr rcs 1
is being used, an empty file is checked in and
.Ar current
is removed,
otherwise
.Ar current
is moved to
.Ar backup .
.El
.Ic basename Ar file Op Ar suffix
Just like
.Xr basename 1 ,
except implemented using shell built-in commands, and usable before the
.Pa /usr/bin
direcory is available.
.It Ic checkyesno Ar var
Return 0 if
.Ar var
is defined to
.Sq YES ,
.Sq TRUE ,
.Sq ON ,
or
.Sq 1 .
Return 1 if
.Ar var
is defined to
.Sq NO ,
.Sq FALSE ,
.Sq OFF ,
or
.Sq 0 .
Otherwise, warn that
.Ar var
is not set correctly.
The values are case insensitive.
.Pp
Note that the warning message shown by this function when
.Ar var
is not set references a manual page where the user can find more information.
Its name is picked up from the
.Sy rcvar_manpage
variable.
.It Ic check_pidfile Ar pidfile Ar procname Op Ar interpreter
Parses the first word of the first line of
.Ar pidfile
for a PID, and ensures that the process with that PID
is running and its first argument matches
.Ar procname .
Prints the matching PID if successful, otherwise nothing.
If
.Ar interpreter
is provided, parse the first line of
.Ar procname ,
ensure that the line is of the form
.Dl #! interpreter [...]
and use
.Ar interpreter
with its optional arguments and
.Ar procname
appended as the process string to search for.
.It Ic check_process Ar procname Op Ar interpreter
Prints the PIDs of any processes that are running with a first
argument that matches
.Ar procname .
.Ar interpreter
is handled as per
.Ic check_pidfile .
.It Ic collapse_backslash_newline
Copy input to output, collapsing
.Ao backslash Ac Ns Ao newline Ac
to nothing, but leaving other backslashes alone.
.Ic dirname Ar file
Just like
.Xr dirname 1 ,
except implemented using shell built-in commands, and usable before the
.Pa /usr/bin
direcory is available.
.It Ic err Ar exitval Ar message
Display an error message to
.Em stderr ,
log it to the system log
using
.Xr logger 1 ,
and
.Cm exit
with an exit value of
.Ar exitval .
The error message consists of the script name
(from
.Sy $0 ) ,
followed by
.Dq ": ERROR: " ,
and then
.Ar message .
.It Ic load_rc_config Ar command
Source in the
.Xr rc.conf 5
configuration files for
.Ar command .
First,
.Pa /etc/rc.conf
is sourced if it has not yet been read in.
Then,
.Pa /etc/rc.conf.d/ Ns Ar command
is sourced if it is an existing file.
The latter may also contain other variable assignments to override
.Ic run_rc_command
arguments defined by the calling script, to provide an easy
mechanism for an administrator to override the behaviour of a given
.Xr rc.d 8
script without requiring the editing of that script.
.It Ic load_rc_config_var Ar command Ar var
Read the
.Xr rc.conf 5
variable
.Ar var
for
.Ar command
and set in the current shell, using
.Ic load_rc_config
in a sub-shell to prevent unwanted side effects from other variable
assignments.
.It Ic mount_critical_filesystems Ar type
Go through a list of critical file systems,
as found in the
.Xr rc.conf 5
variable
.Sy critical_filesystems_ Ns Ar type ,
mounting each one that
is not currently mounted.
.It Ic no_rc_postprocess Ar command Op Ar arguments
Execute the specified command with the specified arguments,
in such a way that its output bypasses the post-processor that
.Xr rc 8
uses for most commands.
This implies that the output will not appear in the
.Pa /var/run/rc.log
file, and will appear on the console regardless of the
value of
.Va rc_silent .
This is expected to be useful for interactive commands,
and this mechanism is automatically used by
.Ic run_rc_command
when a script contains the
.Xr rcorder 8
keyword
.Dq interactive .
.Pp
If invoked from a context that does not appear to be under the control of
.Xr rc 8 ,
then the command is executed without special treatment.
.It Ic print_rc_metadata Ar string
Print the specified
.Ar string
in such a way that it should be handled as meta-data by the
.Xr rc 8
post-processor.
If invoked from a context that does not appear to be under the control of
.Xr rc 8 ,
then the
.Ar string
is discarded.
.Pp
Any
.Xr rc.d 8
script may invoke this function with an argument that begins with
.Dq note: ,
followed by one line of arbitrary text;
the text will be logged by
.Xr rc 8
but will not be displayed on the console.
.Pp
The use of arguments that do not begin with
.Dq note:
is reserved for internal use by
.Xr rc 8
and
.Nm .
.It Ic print_rc_normal Oo Fl n Oc Ar string
Print the specified
.Ar string
in such a way that it should be handled as normal output by the
.Xr rc 8
post-processor.
If invoked from a context that does not appear to be under the control of
.Xr rc 8 ,
then the
.Ar string
is printed to standard output.
.Pp
If the
.Fl n
flag is specified, then the string is printed without a newline.
.Pp
Intended use cases include:
.Bl -bullet
.It
An rc.d script can use
.Dq Sy print_rc_normal Fl n
to print a partial line in such a way that it appears
immediately instead of being buffered by
.Xr rc 8 Ap s
post-processor.
.It
An rc.d script that is run via the
.Sy no_rc_postprocess
function (so most of its output is invisible to
.Xr rc 8 Ap s
post-processor) can use
.Sy print_rc_normal
to force some of its output to be seen by the post-processor.
.El
.It Ic rc_usage Ar command Op Ar ...
Print a usage message for
.Sy $0 ,
with
.Ar commands
being the list of valid arguments
prefixed by
.Dq "[fast|force|one]" .
.It Ic reverse_list Ar item Op Ar ...
Print the list of
.Ar items
in reverse order.
.It Ic run_rc_command Ar argument Op Ar parameter ...
Run the
.Ar argument
method for the current
.Xr rc.d 8
script, based on the settings of various shell variables.
.Ic run_rc_command
is extremely flexible, and allows fully functional
.Xr rc.d 8
scripts to be implemented in a small amount of shell code.
The optional set of parameters is passed verbatim to the command, but not to its
pre/post hooks.
.Pp
.Ar argument
is searched for in the list of supported commands, which may be one
of:
.Bl -tag -width restart -offset indent
.It Sy start
Start the service.
This should check that the service is to be started as specified by
.Xr rc.conf 5 .
Also checks if the service is already running and refuses to start if
it is.
This latter check is not performed by standard
.Nx
scripts if the system is starting directly to multi-user mode, to
speed up the boot process.
.It Sy stop
If the service is to be started as specified by
.Xr rc.conf 5 ,
stop the service.
This should check that the service is running and complain if it's not.
.It Sy restart
Perform a
.Sy stop
then a
.Sy start .
Defaults to displaying the process ID of the program (if running).
.It Sy rcvar
Display which
.Xr rc.conf 5
variables are used to control the startup of the service (if any).
.El
.Pp
If
.Sy pidfile
or
.Sy procname
is set, also support:
.Bl -tag -width restart -offset indent
.It Sy poll
Wait for the command to exit.
.It Sy status
Show the status of the process.
.El
.Pp
Other supported commands are listed in the optional variable
.Sy extra_commands .
.Pp
.Ar argument
may have one of the following prefixes which alters its operation:
.Bl -tag -width "Prefix" -offset indent
.It Sy fast
Skip the check for an existing running process,
and sets
.Sy rc_fast=YES .
.It Sy force
Skip the checks for
.Sy rcvar
being set to yes,
and sets
.Sy rc_force=YES .
This ignores
.Ar argument Ns Sy _precmd
returning non-zero, and ignores any of the
.Sy required_*
tests failing, and always returns a zero exit status.
.It Sy one
Skip the checks for
.Sy rcvar
being set to yes, but performs all the other prerequisite tests.
.El
.Pp
.Ic run_rc_command
uses the following shell variables to control its behaviour.
Unless otherwise stated, these are optional.
.Bl -tag -width procname -offset indent
.It Sy name
The name of this script.
This is not optional.
.It Sy rcvar
The value of
.Sy rcvar
is checked with
.Ic checkyesno
to determine if this method should be run.
.It Sy rcvar_manpage
The manual page containing information about
.Sy rcvar .
It will be part of the warning message shown when
.Sy rcvar
is undefined.
Defaults to
.Xr rc.conf 5 .
.It Sy command
Full path to the command.
Not required if
.Ar argument Ns Sy _cmd
is defined for each supported keyword.
.It Sy command_args
Optional arguments and/or shell directives for
.Sy command .
.It Sy command_interpreter
.Sy command
is started with
.Dl #! command_interpreter [...]
which results in its
.Xr ps 1
command being
.Dl command_interpreter [...] command
so use that string to find the PID(s) of the running command
rather than
.Ql command .
.It Sy extra_commands
Extra commands/keywords/arguments supported.
.It Sy pidfile
Path to pid file.
Used to determine the PID(s) of the running command.
If
.Sy pidfile
is set, use
.Dl check_pidfile $pidfile $procname
to find the PID.
Otherwise, if
.Sy command
is set, use
.Dl check_process $procname
to find the PID.
.It Sy procname
Process name to check for.
Defaults to the value of
.Sy command .
.It Sy required_dirs
Check for the existence of the listed directories
before running the default start method.
.It Sy required_files
Check for the readability of the listed files
before running the default start method.
.It Sy required_vars
Perform
.Ic checkyesno
on each of the list variables
before running the default start method.
.It Sy ${name}_chdir
Directory to
.Ic cd
to before running
.Sy command ,
if
.Sy ${name}_chroot
is not provided.
.It Sy ${name}_chroot
Directory to
.Xr chroot 8
to before running
.Sy command .
Only supported after
.Pa /usr
is mounted.
.It Sy ${name}_env
List of additional or modified environment variables to set
when starting
.Sy command .
.It Sy ${name}_flags
Arguments to call
.Sy command
with.
This is usually set in
.Xr rc.conf 5 ,
and not in the
.Xr rc.d 8
script.
The environment variable
.Sq Ev flags
can be used to override this.
.It Sy ${name}_nice
.Xr nice 1
level to run
.Sy command
as.
Only supported after
.Pa /usr
is mounted.
.It Sy ${name}_user
User to run
.Sy command
as, using
.Xr chroot 8 .
if
.Sy ${name}_chroot
is set, otherwise
uses
.Xr su 1 .
Only supported after
.Pa /usr
is mounted.
.It Sy ${name}_group
Group to run the chrooted
.Sy command
as.
.It Sy ${name}_groups
Comma separated list of supplementary groups to run the chrooted
.Sy command
with.
.It Ar argument Ns Sy _cmd
Shell commands which override the default method for
.Ar argument .
.It Ar argument Ns Sy _precmd
Shell commands to run just before running
.Ar argument Ns Sy _cmd
or the default method for
.Ar argument .
If this returns a non-zero exit code, the main method is not performed.
If the default method is being executed, this check is performed after
the
.Sy required_*
checks and process (non-)existence checks.
.It Ar argument Ns Sy _postcmd
Shell commands to run if running
.Ar argument Ns Sy _cmd
or the default method for
.Ar argument
returned a zero exit code.
.It Sy sig_stop
Signal to send the processes to stop in the default
.Sy stop
method.
Defaults to
.Dv SIGTERM .
.It Sy sig_reload
Signal to send the processes to reload in the default
.Sy reload
method.
Defaults to
.Dv SIGHUP .
.El
.Pp
For a given method
.Ar argument ,
if
.Ar argument Ns Sy _cmd
is not defined, then a default method is provided by
.Sy run_rc_command :
.Bl -tag -width "argument" -offset indent
.It Sy Argument
.Sy Default method
.It Sy start
If
.Sy command
is not running and
.Ic checkyesno Sy rcvar
succeeds, start
.Sy command .
.It Sy stop
Determine the PIDs of
.Sy command
with
.Ic check_pidfile
or
.Ic check_process
(as appropriate),
.Ic kill Sy sig_stop
those PIDs, and run
.Ic wait_for_pids
on those PIDs.
.It Sy reload
Similar to
.Sy stop ,
except that it uses
.Sy sig_reload
instead, and doesn't run
.Ic wait_for_pids .
.It Sy restart
Runs the
.Sy stop
method, then the
.Sy start
method.
.It Sy status
Show the PID of
.Sy command ,
or some other script specific status operation.
.It Sy poll
Wait for
.Sy command
to exit.
.It Sy rcvar
Display which
.Xr rc.conf 5
variable is used (if any).
This method always works, even if the appropriate
.Xr rc.conf 5
variable is set to
.Sq NO .
.El
.Pp
The following variables are available to the methods
(such as
.Ar argument Ns Sy _cmd )
as well as after
.Ic run_rc_command
has completed:
.Bl -tag -width "rc_flags" -offset indent
.It Sy rc_arg
Argument provided to
.Sy run_rc_command ,
after fast and force processing has been performed.
.It Sy rc_flags
Flags to start the default command with.
Defaults to
.Sy ${name}_flags ,
unless overridden by the environment variable
.Sq Ev flags .
This variable may be changed by the
.Ar argument Ns Sy _precmd
method.
.It Sy rc_pid
PID of
.Sy command
(if appropriate).
.It Sy rc_fast
Not empty if
.Dq fast
prefix was used.
.It Sy rc_force
Not empty if
.Dq force
prefix was used.
.El
.It Ic run_rc_script Ar file Ar argument
Start the script
.Ar file
with an argument of
.Ar argument ,
and handle the return value from the script.
.Pp
Various shell variables are unset before
.Ar file
is started:
.Bd -ragged -offset indent
.Sy name ,
.Sy command ,
.Sy command_args ,
.Sy command_interpreter ,
.Sy extra_commands ,
.Sy pidfile ,
.Sy rcvar ,
.Sy required_dirs ,
.Sy required_files ,
.Sy required_vars ,
.Ar argument Ns Sy _cmd ,
.Ar argument Ns Sy _precmd .
.Ar argument Ns Sy _postcmd .
.Ed
.Pp
The startup behaviour of
.Ar file
depends upon the following checks:
.Bl -enum
.It
If
.Ar file
ends in
.Pa .sh ,
it is sourced into the current shell.
.It
If
.Ar file
appears to be a backup or scratch file
(e.g., with a suffix of
.Sq ~ ,
.Sq # ,
.Sq .OLD ,
or
.Sq .orig ) ,
ignore it.
.It
If
.Ar file
is not executable, ignore it.
.It
If the
.Xr rc.conf 5
variable
.Sy rc_fast_and_loose
is empty,
source
.Ar file
in a sub shell,
otherwise source
.Ar file
into the current shell.
.It
If
.Ar file
contains the
.Xr rcorder 8
keyword
.Dq interactive ,
then the command is executed using
.Ic no_rc_postprocess .
.El
.It Ic stop_boot
Prevent booting to multiuser mode.
If the
.Sy autoboot
variable is
.Sq yes ,
then a
.Sy SIGTERM
signal is sent to the parent
process (which is assumed to be
.Xr rc 8 ) .
Otherwise, the shell exits with status
.Li 1 .
.It Ic twiddle
Display one of the characters
.Sq \&/ , \&- , \&\e , \&| ,
followed by a backspace.
Repeated calls to this function will create the appearance of a spinning
symbol, as a different character is displayed on each call.
Output is to
.Pa /dev/tty ,
so this function may be useful even inside a script whose output
has been redirected.
.It Ic wait_for_pids Op Ar pid Op Ar ...
Wait until all of the provided
.Ar pids
don't exist any more, printing the list of outstanding
.Ar pids
every two seconds.
.It Ic warn Ar message
Display a warning message to
.Em stderr
and log it to the system log
using
.Xr logger 1 .
The warning message consists of the script name
(from
.Sy $0 ) ,
followed by
.Dq ": WARNING: " ,
and then
.Ar message .
.It Ic yesno_to_truefalse Ar var
Change the value of the specified variable from any of the
forms acceptable to the
.Ic checkyesno
function, to
.Dq true
or
.Dq false .
.El
.Sh FILES
.Bl -tag -width /etc/rc.subr -compact
.It Pa /etc/rc.subr
The
.Nm
file resides in
.Pa /etc .
.El
.Sh SEE ALSO
.Xr rc.conf 5 ,
.Xr rc 8
.Sh HISTORY
.Nm
appeared in
.Nx 1.3 .
The
.Xr rc.d 8
support functions appeared in
.Nx 1.5 .
Support for the
.Xr rc 8
post-processor appeared in
.Nx 6.0 .