Compare commits
	
		
			19 Commits
		
	
	
		
			openrc-0.5
			...
			openrc-0.6
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					5ec2efaff2 | ||
| 
						 | 
					9ca65be42e | ||
| 
						 | 
					a704b97fd2 | ||
| 
						 | 
					2c0a71172d | ||
| 
						 | 
					cbafcd078d | ||
| 
						 | 
					a165fbe384 | ||
| 
						 | 
					02c12c1cac | ||
| 
						 | 
					084f5e12eb | ||
| 
						 | 
					3b9eaea8ec | ||
| 
						 | 
					dc3ccd8101 | ||
| 
						 | 
					9476a2e721 | ||
| 
						 | 
					1d174cc60c | ||
| 
						 | 
					12af86395f | ||
| 
						 | 
					5b3e5edda2 | ||
| 
						 | 
					775d56b877 | ||
| 
						 | 
					22e2a4f0a1 | ||
| 
						 | 
					ca752a5a2d | ||
| 
						 | 
					93cecab1ed | ||
| 
						 | 
					baf3b2dd45 | 
							
								
								
									
										2
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								Makefile
									
									
									
									
									
								
							@@ -4,7 +4,7 @@
 | 
			
		||||
 | 
			
		||||
include Makefile.inc
 | 
			
		||||
 | 
			
		||||
SUBDIR=		conf.d etc init.d man sh src
 | 
			
		||||
SUBDIR=		conf.d etc init.d man scripts sh src
 | 
			
		||||
 | 
			
		||||
# Build our old net foo or not
 | 
			
		||||
_OLDNET_SH=	case "${MKOLDNET}" in \
 | 
			
		||||
 
 | 
			
		||||
@@ -1,3 +1,3 @@
 | 
			
		||||
NAME=		openrc
 | 
			
		||||
VERSION=	0.5.3
 | 
			
		||||
VERSION=	0.6.0
 | 
			
		||||
PKG=		${NAME}-${VERSION}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										3
									
								
								README
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								README
									
									
									
									
									
								
							@@ -58,7 +58,8 @@ If you installed OpenRC from your chosen distribution, you should report
 | 
			
		||||
bugs directly to them. For example, if you use Gentoo and emerged OpenRC
 | 
			
		||||
then you should reports bugs to http://bugs.gentoo.org.
 | 
			
		||||
 | 
			
		||||
Otherwise, you can report them directly to me at http://bugs.marples.name
 | 
			
		||||
Otherwise, you can report them directly to me at
 | 
			
		||||
http://roy.marples.name/projects/openrc
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
History - by Roy Marples
 | 
			
		||||
 
 | 
			
		||||
@@ -13,7 +13,7 @@ SOS?=	BSD
 | 
			
		||||
 | 
			
		||||
network: network.in network.${OS}
 | 
			
		||||
	cp $@.in $@
 | 
			
		||||
	[ -e $@.${OS} ] && cat $@.${OS} >> $@ || true
 | 
			
		||||
	[ -e $@.${SOS} ] && cat $@.${SOS} >> $@ || true
 | 
			
		||||
 | 
			
		||||
staticroute: staticroute.${SOS}
 | 
			
		||||
	cp $@.${SOS} $@
 | 
			
		||||
 
 | 
			
		||||
@@ -1,3 +1 @@
 | 
			
		||||
CONF+=	ipfw moused powerd rarpd savecore syscons
 | 
			
		||||
 | 
			
		||||
network.${OS}:
 | 
			
		||||
 
 | 
			
		||||
@@ -1,3 +1 @@
 | 
			
		||||
CONF+=	moused rarpd savecore
 | 
			
		||||
 | 
			
		||||
network.${OS}:
 | 
			
		||||
 
 | 
			
		||||
@@ -14,7 +14,7 @@
 | 
			
		||||
#fsck_passno="<2"
 | 
			
		||||
 | 
			
		||||
# Most modern fs's don't require a full fsck on boot, but for those that do
 | 
			
		||||
# it may be adivisable to skip this when running on battery.
 | 
			
		||||
