aboutsummaryrefslogtreecommitdiffstats
path: root/main/wpa_supplicant/wpa_cli.sh
diff options
context:
space:
mode:
authorSören Tempel <soeren+git@soeren-tempel.net>2018-02-28 20:57:47 +0100
committerSören Tempel <soeren+git@soeren-tempel.net>2018-02-28 21:30:58 +0100
commit56826afa0399402f00f4078ff3b8b08f7f5c9093 (patch)
tree613f6587709fde89a76bb96e3cd15ecb5b63699d /main/wpa_supplicant/wpa_cli.sh
parentea4db75da410dcc6daffb6b6d019baf3af4a2160 (diff)
downloadaports-56826afa0399402f00f4078ff3b8b08f7f5c9093.tar.gz
aports-56826afa0399402f00f4078ff3b8b08f7f5c9093.tar.bz2
aports-56826afa0399402f00f4078ff3b8b08f7f5c9093.tar.xz
main/wpa_supplicant: refactor wpa_cli.sh
udhcpc doesn't have link beat detection and the purposes of this script is making udhcpc acquire a new lease when connecting to an access point. The previous version of this script achieved that goal by running ifdown/ifup which is pretty ugly and never worked properly (at least with my setup). A better solution for acquiring a DHCP lease when connecting to a new AP is sending a SIGUSR1 signal to the udhcpc running on the affected interfaces, this solution is implemented in this commit. Together with the wpa_cli OpenRC service added in the previous commit this makes using udhcpc on laptops very convenient. See also: cc8f61f6330f49f1e2522e6fbed88e84e47190c3
Diffstat (limited to 'main/wpa_supplicant/wpa_cli.sh')
-rw-r--r--main/wpa_supplicant/wpa_cli.sh35
1 files changed, 21 insertions, 14 deletions
diff --git a/main/wpa_supplicant/wpa_cli.sh b/main/wpa_supplicant/wpa_cli.sh
index 0a5a6cc036..dd9bc2ca46 100644
--- a/main/wpa_supplicant/wpa_cli.sh
+++ b/main/wpa_supplicant/wpa_cli.sh
@@ -1,33 +1,40 @@
#!/bin/sh
-# Distributed under the terms of the BSD License.
-# Copyright (c) 2015 Sören Tempel <soeren+alpine@soeren-tempel.net>
+# Script for using udhcpc (started by ifup) with wpa_supplicant.
+#
+# Distributed under the same license as wpa_supplicant itself.
+# Copyright (c) 2015,2018 Sören Tempel <soeren+alpine@soeren-tempel.net>
-IFUP="/sbin/ifup"
-IFDOWN="/sbin/ifdown"
-
-if [ -z "${1}" -o -z "${2}" ]; then
+if [ $# -ne 2 ]; then
logger -t wpa_cli "this script should be called from wpa_cli(8)"
exit 1
-elif ! [ -x "${IFUP}" -a -x "${IFDOWN}" ]; then
- logger -t wpa_cli "${IFUP} or ${IFDOWN} doesn't exist"
- exit 1
fi
IFNAME="${1}"
ACTION="${2}"
+SIGNAL=""
+DHCPID=""
+
+# PID file created by the busybox ifup applet for udhcpc.
+DHCPIDFILE="/var/run/udhcpc.${IFNAME}.pid"
+
+if [ ! -e "${DHCPIDFILE}" ]; then
+ logger -t wpa_cli "udhcpc isn't running for interface '${IFNAME}'"
+ exit 1
+fi
-EXEC=""
+logger -t wpa_cli "interface ${IFNAME} ${ACTION}"
case "${ACTION}" in
CONNECTED)
- EXEC="${IFUP}"
+ SIGNAL="USR1"
;;
DISCONNECTED)
- EXEC="${IFDOWN}"
+ SIGNAL="USR2"
;;
*)
logger -t wpa_cli "unknown action '${ACTION}'"
exit 1
esac
-logger -t wpa_cli "interface ${IFNAME} ${ACTION}"
-${EXEC} "${IFNAME}" || logger -t wpa_cli "executing '${EXEC}' failed"
+read -r DHCPID < "${DHCPIDFILE}"
+kill -${SIGNAL} "${DHCPID}" || logger -t wpa_cli \
+ "Couldn't send '${SIGNAL}' to '${DHCPID}'"