Compare commits
	
		
			63 Commits
		
	
	
		
			openrc-0.9
			...
			openrc-0.9
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					04e6696782 | ||
| 
						 | 
					85193674da | ||
| 
						 | 
					a73c26a70b | ||
| 
						 | 
					6fcc55cef8 | ||
| 
						 | 
					380752f4e0 | ||
| 
						 | 
					e7649f117a | ||
| 
						 | 
					66f4305e1c | ||
| 
						 | 
					4255ba175b | ||
| 
						 | 
					d02d3af02e | ||
| 
						 | 
					61e05331d1 | ||
| 
						 | 
					f2e404ab66 | ||
| 
						 | 
					adde73141f | ||
| 
						 | 
					84aa4ba818 | ||
| 
						 | 
					982ac38f35 | ||
| 
						 | 
					cd52fecc4e | ||
| 
						 | 
					dbfcf23273 | ||
| 
						 | 
					f583030e3c | ||
| 
						 | 
					1771a83b92 | ||
| 
						 | 
					e873ef2ba7 | ||
| 
						 | 
					26edfe369c | ||
| 
						 | 
					34b7632d1d | ||
| 
						 | 
					fb8db18d79 | ||
| 
						 | 
					6d5a2d5f9e | ||
| 
						 | 
					810f2e55fb | ||
| 
						 | 
					372745844b | ||
| 
						 | 
					191ea10f86 | ||
| 
						 | 
					0d6ae379f4 | ||
| 
						 | 
					2471d741f7 | ||
| 
						 | 
					759f4ca4f2 | ||
| 
						 | 
					6c8e8e2a96 | ||
| 
						 | 
					29da0c8bf0 | ||
| 
						 | 
					49e99a7393 | ||
| 
						 | 
					8dcb7554ee | ||
| 
						 | 
					b754a27f62 | ||
| 
						 | 
					ec65f181ea | ||
| 
						 | 
					b12cb2f507 | ||
| 
						 | 
					1875db4ff6 | ||
| 
						 | 
					26ceddae5e | ||
| 
						 | 
					20f612080c | ||
| 
						 | 
					5615325a84 | ||
| 
						 | 
					537171eac2 | ||
| 
						 | 
					415f480410 | ||
| 
						 | 
					acf77b73af | ||
| 
						 | 
					9a01f68515 | ||
| 
						 | 
					7b1c1e1623 | ||
| 
						 | 
					8bb4b759eb | ||
| 
						 | 
					e5eb062f05 | ||
| 
						 | 
					f6dc3d5ae9 | ||
| 
						 | 
					3e2001f6a2 | ||
| 
						 | 
					ed4605bf9f | ||
| 
						 | 
					461c69acdb | ||
| 
						 | 
					879e1acd5d | ||
| 
						 | 
					06f6ce408c | ||
| 
						 | 
					ac2391e0cb | ||
| 
						 | 
					ce9994f7ca | ||
| 
						 | 
					a38a5071f3 | ||
| 
						 | 
					2569eb644e | ||
| 
						 | 
					dd45506a40 | ||
| 
						 | 
					46b96eb80d | ||
| 
						 | 
					e574b5d441 | ||
| 
						 | 
					5e01051c4e | ||
| 
						 | 
					8ea1190486 | ||
| 
						 | 
					a1c655949f | 
@@ -1,3 +1,3 @@
 | 
			
		||||
NAME=		openrc
 | 
			
		||||
VERSION=	0.9.7
 | 
			
		||||
VERSION=	0.9.8.2
 | 
			
		||||
PKG=		${NAME}-${VERSION}
 | 
			
		||||
 
 | 
			
		||||
@@ -388,6 +388,17 @@
 | 
			
		||||
#
 | 
			
		||||
# ${IFACE} is set to the interface being brought up/down
 | 
			
		||||
# ${IFVAR} is ${IFACE} converted to variable name bash allows
 | 
			
		||||
#
 | 
			
		||||
# For historical and compatibility reasons, preup is actually normally called
 | 
			
		||||
# in the following sequence: up ; preup ; up.
 | 
			
		||||
# The first up causes the kernel to initialize the device, so
 | 
			
		||||
# that it is available for use in the preup function.  However, for some
 | 
			
		||||
# hardware, e.g. CAN devices, some configuration is needed before trying to up
 | 
			
		||||
# the interface will actually work. For such hardware, the
 | 
			
		||||
# up_before_preup variables will allow skipping the first up call if set
 | 
			
		||||
# to yes.
 | 
			
		||||
#up_before_preup_IFVAR="NO"
 | 
			
		||||
#up_before_preup="NO"
 | 
			
		||||
 | 
			
		||||
#preup() {
 | 
			
		||||
#	# Remember to return 0 on success
 | 
			
		||||
 
 | 
			
		||||
@@ -68,6 +68,7 @@
 | 
			
		||||
# NOTE: ifconfig creates an aliased device for each extra IPv4 address
 | 
			
		||||
#       (eth0:1, eth0:2, etc)
 | 
			
		||||
#       iproute2 does not do this as there is no need to
 | 
			
		||||
# WARNING: You cannot mix multiple addresses on a line with other parameters!
 | 
			
		||||
#config_eth0="192.168.0.2/24 192.168.0.3/24 192.168.0.4/24"
 | 
			
		||||
# However, that only works with CIDR addresses, so you can't use netmask.
 | 
			
		||||
 | 
			
		||||
@@ -85,6 +86,14 @@
 | 
			
		||||
# If you don't want ANY address (only useful when calling for advanced stuff)
 | 
			
		||||
#config_eth0="null"
 | 
			
		||||
 | 
			
		||||
# If you need to pass parameters to go with an address, you can do so on the
 | 
			
		||||
# same line as the address. You should split multiple addresses with newlines.
 | 
			
		||||
# WARNING: You cannot mix multiple addresses on a line with other parameters!
 | 
			
		||||
#config_eth0="192.168.0.2/24 scope host"
 | 
			
		||||
#config_eth0="4321:0:1:2:3:4:567:89ab/64 nodad home preferred_lft 0"
 | 
			
		||||
#config_eth0="192.168.0.2/24 scope host
 | 
			
		||||
#4321:0:1:2:3:4:567:89ab/64 nodad home preferred_lft 0"
 | 
			
		||||
 | 
			
		||||
# Here's how to do routing if you need it
 | 
			
		||||
# We add an IPv4 default route, IPv4 subnet route and an IPv6 unicast route
 | 
			
		||||
#routes_eth0="default via 192.168.0.1
 | 
			
		||||
@@ -790,7 +799,7 @@
 | 
			
		||||
 | 
			
		||||
#-----------------------------------------------------------------------------
 | 
			
		||||
# TUN/TAP
 | 
			
		||||
# For TUN/TAP support emerge net-misc/openvpn or sys-apps/usermode-utilities
 | 
			
		||||
# For TUN/TAP support install iproute2, openvpn or usermode-utilities
 | 
			
		||||
#
 | 
			
		||||
# You must specify if we're a tun or tap device. Then you can give it any
 | 
			
		||||
# name you like - such as vpn
 | 
			
		||||
@@ -801,6 +810,9 @@
 | 
			
		||||
#tuntap_tap0="tap"
 | 
			
		||||
#config_tap0="192.168.0.1/24"
 | 
			
		||||
 | 
			
		||||
# Use something like this to pass custom options to iproute2 during
 | 
			
		||||
# tunnel creation. This sets the user and group ownership of the node.
 | 
			
		||||
#iproute2_tun1="user foo group bar"
 | 
			
		||||
# For passing custom options to tunctl use something like the following.  This
 | 
			
		||||
# example sets the owner to adm
 | 
			
		||||
#tunctl_tun1="-u adm"
 | 
			
		||||
@@ -929,6 +941,8 @@
 | 
			
		||||
# /etc/iproute2/rt_tables, an example follows:
 | 
			
		||||
# 2 oob
 | 
			
		||||
# 3 external
 | 
			
		||||
#
 | 
			
		||||
# IPv6 RPDB entries are to be found in the rules6_IFVAR variables:
 | 
			
		||||
 | 
			
		||||
#rules_eth0="
 | 
			
		||||
#from ZZZ.ZZZ.200.128/27 table oob priority 500
 | 
			
		||||
@@ -943,6 +957,11 @@
 | 
			
		||||
#XXX.XXX.112.0/24 dev eth1 table external scope link
 | 
			
		||||
#default via XXX.XXX.112.1 dev eth1"
 | 
			
		||||
 | 
			
		||||
# IPv6 example:
 | 
			
		||||
#rules6_eth0="
 | 
			
		||||
#from 2001:0DB8:AAAA:BBBB::/64 table vpn priority 100
 | 
			
		||||
#to 2001:0DB8:AAAA:BBBB::/64 table vpn priority 150"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#-----------------------------------------------------------------------------
 | 
			
		||||
# System
 | 
			
		||||
@@ -1092,6 +1111,17 @@
 | 
			
		||||
#
 | 
			
		||||
# ${IFACE} is set to the interface being brought up/down
 | 
			
		||||
# ${IFVAR} is ${IFACE} converted to variable name bash allows
 | 
			
		||||
#
 | 
			
		||||
# For historical and compatibility reasons, preup is actually normally called
 | 
			
		||||
# in the following sequence: up ; preup ; up.
 | 
			
		||||
# The first up causes the kernel to initialize the device, so
 | 
			
		||||
# that it is available for use in the preup function.  However, for some
 | 
			
		||||
# hardware, e.g. CAN devices, some configuration is needed before trying to up
 | 
			
		||||
# the interface will actually work. For such hardware, the
 | 
			
		||||
# up_before_preup variables will allow skipping the first up call if set
 | 
			
		||||
# to yes.
 | 
			
		||||
#up_before_preup_IFVAR="NO"
 | 
			
		||||
#up_before_preup="NO"
 | 
			
		||||
 | 
			
		||||
#preup() {
 | 
			
		||||
#	# Test for link on the interface prior to bringing it up.  This
 | 
			
		||||
 
 | 
			
		||||
@@ -21,4 +21,3 @@ rc_sys="@RC_SYS_DEFAULT@"
 | 
			
		||||
# This is the number of tty's used in most of the rc-scripts (like
 | 
			
		||||
# consolefont, numlock, etc ...)
 | 
			
		||||
rc_tty_number=12
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -117,7 +117,7 @@ start()
 | 
			
		||||
		fi
 | 
			
		||||
	done
 | 
			
		||||
 | 
			
		||||
	if [ "$RC_UNAME" = Linux -a -d /run ]; then
 | 
			
		||||
	if [ "$RC_UNAME" = Linux -a -d /run ] && false; then
 | 
			
		||||
		migrate_to_run	/var/lock /run/lock
 | 
			
		||||
		migrate_to_run	/var/run /run
 | 
			
		||||
	fi
 | 
			
		||||
 
 | 
			
		||||