# it may be advisable to skip this when running on battery.
 | 
			
		||||
# WARNING: Do not turn this off if you have any JFS partitions.
 | 
			
		||||
fsck_on_battery="YES"
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										4
									
								
								conf.d/network.BSD
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								conf.d/network.BSD
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,4 @@
 | 
			
		||||
 | 
			
		||||
# You can assign a default route
 | 
			
		||||
#defaultroute="192.168.0.1"
 | 
			
		||||
#defaultroute6="2001:a:b:c"
 | 
			
		||||
@@ -1,8 +1,17 @@
 | 
			
		||||
 | 
			
		||||
# You can assign a default route
 | 
			
		||||
#defaultroute="gw 192.168.0.1"
 | 
			
		||||
#defaultroute6="gw 2001:a:b:c"
 | 
			
		||||
 | 
			
		||||
# ifconfig under Linux is not that powerful and doesn't easily handle
 | 
			
		||||
# multiple addresses
 | 
			
		||||
# On the other hand, ip (iproute2) is quite powerful and is also supported
 | 
			
		||||
#ip_eth0="192.168.0.10/24; 192.168.10.10/24"
 | 
			
		||||
 | 
			
		||||
# You can also use ip to add the default route.
 | 
			
		||||
#defaultiproute="via 192.168.0.1"
 | 
			
		||||
#defaultiproute6="via 2001:a:b:c"
 | 
			
		||||
 | 
			
		||||
# ip doesn't handle MTU like ifconfig, but we can do it like so
 | 
			
		||||
#ifup_eth0="ip link set \$int mtu 1500"
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -9,8 +9,6 @@
 | 
			
		||||
# You should note that we don't stop the network at system shutdown by default.
 | 
			
		||||
# If you really need this, then set shutdown_network=YES
 | 
			
		||||
 | 
			
		||||
# You can assign a default route
 | 
			
		||||
#defaultroute="192.168.0.1"
 | 
			
		||||
# Lastly, the interfaces variable pulls in virtual interfaces that cannot
 | 
			
		||||
# be automatically detected.
 | 
			
		||||
#interfaces="br0 bond0 vlan0"
 | 
			
		||||
 
 | 
			
		||||
@@ -1,2 +1,6 @@
 | 
			
		||||
# Example static route. See route(8) for syntax.
 | 
			
		||||
staticroute="net 192.168.0.0 -netmask 255.255.0.0 10.73.1.1"
 | 
			
		||||
# Separate multiple routes using ; or new lines.
 | 
			
		||||
# /etc/route.conf(5) takes precedence over this configuration.
 | 
			
		||||
 | 
			
		||||
# Example static routes. See route(8) for syntax.
 | 
			
		||||
#staticroute="net 192.168.0.0 -netmask 255.255.255.0 10.73.1.1
 | 
			
		||||
#net 192.168.1.0 -netmask 255.255.255.0 10.73.1.1"
 | 
			
		||||
 
 | 
			
		||||
@@ -1,2 +1,8 @@
 | 
			
		||||
# Example static route. See route(8) for syntax.
 | 
			
		||||
staticroute="net 192.168.0.0 netmask 255.255.0.0 gw 10.73.1.1"
 | 
			
		||||
# Separate multiple routes using ; or new lines.
 | 
			
		||||
 | 
			
		||||
# Example static routes. See route(8) for syntax.
 | 
			
		||||
#staticroute="net 192.168.0.0 netmask 255.255.255.0 gw 10.73.1.1
 | 
			
		||||
#net 192.168.1.0 netmask 255.255.255.0 gw 10.73.1.1"
 | 
			
		||||
 | 
			
		||||
# Example static routes using iproute2. See ip(8) for syntax.
 | 
			
		||||
#staticiproute="192.168.0.0/24 via 10.73.1.1; 192.168.1.0/24 via 10.73.1.1"
 | 
			
		||||
 
 | 
			
		||||
@@ -43,11 +43,6 @@
 | 
			
		||||
#       (eth0:1, eth0:2, etc)
 | 
			
		||||
