summaryrefslogtreecommitdiff
path: root/src/libs6/s6_fdholder_retrieve_cb.c
blob: 753f12b4981d3a6713316404848a2634555bfd50 (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
/* ISC license. */

#include <errno.h>

#include <skalibs/posixishard.h>
#include <skalibs/unixmessage.h>

#include <s6/s6-fdholder.h>

int s6_fdholder_retrieve_cb (unixmessage_t const *m, void *p)
{
  s6_fdholder_retrieve_result_t *res = p ;
  if (m->len != 1) goto err ;
  if (m->s[0])
  {
    if (m->nfds) goto err ;
    res->err = m->s[0] ;
    return 1 ;
  }
  if (m->nfds != 1) goto err ;
  res->fd = m->fds[0] ;
  res->err = 0 ;
  return 1 ;

 err:
  unixmessage_drop(m) ;
  return (errno = EPROTO, 0) ;
}