Mail archive
alpine-aports

[alpine-aports] [PATCH] testing/wpa_actiond: new aport

From: Marian Buschsieweke <marian.buschsieweke_at_ovgu.de>
Date: Tue, 20 Jun 2017 09:54:59 +0200

Daemon that connects to wpa_supplicant and handles connect and disconnect events
https://git.archlinux.org/wpa_actiond.git

Use case: A plain and simple way to automatically configure wireless networks
depending on SSID by invoking user supplied scripts.

I provided a patch to convert the nested function into a regular one, so that
GCC won't generate a trampoline. In addition, OpenRC integration was added.
---
 testing/wpa_actiond/APKBUILD            | 46 ++++++++++++++++
 testing/wpa_actiond/no_trampoline.patch | 95 +++++++++++++++++++++++++++++++++
 testing/wpa_actiond/wpa_actiond.confd   | 16 ++++++
 testing/wpa_actiond/wpa_actiond.initd   | 22 ++++++++
 4 files changed, 179 insertions(+)
 create mode 100644 testing/wpa_actiond/APKBUILD
 create mode 100644 testing/wpa_actiond/no_trampoline.patch
 create mode 100644 testing/wpa_actiond/wpa_actiond.confd
 create mode 100644 testing/wpa_actiond/wpa_actiond.initd