#       iproute2 does not do this as there is no need to
 | 
			
		||||
#config_eth0="192.168.0.2/24 192.168.0.3/24 192.168.0.4/24"
 | 
			
		||||
# Or you can use sequence expressions
 | 
			
		||||
#config_eth0="192.168.0.{2..4}/24"  FIXME - may not work with baselayout2
 | 
			
		||||
# which does the same as above. Be careful though as if you use this and
 | 
			
		||||
# fallbacks, you have to ensure that both end up with the same number of
 | 
			
		||||
# values otherwise your fallback won't work correctly.
 | 
			
		||||
 | 
			
		||||
# You can also use IPv6 addresses
 | 
			
		||||
# (you should always specify a prefix length with IPv6 here)
 | 
			
		||||
@@ -242,12 +237,12 @@
 | 
			
		||||
 | 
			
		||||
##################################################
 | 
			
		||||
# wpa_supplicant
 | 
			
		||||
# emerge net-wireless/wpa-supplicant
 | 
			
		||||
# emerge net-wireless/wpa_supplicant
 | 
			
		||||
# Wireless options are held in /etc/wpa_supplicant/wpa_supplicant.conf
 | 
			
		||||
# Console the wpa_supplicant.conf.example that is installed in
 | 
			
		||||
# Consult the wpa_supplicant.conf.example that is installed in
 | 
			
		||||
# /usr/share/doc/wpa_supplicant
 | 
			
		||||
 | 
			
		||||
# By default we don't wait for wpa_suppliant to associate and authenticate.
 | 
			
		||||
# By default we don't wait for wpa_supplicant to associate and authenticate.
 | 
			
		||||
# If you would like to, so can specify how long in seconds
 | 
			
		||||
#associate_timeout_eth0=60
 | 
			
		||||
# A value of 0 means wait forever.
 | 
			
		||||
 
 | 
			
		||||
@@ -70,11 +70,6 @@
 | 
			
		||||
#       iproute2 does not do this as there is no need to
 | 
			
		||||
#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.
 | 
			
		||||
# Or you can use sequence expressions
 | 
			
		||||
#config_eth0="192.168.0.{2..4}/24"
 | 
			
		||||
# which does the same as above. Be careful though as if you use this and
 | 
			
		||||
# fallbacks, you have to ensure that both end up with the same number of
 | 
			
		||||
# values otherwise your fallback won't work correctly.
 | 
			
		||||
 | 
			
		||||
# You can also use IPv6 addresses
 | 
			
		||||
# (you should always specify a prefix length with IPv6 here)
 | 
			
		||||
@@ -341,16 +336,16 @@
 | 
			
		||||
 | 
			
		||||
############################################################
 | 
			
		||||
# wpa_supplicant
 | 
			
		||||
# emerge net-wireless/wpa-supplicant
 | 
			
		||||
# emerge net-wireless/wpa_supplicant
 | 
			
		||||
# Wireless options are held in /etc/wpa_supplicant/wpa_supplicant.conf
 | 
			
		||||
# Console the wpa_supplicant.conf.example that is installed in
 | 
			
		||||
# Consult the wpa_supplicant.conf.example that is installed in
 | 
			
		||||
# /usr/share/doc/wpa_supplicant
 | 
			
		||||
# To configure wpa_supplicant
 | 
			
		||||
#wpa_supplicant_ath0="-Dmadwifi" # For Atheros based cards
 | 
			
		||||
# Consult wpa_supplicant for more drivers - the default is -Dwext which should
 | 
			
		||||
# work for most cards.
 | 
			
		||||
 | 
			
		||||
# By default we don't wait for wpa_suppliant to associate and authenticate.
 | 
			
		||||
# By default we don't wait for wpa_supplicant to associate and authenticate.
 | 
			
		||||
# If you need to change this behaviour then you don't know how our scripts work
 | 
			
		||||
# and setting this value could cause strange things to happen.
 | 
			
		||||
# If you would like to, so can specify how long in seconds.
 | 
			
		||||
 
 | 
			
		||||
