diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2024-04-18 14:07:08 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2024-04-18 14:07:08 +0000 |
commit | 19545d58da11e9d2bcce777d83daccc98017f5c0 (patch) | |
tree | 9cc1c9e5c308eb8f0da81c32c9084d2c23571dcd /src | |
parent | 68e2f72d92bf756edf7c9913fba25956c3395cdf (diff) | |
download | s6-rc-19545d58da11e9d2bcce777d83daccc98017f5c0.tar.xz |
Prepare for 0.5.4.3; get rid of 1st limit in s6-rc-fdholder-filler
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/s6-rc/s6-rc-fdholder-filler.c | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/src/s6-rc/s6-rc-fdholder-filler.c b/src/s6-rc/s6-rc-fdholder-filler.c index 81023bc..3f9b509 100644 --- a/src/s6-rc/s6-rc-fdholder-filler.c +++ b/src/s6-rc/s6-rc-fdholder-filler.c @@ -5,20 +5,22 @@ #include <errno.h> #include <skalibs/types.h> -#include <skalibs/strerr.h> #include <skalibs/sgetopt.h> +#include <skalibs/strerr.h> #include <skalibs/allreadwrite.h> #include <skalibs/tai.h> +#include <skalibs/buffer.h> +#include <skalibs/stralloc.h> #include <s6/fdholder.h> #define USAGE "s6-rc-fdholder-filler [ -1 ] [ -t timeout ] < autofilled-filename" #define dieusage() strerr_dieusage(100, USAGE) +#define dienomem() strerr_diefu1sys(111, "stralloc_catb") #define N 16384 -#define BUFSIZE 65536 -static inline unsigned int class (char c) +static inline unsigned int cclass (char c) { switch (c) { @@ -32,27 +34,37 @@ static inline unsigned int class (char c) } } -static inline unsigned int parse_servicenames (char *s, size_t *indices) +static inline char cnext (void) { - static unsigned char const table[3][5] = + char c ; + ssize_t r = buffer_get(buffer_0, &c, 1) ; + if (r == -1) strerr_diefu1sys(111, "read from stdin") ; + return r ? c : 0 ; +} + +static inline unsigned int parse_servicenames (stralloc *sa, size_t *indices) +{ + static uint8_t const table[3][5] = { { 3, 0, 1, 0, 6 }, { 3, 0, 1, 1, 1 }, { 3, 8, 2, 2, 2 } } ; - size_t pos = 0 ; + size_t pos = sa->len ; size_t n = 0 ; unsigned int state = 0 ; for (; state < 3 ; pos++) { - unsigned char c = table[state][class(s[pos])] ; + char cur = cnext() ; + uint8_t c = table[state][cclass(cur)] ; state = c & 3 ; if (c & 4) { if (n >= N) strerr_dief1x(1, "too many fds") ; indices[n++] = pos ; } - if (c & 8) s[pos] = 0 ; + if (c & 8) { if (!stralloc_0(sa)) dienomem() ; } + else if (!stralloc_catb(sa, &cur, 1)) dienomem() ; } return n ; } @@ -60,11 +72,11 @@ static inline unsigned int parse_servicenames (char *s, size_t *indices) int main (int argc, char const *const *argv) { s6_fdholder_t a = S6_FDHOLDER_ZERO ; + stralloc sa = STRALLOC_ZERO ; tain deadline ; int notif = 0 ; size_t n ; size_t indices[N] ; - char buf[BUFSIZE] ; PROG = "s6-rc-fdholder-filler" ; { unsigned int t = 0 ; @@ -85,12 +97,7 @@ int main (int argc, char const *const *argv) else deadline = tain_infinite_relative ; } - { - size_t r = allread(0, buf, BUFSIZE) ; - if (r >= BUFSIZE) strerr_dief3x(100, "file ", argv[0], " is too big") ; - buf[r] = 0 ; - } - n = parse_servicenames(buf, indices) ; + n = parse_servicenames(&sa, indices) ; if (n) { tain offset = { .sec = TAI_ZERO } ; @@ -103,11 +110,11 @@ int main (int argc, char const *const *argv) tain_add_g(&deadline, &deadline) ; for (; i < n ; i++) { - size_t len = strlen(buf + indices[i]) ; + size_t len = strlen(sa.s + indices[i]) ; if (len + 12 > S6_FDHOLDER_ID_SIZE) { errno = ENAMETOOLONG ; - strerr_diefu2sys(111, "create identifier for ", buf + indices[i]) ; + strerr_diefu2sys(111, "create identifier for ", sa.s + indices[i]) ; } if (pipe(p) < 0) strerr_diefu1sys(111, "create pipe") ; @@ -116,7 +123,7 @@ int main (int argc, char const *const *argv) offset.nano = i << 1 ; tain_add(&dump[i<<1].limit, &dump[i<<1].limit, &offset) ; memcpy(dump[i<<1].id, "pipe:s6rc-r-", 12) ; - memcpy(dump[i<<1].id + 12, buf + indices[i], len + 1) ; + memcpy(dump[i<<1].id + 12, sa.s + indices[i], len + 1) ; dump[(i<<1)+1].fd = p[1] ; offset.nano = 1 ; tain_add(&dump[(i<<1)+1].limit, &dump[i<<1].limit, &offset) ; |