blob: 128f9ccd57ee582a1aa81a10923f289c64381792 (
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
|
/* ISC license. */
#include <stdint.h>
#include <errno.h>
#include <skalibs/error.h>
#include <skalibs/types.h>
#include <skalibs/genalloc.h>
#include <skalibs/gensetdyn.h>
#include <skalibs/unixmessage.h>
#include <skalibs/skaclient.h>
#include <s6/s6lock.h>
static int msghandler (unixmessage_t const *m, void *context)
{
s6lock_t *a = (s6lock_t *)context ;
char *p ;
uint16_t id ;
if (m->len != 3 || m->nfds) return (errno = EPROTO, 0) ;
uint16_unpack_big(m->s, &id) ;
p = GENSETDYN_P(char, &a->data, id) ;
if (*p == EBUSY) *p = m->s[2] ;
else if (error_isagain(*p)) *p = m->s[2] ? m->s[2] : EBUSY ;
else return (errno = EPROTO, 0) ;
if (!genalloc_append(uint16_t, &a->list, &id)) return 0 ;
return 1 ;
}
int s6lock_update (s6lock_t *a)
{
genalloc_setlen(uint16_t, &a->list, 0) ;
return skaclient_update(&a->connection, &msghandler, a) ;
}
|