about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
4 files changed, 25 insertions, 6 deletions
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)