about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2019-11-17 14:08:44 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2019-11-17 14:08:44 +0000
commit29c3282e7c73474642dc48d60ef90d79385c2a1b (patch)
tree06eb15ec1674fe35f78d2ddff7ca90b314308a01
parentcc74d3000e81af2533c386b7f55912f2e60e5a99 (diff)
downloadbcnm-29c3282e7c73474642dc48d60ef90d79385c2a1b.tar.gz
bcnm-29c3282e7c73474642dc48d60ef90d79385c2a1b.tar.xz
bcnm-29c3282e7c73474642dc48d60ef90d79385c2a1b.zip
Apply smaeul's fixes; add --with-tmpdir configure option
-rw-r--r--AUTHORS3
-rwxr-xr-xconfigure7
-rw-r--r--package/deps.mak2
-rw-r--r--src/libwpactrl/wpactrl_fd_recv.c2
-rw-r--r--src/libwpactrl/wpactrl_start.c25
-rw-r--r--src/libwpactrl/wpactrl_update.c2
-rw-r--r--src/libwpactrl/wpactrl_xchg_event.c2
7 files changed, 35 insertions, 8 deletions
diff --git a/AUTHORS b/AUTHORS
index c1a5cf7..25ca673 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -1,4 +1,7 @@
 Main author:
   Laurent Bercot <ska-skaware@skarnet.org>
 
+Contributors:
+  Samuel Holland <samuel@sholland.org>
+
 Thanks to:
diff --git a/configure b/configure
index 05a74f9..45910d2 100755
--- a/configure
+++ b/configure
@@ -45,6 +45,7 @@ Optional features:
   --enable-slashpackage[=ROOT]  assume /package installation at ROOT [disabled]
   --enable-absolute-paths       do not rely on PATH to access this package's binaries,
                                   hardcode absolute BINDIR/foobar paths instead [disabled]
+  --with-tmpdir=DIR             assume a writable-for-all directory at DIR [/tmp]
 
 EOF
 exit 0
@@ -158,6 +159,7 @@ addlibdpath=''
 vpaths=''
 vpathd=''
 build=
+tmpdir=/tmp
 
 for arg ; do
   case "$arg" in
@@ -191,6 +193,7 @@ for arg ; do
     --enable-*|--disable-*|--with-*|--without-*|--*dir=*) ;;
     --host=*|--target=*) target=${arg#*=} ;;
     --build=*) build=${arg#*=} ;;
+    --with-tmpdir=*) tmpdir=${arg#*=} ;;
     -* ) echo "$0: unknown option $arg" ;;
     *=*) ;;
     *) target=$arg ;;
@@ -212,7 +215,7 @@ fi
 
 # Expand installation directories
 stripdir prefix
-for i in exec_prefix dynlibdir libexecdir bindir libdir includedir sysdeps sproot ; do
+for i in exec_prefix dynlibdir libexecdir bindir libdir includedir sysdeps sproot tmpdir ; do
   eval tmp=\${$i}
   eval $i=$tmp
   stripdir $i
@@ -396,6 +399,7 @@ sproot := $sproot
 version := $version
 home := $home
 exthome := $exthome
+tmpdir := $tmpdir
 SPAWN_LIB := ${spawn_lib}
 SOCKET_LIB := ${socket_lib}
 SYSCLOCK_LIB := ${sysclock_lib}
@@ -465,6 +469,7 @@ else
   echo "#define ${package_macro_name}_EXTBINPREFIX \"\""
 fi
 echo "#define ${package_macro_name}_LIBEXECPREFIX \"$libexecdir/\""
+echo "#define ${package_macro_name}_TMPDIR \"$tmpdir\""
 echo
 echo "#endif"
 exec 1>&3 3>&-
