From d7242bda59ec2ec056508b39cb532b5e7318dd13 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Fri, 22 Dec 2017 17:37:09 +0000 Subject: Port ftrigr and s6lock to textclient --- src/include/s6/ftrigr.h | 11 ++++----- src/include/s6/s6lock.h | 9 +++---- src/libs6/ftrigr_end.c | 4 +-- src/libs6/ftrigr_start.c | 5 ++-- src/libs6/ftrigr_startf.c | 5 ++-- src/libs6/ftrigr_subscribe.c | 18 +++----------- src/libs6/ftrigr_unsubscribe.c | 12 +++------ src/libs6/ftrigr_updateb.c | 19 +++++++------- src/libs6/s6-ftrigrd.c | 52 +++++++++++++++++++-------------------- src/libs6/s6lock_acquire.c | 12 +++------ src/libs6/s6lock_end.c | 4 +-- src/libs6/s6lock_release.c | 12 +++------ src/libs6/s6lock_start.c | 5 ++-- src/libs6/s6lock_startf.c | 7 +++--- src/libs6/s6lock_update.c | 17 +++++++------ src/libs6/s6lockd.c | 56 +++++++++++++++++++++--------------------- 16 files changed, 111 insertions(+), 137 deletions(-) (limited to 'src') diff --git a/src/include/s6/ftrigr.h b/src/include/s6/ftrigr.h index 425a689..3efb206 100644 --- a/src/include/s6/ftrigr.h +++ b/src/include/s6/ftrigr.h @@ -10,13 +10,13 @@ #include #include #include -#include +#include #include /* Constants */ -#define FTRIGR_IPCPATH SKALIBS_SPROOT "/service/ftrigrd/s" +#define FTRIGR_IPCPATH SKALIBS_SPROOT "/run/service/ftrigrd/s" #define FTRIGRD_PROG S6_BINPREFIX "s6-ftrigrd" #define FTRIGR_BANNER1 "ftrigr v1.0 (b)\n" @@ -54,13 +54,12 @@ extern ftrigr1_t const ftrigr1_zero ; typedef struct ftrigr_s ftrigr, ftrigr_t, *ftrigr_ref, *ftrigr_t_ref ; struct ftrigr_s { - skaclient_t connection ; + textclient_t connection ; genalloc list ; /* array of uint16_t */ size_t head ; gensetdyn data ; /* set of ftrigr1_t */ - skaclient_buffer_t buffers ; } ; -#define FTRIGR_ZERO { .connection = SKACLIENT_ZERO, .list = GENALLOC_ZERO, .head = 0, .data = GENSETDYN_INIT(ftrigr1_t, 2, 0, 1) } +#define FTRIGR_ZERO { .connection = TEXTCLIENT_ZERO, .list = GENALLOC_ZERO, .head = 0, .data = GENSETDYN_INIT(ftrigr1_t, 2, 0, 1) } extern ftrigr_t const ftrigr_zero ; @@ -75,7 +74,7 @@ extern void ftrigr_end (ftrigr_t *) ; /* Instant primitives for async programming */ -#define ftrigr_fd(a) skaclient_fd(&(a)->connection) +#define ftrigr_fd(a) textclient_fd(&(a)->connection) extern int ftrigr_updateb (ftrigr_t *) ; extern int ftrigr_update (ftrigr_t *) ; extern int ftrigr_check (ftrigr_t *, uint16_t, char *) ; diff --git a/src/include/s6/s6lock.h b/src/include/s6/s6lock.h index 8ac0127..b1f69c4 100644 --- a/src/include/s6/s6lock.h +++ b/src/include/s6/s6lock.h @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include @@ -27,12 +27,11 @@ typedef struct s6lock_s s6lock_t, *s6lock_t_ref ; struct s6lock_s { - skaclient_t connection ; + textclient_t connection ; genalloc list ; /* array of uint16_t */ gensetdyn data ; /* set of char */ - skaclient_buffer_t buffers ; } ; -#define S6LOCK_ZERO { .connection = SKACLIENT_ZERO, .list = GENALLOC_ZERO, .data = GENSETDYN_INIT(int, 2, 0, 1) } +#define S6LOCK_ZERO { .connection = TEXTCLIENT_ZERO, .list = GENALLOC_ZERO, .data = GENSETDYN_INIT(int, 2, 0, 1) } extern s6lock_t const s6lock_zero ; @@ -47,7 +46,7 @@ extern void s6lock_end (s6lock_t *) ; /* Asynchronous primitives */ -#define s6lock_fd(a) skaclient_fd(&(a)->connection) +#define s6lock_fd(a) textclient_fd(&(a)->connection) extern int s6lock_update (s6lock_t *) ; extern int s6lock_check (s6lock_t *, uint16_t) ; diff --git a/src/libs6/ftrigr_end.c b/src/libs6/ftrigr_end.c index 9783601..555053f 100644 --- a/src/libs6/ftrigr_end.c +++ b/src/libs6/ftrigr_end.c @@ -3,13 +3,13 @@ #include #include #include -#include +#include #include void ftrigr_end (ftrigr_ref a) { gensetdyn_free(&a->data) ; genalloc_free(uint16_t, &a->list) ; - skaclient_end(&a->connection) ; + textclient_end(&a->connection) ; *a = ftrigr_zero ; } diff --git a/src/libs6/ftrigr_start.c b/src/libs6/ftrigr_start.c index 4cf9e72..5b6e8af 100644 --- a/src/libs6/ftrigr_start.c +++ b/src/libs6/ftrigr_start.c @@ -1,10 +1,9 @@ /* ISC license. */ -#include -#include +#include #include int ftrigr_start (ftrigr_t *a, char const *path, tain_t const *deadline, tain_t *stamp) { - return skaclient_start_b(&a->connection, &a->buffers, path, 0, FTRIGR_BANNER1, FTRIGR_BANNER1_LEN, FTRIGR_BANNER2, FTRIGR_BANNER2_LEN, deadline, stamp) ; + return textclient_start(&a->connection, path, 0, FTRIGR_BANNER1, FTRIGR_BANNER1_LEN, FTRIGR_BANNER2, FTRIGR_BANNER2_LEN, deadline, stamp) ; } diff --git a/src/libs6/ftrigr_startf.c b/src/libs6/ftrigr_startf.c index 47c310d..ff02792 100644 --- a/src/libs6/ftrigr_startf.c +++ b/src/libs6/ftrigr_startf.c @@ -1,12 +1,11 @@ /* ISC license. */ -#include -#include +#include #include int ftrigr_startf (ftrigr_t *a, tain_t const *deadline, tain_t *stamp) { static char const *const cargv[2] = { FTRIGRD_PROG, 0 } ; static char const *const cenvp[1] = { 0 } ; - return skaclient_startf_b(&a->connection, &a->buffers, cargv[0], cargv, cenvp, SKACLIENT_OPTION_WAITPID, FTRIGR_BANNER1, FTRIGR_BANNER1_LEN, FTRIGR_BANNER2, FTRIGR_BANNER2_LEN, deadline, stamp) ; + return textclient_startf(&a->connection, cargv, cenvp, TEXTCLIENT_OPTION_WAITPID, FTRIGR_BANNER1, FTRIGR_BANNER1_LEN, FTRIGR_BANNER2, FTRIGR_BANNER2_LEN, deadline, stamp) ; } diff --git a/src/libs6/ftrigr_subscribe.c b/src/libs6/ftrigr_subscribe.c index cbbde1e..72b87dc 100644 --- a/src/libs6/ftrigr_subscribe.c +++ b/src/libs6/ftrigr_subscribe.c @@ -9,15 +9,15 @@ #include #include #include -#include +#include #include uint16_t ftrigr_subscribe (ftrigr_t *a, char const *path, char const *re, uint32_t options, tain_t const *deadline, tain_t *stamp) { size_t pathlen = strlen(path) ; size_t relen = strlen(re) ; + ftrigr1_t ft = { .options = options, .state = FR1STATE_LISTENING, .what = STRALLOC_ZERO } ; uint32_t i ; - char err ; char tmp[15] = "--L" ; struct iovec v[3] = { { .iov_base = tmp, .iov_len = 15 }, { .iov_base = (char *)path, .iov_len = pathlen + 1 }, { .iov_base = (char *)re, .iov_len = relen + 1 } } ; if (!gensetdyn_new(&a->data, &i)) return 0 ; @@ -30,23 +30,13 @@ uint16_t ftrigr_subscribe (ftrigr_t *a, char const *path, char const *re, uint32 uint32_pack_big(tmp+3, options) ; uint32_pack_big(tmp+7, (uint32_t)pathlen) ; uint32_pack_big(tmp+11, (uint32_t)relen) ; - if (!skaclient_sendv(&a->connection, v, 3, &skaclient_default_cb, &err, deadline, stamp)) + if (!textclient_commandv(&a->connection, v, 3, deadline, stamp)) { int e = errno ; gensetdyn_delete(&a->data, i) ; errno = e ; return 0 ; } - if (err) - { - gensetdyn_delete(&a->data, i) ; - return (errno = err, 0) ; - } - { - ftrigr1_t *p = GENSETDYN_P(ftrigr1_t, &a->data, i) ; - p->options = options ; - p->state = FR1STATE_LISTENING ; - p->what = stralloc_zero ; - } + *GENSETDYN_P(ftrigr1_t, &a->data, i) = ft ; return (uint16_t)(i+1) ; } diff --git a/src/libs6/ftrigr_unsubscribe.c b/src/libs6/ftrigr_unsubscribe.c index a96ddb0..557f5ea 100644 --- a/src/libs6/ftrigr_unsubscribe.c +++ b/src/libs6/ftrigr_unsubscribe.c @@ -4,12 +4,13 @@ #include #include #include -#include +#include #include int ftrigr_unsubscribe (ftrigr_t *a, uint16_t i, tain_t const *deadline, tain_t *stamp) { ftrigr1_t *p ; + char pack[3] = "--U" ; if (!i--) return (errno = EINVAL, 0) ; p = GENSETDYN_P(ftrigr1_t, &a->data, i) ; if (!p) return (errno = EINVAL, 0) ; @@ -24,13 +25,8 @@ int ftrigr_unsubscribe (ftrigr_t *a, uint16_t i, tain_t const *deadline, tain_t } default : break ; } - { - char err ; - char pack[3] = "--U" ; - uint16_pack_big(pack, i) ; - if (!skaclient_send(&a->connection, pack, 3, &skaclient_default_cb, &err, deadline, stamp)) return 0 ; - if (err) return (errno = err, 0) ; - } + uint16_pack_big(pack, i) ; + if (!textclient_command(&a->connection, pack, 3, deadline, stamp)) return 0 ; stralloc_free(&p->what) ; *p = ftrigr1_zero ; return gensetdyn_delete(&a->data, i) ; diff --git a/src/libs6/ftrigr_updateb.c b/src/libs6/ftrigr_updateb.c index edf6f2c..5f0bd77 100644 --- a/src/libs6/ftrigr_updateb.c +++ b/src/libs6/ftrigr_updateb.c @@ -1,6 +1,7 @@ /* ISC license. */ #include +#include #include #include #include @@ -8,8 +9,7 @@ #include #include #include -#include -#include +#include #include static inline int appears (uint16_t, uint16_t const *, size_t) gccattr_pure ; @@ -20,26 +20,27 @@ static inline int appears (uint16_t id, uint16_t const *list, size_t len) return 0 ; } -static int msghandler (unixmessage_t const *m, void *context) +static int msghandler (struct iovec const *v, void *context) { ftrigr_t *a = (ftrigr_t *)context ; ftrigr1_t *p ; int addit = 1 ; + char const *s = v->iov_base ; uint16_t id ; - if (m->len != 4 || m->nfds) return (errno = EPROTO, 0) ; - uint16_unpack_big(m->s, &id) ; + if (v->iov_len != 4) return (errno = EPROTO, 0) ; + uint16_unpack_big(s, &id) ; p = GENSETDYN_P(ftrigr1_t, &a->data, id) ; if (!p) return 1 ; if (p->state != FR1STATE_LISTENING) return (errno = EINVAL, 0) ; if (!genalloc_readyplus(uint16_t, &a->list, 1)) return 0 ; - switch (m->s[2]) + switch (s[2]) { case 'd' : - if (!stralloc_catb(&p->what, m->s + 3, 1)) return 0 ; + if (!stralloc_catb(&p->what, s + 3, 1)) return 0 ; p->state = FR1STATE_WAITACK ; break ; case '!' : - if (!stralloc_catb(&p->what, m->s + 3, 1)) return 0 ; + if (!stralloc_catb(&p->what, s + 3, 1)) return 0 ; if (p->options & FTRIGR_REPEAT) { if (p->what.len > 1 @@ -60,6 +61,6 @@ static int msghandler (unixmessage_t const *m, void *context) int ftrigr_updateb (ftrigr_t *a) { size_t curlen = genalloc_len(uint16_t, &a->list) ; - int r = skaclient_update(&a->connection, &msghandler, a) ; + int r = textclient_update(&a->connection, &msghandler, a) ; return r < 0 ? r : (int)(genalloc_len(uint16_t, &a->list) - curlen) ; } diff --git a/src/libs6/s6-ftrigrd.c b/src/libs6/s6-ftrigrd.c index 7ec2230..dd04548 100644 --- a/src/libs6/s6-ftrigrd.c +++ b/src/libs6/s6-ftrigrd.c @@ -1,5 +1,6 @@ /* ISC license. */ +#include #include #include #include @@ -15,8 +16,8 @@ #include #include #include -#include -#include +#include +#include #include "ftrig1.h" #include @@ -59,10 +60,9 @@ static void cleanup (void) static void trig (uint16_t id, char what, char info) { char pack[4] ; - unixmessage_t m = { .s = pack, .len = 4, .fds = 0, .nfds = 0 } ; uint16_pack_big(pack, id) ; pack[2] = what ; pack[3] = info ; - if (!unixmessage_put(unixmessage_sender_x, &m)) + if (!textmessage_put(textmessage_sender_x, pack, 4)) { cleanup() ; strerr_diefu1sys(111, "build answer") ; @@ -71,11 +71,10 @@ static void trig (uint16_t id, char what, char info) static void answer (char c) { - unixmessage_t m = { .s = &c, .len = 1, .fds = 0, .nfds = 0 } ; - if (!unixmessage_put(unixmessage_sender_1, &m)) + if (!textmessage_put(textmessage_sender_1, &c, 1)) { cleanup() ; - strerr_diefu1sys(111, "unixmessage_put") ; + strerr_diefu1sys(111, "textmessage_put") ; } } @@ -112,16 +111,17 @@ static inline int ftrigio_read (ftrigio_t *p) return 1 ; } -static int parse_protocol (unixmessage_t const *m, void *context) +static int parse_protocol (struct iovec const *v, void *context) { + char const *s = v->iov_base ; uint16_t id ; - if (m->len < 3 || m->nfds) + if (v->iov_len < 3) { cleanup() ; strerr_dief1x(100, "invalid client request") ; } - uint16_unpack_big(m->s, &id) ; - switch (m->s[2]) + uint16_unpack_big(s, &id) ; + switch (s[2]) { case 'U' : /* unsubscribe */ { @@ -139,15 +139,15 @@ static int parse_protocol (unixmessage_t const *m, void *context) { uint32_t options, pathlen, relen ; int r ; - if (m->len < 19) + if (v->iov_len < 19) { answer(EPROTO) ; break ; } - uint32_unpack_big(m->s + 3, &options) ; - uint32_unpack_big(m->s + 7, &pathlen) ; - uint32_unpack_big(m->s + 11, &relen) ; - if (((pathlen + relen + 17) != m->len) || m->s[15 + pathlen] || m->s[m->len - 1]) + uint32_unpack_big(s + 3, &options) ; + uint32_unpack_big(s + 7, &pathlen) ; + uint32_unpack_big(s + 11, &relen) ; + if (((pathlen + relen + 17) != v->iov_len) || s[15 + pathlen] || s[v->iov_len - 1]) { answer(EPROTO) ; break ; @@ -157,13 +157,13 @@ static int parse_protocol (unixmessage_t const *m, void *context) answer(ENFILE) ; break ; } - r = regcomp(&a[n].re, m->s + 16 + pathlen, REG_EXTENDED) ; + r = regcomp(&a[n].re, s + 16 + pathlen, REG_EXTENDED) ; if (r) { answer(r == REG_ESPACE ? ENOMEM : EINVAL) ; break ; } - if (!ftrig1_make(&a[n].trig, m->s + 15)) + if (!ftrig1_make(&a[n].trig, s + 15)) { regfree(&a[n].re) ; answer(errno) ; @@ -200,7 +200,7 @@ int main (void) tain_t deadline ; tain_now_g() ; tain_addsec_g(&deadline, 2) ; - if (!skaclient_server_01x_init_g(FTRIGR_BANNER1, FTRIGR_BANNER1_LEN, FTRIGR_BANNER2, FTRIGR_BANNER2_LEN, &deadline)) + if (!textclient_server_01x_init_g(FTRIGR_BANNER1, FTRIGR_BANNER1_LEN, FTRIGR_BANNER2, FTRIGR_BANNER2_LEN, &deadline)) strerr_diefu1sys(111, "sync with client") ; } @@ -210,9 +210,9 @@ int main (void) unsigned int i = 0 ; x[0].fd = 0 ; x[0].events = IOPAUSE_EXCEPT | IOPAUSE_READ ; - x[1].fd = 1 ; x[1].events = IOPAUSE_EXCEPT | (unixmessage_sender_isempty(unixmessage_sender_1) ? 0 : IOPAUSE_WRITE) ; - x[2].fd = unixmessage_sender_fd(unixmessage_sender_x) ; - x[2].events = IOPAUSE_EXCEPT | (unixmessage_sender_isempty(unixmessage_sender_x) ? 0 : IOPAUSE_WRITE) ; + x[1].fd = 1 ; x[1].events = IOPAUSE_EXCEPT | (textmessage_sender_isempty(textmessage_sender_1) ? 0 : IOPAUSE_WRITE) ; + x[2].fd = textmessage_sender_fd(textmessage_sender_x) ; + x[2].events = IOPAUSE_EXCEPT | (textmessage_sender_isempty(textmessage_sender_x) ? 0 : IOPAUSE_WRITE) ; for (; i < n ; i++) { a[i].xindex = 3 + i ; @@ -231,13 +231,13 @@ int main (void) /* client is reading */ if (x[1].revents & IOPAUSE_WRITE) - if (!unixmessage_sender_flush(unixmessage_sender_1) && !error_isagain(errno)) + if (!textmessage_sender_flush(textmessage_sender_1) && !error_isagain(errno)) { cleanup() ; strerr_diefu1sys(111, "flush stdout") ; } if (x[2].revents & IOPAUSE_WRITE) - if (!unixmessage_sender_flush(unixmessage_sender_x) && !error_isagain(errno)) + if (!textmessage_sender_flush(textmessage_sender_x) && !error_isagain(errno)) { cleanup() ; return 1 ; @@ -251,9 +251,9 @@ int main (void) } /* client is writing */ - if (!unixmessage_receiver_isempty(unixmessage_receiver_0) || x[0].revents & IOPAUSE_READ) + if (!textmessage_receiver_isempty(textmessage_receiver_0) || x[0].revents & IOPAUSE_READ) { - if (unixmessage_handle(unixmessage_receiver_0, &parse_protocol, 0) < 0) + if (textmessage_handle(textmessage_receiver_0, &parse_protocol, 0) < 0) { if (errno == EPIPE) break ; /* normal exit */ cleanup() ; diff --git a/src/libs6/s6lock_acquire.c b/src/libs6/s6lock_acquire.c index b9791bf..3ce6c77 100644 --- a/src/libs6/s6lock_acquire.c +++ b/src/libs6/s6lock_acquire.c @@ -8,13 +8,12 @@ #include #include #include -#include +#include #include int s6lock_acquire (s6lock_t *a, uint16_t *u, char const *path, uint32_t options, tain_t const *limit, tain_t const *deadline, tain_t *stamp) { size_t pathlen = strlen(path) ; - char err ; char tmp[23] = "--<" ; struct iovec v[2] = { { .iov_base = tmp, .iov_len = 23 }, { .iov_base = (char *)path, .iov_len = pathlen + 1 } } ; uint32_t i ; @@ -29,16 +28,13 @@ int s6lock_acquire (s6lock_t *a, uint16_t *u, char const *path, uint32_t options uint32_pack_big(tmp+3, options) ; tain_pack(tmp+7, limit) ; uint32_pack_big(tmp+19, (uint32_t)pathlen) ; - if (!skaclient_sendv(&a->connection, v, 2, &skaclient_default_cb, &err, deadline, stamp)) + if (!textclient_commandv(&a->connection, v, 2, deadline, stamp)) { + int e = errno ; gensetdyn_delete(&a->data, i) ; + errno = e ; return 0 ; } - if (err) - { - gensetdyn_delete(&a->data, i) ; - return (errno = err, 0) ; - } *GENSETDYN_P(char, &a->data, i) = EAGAIN ; *u = i ; return 1 ; diff --git a/src/libs6/s6lock_end.c b/src/libs6/s6lock_end.c index 74e83f1..e278bd8 100644 --- a/src/libs6/s6lock_end.c +++ b/src/libs6/s6lock_end.c @@ -3,13 +3,13 @@ #include #include #include -#include +#include #include void s6lock_end (s6lock_t *a) { gensetdyn_free(&a->data) ; genalloc_free(uint16_t, &a->list) ; - skaclient_end(&a->connection) ; + textclient_end(&a->connection) ; *a = s6lock_zero ; } diff --git a/src/libs6/s6lock_release.c b/src/libs6/s6lock_release.c index caf91a3..293d8f4 100644 --- a/src/libs6/s6lock_release.c +++ b/src/libs6/s6lock_release.c @@ -4,24 +4,20 @@ #include #include #include -#include +#include #include int s6lock_release (s6lock_t *a, uint16_t i, tain_t const *deadline, tain_t *stamp) { char *p = GENSETDYN_P(char, &a->data, i) ; + char pack[3] = "-->" ; if ((*p != EBUSY) && !error_isagain(*p)) { s6lock_check(a, i) ; return 1 ; } - { - char err ; - char pack[3] = "-->" ; - uint16_pack_big(pack, i) ; - if (!skaclient_send(&a->connection, pack, 3, &skaclient_default_cb, &err, deadline, stamp)) return 0 ; - if (err) return (errno = err, 0) ; - } + uint16_pack_big(pack, i) ; + if (!textclient_command(&a->connection, pack, 3, deadline, stamp)) return 0 ; *p = EINVAL ; return gensetdyn_delete(&a->data, i) ; } diff --git a/src/libs6/s6lock_start.c b/src/libs6/s6lock_start.c index c527bee..1b95d75 100644 --- a/src/libs6/s6lock_start.c +++ b/src/libs6/s6lock_start.c @@ -1,10 +1,9 @@ /* ISC license. */ -#include -#include +#include #include int s6lock_start (s6lock_t *a, char const *path, tain_t const *deadline, tain_t *stamp) { - return skaclient_start_b(&a->connection, &a->buffers, path, 0, S6LOCK_BANNER1, S6LOCK_BANNER1_LEN, S6LOCK_BANNER2, S6LOCK_BANNER2_LEN, deadline, stamp) ; + return textclient_start(&a->connection, path, 0, S6LOCK_BANNER1, S6LOCK_BANNER1_LEN, S6LOCK_BANNER2, S6LOCK_BANNER2_LEN, deadline, stamp) ; } diff --git a/src/libs6/s6lock_startf.c b/src/libs6/s6lock_startf.c index c34a595..293d84c 100644 --- a/src/libs6/s6lock_startf.c +++ b/src/libs6/s6lock_startf.c @@ -1,14 +1,13 @@ /* ISC license. */ #include -#include -#include -#include +#include +#include #include int s6lock_startf (s6lock_t *a, char const *lockdir, tain_t const *deadline, tain_t *stamp) { char const *cargv[3] = { S6LOCKD_PROG, lockdir, 0 } ; if (!lockdir) return (errno = EINVAL, 0) ; - return skaclient_startf_b(&a->connection, &a->buffers, cargv[0], cargv, (char const *const *)environ, SKACLIENT_OPTION_WAITPID, S6LOCK_BANNER1, S6LOCK_BANNER1_LEN, S6LOCK_BANNER2, S6LOCK_BANNER2_LEN, deadline, stamp) ; + return textclient_startf(&a->connection, cargv, (char const *const *)environ, TEXTCLIENT_OPTION_WAITPID, S6LOCK_BANNER1, S6LOCK_BANNER1_LEN, S6LOCK_BANNER2, S6LOCK_BANNER2_LEN, deadline, stamp) ; } diff --git a/src/libs6/s6lock_update.c b/src/libs6/s6lock_update.c index a56c276..9795d9d 100644 --- a/src/libs6/s6lock_update.c +++ b/src/libs6/s6lock_update.c @@ -1,25 +1,26 @@ /* ISC license. */ +#include #include #include #include #include #include #include -#include -#include +#include #include -static int msghandler (unixmessage_t const *m, void *context) +static int msghandler (struct iovec const *v, void *context) { s6lock_t *a = (s6lock_t *)context ; + char const *s = v->iov_base ; char *p ; uint16_t id ; - if (m->len != 3 || m->nfds) return (errno = EPROTO, 0) ; - uint16_unpack_big(m->s, &id) ; + if (v->iov_len != 3) return (errno = EPROTO, 0) ; + uint16_unpack_big(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 ; + if (*p == EBUSY) *p = s[2] ; + else if (error_isagain(*p)) *p = s[2] ? s[2] : EBUSY ; else return (errno = EPROTO, 0) ; if (!genalloc_append(uint16_t, &a->list, &id)) return 0 ; return 1 ; @@ -28,5 +29,5 @@ static int msghandler (unixmessage_t const *m, void *context) int s6lock_update (s6lock_t *a) { genalloc_setlen(uint16_t, &a->list, 0) ; - return skaclient_update(&a->connection, &msghandler, a) ; + return textclient_update(&a->connection, &msghandler, a) ; } diff --git a/src/libs6/s6lockd.c b/src/libs6/s6lockd.c index 5899b46..6c4cc1a 100644 --- a/src/libs6/s6lockd.c +++ b/src/libs6/s6lockd.c @@ -1,5 +1,6 @@ /* ISC license. */ +#include #include #include #include @@ -14,8 +15,8 @@ #include #include #include -#include -#include +#include +#include #include #define USAGE "s6lockd lockdir" @@ -55,10 +56,9 @@ static void cleanup (void) static void trig (uint16_t id, char e) { char pack[3] ; - unixmessage_t m = { .s = pack, .len = 3, .fds = 0, .nfds = 0 } ; uint16_pack_big(pack, id) ; pack[2] = e ; - if (!unixmessage_put(unixmessage_sender_x, &m)) + if (!textmessage_put(textmessage_sender_x, pack, 3)) { cleanup() ; strerr_diefu1sys(111, "build answer") ; @@ -67,11 +67,10 @@ static void trig (uint16_t id, char e) static void answer (char c) { - unixmessage_t m = { .s = &c, .len = 1, .fds = 0, .nfds = 0 } ; - if (!unixmessage_put(unixmessage_sender_1, &m)) + if (!textmessage_put(textmessage_sender_1, &c, 1)) { cleanup() ; - strerr_diefu1sys(111, "unixmessage_put") ; + strerr_diefu1sys(111, "textmessage_put") ; } } @@ -102,16 +101,17 @@ static void handle_signals (void) } } -static int parse_protocol (unixmessage_t const *m, void *context) +static int parse_protocol (struct iovec const *v, void *context) { + char *s = v->iov_base ; uint16_t id ; - if (m->len < 3 || m->nfds) + if (v->iov_len < 3) { cleanup() ; strerr_dief1x(100, "invalid client request") ; } - uint16_unpack_big(m->s, &id) ; - switch (m->s[2]) + uint16_unpack_big(s, &id) ; + switch (s[2]) { case '>' : /* release */ { @@ -131,25 +131,25 @@ static int parse_protocol (unixmessage_t const *m, void *context) char const *cargv[3] = { S6LOCKD_HELPER_PROG, 0, 0 } ; char const *cenvp[2] = { 0, 0 } ; uint32_t options, pathlen ; - if (m->len < 23) + if (v->iov_len < 23) { answer(EPROTO) ; break ; } - uint32_unpack_big(m->s + 3, &options) ; - tain_unpack(m->s + 7, &f.limit) ; - uint32_unpack_big(m->s + 19, &pathlen) ; - if (pathlen + 23 != m->len || m->s[m->len - 1]) + uint32_unpack_big(s + 3, &options) ; + tain_unpack(s + 7, &f.limit) ; + uint32_unpack_big(s + 19, &pathlen) ; + if (pathlen + 23 != v->iov_len || s[v->iov_len - 1]) { answer(EPROTO) ; break ; } f.id = id ; - m->s[21] = '.' ; - m->s[22] = '/' ; - cargv[1] = (char const *)m->s + 21 ; + s[21] = '.' ; + s[22] = '/' ; + cargv[1] = (char const *)s + 21 ; if (options & S6LOCK_OPTIONS_EX) cenvp[0] = "S6LOCK_EX=1" ; - f.pid = child_spawn(cargv[0], cargv, cenvp, f.p, 2) ; + f.pid = child_spawn2(cargv[0], cargv, cenvp, f.p) ; if (!f.pid) { answer(errno) ; @@ -204,7 +204,7 @@ int main (int argc, char const *const *argv) tain_now_g() ; tain_addsec_g(&deadline, 2) ; - if (!skaclient_server_01x_init_g(S6LOCK_BANNER1, S6LOCK_BANNER1_LEN, S6LOCK_BANNER2, S6LOCK_BANNER2_LEN, &deadline)) + if (!textclient_server_01x_init_g(S6LOCK_BANNER1, S6LOCK_BANNER1_LEN, S6LOCK_BANNER2, S6LOCK_BANNER2_LEN, &deadline)) strerr_diefu1sys(111, "sync with client") ; for (;;) @@ -216,9 +216,9 @@ int main (int argc, char const *const *argv) tain_add_g(&deadline, &tain_infinite_relative) ; x[0].fd = 0 ; x[0].events = IOPAUSE_EXCEPT | IOPAUSE_READ ; - x[1].fd = 1 ; x[1].events = IOPAUSE_EXCEPT | (unixmessage_sender_isempty(unixmessage_sender_1) ? 0 : IOPAUSE_WRITE ) ; - x[2].fd = unixmessage_sender_fd(unixmessage_sender_x) ; - x[2].events = IOPAUSE_EXCEPT | (unixmessage_sender_isempty(unixmessage_sender_x) ? 0 : IOPAUSE_WRITE) ; + x[1].fd = 1 ; x[1].events = IOPAUSE_EXCEPT | (textmessage_sender_isempty(textmessage_sender_1) ? 0 : IOPAUSE_WRITE ) ; + x[2].fd = textmessage_sender_fd(textmessage_sender_x) ; + x[2].events = IOPAUSE_EXCEPT | (textmessage_sender_isempty(textmessage_sender_x) ? 0 : IOPAUSE_WRITE) ; x[3].fd = sfd ; x[3].events = IOPAUSE_READ ; for (; i < n ; i++) { @@ -257,13 +257,13 @@ int main (int argc, char const *const *argv) /* client is reading */ if (x[1].revents & IOPAUSE_WRITE) - if (!unixmessage_sender_flush(unixmessage_sender_1) && !error_isagain(errno)) + if (!textmessage_sender_flush(textmessage_sender_1) && !error_isagain(errno)) { cleanup() ; strerr_diefu1sys(111, "flush stdout") ; } if (x[2].revents & IOPAUSE_WRITE) - if (!unixmessage_sender_flush(unixmessage_sender_x) && !error_isagain(errno)) + if (!textmessage_sender_flush(textmessage_sender_x) && !error_isagain(errno)) { cleanup() ; strerr_diefu1sys(111, "flush asyncout") ; @@ -301,9 +301,9 @@ int main (int argc, char const *const *argv) if (x[3].revents & (IOPAUSE_READ | IOPAUSE_EXCEPT)) handle_signals() ; /* client is writing */ - if (!unixmessage_receiver_isempty(unixmessage_receiver_0) || x[0].revents & IOPAUSE_READ) + if (!textmessage_receiver_isempty(textmessage_receiver_0) || x[0].revents & IOPAUSE_READ) { - if (unixmessage_handle(unixmessage_receiver_0, &parse_protocol, 0) < 0) + if (textmessage_handle(textmessage_receiver_0, &parse_protocol, 0) < 0) { if (errno == EPIPE) break ; /* normal exit */ cleanup() ; -- cgit v1.2.3