@@ -30,38 +30,6 @@ _forcefsck()
 | 
			
		||||
	[ -e /forcefsck ] || get_bootparam forcefsck
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
_on_ac_power()
 | 
			
		||||
{
 | 
			
		||||
	if [ -f /proc/acpi/ac_adapter/AC*/state ]; then
 | 
			
		||||
		cat /proc/acpi/ac_adapter/AC*/state | while read line; do
 | 
			
		||||
			case "$line" in
 | 
			
		||||
			"state:"*"off-line") return 128;;
 | 
			
		||||
			esac
 | 
			
		||||
		done
 | 
			
		||||
	elif [ -f /proc/pmu/info ]; then
 | 
			
		||||
		cat /proc/pmu/info | while read line; do
 | 
			
		||||
			case "$line" in
 | 
			
		||||
			"AC Power"*": 0") return 128;;
 | 
			
		||||
			esac
 | 
			
		||||
		done
 | 
			
		||||
	elif type envstat >/dev/null 2>&1; then
 | 
			
		||||
		# NetBSD has envstat
 | 
			
		||||
		envstat -d acpiacad0 2>/dev/null | while read line; do
 | 
			
		||||
			case "$line" in
 | 
			
		||||
			"connected:"*"OFF") return 128;;
 | 
			
		||||
			esac
 | 
			
		||||
		done
 | 
			
		||||
	elif sysctl -q hw.acpi.acline >/dev/null 2>/dev/null; then
 | 
			
		||||
		case $(sysctl -n hw.acpi.acline) in
 | 
			
		||||
		0) return 1;;
 | 
			
		||||
		*) return 0;;
 | 
			
		||||
		esac
 | 
			
		||||
	else
 | 
			
		||||
		return 0
 | 
			
		||||
	fi
 | 
			
		||||
	[ $? != 128 ]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
start()
 | 
			
		||||
{
 | 
			
		||||
	local fsck_opts= p= check_extra=
 | 
			
		||||
@@ -73,7 +41,7 @@ start()
 | 
			
		||||
	if _forcefsck; then
 | 
			
		||||
		fsck_opts="$fsck_opts -f"
 | 
			
		||||
		check_extra="(check forced)"
 | 
			
		||||
	elif ! yesno ${fsck_on_battery:-YES} && ! _on_ac_power; then
 | 
			
		||||
	elif ! yesno ${fsck_on_battery:-YES} && ! on_ac_power; then
 | 
			
		||||
		ewarn "Skipping fsck due to not being on AC power"
 | 
			
		||||
		return 0
 | 
			
		||||
	fi
 | 
			
		||||
 
 | 
			
		||||
@@ -112,6 +112,7 @@ runip()
 | 
			
		||||
	# Ensure we have a valid broadcast address
 | 
			
		||||
	case "$@" in
 | 
			
		||||
	*" broadcast "*|*" brd "*) ;;
 | 
			
		||||
	*:*) ;; # Ignore IPv6
 | 
			
		||||
	*) set -- "$@" brd +;;
 | 
			
		||||
	esac
 | 
			
		||||
 | 
			
		||||
@@ -136,6 +137,7 @@ routeflush()
 | 
			
		||||
	if [ "$RC_UNAME" = Linux ]; then
 | 
			
		||||
		if [ -x /sbin/ip ]; then
 | 
			
		||||
			ip route flush scope global
 | 
			
		||||
			ip route delete default 2>/dev/null
 | 
			
		||||
		else
 | 
			
		||||
			# Sadly we also delete some link routes, but
 | 
			
		||||
			# this cannot be helped
 | 
			
		||||
@@ -155,6 +157,8 @@ routeflush()
 | 
			
		||||
				esac
 | 
			
		||||
				route del $flags $dest $netmask $xtra
 | 
			
		||||
			done
 | 
			
		||||
			# Erase any default dev eth0 routes
 | 
			
		||||
			route del default 2>/dev/null
 | 
			
		||||
		fi
 | 
			
		||||
	else
 | 
			
		||||
		route -qn flush
 | 
			
		||||