diff --git a/testing/wpa_actiond/APKBUILD b/testing/wpa_actiond/APKBUILD
new file mode 100644
index 0000000000..e0b14f5232
--- /dev/null
+++ b/testing/wpa_actiond/APKBUILD
_at_@ -0,0 +1,46 @@
+# Contributor: Marian <marian.buschsieweke_at_ovgu.de>
+# Maintainer: Marian <marian.buschsieweke_at_ovgu.de>
+pkgname=wpa_actiond
+pkgver=1.4
+pkgrel=1
+pkgdesc="Daemon that connects to wpa_supplicant and handles connect and disconnect events"
+url="https://git.archlinux.org/wpa_actiond.git/"
+arch="all"
+license="GPL2"
+depends=""
+makedepends=""
+subpackages=""
+source="https://git.archlinux.org/${pkgname}.git/snapshot/${pkgname}-${pkgver}.tar.xz
+        no_trampoline.patch
+        wpa_actiond.confd
+        wpa_actiond.initd"
+options="!check"
+
+_builddir="$srcdir/$pkgname-$pkgver"
+
+prepare() {
+    local i
+    cd "$_builddir"
+    for i in $source; do
+        case $i in
+        *.patch) msg $i; patch -p1 -i "$srcdir"/$i || return 1;;
+        esac
+    done
+}
+
+build() {
+	cd "$_builddir"
+	make
+}
+
+package() {
+	cd "$_builddir"
+	install -Dm755 -t "${pkgdir}/usr/sbin/" wpa_actiond
+	install -Dm755 ../wpa_actiond.initd "${pkgdir}/etc/init.d/wpa_actiond"
+	install -Dm755 ../wpa_actiond.confd "${pkgdir}/etc/conf.d/wpa_actiond"
+}
+
+sha512sums="1ac38cdb6ce534cb14cfada4def31c17feff61408868ffd63cd1a516cdbade992719b575a96f5ab4046a1d451bfae526ccdf8eb68cfc7bdc022df3506ae07296  wpa_actiond-1.4.tar.xz
+ebd49ffe1a83e08cd51d99677ce8c3f84ecdd4f3ec4a2c81a336bd87af56db0d36534003f9d7c3b34de129a3a4ef4ee4e9683f2a54729af86c946206c11cd20d  no_trampoline.patch
+104ffd6e04d8f69fb238428256e2bc4a8e6acd5e333fc411a72b5ae2d82f4efff6e8d4e08a282ca1a8c2ffe0b2a7fd8cd3ac222e19d6c177c721b957ef4fa5e9  wpa_actiond.confd
+8e902f2bd6bad2983e1048d18a150176b65608bd74971a72fe66cd03dba3f80893240294ffac83820fc5c46e5cb10c9267d53f60c4d2d55f7a3e45005e12fbbe  wpa_actiond.initd"
diff --git a/testing/wpa_actiond/no_trampoline.patch b/testing/wpa_actiond/no_trampoline.patch
new file mode 100644
index 0000000000..560f05aafb
--- /dev/null
+++ b/testing/wpa_actiond/no_trampoline.patch
_at_@ -0,0 +1,95 @@
+--- wpa_actiond-1.4-old/wpa_actiond.c
++++ wpa_actiond-1.4-new/wpa_actiond.c
+_at_@ -72,6 +72,23 @@
+   WPA_ACTIOND_LOG_CUSTOM_ERROR
+ };
+ 
++/* wpa_supplicant control structure */
++static struct wpa_ctrl *ctrl;
++  
++/* states and events */
++static enum wpastate state = WPA_ACTIOND_STATE_UNDEFINED;
++static enum wpaevent ev;
++/* select stuff */
++static int ctrl_fd;
++static fd_set ctrl_fds;
++/* save ssid */
++static char ssid[SSIDLEN], old_ssid[SSIDLEN];
++static char idstr[IDSTRLEN], old_idstr[IDSTRLEN];
++/* for terminate handler*/
++static const char *iface;
++static const char *script;
++static const char *pidfile;
++
+ static void logevent(enum wpa_actiond_logevent l, const char *iface, const char *arg) {
+   static int isopen = 0, tostderr = 0;
+ 
+_at_@ -270,48 +287,43 @@
+   }
+ }
+ 
+-static void loop(const char *iface, const char *ctrlpath, const int disconnect_timeout, const char *script, const char *pidfile) {
+-  /* wpa_supplicant control structure */
+-  struct wpa_ctrl *ctrl;
++static void terminate(int s) {
++  if(state == WPA_ACTIOND_STATE_CONNECTED || state == WPA_ACTIOND_STATE_CONNECTION_LOST) {
++    logevent(WPA_ACTIOND_LOG_DISCONNECTED, iface, ssid);
++    action(WPA_ACTIOND_ACTION_DISCONNECT, iface, ssid, idstr, wpa_ctrl_get_fd(ctrl), script);
++  }
++  logevent(WPA_ACTIOND_LOG_TERMINATE, iface, "");
++
++  FD_ZERO(&ctrl_fds);
++  wpa_ctrl_detach(ctrl);
++  wpa_ctrl_close(ctrl);
++  unlink(pidfile);
++  exit(0);
++}
++
++static void loop(const char *_iface, const char *ctrlpath, const int disconnect_timeout, const char *_script, const char *_pidfile) {
+   /* buffer for wpa_supplicant replies */
+   char reply[BUFLEN];
+   size_t reply_len;
+-  /* states and events */
+-  enum wpastate state = WPA_ACTIOND_STATE_UNDEFINED;
+-  enum wpaevent ev;
+-  /* select stuff */
+-  int ctrl_fd;
+-  fd_set ctrl_fds;
+   int r;
+   /* select timeout */
+   struct timeval timeout;
+   struct timeval ping_timeout;
+-  /* save ssid */
+-  char ssid[SSIDLEN], old_ssid[SSIDLEN];
+-  char idstr[IDSTRLEN], old_idstr[IDSTRLEN];
+   /* path to control socket */
+   char *ctrlsock = NULL;
+   int ctrlsocklen;
+ 
++  /* set up globals for terminate signal handler */
++  iface = _iface;
++  script = _script;
++  pidfile = _pidfile;
++
+   ssid[0] = '\0';
+   old_ssid[0] = '\0';
+   idstr[0] = '\0';
+   old_idstr[0] = '\0';
+ 
+   /* set up signals */
+-  void terminate(int s) {
+-    if(state == WPA_ACTIOND_STATE_CONNECTED || state == WPA_ACTIOND_STATE_CONNECTION_LOST) {
+-      logevent(WPA_ACTIOND_LOG_DISCONNECTED, iface, ssid);
+-      action(WPA_ACTIOND_ACTION_DISCONNECT, iface, ssid, idstr, wpa_ctrl_get_fd(ctrl), script);
+-    }
+-    logevent(WPA_ACTIOND_LOG_TERMINATE, iface, "");
+-
+-    FD_ZERO(&ctrl_fds);
+-    wpa_ctrl_detach(ctrl);
+-    wpa_ctrl_close(ctrl);
+-    unlink(pidfile);
+-    exit(0);
+-  }
+   signal(SIGTERM, terminate);
+   signal(SIGHUP, SIG_IGN);
+ 
diff --git a/testing/wpa_actiond/wpa_actiond.confd b/testing/wpa_actiond/wpa_actiond.confd
new file mode 100644
index 0000000000..86fcb6a6e8
--- /dev/null
+++ b/testing/wpa_actiond/wpa_actiond.confd
_at_@ -0,0 +1,16 @@
+# /etc/conf.d/wpa_actiond: config file for /etc/init.d/wpa_actiond
+
+# Interface to listen at
+WPA_ACTIOND_INTERFACE="wlan0"
+
+# Replace with custom script:
+WPA_ACTIOND_SCRIPT="/usr/bin/logger"
+# >  The action script takes four parameters:
+# >   1) The interface name
+# >   2) The SSID of the wireless network or empty string if using wired driver
+# >   3) The id_str parameter of the wpa_supplicant network section
+# >   4) One of the strings CONNECT, LOST, REESTABLISHED, FAILED and DISCONNECT
+
+# Add custom arguments
+WPA_ACTIOND_OPTS=""
+# see `wpa_actiond -h` for mor information
diff --git a/testing/wpa_actiond/wpa_actiond.initd b/testing/wpa_actiond/wpa_actiond.initd
new file mode 100644
index 0000000000..9861168871
--- /dev/null
+++ b/testing/wpa_actiond/wpa_actiond.initd
_at_@ -0,0 +1,22 @@
+#!/sbin/openrc-run
+
+depend()
+{
+	need net wpa_supplicant
+}
+
+start()
+{
+	ebegin "Starting wpa_actiond"
+	start-stop-daemon --start --quiet --exec /usr/sbin/wpa_actiond -p /var/run/wpa_actiond.pid -- \
+		-i ${WPA_ACTIOND_INTERFACE} -a ${WPA_ACTIOND_SCRIPT} ${WPA_ACTIOND_OPTS}
+	eend $?
+}
+
+stop()
+{
+	ebegin "Stopping wpa_actiond"
+	start-stop-daemon --stop --quiet --exec /usr/sbin/wpa_actiond -p /var/run/wpa_actiond.pid
+	eend $?
+}
+
-- 
2.13.1
---
Unsubscribe:  alpine-aports+unsubscribe_at_lists.alpinelinux.org
Help:         alpine-aports+help_at_lists.alpinelinux.org
---
Received on Tue Jun 20 2017 - 09:54:59 GMT