diff --git a/package/deps.mak b/package/deps.mak
index 39cba54..26807a4 100644
--- a/package/deps.mak
+++ b/package/deps.mak
@@ -26,7 +26,7 @@ src/libwpactrl/wpactrl_removenetwork.o src/libwpactrl/wpactrl_removenetwork.lo:
 src/libwpactrl/wpactrl_scan_parse.o src/libwpactrl/wpactrl_scan_parse.lo: src/libwpactrl/wpactrl_scan_parse.c src/include/bcnm/wpactrl.h
 src/libwpactrl/wpactrl_selectnetwork.o src/libwpactrl/wpactrl_selectnetwork.lo: src/libwpactrl/wpactrl_selectnetwork.c src/include/bcnm/wpactrl.h
 src/libwpactrl/wpactrl_setnetworkoption.o src/libwpactrl/wpactrl_setnetworkoption.lo: src/libwpactrl/wpactrl_setnetworkoption.c src/include/bcnm/wpactrl.h
-src/libwpactrl/wpactrl_start.o src/libwpactrl/wpactrl_start.lo: src/libwpactrl/wpactrl_start.c src/include/bcnm/wpactrl.h src/libwpactrl/wpactrl-internal.h
+src/libwpactrl/wpactrl_start.o src/libwpactrl/wpactrl_start.lo: src/libwpactrl/wpactrl_start.c src/include/bcnm/config.h src/include/bcnm/wpactrl.h src/libwpactrl/wpactrl-internal.h
 src/libwpactrl/wpactrl_startscan.o src/libwpactrl/wpactrl_startscan.lo: src/libwpactrl/wpactrl_startscan.c src/include/bcnm/wpactrl.h src/libwpactrl/wpactrl-internal.h
 src/libwpactrl/wpactrl_update.o src/libwpactrl/wpactrl_update.lo: src/libwpactrl/wpactrl_update.c src/include/bcnm/wpactrl.h src/libwpactrl/wpactrl-internal.h
 src/libwpactrl/wpactrl_xchg_cbres_free.o src/libwpactrl/wpactrl_xchg_cbres_free.lo: src/libwpactrl/wpactrl_xchg_cbres_free.c src/include/bcnm/wpactrl.h
diff --git a/src/libwpactrl/wpactrl_fd_recv.c b/src/libwpactrl/wpactrl_fd_recv.c
index c6d0619..9640b6c 100644
--- a/src/libwpactrl/wpactrl_fd_recv.c
+++ b/src/libwpactrl/wpactrl_fd_recv.c
@@ -37,5 +37,5 @@ ssize_t wpactrl_fd_recv (int fd, char *s, size_t len)
   ssize_t r ;
   do r = recvmsg(fd, &msghdr, bsd_braindeadness_workaround_flags) ;
   while (r == -1 && errno == EINTR) ;
-  return r > 0 && msghdr.msg_flags | MSG_TRUNC ? (errno = EMSGSIZE, -1) : r ;
+  return r > 0 && msghdr.msg_flags & MSG_TRUNC ? (errno = EMSGSIZE, -1) : r ;
 }
diff --git a/src/libwpactrl/wpactrl_start.c b/src/libwpactrl/wpactrl_start.c
index ac77870..a3e5331 100644
--- a/src/libwpactrl/wpactrl_start.c
+++ b/src/libwpactrl/wpactrl_start.c
@@ -2,9 +2,15 @@
 
 #include <string.h>
 #include <errno.h>
+
+#include <skalibs/posixplz.h>
+#include <skalibs/stralloc.h>
 #include <skalibs/djbunix.h>
 #include <skalibs/webipc.h>
+#include <skalibs/skamisc.h>
 #include <skalibs/unix-timed.h>
+
+#include <bcnm/config.h>
 #include <bcnm/wpactrl.h>
 #include "wpactrl-internal.h"
 