@@ -249,11 +253,26 @@ start()
 | 
			
		||||
 | 
			
		||||
	if [ -n "$defaultroute" ]; then
 | 
			
		||||
		ebegin "Setting default route $defaultroute"
 | 
			
		||||
		route add default $defaultroute
 | 
			
		||||
		eend $?
 | 
			
		||||
	elif [ -n "$defaultiproute" ]; then
 | 
			
		||||
		ebegin "Setting default route $defaultiproute"
 | 
			
		||||
		ip route add default $defaultiproute
 | 
			
		||||
		eend $?
 | 
			
		||||
	fi
 | 
			
		||||
 | 
			
		||||
	if [ -n "$defaultroute6" ]; then
 | 
			
		||||
		ebegin "Setting default route $defaultroute6"
 | 
			
		||||
		if [ "$RC_UNAME" = Linux ]; then
 | 
			
		||||
			route add default gw $defaultroute
 | 
			
		||||
			routecmd="route -A inet6 add"
 | 
			
		||||
		else
 | 
			
		||||
			route add default $defaultroute
 | 
			
		||||
			routecmd="route -inet6 add"
 | 
			
		||||
		fi
 | 
			
		||||
		$routecmd default $defaultroute6
 | 
			
		||||
		eend $?
 | 
			
		||||
	elif [ -n "$defaultiproute6" ]; then
 | 
			
		||||
		ebegin "Setting default route $defaultiproute6"
 | 
			
		||||
		ip -f inet6 route add default $defaultiproute6
 | 
			
		||||
		eend $?
 | 
			
		||||
	fi
 | 
			
		||||
 | 
			
		||||
@@ -282,6 +301,11 @@ stop()
 | 
			
		||||
		then
 | 
			
		||||
			veinfo "$int"
 | 
			
		||||
			runargs /etc/ifdown."$int" "$downcmd"
 | 
			
		||||
			if [ -x /sbin/ip ]; then
 | 
			
		||||
				# We need to do this, otherwise we may
 | 
			
		||||
				# fail to add things correctly on restart
 | 
			
		||||
				ip address flush dev "$int" 2>/dev/null
 | 
			
		||||
			fi
 | 
			
		||||
			ifconfig "$int" down 2>/dev/null
 | 
			
		||||
			ifconfig "$int" destroy 2>/dev/null
 | 
			
		||||
		fi
 | 
			
		||||
 
 | 
			
		||||
