summaryrefslogtreecommitdiff
path: root/src/libwpactrl/wpactrl_start.c
blob: 86a266b7f9d1dfa19a38527440a02d7cdd37f147 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* ISC license. */

#include <string.h>
#include <errno.h>
#include <skalibs/djbunix.h>
#include <skalibs/webipc.h>
#include <skalibs/unix-timed.h>
#include <bcnm/wpactrl.h>
#include "wpactrl-internal.h"

int wpactrl_start (wpactrl_t *a, char const *path, tain_t const *deadline, tain_t *stamp)
{
  int fda, fds ;
  fds = ipc_datagram_nbcoe() ;
  if (fds < 0) goto err ;
  if (!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 ;
  {
    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 ;
  }
  a->fds = fds ;
  a->fda = fda ;
  return 1 ;

 erra:
  {
    int e = errno ;
    fd_close(fda) ;
    errno = e ;
  }
 errs:
  {
    int e = errno ;
    fd_close(fds) ;
    errno = e ;
  }
 err:
  return 0 ;
}