summaryrefslogtreecommitdiff
path: root/src/libs6/s6lock_update.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2014-12-05 22:26:11 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2014-12-05 22:26:11 +0000
commit90b12bd71bb9fc79a4640b9112c13ef529d0196a (patch)
tree523b3f4ee2969e7a729bab2ba749c4b924ae62af /src/libs6/s6lock_update.c
downloads6-90b12bd71bb9fc79a4640b9112c13ef529d0196a.tar.xz
Initial commit
Diffstat (limited to 'src/libs6/s6lock_update.c')
-rw-r--r--src/libs6/s6lock_update.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/libs6/s6lock_update.c b/src/libs6/s6lock_update.c
new file mode 100644
index 0000000..6e6a2a0
--- /dev/null
+++ b/src/libs6/s6lock_update.c
@@ -0,0 +1,31 @@
+/* ISC license. */
+
+#include <errno.h>
+#include <skalibs/error.h>
+#include <skalibs/uint16.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 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, &a->list, &id)) return 0 ;
+ return 1 ;
+}
+
+int s6lock_update (s6lock_t *a)
+{
+ genalloc_setlen(uint16, &a->list, 0) ;
+ return skaclient_update(&a->connection, &msghandler, a) ;
+}