@@ -15,32 +15,47 @@ depend()
 | 
			
		||||
	keyword -jail -prefix -vserver
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pre_flight_checks()
 | 
			
		||||
{
 | 
			
		||||
	route=route
 | 
			
		||||
	[ -s /etc/route.conf ] && return 0
 | 
			
		||||
 | 
			
		||||
	if [ -n "$staticiproute" ]; then
 | 
			
		||||
		route="ip route"
 | 
			
		||||
		staticroute="$staticiproute"
 | 
			
		||||
	fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
dump_args()
 | 
			
		||||
{
 | 
			
		||||
	# Route configuration file, as used by the NetBSD RC system
 | 
			
		||||
	if [ -s /etc/route.conf ]; then
 | 
			
		||||
		cat /etc/route.conf
 | 
			
		||||
	else
 | 
			
		||||
		case "$staticroute" in
 | 
			
		||||
		*"$__nl"*)
 | 
			
		||||
			echo "$staticroute"
 | 
			
		||||
			;;
 | 
			
		||||
		*)
 | 
			
		||||
			(
 | 
			
		||||
		 		set -o noglob
 | 
			
		||||
				IFS=';'; set -- $staticroute
 | 
			
		||||
				IFS="$__nl"; echo "$*"
 | 
			
		||||
			)
 | 
			
		||||
			;;
 | 
			
		||||
		esac
 | 
			
		||||
		return $?
 | 
			
		||||
	fi
 | 
			
		||||
 | 
			
		||||
	case "$staticroute" in
 | 
			
		||||
	*"$__nl"*)
 | 
			
		||||
		echo "$staticroute"
 | 
			
		||||
		;;
 | 
			
		||||
	*)
 | 
			
		||||
		(
 | 
			
		||||
			set -o noglob
 | 
			
		||||
			IFS=';'; set -- $staticroute
 | 
			
		||||
			IFS="$__nl"; echo "$*"
 | 
			
		||||
		)
 | 
			
		||||
		;;
 | 
			
		||||
	esac
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
do_routes()
 | 
			
		||||
{
 | 
			
		||||
	local xtra=
 | 
			
		||||
	local xtra= family=
 | 
			
		||||
	[ "$RC_UNAME" != Linux ] && xtra=-q
 | 
			
		||||
 | 
			
		||||
	ebegin "$1 static routes"
 | 
			
		||||
	eindent
 | 
			
		||||
	pre_flight_checks
 | 
			
		||||
	dump_args | while read args; do
 | 
			
		||||
		[ -z "$args" ] && continue
 | 
			
		||||
		case "$args" in
 | 
			
		||||
@@ -53,10 +68,26 @@ do_routes()
 | 
			
		||||
			[ $2 = "del" -o $2 = "delete" ] && eval ${args#*-}
 | 
			
		||||
			;;
 | 
			
		||||
		*)
 | 
			
		||||
			route $xtra $2 -$args
 | 
			
		||||
			;;
 | 
			
		||||
			veinfo "$args"
 | 
			
		||||
			case "$route" in
 | 
			
		||||
			"ip route")
 | 
			
		||||
				ip route $2 $args
 | 
			
		||||
				;;
 | 
			
		||||
			*)
 | 
			
		||||
				# Linux route does cannot work it out ...
 | 
			
		||||
				if [ "$RC_UNAME" = Linux ]; then
 | 
			
		||||
					case "$args" in
 | 
			
		||||
					*:*) family="-A inet6";;
 | 
			
		||||
					*) family=;;
 | 
			
		||||
					esac
 | 
			
		||||
				fi
 | 
			
		||||
				route $famly $xtra $2 -$args
 | 
			
		||||
				;;
 | 
			
		||||
			esac
 | 
			
		||||
			veend $?
 | 
			
		||||
		esac
 | 
			
		||||
	done
 | 
			
		||||
	eoutdent
 | 
			
		||||
	eend 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -22,7 +22,7 @@
 | 
			
		||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 | 
			
		||||
.\" SUCH DAMAGE.
 | 
			
		||||
.\"
 | 
			
		||||
.Dd October 14, 2009
 | 
			
		||||
.Dd December 14, 2009
 | 
			
		||||
.Dt START-STOP-DAEMON 8 SMM
 | 
			
		||||
.Os OpenRC
 | 
			
		||||
.Sh NAME
 | 
			
		||||
@@ -136,6 +136,10 @@ option. Only useful when used with daemons that run in the foreground and
 | 
			
		||||
forced into the background with the
 | 
			
		||||
.Fl -b , -background
 | 
			
		||||
option.
 | 
			
		||||
.It Fl I , -ionice Ar class Ns Op : Ns Ar data
 | 
			
		||||
Modifies the IO scheduling priority of the daemon.
 | 
			
		||||
Class can be 0 for none, 1 for real time, 2 for best effort and 3 for idle.
 | 
			
		||||
Data can be from 0 to 7 inclusive.
 | 
			
		||||
.It Fl N , -nice Ar level
 | 
			
		||||
Modifies the scheduling priority of the daemon.
 | 
			
		||||
.It Fl 1 , -stdout Ar logfile
 | 
			
		||||
 
 | 
			
		||||
@@ -42,7 +42,8 @@ _ifindex()
 | 
			
		||||
