about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2019-11-17 14:27:09 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2019-11-17 14:27:09 +0000
commitec17a98d42d8f90d8cbefb01943562a63f2e74d5 (patch)
tree511cbe97adce96983935c4cea14a067cc66ddce5
parent29c3282e7c73474642dc48d60ef90d79385c2a1b (diff)
downloadbcnm-ec17a98d42d8f90d8cbefb01943562a63f2e74d5.tar.gz
bcnm-ec17a98d42d8f90d8cbefb01943562a63f2e74d5.tar.xz
bcnm-ec17a98d42d8f90d8cbefb01943562a63f2e74d5.zip
Actually clean up the filesystem when ending a session
 This requires storing the client path in the wpactrl_t,
which uses memory, GOD I HATE THAT STUPID IPC MECHANISM
-rw-r--r--doc/libwpactrl/index.html5
-rw-r--r--src/include/bcnm/wpactrl.h3
-rw-r--r--src/libwpactrl/wpactrl_end.c7
-rw-r--r--src/libwpactrl/wpactrl_start.c13
4 files changed, 20 insertions, 8 deletions
diff --git a/doc/libwpactrl/index.html b/doc/libwpactrl/index.html
index 6f114c3..204f9f8 100644
--- a/doc/libwpactrl/index.html
+++ b/doc/libwpactrl/index.html
@@ -132,7 +132,10 @@ will immediately be aborted.
 
 <p>
 <code> int wpactrl_end (wpactrl_t *a) </code> <br />
-Ends the session, freeing all used resources.
+Ends the session, freeing all used resources. It is important
+to use this function even if your process exits right away,
+because <tt>wpactrl_end()</tt> will also delete entries in
+the filesystem.
 </p>
 
 <h3> Low-level command sending </h3>
diff --git a/src/include/bcnm/wpactrl.h b/src/include/bcnm/wpactrl.h
index 102c063..a81385e 100644
--- a/src/include/bcnm/wpactrl.h
+++ b/src/include/bcnm/wpactrl.h
@@ -47,8 +47,9 @@ struct wpactrl_s
   size_t datahead ;
   stralloc data ;
   stralloc filters ;
+  stralloc clientpath ;
 } ;
-#define WPACTRL_ZERO { -1, -1, 0, TAIN_ZERO, 0, STRALLOC_ZERO, STRALLOC_ZERO }
+#define WPACTRL_ZERO { -1, -1, 0, TAIN_ZERO, 0, STRALLOC_ZERO, STRALLOC_ZERO, STRALLOC_ZERO }
 
 #define WPACTRL_OPTION_NOFILTER 0x0001U
 
diff --git a/src/libwpactrl/wpactrl_end.c b/src/libwpactrl/wpactrl_end.c
index a14b6c8..41ea81a 100644
--- a/src/libwpactrl/wpactrl_end.c
+++ b/src/libwpactrl/wpactrl_end.c
@@ -1,14 +1,21 @@
 /* ISC license. */
 
+#include <skalibs/posixplz.h>
 #include <skalibs/stralloc.h>
 #include <skalibs/djbunix.h>
+
 #include <bcnm/wpactrl.h>
 
 void wpactrl_end (wpactrl_t *a)
 {
+  a->clientpath.s[a->clientpath.len - 2] = 's' ;
+  unlink_void(a->clientpath.s) ;
+  a->clientpath.s[a->clientpath.len - 2] = 'a' ;
+  unlink_void(a->clientpath.s) ;
   fd_close(a->fda) ;
   fd_close(a->fds) ;
   stralloc_free(&a->filters) ;
   stralloc_free(&a->data) ;
+  stralloc_free(&a->clientpath) ;
   *a = wpactrl_zero ;
 }
diff --git a/src/libwpactrl/wpactrl_start.c b/src/libwpactrl/wpactrl_start.c
index a3e5331..df2b480 100644
--- a/src/libwpactrl/wpactrl_start.c
+++ b/src/libwpactrl/wpactrl_start.c
@@ -18,14 +18,13 @@ 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 ;
+  if (!stralloc_cats(&sa, "/libwpactrl")
+   || !sauniquename(&sa)
+   || !stralloc_catb(&sa, ":s", 3)) goto err ;
   fds = ipc_datagram_nbcoe() ;
   if (fds < 0) goto err ;
   unlink_void(sa.s) ;
@@ -34,7 +33,7 @@ int wpactrl_start (wpactrl_t *a, char const *path, unsigned int timeout, tain_t
    || !ipc_timed_connect(fds, path, &deadline, stamp)) goto errs ;
   fda = ipc_datagram_nbcoe() ;
   if (fda < 0) goto errs ;
-  sa.s[pos] = 'a' ;
+  sa.s[sa.len - 2] = 'a' ;
   unlink_void(sa.s) ;
   if (ipc_bind(fda, sa.s) == -1
    || !ipc_timed_connect(fda, path, &deadline, stamp)
@@ -45,7 +44,9 @@ int wpactrl_start (wpactrl_t *a, char const *path, unsigned int timeout, tain_t
     r = wpactrl_fd_timed_recv(fda, answer, 3, &deadline, stamp) ;
     if (r != 3 || memcmp(answer, "OK\n", 3)) goto erra ;
   }
-  stralloc_free(&sa) ;
+  if (!stralloc_shrink(&sa)) goto erra ;
+
+  a->clientpath = sa ;
   a->fds = fds ;
   a->fda = fda ;
   a->tto = tto ;