PageRenderTime 207ms CodeModel.GetById 201ms app.highlight 4ms RepoModel.GetById 0ms app.codeStats 1ms

/rc0.d/S15wpa-ifupdown

http://github.com/brinkman83/bashrc
Shell | 88 lines | 54 code | 11 blank | 23 comment | 9 complexity | 87ca34ea160f4d1bd9adb18999668c35 MD5 | raw file
 1#!/bin/sh
 2
 3### BEGIN INIT INFO
 4# Provides:             wpa-ifupdown
 5# Required-Start:       $network
 6# Required-Stop:        $network $remote_fs
 7# Should-Start:
 8# Should-Stop:
 9# Default-Start:
10# Default-Stop:         0 6
11# Short-Description:    Stop wpa_supplicant processes started via ifupdown
12# Description:          Run ifdown on interfaces authenticated via
13#                       wpa_supplicant. Sendsigs terminates wpa_supplicant
14#                       processes before networking is stopped causing each
15#                       network interface authenticated via a wpa_supplicant
16#                       daemon to be terminated abrubtly.
17#                       Since initscripts package version 2.86.ds1-48 an
18#                       interface exists to omit process id's from sendsigs. If
19#                       this interface is present this script is a no-op.
20### END INIT INFO
21
22PATH=/usr/sbin:/usr/bin:/sbin:/bin
23
24test -d /var/run || exit 0
25
26test -x /sbin/ifdown || exit 0
27
28. /lib/lsb/init-functions
29
30stop_wpa_action () {
31	test -x /sbin/wpa_action || return 0
32	IFACES=$(find /var/run -maxdepth 1 -type f -name 'wpa_action.*.pid' -printf '%P\n' | \
33		cut -d'.' -f2 2>/dev/null)
34	if test -n "$IFACES"; then
35		log_daemon_msg "Stopping wpa_action roaming interfaces"
36		for iface in $IFACES; do
37			log_progress_msg "$iface"
38			# wpa_action executes /sbin/ifdown
39			wpa_action "$iface" stop >/dev/null 2>&1
40		done
41		log_end_msg 0
42	fi
43}
44
45stop_wpa_supplicant () {
46	IFACES=$(find /var/run -maxdepth 1 -type f -name 'wpa_supplicant.*.pid' -printf '%P\n' | \
47		grep -v wpa_supplicant.dbus.pid | cut -d'.' -f2 2>/dev/null)
48	if test -n "$IFACES"; then
49		log_daemon_msg "Stopping wpa_supplicant interfaces"
50		for iface in $IFACES; do
51			log_progress_msg "$iface"
52			ifdown "$iface" >/dev/null 2>&1
53		done
54		log_end_msg 0
55	fi
56}
57
58sendsigs_omission_support () {
59	if [ -d /lib/init/rw/sendsigs.omit.d/ ]; then
60		# Debian
61		return 0
62	elif [ -d /var/run/sendsigs.omit.d/ ]; then
63		# Ubuntu, cf. https://bugs.launchpad.net/bugs/181541
64		return 0
65	fi
66
67	return 1
68}
69
70case "$1" in
71	start|restart|force-reload)
72		# No-op
73		;;
74	stop)
75		if sendsigs_omission_support; then
76			stop_wpa_action
77		else
78			stop_wpa_action
79			stop_wpa_supplicant
80		fi
81		;;
82	*)
83		echo "Usage: $0 {start|stop|restart|force-reload}" >&2
84		exit 3
85		;;
86esac
87
88exit 0