@@ -21,11 +21,11 @@ depend()
 | 
			
		||||
	need localmount
 | 
			
		||||
	after bootmisc
 | 
			
		||||
	provide net
 | 
			
		||||
	keyword -jail -prefix -vserver
 | 
			
		||||
	keyword -shutdown -jail -prefix -vserver
 | 
			
		||||
 | 
			
		||||
	case "${IFACE}" in
 | 
			
		||||
		lo|lo0);;
 | 
			
		||||
		*) after net.lo net.lo0;;
 | 
			
		||||
		*) after net.lo net.lo0 dbus;;
 | 
			
		||||
	esac
 | 
			
		||||
 | 
			
		||||
	if [ "$(command -v "depend_${IFVAR}")" = "depend_${IFVAR}" ]; then
 | 
			
		||||
@@ -169,6 +169,36 @@ _configure_variables()
 | 
			
		||||
	done
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
_which()
 | 
			
		||||
{
 | 
			
		||||
	local i OIFS
 | 
			
		||||
	# Empty
 | 
			
		||||
	[ -z "$1" ] && return
 | 
			
		||||
	# check paths
 | 
			
		||||
	OIFS="$IFS"
 | 
			
		||||
	IFS=:
 | 
			
		||||
	for i in $PATH ; do
 | 
			
		||||
		[ -x $i/$1 ] && echo $i/$1 && break
 | 
			
		||||
	done
 | 
			
		||||
	IFS=$OIFS
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Like _which, but also consider shell builtins, and multiple alternatives
 | 
			
		||||
_program_available()
 | 
			
		||||
{
 | 
			
		||||
	[ -z "$1" ] && return 0
 | 
			
		||||
	local x=
 | 
			
		||||
	for x; do
 | 
			
		||||
		case "${x}" in
 | 
			
		||||
			/*) [ -x "${x}" ] && break;;
 | 
			
		||||
			*) type "${x}" >/dev/null 2>&1 && break;;
 | 
			
		||||
		esac
 | 
			
		||||
		unset x
 | 
			
		||||
	done
 | 
			
		||||
	[ -n "${x}" ] && echo $x && return 0
 | 
			
		||||
	return 1
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
_show_address()
 | 
			
		||||
{
 | 
			
		||||
	einfo "received address $(_get_inet_address "${IFACE}")"
 | 
			
		||||
@@ -311,11 +341,10 @@ _load_modules()
 | 
			
		||||
 | 
			
		||||
		eval set -- \$module_${i}_program
 | 
			
		||||
		if [ -n "$1" ]; then
 | 
			
		||||
			x=
 | 
			
		||||
			for x; do
 | 
			
		||||
				[ -x "${x}" ] && break
 | 
			
		||||
			done
 | 
			
		||||
			[ -x "${x}" ] || continue
 | 
			
		||||
			if ! _program_available "$@" >/dev/null; then
 | 
			
		||||
				vewarn "Skipping module $mod due to missing program: $@"
 | 
			
		||||
				continue
 | 
			
		||||
			fi
 | 
			
		||||
		fi
 | 
			
		||||
		if ${starting}; then
 | 
			
		||||
			eval set -- \$module_${i}_program_start
 | 
			
		||||
@@ -323,15 +352,10 @@ _load_modules()
 | 
			
		||||
			eval set -- \$module_${i}_program_stop
 | 
			
		||||
		fi
 | 
			
		||||
		if [ -n "$1" ]; then
 | 
			
		||||
			x=
 | 
			
		||||
			for x; do
 | 
			
		||||
				case "${x}" in
 | 
			
		||||
					/*) [ -x "${x}" ] && break;;
 | 
			
		||||
					*) type "${x}" >/dev/null 2>&1 && break;;
 | 
			
		||||
				esac
 | 
			
		||||
				unset x
 | 
			
		||||
			done
 | 
			
		||||
			[ -n "${x}" ] || continue
 | 
			
		||||
			if ! _program_available "$@" >/dev/null; then
 | 
			
		||||
				vewarn "Skipping module $mod due to missing program: $@"
 | 
			
		||||
				continue
 | 
			
		||||
			fi
 | 
			
		||||
		fi
 | 
			
		||||
 | 
			
		||||
		eval provides=\$module_${i}_provide
 | 
			
		||||
@@ -407,16 +431,18 @@ _load_config()
 | 
			
		||||
	set -- ${config}
 | 
			
		||||
 | 
			
		||||
	# We should support a space separated array for cidr configs
 | 
			
		||||
	# But only as long as they do not contain other parameters for the address
 | 
			
		||||
	if [ $# = 1 ]; then
 | 
			
		||||
		unset IFS
 | 
			
		||||
		set -- ${config}
 | 
			
		||||
		# Of course, we may have a single address added old style.
 | 
			
		||||
		case "$2" in
 | 
			
		||||
			netmask|broadcast|brd|brd+|peer|pointopoint)
 | 
			
		||||
				local IFS="$__IFS"
 | 
			
		||||
				set -- ${config}
 | 
			
		||||
				;;
 | 
			
		||||
		esac
 | 
			
		||||
		# If the NEXT argument is a v4 or v6 address, it's the next config.
 | 
			
		||||
		# Otherwise, it's arguments to the first config...
 | 
			
		||||
		if [ "${2#*.*}" = "${2}" -a "${2#*:*}" = "${2}" ]; then
 | 
			
		||||
			# Not an IPv4/IPv6
 | 
			
		||||
			local IFS="$__IFS"
 | 
			
		||||
			set -- ${config}
 | 
			
		||||
		fi
 | 
			
		||||
	fi
 | 
			
		||||
 | 
			
		||||
	# Ensure that loopback has the correct address
 | 
			
		||||
@@ -488,7 +514,9 @@ start()
 | 
			
		||||
{
 | 
			
		||||
	local IFACE=${RC_SVCNAME#*.} oneworked=false fallback=false module=
 | 
			
		||||
	local IFVAR=$(shell_var "${IFACE}") cmd= our_metric=
 | 
			
		||||
	local metric=0
 | 
			
		||||
	local metric=0 _up_before_preup
 | 
			
		||||
	eval _up_before_preup="\$up_before_preup_${IFVAR}"
 | 
			
		||||
	[ -z "${_up_before_preup}" ] && _up_before_preup=$up_before_preup
 | 
			
		||||
 | 
			
		||||
	einfo "Bringing up interface ${IFACE}"
 | 
			
		||||
	eindent
 | 
			
		||||
@@ -502,7 +530,7 @@ start()
 | 
			
		||||
	# available in preup and afterwards incase the user inadvertently
 | 
			
		||||
	# brings it down
 | 
			
		||||
	if [ "$(command -v preup)" = "preup" ]; then
 | 
			
		||||
		_up 2>/dev/null
 | 
			
		||||
		yesno "${_up_before_preup:-yes}" && _up 2>/dev/null
 | 
			
		||||
		ebegin "Running preup"
 | 
			
		||||
		eindent
 | 
			
		||||
		preup || return 1
 | 
			
		||||
 
 | 
			
		||||
@@ -61,28 +61,34 @@ mount_misc()
 | 
			
		||||
		fi
 | 
			
		||||
	fi
 | 
			
		||||
 | 
			
		||||
	# Setup Kernel Support for cgroup
 | 
			
		||||
	if [ -d /sys/fs/cgroup ]; then
 | 
			
		||||
		if grep -qs cgroup /proc/filesystems && \
 | 
			
		||||
			! mountinfo -q /sys/fs/cgroup; then
 | 
			
		||||
	# set up kernel support for cgroups
 | 
			
		||||
	if [ -d /sys/fs/cgroup ] && ! mountinfo -q /sys/fs/cgroup; then
 | 
			
		||||
		if grep -qs cgroup /proc/filesystems; then
 | 
			
		||||
			ebegin "Mounting cgroup filesystem"
 | 
			
		||||
			mount -n -t tmpfs -o  nodev,noexec,nosuid \
 | 
			
		||||
				cgroup /sys/fs/cgroup
 | 
			
		||||
			local opts="nodev,noexec,nosuid,mode=755,size=${rc_cgroupsize:-10m}"
 | 
			
		||||
			mount -n -t tmpfs -o ${opts} cgroup_root /sys/fs/cgroup
 | 
			
		||||
			eend $?
 | 
			
		||||
		fi
 | 
			
		||||
		if ! mountinfo -q /sys/fs/cgroup/openrc; then
 | 
			
		||||
			ebegin "creating openrc control group"
 | 
			
		||||
			mkdir /sys/fs/cgroup/openrc
 | 
			
		||||
			mount -n -t cgroup -o  nodev,noexec,nosuid \
 | 
			
		||||
				openrc /sys/fs/cgroup/openrc
 | 
			
		||||
			echo 1 > /sys/fs/cgroup/openrc/notify_on_release
 | 
			
		||||
			echo @LIBEXECDIR@/sh/cgroup-release-agent.sh \
 | 
			
		||||
				> /sys/fs/cgroup/openrc/release_agent
 | 
			
		||||
			eend
 | 
			
		||||
		fi
 | 
			
		||||
	fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
mount_cgroups()
 | 
			
		||||
{
 | 
			
		||||
	yesno ${rc_cgroups:-YES} || return 0
 | 
			
		||||
	if [ ! -e /proc/cgroups ]; then
 | 
			
		||||
		return 0
 | 
			
		||||
	fi
 | 
			
		||||
 | 
			
		||||
	while read name hier groups enabled rest; do
 | 
			
		||||
		case "${enabled}" in
 | 
			
		||||
			1)	mkdir /sys/fs/cgroup/${name}
 | 
			
		||||
				mount -t cgroup -o nodev,noexec,nosuid,${name} \
 | 
			
		||||
					${name} /sys/fs/cgroup/${name}
 | 
			
		||||
				;;
 | 
			
		||||
		esac
 | 
			
		||||
	done < /proc/cgroups
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
start()
 | 
			
		||||
{
 | 
			
		||||
	local retval
 | 
			
		||||
@@ -90,6 +96,11 @@ start()
 | 
			
		||||
	retval=$?
 | 
			
		||||
	if [ $retval -eq 0 ]; then
 | 
			
		||||
		mount_misc
 | 
			
		||||
		retval=$?
 | 
			
		||||
	fi
 | 
			
		||||
	if [ $retval -eq 0 ]; then
 | 
			
		||||
		mount_cgroups
 | 
			
		||||
		retval=$?
 | 
			
		||||
	fi
 | 
			
		||||
	return $retval
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -21,7 +21,7 @@
 | 
			
		||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 | 
			
		||||
.\" SUCH DAMAGE.
 | 
			
		||||
.\"
 | 
			
		||||
.Dd November 4, 2009
 | 
			
		||||
.Dd December 31, 2011
 | 
			
		||||
.Dt RUNSCRIPT 8 SMM
 | 
			
		||||
.Os OpenRC
 | 
			
		||||
.Sh NAME
 | 
			
		||||
@@ -99,7 +99,9 @@ the service has already been stopped.
 | 
			
		||||
.It Ar description
 | 
			
		||||
String describing the service.
 | 
			
		||||
.It Ar description_$command
 | 
			
		||||
String describing the extra command the.
 | 
			
		||||
String describing the extra command.
 | 
			
		||||
.It Ar start_stop_daemon_args
 | 
			
		||||
List of arguments passed to start-stop-daemon when starting the daemon.
 | 
			
		||||
.It Ar command
 | 
			
		||||
Daemon to start or stop via
 | 
			
		||||
.Nm start-stop-daemon
 | 
			
		||||
@@ -110,6 +112,9 @@ List of arguments to pass to the daemon when starting.
 | 
			
		||||
Pidfile to use for the above defined command.
 | 
			
		||||
.It Ar name
 | 
			
		||||
Display name used for the above defined command.
 | 
			
		||||
.It Ar retry
 | 
			
		||||
Retry schedule to use when stopping the daemon. It can either be a
 | 
			
		||||
timeout in seconds or multiple signal/timeout pairs (like SIGTERM/5).
 | 
			
		||||
.El
 | 
			
		||||
.Sh DEPENDENCIES
 | 
			
		||||
You should define a
 | 
			
		||||
@@ -142,7 +147,7 @@ Tags a service with a keyword. Here's the keywords we currently understand:-
 | 
			
		||||
.Bl -tag -width indent
 | 
			
		||||
.It Dv -shutdown
 | 
			
		||||
Don't stop this service when shutting the system down.
 | 
			
		||||
This normally quite safe as remaining daemons will be sent a SIGTERM just
 | 
			
		||||
This is normally quite safe as remaining daemons will be sent a SIGTERM just
 | 
			
		||||
before final shutdown.
 | 
			
		||||
Network related services such as the network and dhcpcd init scripts normally
 | 
			
		||||
have this keyword.
 | 
			
		||||
@@ -224,7 +229,7 @@ seconds until all files exist.
 | 
			
		||||
Returns 0 if all files exist, otherwise non zero.
 | 
			
		||||
If
 | 
			
		||||
.Ar timeout
 | 
			
		||||
is less then 1 then we wait indefinitely.
 | 
			
		||||
is less than 1 then we wait indefinitely.
 | 
			
		||||
.It Ic is_newer_than Ar file1 Ar file2 ...
 | 
			
		||||
If
 | 
			
		||||
.Ar file1
 | 
			
		||||
@@ -291,8 +296,11 @@ Mark the service as coldplugged.
 | 
			
		||||
Mark the service as inactive.
 | 
			
		||||
.It Xo
 | 
			
		||||
.Ic checkpath
 | 
			
		||||
.Op Fl D , -directory-truncate
 | 
			
		||||
.Op Fl d , -directory
 | 
			
		||||
.Op Fl F , -file-truncate
 | 
			
		||||
.Op Fl f , -file
 | 
			
		||||
.Op Fl p , -pipe
 | 
			
		||||
.Op Fl m , -mode Ar mode
 | 
			
		||||
.Op Fl o , owner Ar owner
 | 
			
		||||
.Ar path ...
 | 
			
		||||
@@ -465,6 +473,12 @@ show()
 | 
			
		||||
 | 
			
		||||
.Ed
 | 
			
		||||
.Sh BUGS
 | 
			
		||||
Because of the way we load our configuration files and the need to handle
 | 
			
		||||
more than one service directory, you can only use symlinks in service
 | 
			
		||||
directories to other services in the same directory.
 | 
			
		||||
You cannot symlink to a service in a different directory even if it is
 | 
			
		||||
another service directory.
 | 
			
		||||
.Pp
 | 
			
		||||
is_older_than should return 0 on success.
 | 
			
		||||
Instead we return 1 to be compliant with Gentoo baselayout.
 | 
			
		||||
Users are encouraged to use the is_newer_than function which returns correctly.
 | 
			
		||||
 
 | 
			
		||||
@@ -162,9 +162,8 @@ but with the standard error output.
 | 
			
		||||
These options are only used for stopping daemons:
 | 
			
		||||
.Bl -tag -width indent
 | 
			
		||||
.It Fl R , -retry Ar timeout | Ar signal Ns / Ns Ar timeout
 | 
			
		||||
You can either specify a timeout in seconds or a multiple signal/timeout
 | 
			
		||||
pairs as a stopping schedule.
 | 
			
		||||
If not specified then a default value of SIGTERM/5 is assumed.
 | 
			
		||||
The retry specification can be either a timeout in seconds or multiple
 | 
			
		||||
signal/timeout pairs (like SIGTERM/5).
 | 
			
		||||
.El
 | 
			
		||||
.Sh ENVIRONMENT
 | 
			
		||||
.Va SSD_NICELEVEL
 | 
			
		||||
 
 | 
			
		||||
@@ -95,16 +95,28 @@ bonding_pre_start()
 | 
			
		||||
	_up
 | 
			
		||||
 | 
			
		||||
	# finally add in slaves
 | 
			
		||||
	# things needed in the process, and if they are done by ifenslave, openrc, and/or the kernel.
 | 
			
		||||
	# down new slave interface: ifenslave, openrc
 | 
			
		||||
	# set mtu: ifenslave, kernel
 | 
			
		||||
	# set slave MAC: ifenslave, kernel
 | 
			
		||||
	eoutdent
 | 
			
		||||
	if [ -d /sys/class/net ]; then
 | 
			
		||||
		sys_bonding_path=/sys/class/net/"${IFACE}"/bonding
 | 
			
		||||
		local oiface
 | 
			
		||||
		oiface=$IFACE
 | 
			
		||||
		if [ -n "${primary}" ]; then
 | 
			
		||||
			IFACE=$primary 
 | 
			
		||||
			_down
 | 
			
		||||
			IFACE=$oiface
 | 
			
		||||
			echo "+${primary}" >$sys_bonding_path/slaves
 | 
			
		||||
			echo "${primary}" >$sys_bonding_path/primary
 | 
			
		||||
		fi
 | 
			
		||||
		for s in ${slaves}; do
 | 
			
		||||
			[ "${s}" = "${primary}" ] && continue
 | 
			
		||||
			if ! grep -q ${s} $sys_bonding_path/slaves; then
 | 
			
		||||
				IFACE=$s 
 | 
			
		||||
				_down
 | 
			
		||||
				IFACE=$oiface
 | 
			
		||||
				echo "+${s}" >$sys_bonding_path/slaves
 | 
			
		||||
			fi
 | 
			
		||||
		done
 | 
			
		||||
 
 | 
			
		||||
@@ -1,19 +1,10 @@
 | 
			
		||||
# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
 | 
			
		||||
# Released under the 2-clause BSD license.
 | 
			
		||||
 | 
			
		||||
_br2684ctl()
 | 
			
		||||
{
 | 
			
		||||
	if [ -x /usr/sbin/br2684ctl ]; then
 | 
			
		||||
		echo /usr/sbin/br2684ctl
 | 
			
		||||
	else
 | 
			
		||||
		echo /sbin/br2684ctl
 | 
			
		||||
	fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
br2684ctl_depend()
 | 
			
		||||
{
 | 
			
		||||
	before ppp
 | 
			
		||||
	program start $(_br2684ctl)
 | 
			
		||||
	program start br2684ctl
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
_config_vars="$_config_vars bridge bridge_add brctl"
 | 
			
		||||
@@ -42,7 +33,7 @@ br2684ctl_pre_start()
 | 
			
		||||
	esac
 | 
			
		||||
 | 
			
		||||
	einfo "Starting RFC 2684 Bridge control on ${IFACE}"
 | 
			
		||||
	start-stop-daemon --start --exec $(_br2684ctl) --background \
 | 
			
		||||
	start-stop-daemon --start --exec $(_which br2684ctl) --background \
 | 
			
		||||
		--make-pidfile --pidfile "/var/run/br2684ctl-${IFACE}.pid" \
 | 
			
		||||
		-- -c "${IFACE#nas*}" ${opts}
 | 
			
		||||
	eend $?
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,7 @@
 | 
			
		||||
bridge_depend()
 | 
			
		||||
{
 | 
			
		||||
	before interface macnet
 | 
			
		||||
	program /sbin/brctl
 | 
			
		||||
	program brctl
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
_config_vars="$_config_vars bridge bridge_add brctl"
 | 
			
		||||
 
 | 
			
		||||
@@ -1,13 +1,9 @@
 | 
			
		||||
# Copyright (c) 2011 by Gentoo Foundation
 | 
			
		||||
# Released under the 2-clause BSD license.
 | 
			
		||||
 | 
			
		||||
_ethtool() {
 | 
			
		||||
	echo /usr/sbin/ethtool
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ethtool_depend()
 | 
			
		||||
{
 | 
			
		||||
	program $(_ethtool)
 | 
			
		||||
	program ethtool
 | 
			
		||||
	before interface
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -43,7 +39,7 @@ ethtool_pre_start() {
 | 
			
		||||
			args_pretty="--${opt} $IFACE ${args_pretty}"
 | 
			
		||||
			args="--${opt} $IFACE ${args}"
 | 
			
		||||
			ebegin "ethtool ${args_pretty}"
 | 
			
		||||
			$(_ethtool) ${args}
 | 
			
		||||
			ethtool ${args}
 | 
			
		||||
			rc=$?
 | 
			
		||||
			eend $rc "ethtool exit code $rc"
 | 
			
		||||
			# TODO: ethtool has MANY different exit codes, with no
 | 
			
		||||
 
 | 
			
		||||
@@ -242,3 +242,23 @@ ifconfig_post_start()
 | 
			
		||||
		eend 0
 | 
			
		||||
	fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Is the interface administratively/operationally up?
 | 
			
		||||
# The 'UP' status in ifconfig is the administrative status
 | 
			
		||||
# Operational state does not seem to be available in BSD?
 | 
			
		||||
# 0: up
 | 
			
		||||
# 1: down
 | 
			
		||||
# 2: invalid arguments
 | 
			
		||||
is_admin_up()
 | 
			
		||||
{
 | 
			
		||||
	local iface="$1"
 | 
			
		||||
	[ -z "$iface" ] && iface="$IFACE"
 | 
			
		||||
	ifconfig "${iface}" | \
 | 
			
		||||
	sed -n '1,1{ /flags=.*[<,]UP[,>]/{ q 0 }}; q 1; '
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
is_oper_up()
 | 
			
		||||
{
 | 
			
		||||
	eerror "TODO: is_oper_up not available on BSD"
 | 
			
		||||
	return 2
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -188,6 +188,12 @@ _add_route()
 | 
			
		||||
	if [ "$1" = "-A" -o "$1" = "-f" -o "$1" = "-family" ]; then
 | 
			
		||||
		family="-A $2"
 | 
			
		||||
		shift; shift
 | 
			
		||||
	elif [ "$1" = "-4" ]; then
 | 
			
		||||
	    family="-A inet"
 | 
			
		||||
		shift
 | 
			
		||||
	elif [ "$1" = "-6" ]; then
 | 
			
		||||
	    family="-A inet6"
 | 
			
		||||
		shift
 | 
			
		||||
	fi
 | 
			
		||||
 | 
			
		||||
	if [ -n "${metric}" ]; then
 | 
			
		||||
@@ -297,3 +303,26 @@ ifconfig_post_stop()
 | 
			
		||||
	iptunnel del "${IFACE}"
 | 
			
		||||
	eend $?
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Is the interface administratively/operationally up?
 | 
			
		||||
# The 'UP' status in ifconfig/iproute2 is the administrative status
 | 
			
		||||
# Operational state is available in iproute2 output as 'state UP', or the
 | 
			
		||||
# operstate sysfs variable.
 | 
			
		||||
# 0: up
 | 
			
		||||
# 1: down
 | 
			
		||||
# 2: invalid arguments
 | 
			
		||||
is_admin_up()
 | 
			
		||||
{
 | 
			
		||||
	local iface="$1"
 | 
			
		||||
	[ -z "$iface" ] && iface="$IFACE"
 | 
			
		||||
	ifconfig "${iface}" | \
 | 
			
		||||
	sed -n '1,1{ /flags=.*[<,]UP[,>]/{ q 0 }}; q 1; '
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
is_oper_up()
 | 
			
		||||
{
 | 
			
		||||
	local iface="$1"
 | 
			
		||||
	[ -z "$iface" ] && iface="$IFACE"
 | 
			
		||||
	read state </sys/class/net/"${iface}"/operstate
 | 
			
		||||
	[ "x$state" = "up" ]
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -6,10 +6,18 @@ _config_vars="$_config_vars link suffix relay"
 | 
			
		||||
ip6to4_depend()
 | 
			
		||||
{
 | 
			
		||||
	after interface
 | 
			
		||||
	program ip
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ip6to4_start()
 | 
			
		||||
ip6to4_pre_start()
 | 
			
		||||
{
 | 
			
		||||
	# ALL interfaces run pre_start blocks, not just those with something
 | 
			
		||||
	# assigned, so we must check if we need to run on this interface before we
 | 
			
		||||
	# do so.
 | 
			
		||||
	local config
 | 
			
		||||
	eval config=\$config_${IFVAR}
 | 
			
		||||
	[ "$config" = "ip6to4" ] || return 0
 | 
			
		||||
 | 
			
		||||
	case " ${MODULES} " in
 | 
			
		||||
		*" ifconfig "*)
 | 
			
		||||
			if [ "${IFACE}" != "sit0" ]; then
 | 
			
		||||
@@ -19,7 +27,7 @@ ip6to4_start()
 | 
			
		||||
			fi
 | 
			
		||||
	esac
 | 
			
		||||
 | 
			
		||||
	local host= suffix= relay= addr= iface=${IFACE} new= localip=
 | 
			
		||||
	local host= suffix= relay= addr= iface=${IFACE} config_ip6to4= localip=
 | 
			
		||||
	eval host=\$link_${IFVAR}
 | 
			
		||||
	if [ -z "${host}" ]; then
 | 
			
		||||
		eerror "link_${IFVAR} not set"
 | 
			
		||||
@@ -67,7 +75,7 @@ ip6to4_start()
 | 
			
		||||
		veinfo "Derived IPv6 address: ${ip6}"
 | 
			
		||||
 | 
			
		||||
		# Now apply our IPv6 address to our config
 | 
			
		||||
		new="${new}${new:+ }${ip6}/16"
 | 
			
		||||
		config_ip6to4="${config_ip6to4}${config_ip6to4:+ }${ip6}/48"
 | 
			
		||||
 | 
			
		||||
		if [ -n "${localip}" ]; then
 | 
			
		||||
			localip="any"
 | 
			
		||||
@@ -76,7 +84,7 @@ ip6to4_start()
 | 
			
		||||
		fi
 | 
			
		||||
	done
 | 
			
		||||
 | 
			
		||||
	if [ -z "${new}" ]; then
 | 
			
		||||
	if [ -z "${config_ip6to4}" ]; then
 | 
			
		||||
		eerror "No global IPv4 addresses found on interface ${host}"
 | 
			
		||||
		return 1
 | 
			
		||||
	fi
 | 
			
		||||
@@ -87,13 +95,22 @@ ip6to4_start()
 | 
			
		||||
		eend $? || return 1
 | 
			
		||||
		_up
 | 
			
		||||
	fi
 | 
			
		||||
	routes_ip6to4="2003::/3 via ::${relay} metric 2147483647"
 | 
			
		||||
	service_set_value "config_ip6to4_$IFVAR" "$config_ip6to4"
 | 
			
		||||
	service_set_value "routes_ip6to4_$IFVAR" "$routes_ip6to4"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ip6to4_start()
 | 
			
		||||
{
 | 
			
		||||
	local config_ip6to4=$(service_get_value "config_ip6to4_$IFVAR")
 | 
			
		||||
	local routes_ip6to4=$(service_get_value "routes_ip6to4_$IFVAR")
 | 
			
		||||
 | 
			
		||||
	# Now apply our config
 | 
			
		||||
	eval config_${config_index}=\'"${new}"\'
 | 
			
		||||
	eval config_${config_index}=\'"${config_ip6to4}"\'
 | 
			
		||||
	: $(( config_index -= 1 ))
 | 
			
		||||
 | 
			
		||||
	# Add a route for us, ensuring we don't delete anything else
 | 
			
		||||
	local routes="$(_get_array "routes_${IFVAR}")
 | 
			
		||||
2003::/3 via ::${relay} metric 2147483647"
 | 
			
		||||
$routes_ip6to4"
 | 
			
		||||
	eval routes_${IFVAR}=\$routes
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										144
									
								
								net/iproute2.sh
									
									
									
									
									
								
							
							
						
						
									
										144
									
								
								net/iproute2.sh
									
									
									
									
									
								
							@@ -1,18 +1,9 @@
 | 
			
		||||
# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
 | 
			
		||||
# Released under the 2-clause BSD license.
 | 
			
		||||
 | 
			
		||||
_ip()
 | 
			
		||||
{
 | 
			
		||||
	if [ -x /bin/ip ]; then
 | 
			
		||||
		echo /bin/ip
 | 
			
		||||
	else
 | 
			
		||||
		echo /sbin/ip
 | 
			
		||||
	fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
iproute2_depend()
 | 
			
		||||
{
 | 
			
		||||
	program $(_ip)
 | 
			
		||||
	program ip
 | 
			
		||||
	provide interface
 | 
			
		||||
	after ifconfig
 | 
			
		||||
}
 | 
			
		||||
@@ -110,31 +101,54 @@ _add_address()
 | 
			
		||||
		ip addr add "$@" dev "${IFACE}" 2>/dev/null
 | 
			
		||||
		return 0
 | 
			
		||||
	fi
 | 
			
		||||
 | 
			
		||||
	local x
 | 
			
		||||
	local address netmask broadcast peer anycast label scope
 | 
			
		||||
	local valid_lft preferred_lft home nodad
 | 
			
		||||
	local confflaglist
 | 
			
		||||
	address="$1" ; shift
 | 
			
		||||
	while [ -n "$*" ]; do
 | 
			
		||||
		case "$1" in
 | 
			
		||||
			netmask)
 | 
			
		||||
				netmask="/$(_netmask2cidr "$2")" ; shift ; shift ;;
 | 
			
		||||
			broadcast|brd)
 | 
			
		||||
				broadcast="broadcast $2" ; shift ; shift ;;
 | 
			
		||||
			pointopoint|pointtopoint|peer)
 | 
			
		||||
				peer="peer $2" ; shift ; shift ;;
 | 
			
		||||
			anycast|label|scope|valid_lft|preferred_lft)
 | 
			
		||||
				eval "$1=$2" ; shift ; shift ;;
 | 
			
		||||
			home|nodad)
 | 
			
		||||
				eval "$1=$1" ; shift ;;
 | 
			
		||||
		x=$1 ; shift
 | 
			
		||||
		case "$x" in
 | 
			
		||||
			netmask|ne*)
 | 
			
		||||
				netmask="/$(_netmask2cidr "$1")" ; shift ;;
 | 
			
		||||
			broadcast|brd|br*)
 | 
			
		||||
				broadcast="$1" ; shift ;;
 | 
			
		||||
			pointopoint|pointtopoint|peer|po*|pe*)
 | 
			
		||||
				peer="$1" ; shift ;;
 | 
			
		||||
			anycast|label|scope|valid_lft|preferred_lft|a*|l*|s*|v*|pr*)
 | 
			
		||||
				case $x in
 | 
			
		||||
					a*) x=anycast ;;
 | 
			
		||||
					l*) x=label ;;
 | 
			
		||||
					s*) x=scope ;;
 | 
			
		||||
					v*) x=valid_lft ;;
 | 
			
		||||
					pr*) x=preferred_lft ;;
 | 
			
		||||
				esac
 | 
			
		||||
				eval "$x=$1" ; shift ;;
 | 
			
		||||
			home|nodad|h*|no*)
 | 
			
		||||
				case $x in h*) x=home ;; n*) x=nodad ;; esac
 | 
			
		||||
				# FIXME: If we need to reorder these, this will take more code
 | 
			
		||||
				confflaglist="${confflaglist} $x" ; ;;
 | 
			
		||||
			*)
 | 
			
		||||
				ewarn "Unknown argument to config_$IFACE: $x"
 | 
			
		||||
		esac
 | 
			
		||||
	done
 | 
			
		||||
 | 
			
		||||
	# Always scope lo addresses as host unless specified otherwise
 | 
			
		||||
	if [ "${IFACE}" = "lo" ]; then
 | 
			
		||||
		[ -z "$scope" ] && scope="scope host"
 | 
			
		||||
		[ -z "$scope" ] && scope="host"
 | 
			
		||||
	fi
 | 
			
		||||
 | 
			
		||||
	set -- "${address}${netmask}" $peer $broadcast $anycast $label $scope dev "${IFACE}" $valid_lft $preferred_lft $home $nodad
 | 
			
		||||
	# figure out the broadcast address if it is not specified
 | 
			
		||||
	# This must NOT be set for IPv6 addresses
 | 
			
		||||
	if [ "${address#*:}" = "${address}" ]; then
 | 
			
		||||
		[ -z "$broadcast" ] && broadcast="+"
 | 
			
		||||
	elif [ -n "$broadcast" ]; then
 | 
			
		||||
		eerror "Broadcast keywords are not valid with IPv6 addresses"
 | 
			
		||||
		return 1
 | 
			
		||||
	fi
 | 
			
		||||
 | 
			
		||||
	# This must appear on a single line, continuations cannot be used
 | 
			
		||||
	set -- "${address}${netmask}" ${peer:+peer} ${peer} ${broadcast:+broadcast} ${broadcast} ${anycast:+anycast} ${anycast} ${label:+label} ${label} ${scope:+scope} ${scope} dev "${IFACE}" ${valid_lft:+valid_lft} $valid_lft ${preferred_lft:+preferred_lft} $preferred_lft $confflaglist
 | 
			
		||||
	veinfo ip addr add "$@"
 | 
			
		||||
	ip addr add "$@"
 | 
			
		||||
}
 | 
			
		||||
@@ -146,6 +160,12 @@ _add_route()
 | 
			
		||||
	if [ "$1" = "-A" -o "$1" = "-f" -o "$1" = "-family" ]; then
 | 
			
		||||
		family="-f $2"
 | 
			
		||||
		shift; shift
 | 
			
		||||
	elif [ "$1" = "-4" ]; then
 | 
			
		||||
	    family="-f inet"
 | 
			
		||||
		shift
 | 
			
		||||
	elif [ "$1" = "-6" ]; then
 | 
			
		||||
	    family="-f inet6"
 | 
			
		||||
		shift
 | 
			
		||||
	fi
 | 
			
		||||
 | 
			
		||||
	if [ $# -eq 3 ]; then
 | 
			
		||||
@@ -208,7 +228,13 @@ _trim() {
 | 
			
		||||
# This is our interface to Routing Policy Database RPDB
 | 
			
		||||
# This allows for advanced routing tricks
 | 
			
		||||
_ip_rule_runner() {
 | 
			
		||||
	local cmd rules OIFS="${IFS}"
 | 
			
		||||
	local cmd rules OIFS="${IFS}" family
 | 
			
		||||
	if [ "$1" = "-4" -o "$1" = "-6" ]; then
 | 
			
		||||
		family="$1"
 | 
			
		||||
		shift
 | 
			
		||||
	else
 | 
			
		||||
		family="-4"
 | 
			
		||||
	fi
 | 
			
		||||
	cmd="$1"
 | 
			
		||||
	rules="$2"
 | 
			
		||||
	veindent
 | 
			
		||||
@@ -218,7 +244,7 @@ _ip_rule_runner() {
 | 
			
		||||
		ruN="$(_trim "${ru}")"
 | 
			
		||||
		[ -z "${ruN}" ] && continue
 | 
			
		||||
		vebegin "${cmd} ${ruN}"
 | 
			
		||||
		ip rule ${cmd} ${ru}
 | 
			
		||||
		ip $family rule ${cmd} ${ru}
 | 
			
		||||
		veend $?
 | 
			
		||||
		local IFS="$__IFS"
 | 
			
		||||
	done
 | 
			
		||||
@@ -274,15 +300,30 @@ iproute2_post_start()
 | 
			
		||||
	if [ -e /proc/net/route ]; then
 | 
			
		||||
		local rules="$(_get_array "rules_${IFVAR}")"
 | 
			
		||||
		if [ -n "${rules}" ]; then
 | 
			
		||||
			if ! ip rule list | grep -q "^"; then
 | 
			
		||||
			if ! ip -4 rule list | grep -q "^"; then
 | 
			
		||||
				eerror "IP Policy Routing (CONFIG_IP_MULTIPLE_TABLES) needed for ip rule"
 | 
			
		||||
			else
 | 
			
		||||
				service_set_value "ip_rule" "${rules}"
 | 
			
		||||
				einfo "Adding RPDB rules"
 | 
			
		||||
				_ip_rule_runner add "${rules}"
 | 
			
		||||
				einfo "Adding IPv4 RPDB rules"
 | 
			
		||||
				_ip_rule_runner -4 add "${rules}"
 | 
			
		||||
			fi
 | 
			
		||||
		fi
 | 
			
		||||
		ip route flush table cache dev "${IFACE}"
 | 
			
		||||
		ip -4 route flush table cache dev "${IFACE}"
 | 
			
		||||
	fi
 | 
			
		||||
 | 
			
		||||
	# Kernel may not have IPv6 built in
 | 
			
		||||
	if [ -e /proc/net/ipv6_route ]; then
 | 
			
		||||
		local rules="$(_get_array "rules6_${IFVAR}")"
 | 
			
		||||
		if [ -n "${rules}" ]; then
 | 
			
		||||
			if ! ip -6 rule list | grep -q "^"; then
 | 
			
		||||
				eerror "IPv6 Policy Routing (CONFIG_IPV6_MULTIPLE_TABLES) needed for ip rule"
 | 
			
		||||
			else
 | 
			
		||||
				service_set_value "ip6_rule" "${rules}"
 | 
			
		||||
				einfo "Adding IPv6 RPDB rules"
 | 
			
		||||
				_ip_rule_runner -6 add "${rules}"
 | 
			
		||||
			fi
 | 
			
		||||
		fi
 | 
			
		||||
		ip -6 route flush table cache dev "${IFACE}"
 | 
			
		||||
	fi
 | 
			
		||||
 | 
			
		||||
	if _iproute2_ipv6_tentative; then
 | 
			
		||||
@@ -305,13 +346,27 @@ iproute2_post_stop()
 | 
			
		||||
	if [ -e /proc/net/route ]; then
 | 
			
		||||
		local rules="$(service_get_value "ip_rule")"
 | 
			
		||||
		if [ -n "${rules}" ]; then
 | 
			
		||||
			einfo "Removing RPDB rules"
 | 
			
		||||
			_ip_rule_runner del "${rules}"
 | 
			
		||||
			einfo "Removing IPv4 RPDB rules"
 | 
			
		||||
			_ip_rule_runner -4 del "${rules}"
 | 
			
		||||
		fi
 | 
			
		||||
 | 
			
		||||
		# Only do something if the interface actually exist
 | 
			
		||||
		if _exists; then
 | 
			
		||||
			ip route flush table cache dev "${IFACE}"
 | 
			
		||||
			ip -4 route flush table cache dev "${IFACE}"
 | 
			
		||||
		fi
 | 
			
		||||
	fi
 | 
			
		||||
 | 
			
		||||
	# Kernel may not have IPv6 built in
 | 
			
		||||
	if [ -e /proc/net/ipv6_route ]; then
 | 
			
		||||
		local rules="$(service_get_value "ip6_rule")"
 | 
			
		||||
		if [ -n "${rules}" ]; then
 | 
			
		||||
			einfo "Removing IPv6 RPDB rules"
 | 
			
		||||
			_ip_rule_runner -6 del "${rules}"
 | 
			
		||||
		fi
 | 
			
		||||
 | 
			
		||||
		# Only do something if the interface actually exist
 | 
			
		||||
		if _exists; then
 | 
			
		||||
			ip -6 route flush table cache dev "${IFACE}"
 | 
			
		||||
		fi
 | 
			
		||||
	fi
 | 
			
		||||
 | 
			
		||||
@@ -324,3 +379,26 @@ iproute2_post_stop()
 | 
			
		||||
		fi
 | 
			
		||||
	fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Is the interface administratively/operationally up?
 | 
			
		||||
# The 'UP' status in ifconfig/iproute2 is the administrative status
 | 
			
		||||
# Operational state is available in iproute2 output as 'state UP', or the
 | 
			
		||||
# operstate sysfs variable.
 | 
			
		||||
# 0: up
 | 
			
		||||
# 1: down
 | 
			
		||||
# 2: invalid arguments
 | 
			
		||||
is_admin_up()
 | 
			
		||||
{
 | 
			
		||||
	local iface="$1"
 | 
			
		||||
	[ -z "$iface" ] && iface="$IFACE"
 | 
			
		||||
	ip link show dev $iface | \
 | 
			
		||||
	sed -n '1,1{ /[<,]UP[,>]/{ q 0 }}; q 1; '
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
is_oper_up()
 | 
			
		||||
{
 | 
			
		||||
	local iface="$1"
 | 
			
		||||
	[ -z "$iface" ] && iface="$IFACE"
 | 
			
		||||
	read state </sys/class/net/"${iface}"/operstate
 | 
			
		||||
	[ "x$state" = "up" ]
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -4,6 +4,7 @@
 | 
			
		||||
macchanger_depend()
 | 
			
		||||
{
 | 
			
		||||
	before macnet
 | 
			
		||||
	# no program 'macchanger', as we have partial functionality without it
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
_config_vars="$_config_vars mac"
 | 
			
		||||
 
 | 
			
		||||
@@ -3,18 +3,9 @@
 | 
			
		||||
# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
 | 
			
		||||
# All rights reserved. Released under the 2-clause BSD license.
 | 
			
		||||
 | 
			
		||||
_ip()
 | 
			
		||||
{
 | 
			
		||||
	if [ -x /bin/ip ]; then
 | 
			
		||||
		echo /bin/ip
 | 
			
		||||
	else
 | 
			
		||||
		echo /sbin/ip
 | 
			
		||||
	fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
macvlan_depend()
 | 
			
		||||
{
 | 
			
		||||
	program $(_ip)
 | 
			
		||||
	program ip
 | 
			
		||||
	after interface
 | 
			
		||||
	before dhcp macchanger
 | 
			
		||||
}
 | 
			
		||||
@@ -24,17 +15,6 @@ _is_macvlan()
 | 
			
		||||
	[ -n "$(export RC_SVCNAME="net.${IFACE}"; service_get_value macvlan)" ]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
_check_macvlan()
 | 
			
		||||
{
 | 
			
		||||
	if [ ! -d /sys/module/macvlan ]; then
 | 
			
		||||
		modprobe macvlan
 | 
			
		||||
		if [ ! -d /sys/module/macvlan ]; then
 | 
			
		||||
			eerror "MAC-VLAN support is not present in this kernel"
 | 
			
		||||
			return 1
 | 
			
		||||
		fi
 | 
			
		||||
	fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
macvlan_pre_start()
 | 
			
		||||
{
 | 
			
		||||
	# MAC-VLAN needs an existing interface to link to
 | 
			
		||||
@@ -42,7 +22,11 @@ macvlan_pre_start()
 | 
			
		||||
	eval macvlan=\$macvlan_${IFVAR}
 | 
			
		||||
	[ -z "${macvlan}" ] && return 0
 | 
			
		||||
 | 
			
		||||
	_check_macvlan || return 1
 | 
			
		||||
	case " ${MODULES} " in
 | 
			
		||||
		*" ifconfig "*)
 | 
			
		||||
				eerror "sys-apps/iproute2 is required to configure MACVLANs"
 | 
			
		||||
				return 1 ;;
 | 
			
		||||
	esac
 | 
			
		||||
 | 
			
		||||
	# optional mode, default to "private"
 | 
			
		||||
	local mode=
 | 
			
		||||
@@ -54,7 +38,7 @@ macvlan_pre_start()
 | 
			
		||||
	if [ -n "${e}" ]; then
 | 
			
		||||
		eend 1 "${e}"
 | 
			
		||||
	else
 | 
			
		||||
		eend 0 && service_set_value macvlan "${macvlan}"
 | 
			
		||||
		eend 0 && _up && service_set_value macvlan "${macvlan}"
 | 
			
		||||
	fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -4,9 +4,10 @@
 | 
			
		||||
tuntap_depend()
 | 
			
		||||
{
 | 
			
		||||
	before bridge interface macchanger
 | 
			
		||||
	program ip openvpn tunctl
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
_config_vars="$_config_vars tunctl"
 | 
			
		||||
_config_vars="$_config_vars iproute2 openvpn tunctl"
 | 
			
		||||
 | 
			
		||||
_is_tuntap()
 | 
			
		||||
{
 | 
			
		||||
@@ -16,6 +17,7 @@ _is_tuntap()
 | 
			
		||||
tuntap_pre_start()
 | 
			
		||||
{
 | 
			
		||||
	local tuntap=
 | 
			
		||||
	local rc=
 | 
			
		||||
	eval tuntap=\$tuntap_${IFVAR}
 | 
			
		||||
 | 
			
		||||
	[ -z "${tuntap}" ] && return 0
 | 
			
		||||
@@ -44,30 +46,42 @@ tuntap_pre_start()
 | 
			
		||||
	# Set the base metric to 1000
 | 
			
		||||
	metric=1000
 | 
			
		||||
 | 
			
		||||
	local o_opts= t_opts= do_openvpn=false do_tunctl=false
 | 
			
		||||
	local i_opts= o_opts= t_opts=
 | 
			
		||||
	local do_iproute2=false do_openvpn=false do_tunctl=false
 | 
			
		||||
	eval i_opts=\$iproute2_${IFVAR}
 | 
			
		||||
	eval o_opts=\$openvpn_${IFVAR}
 | 
			
		||||
	eval t_opts=\$tunctl_${IFVAR}
 | 
			
		||||
 | 
			
		||||
	if [ -n "${o_opts}" ] && type openvpn >/dev/null 2>&1; then
 | 
			
		||||
	if [ -n "${i_opts}" ] && type ip >/dev/null 2>&1; then
 | 
			
		||||
		do_iproute2=true
 | 
			
		||||
	elif [ -n "${o_opts}" ] && type openvpn >/dev/null 2>&1; then
 | 
			
		||||
		do_openvpn=true
 | 
			
		||||
	elif [ -n "${t_opts}" ] && type tunctl >/dev/null 2>&1; then
 | 
			
		||||
		do_tunctl=true
 | 
			
		||||
	elif type ip >/dev/null 2>&1; then
 | 
			
		||||
		do_iproute2=true
 | 
			
		||||
	elif type openvpn >/dev/null 2>&1; then
 | 
			
		||||
		do_openvpn=true
 | 
			
		||||
	elif type tunctl >/dev/null 2>&1; then
 | 
			
		||||
		do_tunctl=true
 | 
			
		||||
	fi
 | 
			
		||||
 | 
			
		||||
	if ${do_openvpn}; then
 | 
			
		||||
	if ${do_iproute2}; then
 | 
			
		||||
		ip tuntap add dev "${IFACE}" mode "${tuntap}" ${i_opts}
 | 
			
		||||
		rc=$?
 | 
			
		||||
	elif ${do_openvpn}; then
 | 
			
		||||
		openvpn --mktun --dev-type "${tuntap}" --dev "${IFACE}" \
 | 
			
		||||
			${o_opts} >/dev/null
 | 
			
		||||
		rc=$?
 | 
			
		||||
	elif ${do_tunctl}; then
 | 
			
		||||
		tunctl ${t_opts} -t "${IFACE}" >/dev/null
 | 
			
		||||
		rc=$?
 | 
			
		||||
	else
 | 
			
		||||
		eerror "Neither openvpn nor tunctl has been found, please install"
 | 
			
		||||
		eerror "either \"openvpn\" or \"usermode-utilities\"."
 | 
			
		||||
		eerror "Neither iproute2, openvpn nor tunctl has been found, please install"
 | 
			
		||||
		eerror "either \"iproute2\" \"openvpn\" or \"usermode-utilities\"."
 | 
			
		||||
		rc=1
 | 
			
		||||
	fi
 | 
			
		||||
	eend $? && _up && service_set_value tuntap "${tuntap}"
 | 
			
		||||
	eend $rc && _up && service_set_value tuntap "${tuntap}"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
tuntap_post_stop()
 | 
			
		||||
@@ -75,7 +89,9 @@ tuntap_post_stop()
 | 
			
		||||
	_is_tuntap || return 0
 | 
			
		||||
 | 
			
		||||
	ebegin "Destroying Tun/Tap interface ${IFACE}"
 | 
			
		||||
	if type tunctl >/dev/null 2>&1; then
 | 
			
		||||
	if type ip > /dev/null 2>&1; then
 | 
			
		||||
		ip tuntap del dev ${IFACE} mode $(service_get_value tuntap)
 | 
			
		||||
	elif type tunctl >/dev/null 2>&1; then
 | 
			
		||||
		tunctl -d "${IFACE}" >/dev/null
 | 
			
		||||
	else
 | 
			
		||||
		openvpn --rmtun \
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										23
									
								
								net/vlan.sh
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								net/vlan.sh
									
									
									
									
									
								
							@@ -1,18 +1,9 @@
 | 
			
		||||
# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
 | 
			
		||||
# Released under the 2-clause BSD license.
 | 
			
		||||
 | 
			
		||||
_ip()
 | 
			
		||||
{
 | 
			
		||||
	if [ -x /bin/ip ]; then
 | 
			
		||||
		echo /bin/ip
 | 
			
		||||
	else
 | 
			
		||||
		echo /sbin/ip
 | 
			
		||||
	fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
vlan_depend()
 | 
			
		||||
{
 | 
			
		||||
	program $(_ip)
 | 
			
		||||
	program ip
 | 
			
		||||
	after interface
 | 
			
		||||
	before dhcp
 | 
			
		||||
}
 | 
			
		||||
@@ -51,6 +42,14 @@ vlan_pre_start()
 | 
			
		||||
		eerror "You must convert your vconfig_ VLAN entries to vlan${N} entries."
 | 
			
		||||
		return 1
 | 
			
		||||
	fi
 | 
			
		||||
	local vlans=
 | 
			
		||||
	eval vlans=\$vlans_${IFVAR}
 | 
			
		||||
	[ -z "$vlans" ] && return 0
 | 
			
		||||
	case " ${MODULES} " in
 | 
			
		||||
		*" ifconfig "*)
 | 
			
		||||
				eerror "sys-apps/iproute2 is required to configure VLANs"
 | 
			
		||||
				return 1 ;;
 | 
			
		||||
	esac
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
vlan_post_start()
 | 
			
		||||
@@ -85,7 +84,7 @@ vlan_post_start()
 | 
			
		||||
		eval broadcast=\$broadcast_vlan${vlan}
 | 
			
		||||
		local mtu=
 | 
			
		||||
		eval mtu=\$mtu_vlan${vlan}
 | 
			
		||||
		local opts="${txqueuelen:+txqueuelen} ${txqueuelen} ${mac:+address} ${mac} ${broadcast:+broadcast} ${broadcast} ${mtu+:mtu} ${mtu}"
 | 
			
		||||
		local opts="${txqueuelen:+txqueuelen} ${txqueuelen} ${mac:+address} ${mac} ${broadcast:+broadcast} ${broadcast} ${mtu:+mtu} ${mtu}"
 | 
			
		||||
 | 
			
		||||
		e="$(ip link add link "${IFACE}" name "${vname}" ${opts} type vlan id "${vlan}" ${vflags} ${vingress} ${vegress} 2>&1 1>/dev/null)"
 | 
			
		||||
		if [ -n "${e}" ]; then
 | 
			
		||||
@@ -115,7 +114,7 @@ vlan_pre_stop()
 | 
			
		||||
{
 | 
			
		||||
	local vlan=
 | 
			
		||||
 | 
			
		||||
	_exists || return 1
 | 
			
		||||
	_exists || return 0
 | 
			
		||||
 | 
			
		||||
	for vlan in $(_get_vlans); do
 | 
			
		||||
		einfo "Removing VLAN ${vlan##*.} from ${IFACE}"
 | 
			
		||||
 
 | 
			
		||||
@@ -16,23 +16,6 @@ sourcex()
 | 
			
		||||
	fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
loadconfig()
 | 
			
		||||
{
 | 
			
		||||
	# If we're net.eth0 or openvpn.work then load net or openvpn config
 | 
			
		||||
	_c=${RC_SVCNAME%%.*}
 | 
			
		||||
	if [ -n "$_c" -a "$_c" != "$RC_SVCNAME" ]; then
 | 
			
		||||
		if ! sourcex -e "$1/$_c.$RC_RUNLEVEL"; then
 | 
			
		||||
			sourcex -e "$1/$_c"
 | 
			
		||||
		fi
 | 
			
		||||
	fi
 | 
			
		||||
	unset _c
 | 
			
		||||
 | 
			
		||||
	# Overlay with our specific config
 | 
			
		||||
	if ! sourcex -e "$1/$RC_SVCNAME.$RC_RUNLEVEL"; then
 | 
			
		||||
		sourcex -e "$1/$RC_SVCNAME"
 | 
			
		||||
	fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
sourcex "@SYSCONFDIR@/init.d/functions.sh"
 | 
			
		||||
sourcex "@LIBEXECDIR@/sh/rc-functions.sh"
 | 
			
		||||
 | 
			
		||||
@@ -148,19 +131,6 @@ start()
 | 
			
		||||
		service_inactive && _inactive=true
 | 
			
		||||
		mark_service_inactive
 | 
			
		||||
	fi
 | 
			
		||||
	if [ "$RC_UNAME" = Linux ]; then
 | 
			
		||||
		local cgroup=/sys/fs/cgroup/openrc
 | 
			
		||||
		local svc_cgroup=${cgroup}/${RC_SVCNAME}
 | 
			
		||||
		if mountinfo -q ${cgroup}; then
 | 
			
		||||
			mkdir ${svc_cgroup}
 | 
			
		||||
			for f in cpuset.cpus cpuset.mems; do
 | 
			
		||||
					if [ -f ${cgroup}/${f} ]; then
 | 
			
		||||
							cp ${cgroup}/${f} ${svc_cgroup}
 | 
			
		||||
						fi
 | 
			
		||||
					done
 | 
			
		||||
			echo $$ > ${svc_cgroup}/tasks
 | 
			
		||||
		fi
 | 
			
		||||
	fi
 | 
			
		||||
	eval start-stop-daemon --start \
 | 
			
		||||
		--exec $command \
 | 
			
		||||
		${procname:+--name} $procname \
 | 
			
		||||
@@ -181,6 +151,7 @@ stop()
 | 
			
		||||
	[ -n "$command" -o -n "$procname" -o -n "$pidfile" ] || return 0
 | 
			
		||||
	ebegin "Stopping ${name:-$RC_SVCNAME}"
 | 
			
		||||
	start-stop-daemon --stop \
 | 
			
		||||
		${retry:+--retry} $retry \
 | 
			
		||||
		${command:+--exec} $command \
 | 
			
		||||
		${procname:+--name} $procname \
 | 
			
		||||
		${pidfile:+--pidfile} $pidfile \
 | 
			
		||||
@@ -195,9 +166,21 @@ status()
 | 
			
		||||
 | 
			
		||||
yesno $RC_DEBUG && set -x
 | 
			
		||||
 | 
			
		||||
if ! loadconfig "${RC_SERVICE%/*}/../conf.d"; then
 | 
			
		||||
		loadconfig "@SYSCONFDIR@/conf.d"
 | 
			
		||||
_conf_d=${RC_SERVICE%/*}/../conf.d
 | 
			
		||||
# If we're net.eth0 or openvpn.work then load net or openvpn config
 | 
			
		||||
_c=${RC_SVCNAME%%.*}
 | 
			
		||||
if [ -n "$_c" -a "$_c" != "$RC_SVCNAME" ]; then
 | 
			
		||||
	if ! sourcex -e "$_conf_d/$_c.$RC_RUNLEVEL"; then
 | 
			
		||||
		sourcex -e "$_conf_d/$_c"
 | 
			
		||||
	fi
 | 
			
		||||
fi
 | 
			
		||||
unset _c
 | 
			
		||||
 | 
			
		||||
# Overlay with our specific config
 | 
			
		||||
if ! sourcex -e "$_conf_d/$RC_SVCNAME.$RC_RUNLEVEL"; then
 | 
			
		||||
	sourcex -e "$_conf_d/$RC_SVCNAME"
 | 
			
		||||
fi
 | 
			
		||||
unset _conf_d
 | 
			
		||||
 | 
			
		||||
# Load any system overrides
 | 
			
		||||
sourcex -e "@SYSCONFDIR@/rc.conf"
 | 
			
		||||
 
 | 
			
		||||
@@ -32,6 +32,7 @@
 | 
			
		||||
#include <sys/types.h>
 | 
			
		||||
#include <sys/stat.h>
 | 
			
		||||
 | 
			
		||||
#include <features.h>
 | 
			
		||||
#include <errno.h>
 | 
			
		||||
#include <fcntl.h>
 | 
			
		||||
#include <getopt.h>
 | 
			
		||||
@@ -46,44 +47,68 @@
 | 
			
		||||
#include "einfo.h"
 | 
			
		||||
#include "rc-misc.h"
 | 
			
		||||
 | 
			
		||||
typedef enum {
 | 
			
		||||
	inode_unknown = 0,
 | 
			
		||||
	inode_file = 1,
 | 
			
		||||
	inode_dir = 2,
 | 
			
		||||
	inode_fifo = 3,
 | 
			
		||||
} inode_t;
 | 
			
		||||
 | 
			
		||||
extern const char *applet;
 | 
			
		||||
 | 
			
		||||
static int
 | 
			
		||||
do_check(char *path, uid_t uid, gid_t gid, mode_t mode, int file)
 | 
			
		||||
do_check(char *path, uid_t uid, gid_t gid, mode_t mode, inode_t type, bool trunc)
 | 
			
		||||
{
 | 
			
		||||
	struct stat st;
 | 
			
		||||
	int fd;
 | 
			
		||||
	int fd, flags;
 | 
			
		||||
 | 
			
		||||
	if (stat(path, &st)) {
 | 
			
		||||
		if (file) {
 | 
			
		||||
		if (type == inode_file) {
 | 
			
		||||
			einfo("%s: creating file", path);
 | 
			
		||||
			if (!mode)
 | 
			
		||||
				mode = S_IRUSR | S_IWUSR | S_IRGRP |
 | 
			
		||||
				    S_IWGRP | S_IROTH;
 | 
			
		||||
			if ((fd = open(path, O_CREAT, mode)) == -1) {
 | 
			
		||||
			if (!mode) /* 664 */
 | 
			
		||||
				mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
 | 
			
		||||
			flags = O_CREAT|O_NDELAY|O_WRONLY|O_NOCTTY;
 | 
			
		||||
#ifdef __USE_XOPEN2K8
 | 
			
		||||
			flags |= O_CLOEXEC|O_NOFOLLOW;
 | 
			
		||||
#endif
 | 
			
		||||
			if (trunc)
 | 
			
		||||
				flags |= O_TRUNC;
 | 
			
		||||
			if ((fd = open(path, flags, mode)) == -1) {
 | 
			
		||||
				eerror("%s: open: %s", applet, strerror(errno));
 | 
			
		||||
				return -1;
 | 
			
		||||
			}
 | 
			
		||||
			close (fd);
 | 
			
		||||
		} else {
 | 
			
		||||
		} else if (type == inode_dir) {
 | 
			
		||||
			einfo("%s: creating directory", path);
 | 
			
		||||
			if (!mode)
 | 
			
		||||
			if (!mode) /* 775 */
 | 
			
		||||
				mode = S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH;
 | 
			
		||||
			if (mkdir(path, mode)) {
 | 
			
		||||
			if (mkdir(path, mode) == -1) {
 | 
			
		||||
				eerror("%s: mkdir: %s", applet,
 | 
			
		||||
				    strerror (errno));
 | 
			
		||||
				return -1;
 | 
			
		||||
			}
 | 
			
		||||
			mode = 0;
 | 
			
		||||
		} else if (type == inode_fifo) {
 | 
			
		||||
			einfo("%s: creating fifo", path);
 | 
			
		||||
			if (!mode) /* 600 */
 | 
			
		||||
				mode = S_IRUSR | S_IWUSR;
 | 
			
		||||
			if (mkfifo(path, mode) == -1) {
 | 
			
		||||
				eerror("%s: mkfifo: %s", applet,
 | 
			
		||||
				    strerror (errno));
 | 
			
		||||
				return -1;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
		if ((file && S_ISDIR(st.st_mode)) ||
 | 
			
		||||
		    (!file && !S_ISDIR(st.st_mode)))
 | 
			
		||||
		{
 | 
			
		||||
			if (file)
 | 
			
		||||
				eerror("%s: is a directory", path);
 | 
			
		||||
			else
 | 
			
		||||
				eerror("%s: is a file", path);
 | 
			
		||||
		if (type != inode_dir && S_ISDIR(st.st_mode)) {
 | 
			
		||||
			eerror("%s: is a directory", path);
 | 
			
		||||
			return 1;
 | 
			
		||||
		}
 | 
			
		||||
		if (type != inode_file && S_ISREG(st.st_mode)) {
 | 
			
		||||
			eerror("%s: is a file", path);
 | 
			
		||||
			return 1;
 | 
			
		||||
		}
 | 
			
		||||
		if (type != inode_fifo && S_ISFIFO(st.st_mode)) {
 | 
			
		||||
			eerror("%s: is a fifo", path);
 | 
			
		||||
			return -1;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
@@ -143,17 +168,23 @@ parse_owner(struct passwd **user, struct group **group, const char *owner)
 | 
			
		||||
 | 
			
		||||
#include "_usage.h"
 | 
			
		||||
#define extraopts "path1 path2 ..."
 | 
			
		||||
#define getoptstring "dfm:o:" getoptstring_COMMON
 | 
			
		||||
#define getoptstring "dDfFpm:o:" getoptstring_COMMON
 | 
			
		||||
static const struct option longopts[] = {
 | 
			
		||||
	{ "directory",      0, NULL, 'd'},
 | 
			
		||||
	{ "file",           0, NULL, 'f'},
 | 
			
		||||
	{ "mode",           1, NULL, 'm'},
 | 
			
		||||
	{ "owner",          1, NULL, 'o'},
 | 
			
		||||
	{ "directory",          0, NULL, 'd'},
 | 
			
		||||
	{ "directory-truncate", 0, NULL, 'D'},
 | 
			
		||||
	{ "file",               0, NULL, 'f'},
 | 
			
		||||
	{ "file-truncate",      0, NULL, 'F'},
 | 
			
		||||
	{ "pipe",               0, NULL, 'p'},
 | 
			
		||||
	{ "mode",               1, NULL, 'm'},
 | 
			
		||||
	{ "owner",              1, NULL, 'o'},
 | 
			
		||||
	longopts_COMMON
 | 
			
		||||
};
 | 
			
		||||
static const char * const longopts_help[] = {
 | 
			
		||||
	"Check if a directory",
 | 
			
		||||
	"Check if a file",
 | 
			
		||||
	"Create a directory if not exists",
 | 
			
		||||
	"Create/empty directory",
 | 
			
		||||
	"Create a file if not exists",
 | 
			
		||||
	"Truncate file",
 | 
			
		||||
	"Create a named pipe (FIFO) if not exists",
 | 
			
		||||
	"Mode to check",
 | 
			
		||||
	"Owner to check (user:group)",
 | 
			
		||||
	longopts_help_COMMON
 | 
			
		||||
@@ -169,18 +200,26 @@ checkpath(int argc, char **argv)
 | 
			
		||||
	mode_t mode = 0;
 | 
			
		||||
	struct passwd *pw = NULL;
 | 
			
		||||
	struct group *gr = NULL;
 | 
			
		||||
	bool file = 0;
 | 
			
		||||
	inode_t type = inode_unknown;
 | 
			
		||||
	int retval = EXIT_SUCCESS;
 | 
			
		||||
	bool trunc = 0;
 | 
			
		||||
 | 
			
		||||
	while ((opt = getopt_long(argc, argv, getoptstring,
 | 
			
		||||
		    longopts, (int *) 0)) != -1)
 | 
			
		||||
	{
 | 
			
		||||
		switch (opt) {
 | 
			
		||||
		case 'D':
 | 
			
		||||
			trunc = 1;
 | 
			
		||||
		case 'd':
 | 
			
		||||
			file = 0;
 | 
			
		||||
			type = inode_dir;
 | 
			
		||||
			break;
 | 
			
		||||
		case 'F':
 | 
			
		||||
			trunc = 1;
 | 
			
		||||
		case 'f':
 | 
			
		||||
			file = 1;
 | 
			
		||||
			type = inode_file;
 | 
			
		||||
			break;
 | 
			
		||||
		case 'p':
 | 
			
		||||
			type = inode_fifo;
 | 
			
		||||
			break;
 | 
			
		||||
		case 'm':
 | 
			
		||||
			if (parse_mode(&mode, optarg) != 0)
 | 
			
		||||
@@ -208,7 +247,7 @@ checkpath(int argc, char **argv)
 | 
			
		||||
		gid = gr->gr_gid;
 | 
			
		||||
 | 
			
		||||
	while (optind < argc) {
 | 
			
		||||
		if (do_check(argv[optind], uid, gid, mode, file))
 | 
			
		||||
		if (do_check(argv[optind], uid, gid, mode, type, trunc))
 | 
			
		||||
			retval = EXIT_FAILURE;
 | 
			
		||||
		optind++;
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -276,8 +276,14 @@ rc_logger_open(const char *level)
 | 
			
		||||
			fclose(log);
 | 
			
		||||
			fclose(plog);
 | 
			
		||||
		} else {
 | 
			
		||||
			log_error = 1;
 | 
			
		||||
			eerror("Error: fopen(%s) failed: %s", logfile, strerror(errno));
 | 
			
		||||
			/*
 | 
			
		||||
			 * logfile or its basedir may be read-only during sysinit and
 | 
			
		||||
			 * shutdown so skip the error in this case
 | 
			
		||||
			 */
 | 
			
		||||
			if ((strcmp(level, RC_LEVEL_SHUTDOWN) != 0) && (strcmp(level, RC_LEVEL_SYSINIT) != 0)) {
 | 
			
		||||
				log_error = 1;
 | 
			
		||||
				eerror("Error: fopen(%s) failed: %s", logfile, strerror(errno));
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		/* Try to keep the temporary log in case of errors */
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										27
									
								
								src/rc/rc.c
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								src/rc/rc.c
									
									
									
									
									
								
							@@ -173,7 +173,7 @@ proc_getent(const char *ent)
 | 
			
		||||
{
 | 
			
		||||
	FILE *fp;
 | 
			
		||||
	char *proc, *p, *value = NULL;
 | 
			
		||||
	size_t i;
 | 
			
		||||
	size_t i, len;
 | 
			
		||||
 | 
			
		||||
	if (!exists("/proc/cmdline"))
 | 
			
		||||
		return NULL;
 | 
			
		||||
@@ -187,16 +187,25 @@ proc_getent(const char *ent)
 | 
			
		||||
	i = 0;
 | 
			
		||||
	if (rc_getline(&proc, &i, fp) == -1 || proc == NULL)
 | 
			
		||||
		eerror("rc_getline: %s", strerror(errno));
 | 
			
		||||
	if (*proc && (p = strstr(proc, ent))) {
 | 
			
		||||
		i = p - proc;
 | 
			
		||||
		if (i == '\0' || proc[i - 1] == ' ') {
 | 
			
		||||
			p += strlen(ent);
 | 
			
		||||
			if (*p == '=')
 | 
			
		||||
				p++;
 | 
			
		||||
			value = xstrdup(strsep(&p, " "));
 | 
			
		||||
 | 
			
		||||
	if (proc != NULL) {
 | 
			
		||||
		len = strlen(ent);
 | 
			
		||||
 | 
			
		||||
		while ((p = strsep(&proc, " "))) {
 | 
			
		||||
			if (strncmp(ent, p, len) == 0 && (p[len] == '\0' || p[len] == ' ' || p[len] == '=')) {
 | 
			
		||||
				p += len;
 | 
			
		||||
 | 
			
		||||
				if (*p == '=')
 | 
			
		||||
					p++;
 | 
			
		||||
 | 
			
		||||
				value = xstrdup(p);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	} else
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (!value)
 | 
			
		||||
		errno = ENOENT;
 | 
			
		||||
 | 
			
		||||
	fclose(fp);
 | 
			
		||||
	free(proc);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -821,7 +821,7 @@ svc_start(void)
 | 
			
		||||
		svc_start_real();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
static int
 | 
			
		||||
svc_stop_check(RC_SERVICE *state)
 | 
			
		||||
{
 | 
			
		||||
	*state = rc_service_state(service);
 | 
			
		||||
@@ -848,7 +848,7 @@ svc_stop_check(RC_SERVICE *state)
 | 
			
		||||
 | 
			
		||||
	if (*state & RC_SERVICE_STOPPED) {
 | 
			
		||||
		ewarn("WARNING: %s is already stopped", applet);
 | 
			
		||||
		exit(EXIT_SUCCESS);
 | 
			
		||||
		return 1;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	rc_service_mark(service, RC_SERVICE_STOPPING);
 | 
			
		||||
@@ -861,6 +861,8 @@ svc_stop_check(RC_SERVICE *state)
 | 
			
		||||
		else if (rc_service_in_runlevel(service, RC_LEVEL_BOOT))
 | 
			
		||||
			ewarn("WARNING: you are stopping a boot service");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
@@ -986,7 +988,7 @@ svc_stop_real(void)
 | 
			
		||||
	rc_plugin_run(RC_HOOK_SERVICE_STOP_OUT, applet);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
static int
 | 
			
		||||
svc_stop(void)
 | 
			
		||||
{
 | 
			
		||||
	RC_SERVICE state;
 | 
			
		||||
@@ -995,13 +997,16 @@ svc_stop(void)
 | 
			
		||||
	if (dry_run)
 | 
			
		||||
		einfon("stop:");
 | 
			
		||||
	else
 | 
			
		||||
		svc_stop_check(&state);
 | 
			
		||||
		if (svc_stop_check(&state) == 1)
 | 
			
		||||
			return 1; /* Service has been stopped already */
 | 
			
		||||
	if (deps)
 | 
			
		||||
		svc_stop_deps(state);
 | 
			
		||||
	if (dry_run)
 | 
			
		||||
		printf(" %s\n", applet);
 | 
			
		||||
	else
 | 
			
		||||
		svc_stop_real();
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
@@ -1100,9 +1105,11 @@ runscript(int argc, char **argv)
 | 
			
		||||
	bool doneone = false;
 | 
			
		||||
	int retval, opt, depoptions = RC_DEP_TRACE;
 | 
			
		||||
	RC_STRING *svc;
 | 
			
		||||
	char *save = NULL;
 | 
			
		||||
	char path[PATH_MAX], lnk[PATH_MAX];
 | 
			
		||||
	char *dir, *save = NULL, *saveLnk = NULL;
 | 
			
		||||
	char pidstr[10];
 | 
			
		||||
	size_t l = 0, ll;
 | 
			
		||||
 	const char *file;
 | 
			
		||||
	struct stat stbuf;
 | 
			
		||||
 | 
			
		||||
	/* Show help if insufficient args */
 | 
			
		||||
@@ -1119,7 +1126,40 @@ runscript(int argc, char **argv)
 | 
			
		||||
 | 
			
		||||
	atexit(cleanup);
 | 
			
		||||
 | 
			
		||||
	service = xstrdup(argv[1]);
 | 
			
		||||
	/* We need to work out the real full path to our service.
 | 
			
		||||
	 * This works fine, provided that we ONLY allow multiplexed services
 | 
			
		||||
	 * to exist in the same directory as the master link.
 | 
			
		||||
	 * Also, the master link as to be a real file in the init dir. */
 | 
			
		||||
	if (!realpath(argv[1], path)) {
 | 
			
		||||
		fprintf(stderr, "realpath: %s\n", strerror(errno));
 | 
			
		||||
		exit(EXIT_FAILURE);
 | 
			
		||||
	}
 | 
			
		||||
	memset(lnk, 0, sizeof(lnk));
 | 
			
		||||
	if (readlink(argv[1], lnk, sizeof(lnk)-1)) {
 | 
			
		||||
		dir = dirname(path);
 | 
			
		||||
		if (strchr(lnk, '/')) {
 | 
			
		||||
			save = xstrdup(dir);
 | 
			
		||||
			saveLnk = xstrdup(lnk);
 | 
			
		||||
			dir = dirname(saveLnk);
 | 
			
		||||
			if (strcmp(dir, save) == 0)
 | 
			
		||||
				file = basename_c(argv[1]);
 | 
			
		||||
			else
 | 
			
		||||
				file = basename_c(lnk);
 | 
			
		||||
			dir = save;
 | 
			
		||||
		} else
 | 
			
		||||
			file = basename_c(argv[1]);
 | 
			
		||||
		ll = strlen(dir) + strlen(file) + 2;
 | 
			
		||||
		service = xmalloc(ll);
 | 
			
		||||
		snprintf(service, ll, "%s/%s", dir, file);
 | 
			
		||||
		if (stat(service, &stbuf) != 0) {
 | 
			
		||||
			free(service);
 | 
			
		||||
			service = xstrdup(lnk);
 | 
			
		||||
		}
 | 
			
		||||
		free(save);
 | 
			
		||||
		free(saveLnk);
 | 
			
		||||
	}
 | 
			
		||||
	if (!service)
 | 
			
		||||
		service = xstrdup(path);
 | 
			
		||||
	applet = basename_c(service);
 | 
			
		||||
 | 
			
		||||
	if (argc < 3)
 | 
			
		||||
@@ -1316,7 +1356,8 @@ runscript(int argc, char **argv)
 | 
			
		||||
				}
 | 
			
		||||
				if (deps && in_background)
 | 
			
		||||
					get_started_services();
 | 
			
		||||
				svc_stop();
 | 
			
		||||
				if (svc_stop() == 1)
 | 
			
		||||
					continue; /* Service has been stopped already */
 | 
			
		||||
				if (deps) {
 | 
			
		||||
					if (!in_background &&
 | 
			
		||||
					    !rc_runlevel_stopping() &&
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user