_is_wireless()
 | 
			
		||||
{
 | 
			
		||||
	# Support new sysfs layout
 | 
			
		||||
	[ -d /sys/class/net/"${IFACE}"/wireless ] && return 0
 | 
			
		||||
	[ -d /sys/class/net/"${IFACE}"/wireless -o \
 | 
			
		||||
		-d /sys/class/net/"${IFACE}"/phy80211 ] && return 0
 | 
			
		||||
 | 
			
		||||
	[ ! -e /proc/net/wireless ] && return 1
 | 
			
		||||
	grep -Eq "^[[:space:]]*${IFACE}:" /proc/net/wireless
 | 
			
		||||
 
 | 
			
		||||
@@ -43,7 +43,8 @@ _ifindex()
 | 
			
		||||
_is_wireless()
 | 
			
		||||
{
 | 
			
		||||
	# Support new sysfs layout
 | 
			
		||||
	[ -d /sys/class/net/"${IFACE}"/wireless ] && return 0
 | 
			
		||||
	[ -d /sys/class/net/"${IFACE}"/wireless -o \
 | 
			
		||||
		-d /sys/class/net/"${IFACE}"/phy80211 ] && return 0
 | 
			
		||||
 | 
			
		||||
	[ ! -e /proc/net/wireless ] && return 1
 | 
			
		||||
	grep -Eq "^[[:space:]]*${IFACE}:" /proc/net/wireless
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										5
									
								
								scripts/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								scripts/Makefile
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
DIR=	${LIBEXECDIR}/bin
 | 
			
		||||
BIN=	on_ac_power
 | 
			
		||||
 | 
			
		||||
MK=	../mk
 | 
			
		||||
include ${MK}/scripts.mk
 | 
			
		||||
							
								
								
									
										33
									
								
								scripts/on_ac_power
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										33
									
								
								scripts/on_ac_power
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,33 @@
 | 
			
		||||
#!/bin/sh
 | 
			
		||||
# Detect AC power or not in a portable way
 | 
			
		||||
# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
 | 
			
		||||
 | 
			
		||||
# Exit 0 if on AC power, 1 if not and 255 if we don't know how to work it out
 | 
			
		||||
if [ -f /proc/acpi/ac_adapter/AC*/state ]; then
 | 
			
		||||
	cat /proc/acpi/ac_adapter/AC*/state | while read line; do
 | 
			
		||||
		case "$line" in
 | 
			
		||||
		"state:"*"off-line") return 128;;
 | 
			
		||||
		esac
 | 
			
		||||
	done
 | 
			
		||||
elif [ -f /proc/pmu/info ]; then
 | 
			
		||||
	cat /proc/pmu/info | while read line; do
 | 
			
		||||
		case "$line" in
 | 
			
		||||
		"AC Power"*": 0") return 128;;
 | 
			
		||||
		esac
 | 
			
		||||
	done
 | 
			
		||||
elif type envstat >/dev/null 2>&1; then
 | 
			
		||||
	# NetBSD has envstat
 | 
			
		||||
	envstat -d acpiacad0 2>/dev/null | while read line; do
 | 
			
		||||
		case "$line" in
 | 
			
		||||
		"connected:"*"OFF") return 128;;
 | 
			
		||||
		esac
 | 
			
		||||
	done
 | 
			
		||||
elif sysctl -q hw.acpi.acline >/dev/null 2>/dev/null; then
 | 
			
		||||
	case $(sysctl -n hw.acpi.acline) in
 | 
			
		||||
	0) return 1;;
 | 
			
		||||
	*) return 0;;
 | 
			
		||||
	esac
 | 
			
		||||
else
 | 
			
		||||
	exit 255
 | 
			
		||||
fi
 | 
			
		||||
[ $? != 128 ]
 | 
			
		||||
@@ -47,6 +47,10 @@
 | 
			
		||||
#include <sys/time.h>
 | 
			
		||||
#include <sys/wait.h>
 | 
			
		||||
 | 
			
		||||
#ifdef __linux__
 | 
			
		||||
#include <sys/syscall.h> /* For io priority */
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include <ctype.h>
 | 
			
		||||
#include <errno.h>
 | 
			
		||||
#include <fcntl.h>
 | 
			
		||||
@@ -104,6 +108,13 @@ static char *changeuser, *ch_root, *ch_dir;
 | 
			
		||||
 | 
			
		||||
extern char **environ;
 | 
			
		||||
 | 
			
		||||
#ifdef __linux__
 | 
			
		||||
