~alpine/aports

2

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

Marian Buschsieweke <marian.buschsieweke@ovgu.de>
Details
Message ID
<20170620075459.8882-1-marian.buschsieweke@ovgu.de>
Sender timestamp
1497945299
DKIM signature
missing
Download raw message
Patch: +179 -0
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
@@ -0,0 +1,46 @@
# Contributor: Marian <marian.buschsieweke@ovgu.de>
# Maintainer: Marian <marian.buschsieweke@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
@@ -0,0 +1,95 @@
--- wpa_actiond-1.4-old/wpa_actiond.c
+++ wpa_actiond-1.4-new/wpa_actiond.c
@@ -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;
 
@@ -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
@@ -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
@@ -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@lists.alpinelinux.org
Help:         alpine-aports+help@lists.alpinelinux.org
---
Leonardo Arena <rnalrd@gmail.com>
Details
Message ID
<70de3a50-0eb9-3288-83e1-859f7ec232f0@gmail.com>
In-Reply-To
<20170620075459.8882-1-marian.buschsieweke@ovgu.de> (view parent)
Sender timestamp
1498206010
DKIM signature
missing
Download raw message
Hi,

the patch was committed with the following amendment:


On 06/20/2017 09:54 AM, Marian Buschsieweke wrote:
> 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
> @@ -0,0 +1,46 @@
> +# Contributor: Marian <marian.buschsieweke@ovgu.de>
> +# Maintainer: Marian <marian.buschsieweke@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"
> +

_buildir is now an "official" APKBUILD variable, hence underscore prefix 
has been removed and APKBUILD update accordingly

> +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
> +}
> +

prepare() function removed since applying patch is by default in abuild 
unless overridden by declaring a custom prepare() function.

Everything else looked good to me.

Thanks!

/eo


---
Unsubscribe:  alpine-aports+unsubscribe@lists.alpinelinux.org
Help:         alpine-aports+help@lists.alpinelinux.org
---
Leonardo Arena <rnalrd@gmail.com>
Details
Message ID
<92b1f953-3c99-a3c1-eb71-4e53f261a33b@gmail.com>
In-Reply-To
<70de3a50-0eb9-3288-83e1-859f7ec232f0@gmail.com> (view parent)
Sender timestamp
1498206902
DKIM signature
missing
Download raw message
[snip]
>> 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
>> @@ -0,0 +1,46 @@
>> +# Contributor: Marian <marian.buschsieweke@ovgu.de>
>> +# Maintainer: Marian <marian.buschsieweke@ovgu.de>
>> +pkgname=wpa_actiond
>> +pkgver=1.4
>> +pkgrel=1

Another thing: initial pkgrel should be set to 0.

Thanks!

/eo



---
Unsubscribe:  alpine-aports+unsubscribe@lists.alpinelinux.org
Help:         alpine-aports+help@lists.alpinelinux.org
---
Reply to thread Export thread (mbox)