about summary refs log tree commit diff
path: root/src/libs6/s6_fdholder_store.c
blob: 40d660a981c52e9ad3b8adfcb03ccaa8a470f0a0 (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
/* ISC license. */

#include <errno.h>

#include <skalibs/allreadwrite.h>
#include <skalibs/tai.h>
#include <skalibs/unixmessage.h>

#include <s6/fdholder.h>

#include <skalibs/posixishard.h>

int s6_fdholder_store (s6_fdholder_t *a, int fd, char const *id, tain const *limit, tain const *deadline, tain *stamp)
{
  unixmessage m ;
  if (!s6_fdholder_store_async(a, fd, id, limit)) return 0 ;
  if (!unixmessage_sender_timed_flush(&a->connection.out, deadline, stamp)) return 0 ;
  if (sanitize_read(unixmessage_timed_receive(&a->connection.in, &m, deadline, stamp)) < 0) return 0 ;
  if (m.len != 1 || m.nfds)
  {
    unixmessage_drop(&m) ;
    return (errno = EPROTO, 0) ;
  }
  return m.s[0] ? (errno = (unsigned char)m.s[0], 0) : 1 ;
}