static inline int ioprio_set(int which, int who, int ioprio)
 | 
			
		||||
{
 | 
			
		||||
	return syscall(SYS_ioprio_set, which, who, ioprio);
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
free_schedulelist(void)
 | 
			
		||||
{
 | 
			
		||||
@@ -589,8 +600,9 @@ expand_home(const char *home, const char *path)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#include "_usage.h"
 | 
			
		||||
#define getoptstring "KN:PR:Sbc:d:e:g:ik:mn:op:s:tu:r:w:x:1:2:" getoptstring_COMMON
 | 
			
		||||
#define getoptstring "I:KN:PR:Sbc:d:e:g:ik:mn:op:s:tu:r:w:x:1:2:" getoptstring_COMMON
 | 
			
		||||
static const struct option longopts[] = {
 | 
			
		||||
	{ "ionice",       1, NULL, 'I'},
 | 
			
		||||
	{ "stop",         0, NULL, 'K'},
 | 
			
		||||
	{ "nicelevel",    1, NULL, 'N'},
 | 
			
		||||
	{ "retry",        1, NULL, 'R'},
 | 
			
		||||
@@ -619,6 +631,7 @@ static const struct option longopts[] = {
 | 
			
		||||
	longopts_COMMON
 | 
			
		||||
};
 | 
			
		||||
static const char * const longopts_help[] = {
 | 
			
		||||
	"Set an ionice class:data when starting", 
 | 
			
		||||
	"Stop daemon",
 | 
			
		||||
	"Set a nicelevel when starting",
 | 
			
		||||
	"Retry schedule to use when stopping",
 | 
			
		||||
@@ -675,7 +688,7 @@ start_stop_daemon(int argc, char **argv)
 | 
			
		||||
	char *pidfile = NULL;
 | 
			
		||||
	char *retry = NULL;
 | 
			
		||||
	int sig = -1;
 | 
			
		||||
	int nicelevel = 0;
 | 
			
		||||
	int nicelevel = 0, ionicec = -1, ioniced = 0;
 | 
			
		||||
	bool background = false;
 | 
			
		||||
	bool makepidfile = false;
 | 
			
		||||
	bool interpreted = false;
 | 
			
		||||
@@ -738,6 +751,17 @@ start_stop_daemon(int argc, char **argv)
 | 
			
		||||
	while ((opt = getopt_long(argc, argv, getoptstring, longopts,
 | 
			
		||||
		    (int *) 0)) != -1)
 | 
			
		||||
		switch (opt) {
 | 
			
		||||
		case 'I': /* --ionice */
 | 
			
		||||
			if (sscanf(optarg, "%d:%d", &ionicec, &ioniced) == 0)
 | 
			
		||||
				eerrorx("%s: invalid ionice `%s'",
 | 
			
		||||
				    applet, optarg);
 | 
			
		||||
			if (ionicec == 0)
 | 
			
		||||
				ioniced = 0;
 | 
			
		||||
			else if (ionicec == 3)
 | 
			
		||||
				ioniced = 7;
 | 
			
		||||
			ionicec <<= 13; /* class shift */
 | 
			
		||||
			break;
 | 
			
		||||
 | 
			
		||||
		case 'K':  /* --stop */
 | 
			
		||||
			stop = true;
 | 
			
		||||
			break;
 | 
			
		||||
@@ -1121,6 +1145,14 @@ start_stop_daemon(int argc, char **argv)
 | 
			
		||||
				    strerror(errno));
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
/* Only linux suports setting an IO priority */
 | 
			
		||||
#ifdef __linux__
 | 
			
		||||
		if (ionicec != -1 &&
 | 
			
		||||
		    ioprio_set(1, mypid, ionicec | ioniced) == -1)
 | 
			
		||||
			eerrorx("%s: ioprio_set %d %d: %s", applet,
 | 
			
		||||
			    ionicec, ioniced, strerror(errno));
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
		if (ch_root && chroot(ch_root) < 0)
 | 
			
		||||
			eerrorx("%s: chroot `%s': %s",
 | 
			
		||||
			    applet, ch_root, strerror(errno));
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user