From 90b12bd71bb9fc79a4640b9112c13ef529d0196a Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Fri, 5 Dec 2014 22:26:11 +0000 Subject: Initial commit --- src/libs6/s6lock_acquire.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/libs6/s6lock_acquire.c (limited to 'src/libs6/s6lock_acquire.c') diff --git a/src/libs6/s6lock_acquire.c b/src/libs6/s6lock_acquire.c new file mode 100644 index 0000000..b0fef54 --- /dev/null +++ b/src/libs6/s6lock_acquire.c @@ -0,0 +1,38 @@ +/* ISC license. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int s6lock_acquire (s6lock_t *a, uint16 *u, char const *path, uint32 options, tain_t const *limit, tain_t const *deadline, tain_t *stamp) +{ + unsigned int pathlen = str_len(path) ; + char err ; + char tmp[23] = "--<" ; + siovec_t v[2] = { { .s = tmp, .len = 23 }, { .s = (char *)path, .len = pathlen + 1 } } ; + unsigned int i ; + if (!gensetdyn_new(&a->data, &i)) return 0 ; + uint16_pack_big(tmp, (uint16)i) ; + uint32_pack_big(tmp+3, options) ; + tain_pack(tmp+7, limit) ; + uint32_pack_big(tmp+19, (uint32)pathlen) ; + if (!skaclient_sendv(&a->connection, v, 2, &skaclient_default_cb, &err, deadline, stamp)) + { + gensetdyn_delete(&a->data, i) ; + return 0 ; + } + if (err) + { + gensetdyn_delete(&a->data, i) ; + return (errno = err, 0) ; + } + *GENSETDYN_P(char, &a->data, i) = EAGAIN ; + *u = i ; + return 1 ; +} -- cgit v1.2.3