diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2019-11-17 14:08:44 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2019-11-17 14:08:44 +0000 |
commit | 29c3282e7c73474642dc48d60ef90d79385c2a1b (patch) | |
tree | 06eb15ec1674fe35f78d2ddff7ca90b314308a01 /src/libwpactrl/wpactrl_start.c | |
parent | cc74d3000e81af2533c386b7f55912f2e60e5a99 (diff) | |
download | bcnm-29c3282e7c73474642dc48d60ef90d79385c2a1b.tar.xz |
Apply smaeul's fixes; add --with-tmpdir configure option
Diffstat (limited to 'src/libwpactrl/wpactrl_start.c')
-rw-r--r-- | src/libwpactrl/wpactrl_start.c | 25 |
1 files changed, 22 insertions, 3 deletions
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 ; } |