@@ -12,22 +18,34 @@ int wpactrl_start (wpactrl_t *a, char const *path, unsigned int timeout, tain_t
 {
   tain_t tto, deadline ;
   int fda, fds ;
+  size_t pos ;
+  stralloc sa = STRALLOC_ZERO ;
   if (timeout) tain_from_millisecs(&tto, timeout) ;
   else tto = tain_infinite_relative ;
+  if (!stralloc_cats(&sa, BCNM_TMPDIR)) return 0 ;
+  if (!stralloc_cats(&sa, "/clientfds")) goto err ;
+  pos = sa.len - 1 ;
+  if (!sauniquename(&sa) || !stralloc_0(&sa)) goto err ;
   fds = ipc_datagram_nbcoe() ;
   if (fds < 0) goto err ;
+  unlink_void(sa.s) ;
   tain_add(&deadline, &tto, stamp) ;
-  if (!ipc_timed_connect(fds, path, &deadline, stamp)) goto errs ;
+  if (ipc_bind(fds, sa.s) == -1
+   || !ipc_timed_connect(fds, path, &deadline, stamp)) goto errs ;
   fda = ipc_datagram_nbcoe() ;
   if (fda < 0) goto errs ;
-  if (!ipc_timed_connect(fda, path, &deadline, stamp)) goto erra ;
-  if (!ipc_timed_send(fda, "ATTACH", 6, &deadline, stamp)) goto erra ;
+  sa.s[pos] = 'a' ;
+  unlink_void(sa.s) ;
+  if (ipc_bind(fda, sa.s) == -1
+   || !ipc_timed_connect(fda, path, &deadline, stamp)
+   || !ipc_timed_send(fda, "ATTACH", 6, &deadline, stamp)) goto erra ;
   {
     ssize_t r ;
     char answer[3] ;
     r = wpactrl_fd_timed_recv(fda, answer, 3, &deadline, stamp) ;
     if (r != 3 || memcmp(answer, "OK\n", 3)) goto erra ;
   }
+  stralloc_free(&sa) ;
   a->fds = fds ;
   a->fda = fda ;
   a->tto = tto ;
@@ -38,5 +56,6 @@ int wpactrl_start (wpactrl_t *a, char const *path, unsigned int timeout, tain_t
  errs:
   fd_close(fds) ;
  err:
+  stralloc_free(&sa) ;
   return 0 ;
 }
diff --git a/src/libwpactrl/wpactrl_update.c b/src/libwpactrl/wpactrl_update.c
index a116d50..5dfefea 100644
--- a/src/libwpactrl/wpactrl_update.c
+++ b/src/libwpactrl/wpactrl_update.c
@@ -18,7 +18,7 @@ static inline int validate (char const *s, size_t len)
   if (!memchr("123456789", s[1], 9)) return 0 ;
   if (s[2] != '>') return 0 ;
   if (strnlen(s, len) < len) return 0 ;
-  return s[len-1] == '\n' ;
+  return 1 ;
 }
 
 int wpactrl_update (wpactrl_t *a)
diff --git a/src/libwpactrl/wpactrl_xchg_event.c b/src/libwpactrl/wpactrl_xchg_event.c
index e9d2f06..d639d24 100644
--- a/src/libwpactrl/wpactrl_xchg_event.c
+++ b/src/libwpactrl/wpactrl_xchg_event.c
@@ -27,7 +27,7 @@ int wpactrl_xchg_event (wpactrl_t *a, wpactrl_xchg_t *dt, tain_t *stamp)
   if (pos >= a->data.len) return 0 ;
   len = strlen(a->data.s + pos) + 1 ;
   if (!(*dt->tab[dt->i].cb)(a, a->data.s + pos, len - 1, dt->aux, stamp)) return -2 ;
-  memmove(a->data.s + pos, a->data.s + pos + len, a->data.len - len) ;
+  memmove(a->data.s + pos, a->data.s + pos + len, a->data.len - pos - len) ;
   a->data.len -= len ;
   wpactrl_filter_remove(a, dt->tab[dt->i].filter) ;
   if (++dt->i == dt->n)