summary refs log tree commit diff
path: root/src/libnsss/nsss_switch_start.c
blob: ba014ae803db37701176a58693e9bb0314483a08 (plain) (blame)
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
/* ISC license. */

#include <skalibs/buffer.h>
#include <skalibs/djbunix.h>
#include <skalibs/socket.h>

#include <nsss/nsss-switch.h>

static inline int nsss_switch_connect (nsss_switch_t *a, char const *path, tain const *deadline, tain *stamp)
{
  int fd = ipc_stream_nbcoe() ;
  if (fd < 0) return 0 ;
  if (!ipc_timed_connect(fd, path, deadline, stamp))
  {
    fd_close(fd) ;
    return 0 ;
  }
  buffer_init(&a->b, &buffer_read, fd, a->buf, NSSS_SWITCH_BUFSIZE) ;
  return 1 ;
}

int nsss_switch_start (nsss_switch_t *a, unsigned int what, char const *path, tain const *deadline, tain *stamp)
{
  if (!a->held && !nsss_switch_connect(a, path, deadline, stamp)) return 0 ;
  a->held |= what & 0x7u ;
  a->path = path ;
  return 1 ;
}