From 2270be82ade6f2e63d652602a3842aa1fca3cb7c Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Mon, 13 Mar 2017 13:08:49 +0000 Subject: Adapt to skalibs-2.5.0.0 --- src/libs6rc/s6rc-servicedir-internal.h | 4 +- src/libs6rc/s6rc_db_check_depcycles.c | 10 +- src/libs6rc/s6rc_db_check_pipelines.c | 8 +- src/libs6rc/s6rc_db_check_revdeps.c | 13 +- src/libs6rc/s6rc_db_read.c | 16 +- src/libs6rc/s6rc_db_read_sizes.c | 4 +- src/libs6rc/s6rc_db_read_uint32.c | 2 +- src/libs6rc/s6rc_graph_closure.c | 5 +- src/libs6rc/s6rc_lock.c | 16 +- src/libs6rc/s6rc_read_uint.c | 4 +- src/libs6rc/s6rc_sanitize_dir.c | 5 +- src/libs6rc/s6rc_servicedir_block.c | 11 +- src/libs6rc/s6rc_servicedir_copy_online.c | 26 +-- src/libs6rc/s6rc_servicedir_internal.c | 23 ++- src/libs6rc/s6rc_servicedir_manage.c | 36 ++--- src/libs6rc/s6rc_servicedir_unblock.c | 9 +- src/libs6rc/s6rc_servicedir_unsupervise.c | 17 +- src/s6-rc/s6-rc-bundle.c | 65 ++++---- src/s6-rc/s6-rc-compile.c | 261 ++++++++++++++---------------- src/s6-rc/s6-rc-db.c | 65 ++++---- src/s6-rc/s6-rc-dryrun.c | 4 +- src/s6-rc/s6-rc-fdholder-filler.c | 15 +- src/s6-rc/s6-rc-init.c | 30 ++-- src/s6-rc/s6-rc-oneshot-run.c | 24 +-- src/s6-rc/s6-rc-update.c | 124 +++++++------- src/s6-rc/s6-rc.c | 78 +++++---- 26 files changed, 419 insertions(+), 456 deletions(-) diff --git a/src/libs6rc/s6rc-servicedir-internal.h b/src/libs6rc/s6rc-servicedir-internal.h index fe05a40..a4af0b9 100644 --- a/src/libs6rc/s6rc-servicedir-internal.h +++ b/src/libs6rc/s6rc-servicedir-internal.h @@ -3,6 +3,8 @@ #ifndef S6RC_SERVICEDIR_INTERNAL_H #define S6RC_SERVICEDIR_INTERNAL_H +#include + typedef enum s6rc_filetype_e s6rc_filetype_t, *s6rc_filetype_t_ref ; enum s6rc_filetype_e { @@ -25,7 +27,7 @@ struct s6rc_servicedir_desc_s } ; extern s6rc_servicedir_desc_t const *s6rc_servicedir_file_list ; -extern unsigned int const s6rc_servicedir_file_maxlen ; +extern size_t const s6rc_servicedir_file_maxlen ; extern int s6rc_servicedir_copy_one (char const *, char const *, s6rc_servicedir_desc_t const *) ; diff --git a/src/libs6rc/s6rc_db_check_depcycles.c b/src/libs6rc/s6rc_db_check_depcycles.c index 5f7baa7..2bf96b4 100644 --- a/src/libs6rc/s6rc_db_check_depcycles.c +++ b/src/libs6rc/s6rc_db_check_depcycles.c @@ -1,9 +1,9 @@ /* ISC license. */ +#include #include #include #include -#include #include typedef struct recinfo_s recinfo_t, *recinfo_t_ref ; @@ -25,7 +25,7 @@ static uint32_t s6rc_db_checknocycle_rec (recinfo_t *recinfo, uint32_t i) bitarray_set(recinfo->gray, i) ; while (j--) { - register uint32_t r = s6rc_db_checknocycle_rec(recinfo, recinfo->db->deps[recinfo->h * recinfo->db->ndeps + recinfo->db->services[i].deps[recinfo->h] + j]) ; + uint32_t r = s6rc_db_checknocycle_rec(recinfo, recinfo->db->deps[recinfo->h * recinfo->db->ndeps + recinfo->db->services[i].deps[recinfo->h] + j]) ; if (r < recinfo->n) return r ; } bitarray_set(recinfo->black, i) ; @@ -40,11 +40,11 @@ int s6rc_db_check_depcycles (s6rc_db_t const *db, int h, diuint32 *problem) unsigned char gray[bitarray_div8(n)] ; unsigned char black[bitarray_div8(n)] ; recinfo_t info = { .db = db, .n = n, .gray = gray, .black = black, .h = !!h } ; - byte_zero(gray, bitarray_div8(n)) ; - byte_zero(black, bitarray_div8(n)) ; + memset(gray, 0, bitarray_div8(n)) ; + memset(black, 0, bitarray_div8(n)) ; while (i--) { - register uint32_t r = s6rc_db_checknocycle_rec(&info, i) ; + uint32_t r = s6rc_db_checknocycle_rec(&info, i) ; if (r < n) { problem->left = i ; diff --git a/src/libs6rc/s6rc_db_check_pipelines.c b/src/libs6rc/s6rc_db_check_pipelines.c index 19f4993..9dd7f2e 100644 --- a/src/libs6rc/s6rc_db_check_pipelines.c +++ b/src/libs6rc/s6rc_db_check_pipelines.c @@ -1,8 +1,8 @@ /* ISC license. */ +#include #include #include -#include #include #include @@ -10,14 +10,14 @@ int s6rc_db_check_pipelines (s6rc_db_t const *db, diuint32 *problem) { uint32_t i = db->nlong ; unsigned char black[bitarray_div8(db->nlong)] ; - byte_zero(black, bitarray_div8(db->nlong)) ; + memset(black, 0, bitarray_div8(db->nlong)) ; while (i--) if (!bitarray_peek(black, i)) { uint32_t j = i ; uint32_t start ; for (;;) { - register uint32_t k = db->services[j].x.longrun.pipeline[0] ; + uint32_t k = db->services[j].x.longrun.pipeline[0] ; if (k >= db->nlong) break ; if (k == i || bitarray_peek(black, k)) { @@ -31,7 +31,7 @@ int s6rc_db_check_pipelines (s6rc_db_t const *db, diuint32 *problem) j = i ; for (;;) { - register uint32_t k = db->services[j].x.longrun.pipeline[1] ; + uint32_t k = db->services[j].x.longrun.pipeline[1] ; if (k >= db->nlong) break ; if (k == i || bitarray_peek(black, k)) { diff --git a/src/libs6rc/s6rc_db_check_revdeps.c b/src/libs6rc/s6rc_db_check_revdeps.c index 3b64c36..0097d06 100644 --- a/src/libs6rc/s6rc_db_check_revdeps.c +++ b/src/libs6rc/s6rc_db_check_revdeps.c @@ -1,7 +1,6 @@ /* ISC license. */ -#include -#include +#include #include #include @@ -10,18 +9,18 @@ int s6rc_db_check_revdeps (s6rc_db_t const *db) size_t n = db->nshort + db->nlong ; size_t m = bitarray_div8(n) ; unsigned char matrix[n * m] ; - register unsigned int i = n ; - register unsigned char const *p = matrix ; - byte_zero(matrix, n * m) ; + unsigned int i = n ; + unsigned char const *p = matrix ; + memset(matrix, 0, n * m) ; while (i--) { - register unsigned int j = db->services[i].ndeps[1] ; + unsigned int j = db->services[i].ndeps[1] ; while (j--) bitarray_not(matrix + m * i, db->deps[db->ndeps + db->services[i].deps[1] + j], 1) ; } i = n ; while (i--) { - register unsigned int j = db->services[i].ndeps[0] ; + unsigned int j = db->services[i].ndeps[0] ; while (j--) bitarray_not(matrix + m * db->deps[db->services[i].deps[0] + j], i, 1) ; } n *= m ; diff --git a/src/libs6rc/s6rc_db_read.c b/src/libs6rc/s6rc_db_read.c index e327c19..8234116 100644 --- a/src/libs6rc/s6rc_db_read.c +++ b/src/libs6rc/s6rc_db_read.c @@ -1,9 +1,9 @@ /* ISC license. */ -#include +#include #include #include -#include +#include #include #include #include @@ -31,7 +31,7 @@ static inline int s6rc_db_check_valid_strings (char const *string, size_t string while (n--) { if (!s6rc_db_check_valid_string(string, stringlen, pos)) return 0 ; - pos += str_len(string + pos) + 1 ; + pos += strlen(string + pos) + 1 ; } return 1 ; } @@ -54,7 +54,7 @@ static inline int s6rc_db_read_services (buffer *b, s6rc_db_t *db) unsigned int n = db->nshort + db->nlong ; unsigned int nargvs = db->nargvs ; unsigned int argvpos = 0 ; - register unsigned int i = 0 ; + unsigned int i = 0 ; for (; i < n ; i++) { s6rc_service_t *sv = db->services + i ; @@ -138,11 +138,11 @@ static inline int s6rc_db_read_buffer (buffer *b, s6rc_db_t *db) { char banner[S6RC_DB_BANNER_START_LEN] ; if (buffer_get(b, banner, S6RC_DB_BANNER_START_LEN) < S6RC_DB_BANNER_START_LEN) return -1 ; - if (byte_diff(banner, S6RC_DB_BANNER_START_LEN, S6RC_DB_BANNER_START)) return 0 ; + if (memcmp(banner, S6RC_DB_BANNER_START, S6RC_DB_BANNER_START_LEN)) return 0 ; } { - register int r = s6rc_db_read_string(b, db->string, db->stringlen) ; + int r = s6rc_db_read_string(b, db->string, db->stringlen) ; if (r < 1) return r ; r = s6rc_db_read_deps(b, db->nshort + db->nlong, db->deps, db->ndeps) ; if (r < 1) return r ; @@ -153,7 +153,7 @@ static inline int s6rc_db_read_buffer (buffer *b, s6rc_db_t *db) { char banner[S6RC_DB_BANNER_END_LEN] ; if (buffer_get(b, banner, S6RC_DB_BANNER_END_LEN) < S6RC_DB_BANNER_END_LEN) return -1 ; - if (byte_diff(banner, S6RC_DB_BANNER_END_LEN, S6RC_DB_BANNER_END)) return 0 ; + if (memcmp(banner, S6RC_DB_BANNER_END, S6RC_DB_BANNER_END_LEN)) return 0 ; } return 1 ; } @@ -165,7 +165,7 @@ int s6rc_db_read (int fdcompiled, s6rc_db_t *db) char buf[BUFFER_INSIZE] ; int fd = open_readatb(fdcompiled, "db") ; if (fd < 0) return -1 ; - buffer_init(&b, &fd_readsv, fd, buf, BUFFER_INSIZE) ; + buffer_init(&b, &buffer_read, fd, buf, BUFFER_INSIZE) ; r = s6rc_db_read_buffer(&b, db) ; e = errno ; fd_close(fd) ; diff --git a/src/libs6rc/s6rc_db_read_sizes.c b/src/libs6rc/s6rc_db_read_sizes.c index de596e2..87fe740 100644 --- a/src/libs6rc/s6rc_db_read_sizes.c +++ b/src/libs6rc/s6rc_db_read_sizes.c @@ -31,7 +31,7 @@ int s6rc_db_read_sizes (int fdcompiled, s6rc_db_t *db) buffer b ; int fd = open_readatb(fdcompiled, "n") ; if (fd < 0) return 0 ; - buffer_init(&b, &fd_readsv, fd, buf, 64) ; + buffer_init(&b, &buffer_read, fd, buf, 64) ; if (!s6rc_db_read_sizes_buffer(&b, db)) { fd_close(fd) ; @@ -39,7 +39,7 @@ int s6rc_db_read_sizes (int fdcompiled, s6rc_db_t *db) } { char c ; - register ssize_t r = buffer_get(&b, &c, 1) ; + ssize_t r = buffer_get(&b, &c, 1) ; if (r < 0) { r = errno ; diff --git a/src/libs6rc/s6rc_db_read_uint32.c b/src/libs6rc/s6rc_db_read_uint32.c index 937847b..9f96b33 100644 --- a/src/libs6rc/s6rc_db_read_uint32.c +++ b/src/libs6rc/s6rc_db_read_uint32.c @@ -7,7 +7,7 @@ int s6rc_db_read_uint32 (buffer *b, uint32_t *x) { - unsigned int w = 0 ; + size_t w = 0 ; char pack[4] ; if (buffer_getall(b, pack, 4, &w) <= 0) return 0 ; uint32_unpack_big(pack, x) ; diff --git a/src/libs6rc/s6rc_graph_closure.c b/src/libs6rc/s6rc_graph_closure.c index 0ec2def..7c3a8f9 100644 --- a/src/libs6rc/s6rc_graph_closure.c +++ b/src/libs6rc/s6rc_graph_closure.c @@ -1,5 +1,6 @@ /* ISC license. */ +#include #include #include #include @@ -32,8 +33,8 @@ void s6rc_graph_closure (s6rc_db_t const *db, unsigned char *bits, unsigned int unsigned int m = bitarray_div8(n) ; unsigned char mark[m] ; recinfo_t info = { .db = db, .n = n, .bits = bits, .mark = mark, .mask = 1 << (bitno & 7), .h = !!h } ; - register unsigned int i = n ; - byte_zero(mark, m) ; + unsigned int i = n ; + memset(mark, 0, m) ; while (i--) if (bits[i] & info.mask) s6rc_graph_closure_rec(&info, i) ; } diff --git a/src/libs6rc/s6rc_lock.c b/src/libs6rc/s6rc_lock.c index 34c2544..dab3035 100644 --- a/src/libs6rc/s6rc_lock.c +++ b/src/libs6rc/s6rc_lock.c @@ -1,9 +1,7 @@ /* ISC license. */ -#include +#include #include -#include -#include #include #include @@ -14,10 +12,10 @@ int s6rc_lock (char const *live, int lwhat, int *llfd, char const *compiled, int if (lwhat) { - size_t llen = str_len(live) ; + size_t llen = strlen(live) ; char lfn[llen + 6] ; - byte_copy(lfn, llen, live) ; - byte_copy(lfn + llen, 6, "/lock") ; + memcpy(lfn, live, llen) ; + memcpy(lfn + llen, "/lock", 6) ; lfd = open_create(lfn) ; if (lfd < 0) return 0 ; if ((lwhat > 1 ? lock_ex(lfd) : lock_sh(lfd)) < 0) { e = errno ; goto lerr ; } @@ -25,10 +23,10 @@ int s6rc_lock (char const *live, int lwhat, int *llfd, char const *compiled, int if (cwhat) { - size_t clen = str_len(compiled) ; + size_t clen = strlen(compiled) ; char cfn[clen + 6] ; - byte_copy(cfn, clen, compiled) ; - byte_copy(cfn + clen, 6, "/lock") ; + memcpy(cfn, compiled, clen) ; + memcpy(cfn + clen, "/lock", 6) ; cfd = open_create(cfn) ; if (cfd < 0) if (cwhat > 1 || errno != EROFS) { e = errno ; goto lerr ; } diff --git a/src/libs6rc/s6rc_read_uint.c b/src/libs6rc/s6rc_read_uint.c index 87022c6..c9f05be 100644 --- a/src/libs6rc/s6rc_read_uint.c +++ b/src/libs6rc/s6rc_read_uint.c @@ -2,14 +2,14 @@ #include #include -#include +#include #include #include int s6rc_read_uint (char const *file, unsigned int *u) { char buf[UINT_FMT + 1] ; - register ssize_t r = openreadnclose(file, buf, UINT_FMT) ; + ssize_t r = openreadnclose(file, buf, UINT_FMT) ; if (r < 0) return (errno == ENOENT) ? 0 : -1 ; buf[byte_chr(buf, r, '\n')] = 0 ; if (!uint0_scan(buf, u)) return (errno = EINVAL, -1) ; diff --git a/src/libs6rc/s6rc_sanitize_dir.c b/src/libs6rc/s6rc_sanitize_dir.c index fa7079d..9f647a9 100644 --- a/src/libs6rc/s6rc_sanitize_dir.c +++ b/src/libs6rc/s6rc_sanitize_dir.c @@ -1,7 +1,6 @@ /* ISC license. */ -#include -#include +#include #include #include #include @@ -9,7 +8,7 @@ int s6rc_sanitize_dir (stralloc *sa, char const *fn, size_t *dirlen) { size_t base = sa->len ; - size_t fnlen = str_len(fn) ; + size_t fnlen = strlen(fn) ; size_t ddirlen ; int wasnull = !sa->s ; if (!sadirname(sa, fn, fnlen)) return 0 ; diff --git a/src/libs6rc/s6rc_servicedir_block.c b/src/libs6rc/s6rc_servicedir_block.c index 9fb28b1..a7e2b12 100644 --- a/src/libs6rc/s6rc_servicedir_block.c +++ b/src/libs6rc/s6rc_servicedir_block.c @@ -1,25 +1,24 @@ /* ISC license. */ -#include +#include #include #include -#include #include #include #include int s6rc_servicedir_block (char const *dir) { - size_t dirlen = str_len(dir) ; + size_t dirlen = strlen(dir) ; s6_svstatus_t status ; char fn[dirlen + 6] ; if (!s6_svstatus_read(dir, &status)) return -1 ; - byte_copy(fn, dirlen, dir) ; - byte_copy(fn + dirlen, 6, "/down") ; + memcpy(fn, dir, dirlen) ; + memcpy(fn + dirlen, "/down", 6) ; if (!touch(fn)) return -1 ; if (s6_svc_writectl(dir, S6_SUPERVISE_CTLDIR, "O", 1) < 0) { - register int e = errno ; + int e = errno ; unlink(fn) ; errno = e ; return -1 ; diff --git a/src/libs6rc/s6rc_servicedir_copy_online.c b/src/libs6rc/s6rc_servicedir_copy_online.c index 902e6ad..e676d5a 100644 --- a/src/libs6rc/s6rc_servicedir_copy_online.c +++ b/src/libs6rc/s6rc_servicedir_copy_online.c @@ -1,10 +1,10 @@ /* ISC license. */ -#include +#include +#include #include #include #include -#include #include #include #include "s6rc-servicedir-internal.h" @@ -12,8 +12,8 @@ int s6rc_servicedir_copy_online (char const *src, char const *dst) { - size_t srclen = str_len(src) ; - size_t dstlen = str_len(dst) ; + size_t srclen = strlen(src) ; + size_t dstlen = strlen(dst) ; unsigned int n ; unsigned int i = 0 ; int wantup = 0 ; @@ -21,11 +21,11 @@ int s6rc_servicedir_copy_online (char const *src, char const *dst) char srcfn[srclen + s6rc_servicedir_file_maxlen + 6] ; char dstfn[dstlen + s6rc_servicedir_file_maxlen + 6] ; char oldfn[dstlen + s6rc_servicedir_file_maxlen + 6] ; - byte_copy(srcfn, srclen, src) ; + memcpy(srcfn, src, srclen) ; srcfn[srclen] = '/' ; - byte_copy(dstfn, dstlen + 1, dst) ; - byte_copy(oldfn, dstlen, dst) ; - byte_copy(oldfn + dstlen, 5, "/old") ; + memcpy(dstfn, dst, dstlen + 1) ; + memcpy(oldfn, dst, dstlen) ; + memcpy(oldfn + dstlen, "/old", 5) ; if (rm_rf(oldfn) < 0 && errno != ENOENT) return 0 ; if (mkdir(oldfn, 0755) < 0) return 0 ; dstfn[dstlen] = '/' ; @@ -35,8 +35,8 @@ int s6rc_servicedir_copy_online (char const *src, char const *dst) for (; s6rc_servicedir_file_list[i].name ; i++) { - str_copy(dstfn + dstlen + 1, s6rc_servicedir_file_list[i].name) ; - str_copy(oldfn + dstlen + 5, s6rc_servicedir_file_list[i].name) ; + strcpy(dstfn + dstlen + 1, s6rc_servicedir_file_list[i].name) ; + strcpy(oldfn + dstlen + 5, s6rc_servicedir_file_list[i].name) ; if (rename(dstfn, oldfn) < 0 && (errno != ENOENT || s6rc_servicedir_file_list[i].options & SVFILE_MANDATORY)) { @@ -61,15 +61,15 @@ int s6rc_servicedir_copy_online (char const *src, char const *dst) errremove: for (; i < n ; i++) { - str_copy(dstfn + dstlen + 1, s6rc_servicedir_file_list[i].name) ; + strcpy(dstfn + dstlen + 1, s6rc_servicedir_file_list[i].name) ; rm_rf(dstfn) ; } i = n ; errrename: while (i--) { - str_copy(dstfn + dstlen + 1, s6rc_servicedir_file_list[i].name) ; - str_copy(oldfn + dstlen + 5, s6rc_servicedir_file_list[i].name) ; + strcpy(dstfn + dstlen + 1, s6rc_servicedir_file_list[i].name) ; + strcpy(oldfn + dstlen + 5, s6rc_servicedir_file_list[i].name) ; rename(oldfn, dstfn) ; } errdir: diff --git a/src/libs6rc/s6rc_servicedir_internal.c b/src/libs6rc/s6rc_servicedir_internal.c index ccc4644..db6b180 100644 --- a/src/libs6rc/s6rc_servicedir_internal.c +++ b/src/libs6rc/s6rc_servicedir_internal.c @@ -1,10 +1,9 @@ /* ISC license. */ -#include +#include #include #include -#include -#include +#include #include #include #include "s6rc-servicedir-internal.h" @@ -24,21 +23,21 @@ static s6rc_servicedir_desc_t const svdir_file_list[] = } ; s6rc_servicedir_desc_t const *s6rc_servicedir_file_list = svdir_file_list ; -unsigned int const s6rc_servicedir_file_maxlen = 15 ; +size_t const s6rc_servicedir_file_maxlen = 15 ; int s6rc_servicedir_copy_one (char const *src, char const *dst, s6rc_servicedir_desc_t const *p) { - size_t srclen = str_len(src) ; - size_t dstlen = str_len(dst) ; - size_t plen = str_len(p->name) ; + size_t srclen = strlen(src) ; + size_t dstlen = strlen(dst) ; + size_t plen = strlen(p->name) ; char srcfn[srclen + plen + 2] ; char dstfn[dstlen + plen + 2] ; - byte_copy(srcfn, srclen, src) ; + memcpy(srcfn, src, srclen) ; srcfn[srclen] = '/' ; - byte_copy(srcfn + srclen + 1, plen + 1, p->name) ; - byte_copy(dstfn, dstlen, dst) ; + memcpy(srcfn + srclen + 1, p->name, plen + 1) ; + memcpy(dstfn, dst, dstlen) ; dstfn[dstlen] = '/' ; - byte_copy(dstfn + dstlen + 1, plen + 1, p->name) ; + memcpy(dstfn + dstlen + 1, p->name, plen + 1) ; switch (p->type) { @@ -61,7 +60,7 @@ int s6rc_servicedir_copy_one (char const *src, char const *dst, s6rc_servicedir_ case FILETYPE_UINT : { unsigned int u ; - register int r = s6rc_read_uint(srcfn, &u) ; + int r = s6rc_read_uint(srcfn, &u) ; if (r < 0 || (!r && p->options & SVFILE_MANDATORY)) return 0 ; if (r) { diff --git a/src/libs6rc/s6rc_servicedir_manage.c b/src/libs6rc/s6rc_servicedir_manage.c index c665564..e4a6692 100644 --- a/src/libs6rc/s6rc_servicedir_manage.c +++ b/src/libs6rc/s6rc_servicedir_manage.c @@ -1,11 +1,9 @@ /* ISC license. */ -#include +#include #include -#include #include #include -#include #include #include #include @@ -20,7 +18,7 @@ static void rollback (char const *live, char const *s, size_t len) { while (len) { - size_t n = str_len(s) + 1 ; + size_t n = strlen(s) + 1 ; s6rc_servicedir_unsupervise(live, s, 0) ; s += n ; len -= n ; } @@ -32,14 +30,14 @@ int s6rc_servicedir_manage (char const *live, tain_t const *deadline, tain_t *st stralloc newnames = STRALLOC_ZERO ; genalloc ids = GENALLOC_ZERO ; /* uint16_t */ gid_t gid = getgid() ; - size_t livelen = str_len(live) ; + size_t livelen = strlen(live) ; int ok = 1 ; int e = 0 ; DIR *dir ; char dirfn[livelen + 13] ; if (!ftrigr_startf(&a, deadline, stamp)) return 0 ; - byte_copy(dirfn, livelen, live) ; - byte_copy(dirfn + livelen, 13, "/servicedirs") ; + memcpy(dirfn, live, livelen) ; + memcpy(dirfn + livelen, "/servicedirs", 13) ; dir = opendir(dirfn) ; if (!dir) goto closederr ; for (;;) @@ -50,30 +48,30 @@ int s6rc_servicedir_manage (char const *live, tain_t const *deadline, tain_t *st if (!d) break ; if (d->d_name[0] == '.') continue ; { - size_t len = str_len(d->d_name) ; + size_t len = strlen(d->d_name) ; int r ; uint16_t id ; char srcfn[livelen + 20 + len] ; char dstfn[livelen + 10 + len] ; - byte_copy(srcfn, livelen + 12, dirfn) ; + memcpy(srcfn, dirfn, livelen + 12) ; srcfn[livelen + 12] = '/' ; - byte_copy(srcfn + livelen + 13, len + 1, d->d_name) ; + memcpy(srcfn + livelen + 13, d->d_name, len + 1) ; r = s6_svc_ok(srcfn) ; if (r < 0) { e = errno ; goto err ; } if (!r) { - byte_copy(srcfn + livelen + 13 + len, 6, "/down") ; + memcpy(srcfn + livelen + 13 + len, "/down", 6) ; if (!touch(srcfn)) { e = errno ; goto err ; } - byte_copy(srcfn + livelen + 14 + len, 6, "event") ; + memcpy(srcfn + livelen + 14 + len, "event", 6) ; if (!ftrigw_fifodir_make(srcfn, gid, 0)) { e = errno ; goto err ; } id = ftrigr_subscribe(&a, srcfn, "s", 0, deadline, stamp) ; if (!id) { e = errno ; goto err ; } - if (!genalloc_append(uint16, &ids, &id)) { e = errno ; goto err ; } + if (!genalloc_append(uint16_t, &ids, &id)) { e = errno ; goto err ; } srcfn[livelen + 13 + len] = 0 ; } - byte_copy(dstfn, livelen, live) ; - byte_copy(dstfn + livelen, 9, "/scandir/") ; - byte_copy(dstfn + livelen + 9, len + 1, d->d_name) ; + memcpy(dstfn, live, livelen) ; + memcpy(dstfn + livelen, "/scandir/", 9) ; + memcpy(dstfn + livelen + 9, d->d_name, len + 1) ; if (symlink(srcfn, dstfn) < 0) { if (!r || errno != EEXIST) { e = errno ; goto err ; } @@ -93,9 +91,9 @@ int s6rc_servicedir_manage (char const *live, tain_t const *deadline, tain_t *st dir_close(dir) ; { char scanfn[livelen + 9] ; - register int r ; - byte_copy(scanfn, livelen, live) ; - byte_copy(scanfn + livelen, 9, "/scandir") ; + int r ; + memcpy(scanfn, live, livelen) ; + memcpy(scanfn + livelen, "/scandir", 9) ; r = s6_svc_writectl(scanfn, S6_SVSCAN_CTLDIR, "a", 1) ; if (r < 0) { e = errno ; goto closederr ; } if (!r) ok = 3 ; diff --git a/src/libs6rc/s6rc_servicedir_unblock.c b/src/libs6rc/s6rc_servicedir_unblock.c index 0c2ae23..2a10bfd 100644 --- a/src/libs6rc/s6rc_servicedir_unblock.c +++ b/src/libs6rc/s6rc_servicedir_unblock.c @@ -1,9 +1,8 @@ /* ISC license. */ -#include +#include #include #include -#include #include #include @@ -11,10 +10,10 @@ int s6rc_servicedir_unblock (char const *dir, int h) { if (h) { - size_t dirlen = str_len(dir) ; + size_t dirlen = strlen(dir) ; char fn[dirlen + 6] ; - byte_copy(fn, dirlen, dir) ; - byte_copy(fn + dirlen, 6, "/down") ; + memcpy(fn, dir, dirlen) ; + memcpy(fn + dirlen, "/down", 6) ; if (unlink(fn) < 0 && errno != ENOENT) return -1 ; if (s6_svc_writectl(dir, S6_SUPERVISE_CTLDIR, "u", 1) < 0) return -1 ; } diff --git a/src/libs6rc/s6rc_servicedir_unsupervise.c b/src/libs6rc/s6rc_servicedir_unsupervise.c index bc5ab63..8b0dbb9 100644 --- a/src/libs6rc/s6rc_servicedir_unsupervise.c +++ b/src/libs6rc/s6rc_servicedir_unsupervise.c @@ -1,24 +1,23 @@ /* ISC license. */ -#include +#include #include -#include #include #include void s6rc_servicedir_unsupervise (char const *live, char const *name, int keepsupervisor) { - size_t namelen = str_len(name) ; - size_t livelen = str_len(live) ; + size_t namelen = strlen(name) ; + size_t livelen = strlen(live) ; char fn[livelen + 14 + namelen] ; - byte_copy(fn, livelen, live) ; - byte_copy(fn + livelen, 9, "/scandir/") ; - byte_copy(fn + livelen + 9, namelen + 1, name) ; + memcpy(fn, live, livelen) ; + memcpy(fn + livelen, "/scandir/", 9) ; + memcpy(fn + livelen + 9, name, namelen + 1) ; unlink(fn) ; if (!keepsupervisor) { - byte_copy(fn + livelen + 1, 12, "servicedirs/") ; - byte_copy(fn + livelen + 13, namelen + 1, name) ; + memcpy(fn + livelen + 1, "servicedirs/", 12) ; + memcpy(fn + livelen + 13, name, namelen + 1) ; s6_svc_writectl(fn, S6_SUPERVISE_CTLDIR, "x", 1) ; } } diff --git a/src/s6-rc/s6-rc-bundle.c b/src/s6-rc/s6-rc-bundle.c index 6e6544b..78bfcbe 100644 --- a/src/s6-rc/s6-rc-bundle.c +++ b/src/s6-rc/s6-rc-bundle.c @@ -1,12 +1,11 @@ /* ISC license. */ -#include +#include #include #include #include #include #include -#include #include #include #include @@ -24,11 +23,11 @@ static void cleanup (char const *compiled) { - size_t len = str_len(compiled) ; + size_t len = strlen(compiled) ; int e = errno ; char fn[len + sizeof("/resolve.cdb.new")] ; - byte_copy(fn, len, compiled) ; - byte_copy(fn + len, sizeof("/resolve.cdb.new"), "/resolve.cdb.new") ; + memcpy(fn, compiled, len) ; + memcpy(fn + len, "/resolve.cdb.new", sizeof("/resolve.cdb.new")) ; unlink(fn) ; errno = e ; } @@ -38,24 +37,24 @@ static void cleanup (char const *compiled) static inline int renameit (char const *compiled, char const *src, char const *dst) { - size_t clen = str_len(compiled) ; - size_t srclen = str_len(src) ; - size_t dstlen = str_len(dst) ; + size_t clen = strlen(compiled) ; + size_t srclen = strlen(src) ; + size_t dstlen = strlen(dst) ; char srcfn[clen + srclen + 2] ; char dstfn[clen + dstlen + 2] ; - byte_copy(srcfn, clen, compiled) ; + memcpy(srcfn, compiled, clen) ; srcfn[clen] = '/' ; - byte_copy(srcfn + clen + 1, srclen + 1, src) ; - byte_copy(dstfn, clen, compiled) ; + memcpy(srcfn + clen + 1, src, srclen + 1) ; + memcpy(dstfn, compiled, clen) ; dstfn[clen] = '/' ; - byte_copy(dstfn + clen + 1, dstlen + 1, dst) ; + memcpy(dstfn + clen + 1, dst, dstlen + 1) ; return rename(srcfn, dstfn) ; } static void check (cdb_t *cr, s6rc_db_t *db, char const *name, int h, int force, char const *compiled) { - size_t namelen = str_len(name) ; - register int r = cdb_find(cr, name, namelen) ; + size_t namelen = strlen(name) ; + int r = cdb_find(cr, name, namelen) ; if (r < 0) strerr_diefu3sys(111, "cdb_find in ", compiled, "/resolve.cdb") ; if (!r) { @@ -74,7 +73,7 @@ static void check (cdb_t *cr, s6rc_db_t *db, char const *name, int h, int force, uint32_unpack_big(pack, &x) ; if (x >= db->nshort + db->nlong) strerr_dief2x(4, "invalid database in ", compiled) ; - if (!str_diff(name, db->string + db->services[x].name)) + if (!strcmp(name, db->string + db->services[x].name)) strerr_dief4x(5, "identifier ", name, " does not represent a bundle for database ", compiled) ; } } @@ -105,7 +104,7 @@ static void modify_resolve (int fdcompiled, s6rc_db_t *db, char const *const *to cdb_traverse_init(&cr, &kpos) ; for (;;) { - register int r = cdb_nextkey(&cr, &kpos) ; + int r = cdb_nextkey(&cr, &kpos) ; if (r < 0) { cleanup(compiled) ; @@ -113,19 +112,19 @@ static void modify_resolve (int fdcompiled, s6rc_db_t *db, char const *const *to } if (!r) break ; { - unsigned int klen = cdb_keylen(&cr) ; + uint32_t klen = cdb_keylen(&cr) ; char ktmp[klen + 1] ; if (cdb_read(&cr, ktmp, klen, cdb_keypos(&cr)) < 0) { cleanup(compiled) ; strerr_diefu3sys(111, "cdb_read ", compiled, "/resolve.cdb") ; } - for (i = 0 ; i < todeln ; i++) if (!str_diffn(todel[i], ktmp, klen)) break ; + for (i = 0 ; i < todeln ; i++) if (!strncmp(todel[i], ktmp, klen)) break ; if (i < todeln) continue ; - for (i = 0 ; i < toaddn ; i++) if (!str_diffn(toadd[i], ktmp, klen)) break ; + for (i = 0 ; i < toaddn ; i++) if (!strncmp(toadd[i], ktmp, klen)) break ; if (i < toaddn) continue ; { - unsigned int dlen = cdb_datalen(&cr) ; + uint32_t dlen = cdb_datalen(&cr) ; char dtmp[dlen + 1] ; if (cdb_read(&cr, dtmp, dlen, cdb_datapos(&cr)) < 0) { @@ -145,14 +144,14 @@ static void modify_resolve (int fdcompiled, s6rc_db_t *db, char const *const *to { char const *const *p = toadd_contents[i] ; unsigned int total = 0 ; - byte_zero(bits, bitarray_div8(n)) ; + memset(bits, 0, bitarray_div8(n)) ; for (; *p ; p++) { - register int r = cdb_find(&cr, *p, str_len(*p)) ; + int r = cdb_find(&cr, *p, strlen(*p)) ; if (r < 0) strerr_diefu3sys(111, "cdb_find in ", compiled, "/resolve.cdb") ; if (!r) strerr_dief4x(3, "identifier ", *p, " does not exist in database ", compiled) ; { - unsigned int j = cdb_datalen(&cr) ; + uint32_t j = cdb_datalen(&cr) ; char pack[j + 1] ; if (cdb_read(&cr, pack, j, cdb_datapos(&cr)) < 0) { @@ -179,7 +178,7 @@ static void modify_resolve (int fdcompiled, s6rc_db_t *db, char const *const *to uint32_pack_big(s, j) ; s += 4 ; } - if (cdb_make_add(&cw, toadd[i], str_len(toadd[i]), pack, total << 2) < 0) + if (cdb_make_add(&cw, toadd[i], strlen(toadd[i]), pack, total << 2) < 0) { cleanup(compiled) ; strerr_diefu1sys(111, "cdb_make_add") ; @@ -234,8 +233,8 @@ static inline void print_help (void) static inline unsigned int lookup (char const *const *table, char const *command) { - register unsigned int i = 0 ; - for (; table[i] ; i++) if (!str_diff(command, table[i])) break ; + unsigned int i = 0 ; + for (; table[i] ; i++) if (!strcmp(command, table[i])) break ; return i ; } @@ -249,7 +248,7 @@ static inline unsigned int parse_command (char const *command) "multiple", 0 } ; - register unsigned int i = lookup(command_table, command) ; + unsigned int i = lookup(command_table, command) ; if (!command_table[i]) dieusage() ; return i ; } @@ -265,7 +264,7 @@ int main (int argc, char const **argv) subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { - register int opt = subgetopt_r(argc, argv, "fl:c:", &l) ; + int opt = subgetopt_r(argc, argv, "fl:c:", &l) ; if (opt == -1) break ; switch (opt) { @@ -289,16 +288,16 @@ int main (int argc, char const **argv) if (what != 2 && argc < 2) dieusage() ; { - size_t livelen = str_len(live) ; + size_t livelen = strlen(live) ; int fdcompiled = -1 ; int compiledlock ; s6rc_db_t dbblob ; - char compiledblob[compiled ? str_len(compiled) : livelen + 10] ; + char compiledblob[compiled ? strlen(compiled) : livelen + 10] ; if (!compiled) { - byte_copy(compiledblob, livelen, live) ; - byte_copy(compiledblob + livelen, 10, "/compiled") ; + memcpy(compiledblob, live, livelen) ; + memcpy(compiledblob + livelen, "/compiled", 10) ; compiled = compiledblob ; } @@ -324,7 +323,7 @@ int main (int argc, char const **argv) char const *argvblob[dbblob.nargvs] ; uint32_t depsblob[dbblob.ndeps << 1] ; char stringblob[dbblob.stringlen] ; - register int r ; + int r ; dbblob.services = serviceblob ; dbblob.argvs = argvblob ; diff --git a/src/s6-rc/s6-rc-compile.c b/src/s6-rc/s6-rc-compile.c index 97ecb3d..657a799 100644 --- a/src/s6-rc/s6-rc-compile.c +++ b/src/s6-rc/s6-rc-compile.c @@ -1,16 +1,12 @@ /* ISC license. */ -#include +#include #include #include #include #include #include -#include -#include -#include -#include -#include +#include #include #include #include @@ -81,7 +77,7 @@ static void *names_dtok (unsigned int d, void *x) static int names_cmp (void const *a, void const *b, void *x) { (void)x ; - return str_diff((char const *)a, (char const *)b) ; + return strcmp((char const *)a, (char const *)b) ; } static genalloc nameinfo = GENALLOC_ZERO ; /* nameinfo_t */ @@ -214,7 +210,7 @@ static int add_name_nocheck (before_t *be, char const *srcdir, char const *name, 0, .type = type } ; - size_t namelen = str_len(name) ; + size_t namelen = strlen(name) ; unsigned int i = genalloc_len(nameinfo_t, &nameinfo) ; if (type == SVTYPE_ONESHOT || type == SVTYPE_LONGRUN) if (!stralloc_catb(&keep, name, namelen + 1)) dienomem() ; @@ -229,7 +225,7 @@ static int add_name_nocheck (before_t *be, char const *srcdir, char const *name, static void check_identifier (char const *srcdir, char const *s) { - if (!byte_diff(s, 5, "s6rc-") && !byte_diff(s, 6, "s6-rc-")) + if (!memcmp(s, "s6rc-", 5) && !memcmp(s, "s6-rc-", 6)) strerr_dief5x(1, "in ", srcdir, ": identifier ", s, " starts with reserved prefix") ; } @@ -273,11 +269,11 @@ static int add_namelist (before_t *be, int dirfd, char const *srcdir, char const char buf[2048] ; int fd = open_readatb(dirfd, list) ; if (fd < 0) return 0 ; - buffer_init(&b, &fd_readsv, fd, buf, 2048) ; + buffer_init(&b, &buffer_read, fd, buf, 2048) ; *listindex = genalloc_len(unsigned int, &be->indices) ; while (cont) { - register int r = skagetln(&b, &satmp, '\n') ; + int r = skagetln(&b, &satmp, '\n') ; if (!r) cont = 0 ; else { @@ -323,7 +319,7 @@ static void read_script (before_t *be, int dirfd, char const *srcdir, char const else { char buf[4096] ; - buffer b = BUFFER_INIT(&fd_readsv, fd, buf, 4096) ; + buffer b = BUFFER_INIT(&buffer_read, fd, buf, 4096) ; r = el_parse_from_buffer(&keep, &b) ; switch (r) { @@ -472,7 +468,7 @@ static inline void add_bundle (before_t *be, int dirfd, char const *srcdir, char static inline void add_source (before_t *be, int dirfd, char const *srcdir, char const *name) { char typestr[8] = "" ; - register size_t r ; + size_t r ; if (verbosity >= 2) strerr_warni4x("parsing ", srcdir, "/", name) ; r = openreadnclose_at(dirfd, "type", typestr, 8) ; if (!r) @@ -482,9 +478,9 @@ static inline void add_source (before_t *be, int dirfd, char const *srcdir, char } if (typestr[r-1] == '\n') r-- ; typestr[r++] = 0 ; - if (!str_diff(typestr, "oneshot")) add_oneshot(be, dirfd, srcdir, name) ; - else if (!str_diff(typestr, "longrun")) add_longrun(be, dirfd, srcdir, name) ; - else if (!str_diff(typestr, "bundle")) add_bundle(be, dirfd, srcdir, name) ; + if (!strcmp(typestr, "oneshot")) add_oneshot(be, dirfd, srcdir, name) ; + else if (!strcmp(typestr, "longrun")) add_longrun(be, dirfd, srcdir, name) ; + else if (!strcmp(typestr, "bundle")) add_bundle(be, dirfd, srcdir, name) ; else strerr_dief6x(1, "invalid ", srcdir, "/", name, "/type", ": must be oneshot, longrun, or bundle") ; } @@ -505,11 +501,11 @@ static inline void add_sources (before_t *be, char const *srcdir) d = readdir(dir) ; if (!d) break ; if (d->d_name[0] == '.') continue ; - if (d->d_name[str_chr(d->d_name, '\n')]) + if (strchr(d->d_name, '\n')) strerr_dief3x(1, "subdirectory of ", srcdir, " contains a newline character") ; check_identifier(srcdir, d->d_name) ; satmp.len = cur ; - if (!stralloc_catb(&satmp, d->d_name, str_len(d->d_name) + 1)) dienomem() ; + if (!stralloc_catb(&satmp, d->d_name, strlen(d->d_name) + 1)) dienomem() ; if (stat(satmp.s + start, &st) < 0) strerr_diefu2sys(111, "stat ", satmp.s + start) ; if (!S_ISDIR(st.st_mode)) continue ; @@ -589,7 +585,7 @@ static void resolve_bundle_rec (bundle_recinfo_t *recinfo, unsigned int i) for (; j < me->n ; j++) { unsigned int id ; - register nameinfo_t const *p ; + nameinfo_t const *p ; avltree_search(&names_map, data.s + listindex[j], &id) ; p = genalloc_s(nameinfo_t, &nameinfo) + id ; switch (p->type) @@ -618,8 +614,8 @@ static inline unsigned int resolve_bundles (bundle_t const *oldb, bundle_t *newb unsigned char mark[nbundles] ; bundle_recinfo_t recinfo = { .oldb = oldb, .newb = newb, .n = nshort + nlong, .nlong = nlong, .nbits = bitarray_div8(nshort + nlong), .indices = indices, .barray = barray, .mark = mark } ; if (verbosity >= 2) strerr_warni1x("resolving bundle names") ; - byte_zero(barray, recinfo.nbits * nbundles) ; - byte_zero(mark, nbundles) ; + memset(barray, 0, recinfo.nbits * nbundles) ; + memset(mark, 0, nbundles) ; for (; i < nbundles ; i++) { newb[i].name = oldb[i].name ; @@ -635,7 +631,7 @@ static inline unsigned int resolve_bundles (bundle_t const *oldb, bundle_t *newb return total ; } -static inline void flatlist_bundles (bundle_t *bundles, unsigned int nbundles, unsigned int nbits, unsigned char const *barray, uint32 *bdeps) +static inline void flatlist_bundles (bundle_t *bundles, unsigned int nbundles, unsigned int nbits, unsigned char const *barray, uint32_t *bdeps) { unsigned int i = 0 ; if (verbosity >= 3) strerr_warni1x("converting bundle array") ; @@ -655,7 +651,7 @@ static void resolve_deps (common_t const *me, unsigned int nlong, unsigned int n for (; j < me->ndeps ; j++) { unsigned int id ; - register nameinfo_t const *p ; + nameinfo_t const *p ; avltree_search(&names_map, data.s + indices[me->depindex + j], &id) ; p = genalloc_s(nameinfo_t, &nameinfo) + id ; switch (p->type) @@ -693,10 +689,10 @@ static void resolve_deps (common_t const *me, unsigned int nlong, unsigned int n } } -static uint32 resolve_prodcons (longrun_t const *longruns, unsigned int i, int h, uint32 nlong) +static uint32_t resolve_prodcons (longrun_t const *longruns, unsigned int i, int h, uint32_t nlong) { unsigned int j ; - register nameinfo_t const *p ; + nameinfo_t const *p ; if (!longruns[i].pipeline[h]) return nlong ; avltree_search(&names_map, data.s + longruns[i].pipeline[h], &j) ; p = genalloc_s(nameinfo_t, &nameinfo) + j ; @@ -705,7 +701,7 @@ static uint32 resolve_prodcons (longrun_t const *longruns, unsigned int i, int h case SVTYPE_LONGRUN : { unsigned int k ; - register nameinfo_t const *q ; + nameinfo_t const *q ; avltree_search(&names_map, data.s + longruns[p->i].pipeline[!h], &k) ; q = genalloc_s(nameinfo_t, &nameinfo) + k ; if (q->type != SVTYPE_LONGRUN) goto err ; @@ -741,7 +737,7 @@ static inline unsigned int resolve_services (s6rc_db_t *db, before_t const *be, unsigned int total[2] = { 0, 0 } ; unsigned int i = 0 ; if (verbosity >= 2) strerr_warni1x("resolving service names") ; - byte_zero(sarray, nbits * n) ; + memset(sarray, 0, nbits * n) ; for (; i < db->nlong ; i++) { srcdirs[i] = longruns[i].srcdir ; @@ -784,7 +780,7 @@ static inline void flatlist_services (s6rc_db_t *db, unsigned char const *sarray unsigned int nbits = bitarray_div8(n) ; diuint32 problem ; unsigned int i = 0 ; - register int r ; + int r ; if (verbosity >= 3) strerr_warni1x("converting service dependency array") ; for (; i < n ; i++) { @@ -825,12 +821,12 @@ static void cleanup (char const *compiled) static void auto_dir (char const *compiled, char const *dir) { - size_t clen = str_len(compiled) ; - size_t dlen = str_len(dir) ; + size_t clen = strlen(compiled) ; + size_t dlen = strlen(dir) ; char fn[clen + dlen + 2] ; - byte_copy(fn, clen, compiled) ; + memcpy(fn, compiled, clen) ; fn[clen] = dlen ? '/' : 0 ; - byte_copy(fn + clen + 1, dlen + 1, dir) ; + memcpy(fn + clen + 1, dir, dlen + 1) ; if (mkdir(fn, 0755) < 0) { cleanup(compiled) ; @@ -840,12 +836,12 @@ static void auto_dir (char const *compiled, char const *dir) static void auto_file (char const *compiled, char const *file, char const *s, unsigned int n) { - size_t clen = str_len(compiled) ; - size_t flen = str_len(file) ; + size_t clen = strlen(compiled) ; + size_t flen = strlen(file) ; char fn[clen + flen + 2] ; - byte_copy(fn, clen, compiled) ; + memcpy(fn, compiled, clen) ; fn[clen] = '/' ; - byte_copy(fn + clen + 1, flen + 1, file) ; + memcpy(fn + clen + 1, file, flen + 1) ; if (!openwritenclose_unsafe(fn, s, n)) { cleanup(compiled) ; @@ -855,12 +851,12 @@ static void auto_file (char const *compiled, char const *file, char const *s, un static void auto_symlink (char const *compiled, char const *name, char const *target) { - size_t clen = str_len(compiled) ; - size_t flen = str_len(name) ; + size_t clen = strlen(compiled) ; + size_t flen = strlen(name) ; char fn[clen + flen + 2] ; - byte_copy(fn, clen, compiled) ; + memcpy(fn, compiled, clen) ; fn[clen] = '/' ; - byte_copy(fn + clen + 1, flen + 1, name) ; + memcpy(fn + clen + 1, name, flen + 1) ; if (symlink(target, fn) < 0) { cleanup(compiled) ; @@ -870,12 +866,12 @@ static void auto_symlink (char const *compiled, char const *name, char const *ta static void auto_rights (char const *compiled, char const *file, mode_t mode) { - size_t clen = str_len(compiled) ; - size_t flen = str_len(file) ; + size_t clen = strlen(compiled) ; + size_t flen = strlen(file) ; char fn[clen + flen + 2] ; - byte_copy(fn, clen, compiled) ; + memcpy(fn, compiled, clen) ; fn[clen] = '/' ; - byte_copy(fn + clen + 1, flen + 1, file) ; + memcpy(fn + clen + 1, file, flen + 1) ; if (chmod(fn, mode) < 0) { cleanup(compiled) ; @@ -905,34 +901,34 @@ static inline void write_sizes (char const *compiled, s6rc_db_t const *db) auto_file(compiled, "n", pack, 20) ; } -static void make_skel (char const *compiled, char const *name, uint64 const *uids, unsigned int uidn, gid_t const *gids, unsigned int gidn, unsigned int notif) +static void make_skel (char const *compiled, char const *name, uid_t const *uids, size_t uidn, gid_t const *gids, size_t gidn, unsigned int notif) { - size_t namelen = str_len(name) ; + size_t namelen = strlen(name) ; char fmt[UINT_FMT] ; size_t i = uint_fmt(fmt, notif) ; fmt[i++] = '\n' ; char fn[namelen + 29] ; - byte_copy(fn, 12, "servicedirs/") ; - byte_copy(fn + 12, namelen + 1, name) ; + memcpy(fn, "servicedirs/", 12) ; + memcpy(fn + 12, name, namelen + 1) ; auto_dir(compiled, fn) ; - byte_copy(fn + 12 + namelen, 17, "/notification-fd") ; + memcpy(fn + 12 + namelen, "/notification-fd", 17) ; auto_file(compiled, fn, fmt, i) ; - byte_copy(fn + 13 + namelen, 5, "data") ; + memcpy(fn + 13 + namelen, "data", 5) ; auto_dir(compiled, fn) ; - byte_copy(fn + 17 + namelen, 7, "/rules") ; + memcpy(fn + 17 + namelen, "/rules", 7) ; auto_dir(compiled, fn) ; if (gidn) { - byte_copy(fn + 23 + namelen, 5, "/gid") ; + memcpy(fn + 23 + namelen, "/gid", 5) ; auto_dir(compiled, fn) ; } - byte_copy(fn + 23 + namelen, 5, "/uid") ; + memcpy(fn + 23 + namelen, "/uid", 5) ; auto_dir(compiled, fn) ; } -static inline void write_oneshot_runner (char const *compiled, uint64 const *uids, unsigned int uidn, gid_t const *gids, unsigned int gidn) +static inline void write_oneshot_runner (char const *compiled, uid_t const *uids, size_t uidn, gid_t const *gids, size_t gidn) { - unsigned int i ; + size_t i ; char fn[34 + sizeof(S6RC_ONESHOT_RUNNER)] = "servicedirs/" S6RC_ONESHOT_RUNNER "/data/rules/gid/" ; make_skel(compiled, S6RC_ONESHOT_RUNNER, uids, uidn, gids, gidn, 3) ; if (gidn) @@ -943,7 +939,7 @@ static inline void write_oneshot_runner (char const *compiled, uint64 const *uid size_t len = gid_fmt(fn + 28 + S6RC_ONESHOT_RUNNER_LEN, gids[i]) ; fn[28 + S6RC_ONESHOT_RUNNER_LEN + len] = 0 ; auto_dir(compiled, fn) ; - byte_copy(fn + 28 + S6RC_ONESHOT_RUNNER_LEN + len, 7, "/allow") ; + memcpy(fn + 28 + S6RC_ONESHOT_RUNNER_LEN + len, "/allow", 7) ; auto_file(compiled, fn, "", 0) ; } } @@ -951,10 +947,10 @@ static inline void write_oneshot_runner (char const *compiled, uint64 const *uid i = uidn ; while (i--) { - size_t len = uint64_fmt(fn + 28 + S6RC_ONESHOT_RUNNER_LEN, uids[i]) ; + size_t len = uid_fmt(fn + 28 + S6RC_ONESHOT_RUNNER_LEN, uids[i]) ; fn[28 + S6RC_ONESHOT_RUNNER_LEN + len] = 0 ; auto_dir(compiled, fn) ; - byte_copy(fn + 28 + S6RC_ONESHOT_RUNNER_LEN + len, 7, "/allow") ; + memcpy(fn + 28 + S6RC_ONESHOT_RUNNER_LEN + len, "/allow", 7) ; auto_file(compiled, fn, "", 0) ; } auto_file(compiled, "servicedirs/" S6RC_ONESHOT_RUNNER "/run", S6RC_ONESHOT_RUNNER_RUNSCRIPT, sizeof(S6RC_ONESHOT_RUNNER_RUNSCRIPT) - 1) ; @@ -965,22 +961,22 @@ static inline int write_pipelines (stralloc *sa, s6rc_db_t const *db) { uint32_t i = db->nlong ; unsigned char black[bitarray_div8(db->nlong)] ; - byte_zero(black, bitarray_div8(db->nlong)) ; + memset(black, 0, bitarray_div8(db->nlong)) ; while (i--) if (!bitarray_peek(black, i)) { uint32_t j = i ; for (;;) { - register uint32_t k = db->services[j].x.longrun.pipeline[0] ; + uint32_t k = db->services[j].x.longrun.pipeline[0] ; if (k >= db->nlong) break ; j = k ; } for (;;) { - register uint32_t k = db->services[j].x.longrun.pipeline[1] ; + uint32_t k = db->services[j].x.longrun.pipeline[1] ; bitarray_set(black, j) ; if (k >= db->nlong) break ; - if (!string_quote(sa, db->string + db->services[k].name, str_len(db->string + db->services[k].name)) + if (!string_quote(sa, db->string + db->services[k].name, strlen(db->string + db->services[k].name)) || !stralloc_catb(sa, " ", 1)) return 0 ; j = k ; } @@ -988,35 +984,35 @@ static inline int write_pipelines (stralloc *sa, s6rc_db_t const *db) return 1 ; } -static inline void write_fdholder (char const *compiled, s6rc_db_t const *db, uint64 const *uids, unsigned int uidn, gid_t const *gids, unsigned int gidn, char const *fdhuser) +static inline void write_fdholder (char const *compiled, s6rc_db_t const *db, uid_t const *uids, size_t uidn, gid_t const *gids, size_t gidn, char const *fdhuser) { size_t base = satmp.len ; make_skel(compiled, S6RC_FDHOLDER, uids, uidn, gids, gidn, 1) ; { - char fn[62 + S6RC_FDHOLDER_LEN + UINT64_FMT] = "servicedirs/" S6RC_FDHOLDER "/data/rules/uid/" ; - char fmt[7 + UINT64_FMT] = "../uid/" ; - size_t i = uint64_fmt(fmt + 7, uids[0]) ; + char fn[62 + S6RC_FDHOLDER_LEN + UID_FMT] = "servicedirs/" S6RC_FDHOLDER "/data/rules/uid/" ; + char fmt[7 + UID_FMT] = "../uid/" ; + size_t i = uid_fmt(fmt + 7, uids[0]) ; fmt[7 + i] = 0 ; - byte_copy(fn + 28 + S6RC_FDHOLDER_LEN, i + 1, fmt + 7) ; + memcpy(fn + 28 + S6RC_FDHOLDER_LEN, fmt + 7, i + 1) ; auto_dir(compiled, fn) ; - byte_copy(fn + 28 + S6RC_FDHOLDER_LEN + i, 7, "/allow") ; + memcpy(fn + 28 + S6RC_FDHOLDER_LEN + i, "/allow", 7) ; auto_file(compiled, fn, "", 0) ; - byte_copy(fn + 29 + S6RC_FDHOLDER_LEN + i, 4, "env") ; + memcpy(fn + 29 + S6RC_FDHOLDER_LEN + i, "env", 4) ; auto_dir(compiled, fn) ; - byte_copy(fn + 32 + S6RC_FDHOLDER_LEN + i, 18, "/S6_FDHOLDER_LIST") ; + memcpy(fn + 32 + S6RC_FDHOLDER_LEN + i, "/S6_FDHOLDER_LIST", 18) ; auto_file(compiled, fn, "\n", 1) ; - byte_copy(fn + 45 + S6RC_FDHOLDER_LEN + i, 12, "STORE_REGEX") ; + memcpy(fn + 45 + S6RC_FDHOLDER_LEN + i, "STORE_REGEX", 12) ; auto_file(compiled, fn, "^pipe:s6rc-\n", 12) ; - byte_copy(fn + 45 + S6RC_FDHOLDER_LEN + i, 15, "RETRIEVE_REGEX") ; + memcpy(fn + 45 + S6RC_FDHOLDER_LEN + i, "RETRIEVE_REGEX", 15) ; auto_symlink(compiled, fn, "S6_FDHOLDER_STORE_REGEX") ; - byte_copy(fn + 45 + S6RC_FDHOLDER_LEN + i, 8, "SETDUMP") ; + memcpy(fn + 45 + S6RC_FDHOLDER_LEN + i, "SETDUMP", 8) ; auto_file(compiled, fn, "\n", 1) ; fn[45 + S6RC_FDHOLDER_LEN + i] = 'G' ; auto_file(compiled, fn, "\n", 1) ; for (i = 1 ; i < uidn ; i++) { - size_t len = uint64_fmt(fn + 28 + S6RC_FDHOLDER_LEN, uids[i]) ; + size_t len = uid_fmt(fn + 28 + S6RC_FDHOLDER_LEN, uids[i]) ; fn[28 + S6RC_FDHOLDER_LEN + len] = 0 ; auto_symlink(compiled, fn, fmt + 7) ; } @@ -1045,7 +1041,7 @@ static inline void write_fdholder (char const *compiled, s6rc_db_t const *db, ui if (fdhuser) { if (!stralloc_cats(&satmp, S6_EXTBINPREFIX "s6-envuidgid -i -- ") - || !string_quote(&satmp, fdhuser, str_len(fdhuser)) + || !string_quote(&satmp, fdhuser, strlen(fdhuser)) || !stralloc_catb(&satmp, "\n", 1)) dienomem() ; } if (!stralloc_cats(&satmp, S6_EXTBINPREFIX "s6-fdholder-daemon -1 ")) dienomem() ; @@ -1059,22 +1055,22 @@ static inline void write_fdholder (char const *compiled, s6rc_db_t const *db, ui auto_rights(compiled, "servicedirs/" S6RC_FDHOLDER "/run", 0755) ; } -static inline void write_specials (char const *compiled, s6rc_db_t const *db, uint64 const *uids, unsigned int uidn, gid_t const *gids, unsigned int gidn, char const *fdhuser) +static inline void write_specials (char const *compiled, s6rc_db_t const *db, uid_t const *uids, size_t uidn, gid_t const *gids, size_t gidn, char const *fdhuser) { write_oneshot_runner(compiled, uids, uidn, gids, gidn) ; write_fdholder(compiled, db, uids, uidn, gids, gidn, fdhuser) ; } -static inline void write_resolve (char const *compiled, s6rc_db_t const *db, bundle_t const *bundles, unsigned int nbundles, uint32 const *bdeps) +static inline void write_resolve (char const *compiled, s6rc_db_t const *db, bundle_t const *bundles, unsigned int nbundles, uint32_t const *bdeps) { - size_t clen = str_len(compiled) ; + size_t clen = strlen(compiled) ; int fd ; struct cdb_make c = CDB_MAKE_ZERO ; unsigned int i = db->nshort + db->nlong ; char fn[clen + 13] ; if (verbosity >= 3) strerr_warni3x("writing ", compiled, "/resolve.cdb") ; - byte_copy(fn, clen, compiled) ; - byte_copy(fn + clen, 13, "/resolve.cdb") ; + memcpy(fn, compiled, clen) ; + memcpy(fn + clen, "/resolve.cdb", 13) ; fd = open_trunc(fn) ; if (fd < 0 || ndelay_off(fd) < 0) { @@ -1092,7 +1088,7 @@ static inline void write_resolve (char const *compiled, s6rc_db_t const *db, bun { char pack[4] ; uint32_pack_big(pack, i) ; - if (cdb_make_add(&c, db->string + db->services[i].name, str_len(db->string + db->services[i].name), pack, 4) < 0) + if (cdb_make_add(&c, db->string + db->services[i].name, strlen(db->string + db->services[i].name), pack, 4) < 0) { cleanup(compiled) ; strerr_diefu1sys(111, "cdb_make_add") ; @@ -1107,7 +1103,7 @@ static inline void write_resolve (char const *compiled, s6rc_db_t const *db, bun char pack[(bundles[i].n << 2) + 1] ; /* +1 because braindead C standard */ for (; j < bundles[i].n ; j++) uint32_pack_big(pack + (j << 2), bdeps[bundles[i].listindex + j]) ; - if (cdb_make_add(&c, data.s + bundles[i].name, str_len(data.s + bundles[i].name), pack, bundles[i].n << 2) < 0) + if (cdb_make_add(&c, data.s + bundles[i].name, strlen(data.s + bundles[i].name), pack, bundles[i].n << 2) < 0) { cleanup(compiled) ; strerr_diefu1sys(111, "cdb_make_add") ; @@ -1151,7 +1147,7 @@ static inline void write_exe_wrapper (char const *compiled, char const *fn, s6rc if (db->services[i].x.longrun.pipeline[0] < db->nlong) { if (!stralloc_cats(&satmp, S6_EXTBINPREFIX "s6-fdholder-retrieve ../s6rc-fdholder/s \"pipe:s6rc-r-") - || !string_quote_nodelim(&satmp, db->string + db->services[i].name, str_len(db->string + db->services[i].name)) + || !string_quote_nodelim(&satmp, db->string + db->services[i].name, strlen(db->string + db->services[i].name)) || !stralloc_cats(&satmp, "\"\n")) dienomem() ; } if (db->services[i].x.longrun.pipeline[1] < db->nlong) @@ -1161,7 +1157,7 @@ static inline void write_exe_wrapper (char const *compiled, char const *fn, s6rc || !stralloc_cats(&satmp, fd == 3 ? "4" : "3") || !stralloc_cats(&satmp, " 0\n" S6_EXTBINPREFIX "s6-fdholder-retrieve ../s6rc-fdholder/s \"pipe:s6rc-w-") - || !string_quote_nodelim(&satmp, consumername, str_len(consumername)) + || !string_quote_nodelim(&satmp, consumername, strlen(consumername)) || !stralloc_cats(&satmp, "\"\n" EXECLINE_EXTBINPREFIX "fdmove 1 0\n" EXECLINE_EXTBINPREFIX "fdmove 0 ") @@ -1179,31 +1175,30 @@ static inline void write_exe_wrapper (char const *compiled, char const *fn, s6rc static inline void write_servicedirs (char const *compiled, s6rc_db_t const *db, char const *const *srcdirs) { - size_t clen = str_len(compiled) ; + size_t clen = strlen(compiled) ; unsigned int i = 2 ; if (verbosity >= 3) strerr_warni3x("writing ", compiled, "/servicedirs") ; for (; i < db->nlong ; i++) { - struct stat st ; - size_t srcdirlen = str_len(srcdirs[i]) ; - size_t len = str_len(db->string + db->services[i].name) ; + size_t srcdirlen = strlen(srcdirs[i]) ; + size_t len = strlen(db->string + db->services[i].name) ; unsigned int fd = 0 ; int ispipelined = db->services[i].x.longrun.pipeline[0] < db->nlong || db->services[i].x.longrun.pipeline[1] < db->nlong ; - register int r ; + int r ; char srcfn[srcdirlen + len + 18] ; char dstfn[clen + len + 30] ; - byte_copy(dstfn, clen, compiled) ; - byte_copy(dstfn + clen, 13, "/servicedirs/") ; - byte_copy(dstfn + clen + 13, len + 1, db->string + db->services[i].name) ; + memcpy(dstfn, compiled, clen) ; + memcpy(dstfn + clen, "/servicedirs/", 13) ; + memcpy(dstfn + clen + 13, db->string + db->services[i].name, len + 1) ; if (mkdir(dstfn, 0755) < 0) { cleanup(compiled) ; strerr_diefu2sys(111, "mkdir ", dstfn) ; } - byte_copy(srcfn, srcdirlen, srcdirs[i]) ; + memcpy(srcfn, srcdirs[i], srcdirlen) ; srcfn[srcdirlen] = '/' ; - byte_copy(srcfn + srcdirlen + 1, len, db->string + db->services[i].name) ; - byte_copy(srcfn + srcdirlen + 1 + len, 17, "/notification-fd") ; + memcpy(srcfn + srcdirlen + 1, db->string + db->services[i].name, len) ; + memcpy(srcfn + srcdirlen + 1 + len, "/notification-fd", 17) ; r = s6rc_read_uint(srcfn, &fd) ; if (r < 0) { @@ -1215,7 +1210,7 @@ static inline void write_servicedirs (char const *compiled, s6rc_db_t const *db, char fmt[UINT_FMT] ; size_t fmtlen = uint_fmt(fmt, fd) ; fmt[fmtlen++] = '\n' ; - byte_copy(dstfn + clen + 13 + len, 17, "/notification-fd") ; + memcpy(dstfn + clen + 13 + len, "/notification-fd", 17) ; if (!openwritenclose_unsafe(dstfn, fmt, fmtlen)) { cleanup(compiled) ; @@ -1223,12 +1218,12 @@ static inline void write_servicedirs (char const *compiled, s6rc_db_t const *db, } } - byte_copy(srcfn + srcdirlen + 1 + len, 5, "/run") ; - byte_copy(dstfn + clen + 13 + len, 5, "/run") ; + memcpy(srcfn + srcdirlen + 1 + len, "/run", 5) ; + memcpy(dstfn + clen + 13 + len, "/run", 5) ; if (ispipelined) { write_exe_wrapper(compiled, dstfn + clen + 1, db, i, fd, "run", 0) ; - byte_copy(dstfn + clen + 17 + len, 6, ".user") ; + memcpy(dstfn + clen + 17 + len, ".user", 6) ; } if (!filecopy_unsafe(srcfn, dstfn, 0755)) { @@ -1236,14 +1231,14 @@ static inline void write_servicedirs (char const *compiled, s6rc_db_t const *db, strerr_diefu4sys(111, "copy ", srcfn, " to ", dstfn) ; } - byte_copy(srcfn + srcdirlen + len + 2, 7, "finish") ; + memcpy(srcfn + srcdirlen + len + 2, "finish", 7) ; if (access(srcfn, R_OK) == 0) { - byte_copy(dstfn + clen + 14 + len, 7, "finish") ; + memcpy(dstfn + clen + 14 + len, "finish", 7) ; if (ispipelined) { write_exe_wrapper(compiled, dstfn + clen + 1, db, i, fd, "finish", 1) ; - byte_copy(dstfn + clen + 20 + len, 6, ".user") ; + memcpy(dstfn + clen + 20 + len, ".user", 6) ; } if (!filecopy_unsafe(srcfn, dstfn, 0755)) { @@ -1252,38 +1247,20 @@ static inline void write_servicedirs (char const *compiled, s6rc_db_t const *db, } } - byte_copy(srcfn + srcdirlen + len + 2, 15, "timeout-finish") ; - byte_copy(dstfn + clen + 14 + len, 15, "timeout-finish") ; + memcpy(srcfn + srcdirlen + len + 2, "timeout-finish", 15) ; + memcpy(dstfn + clen + 14 + len, "timeout-finish", 15) ; filecopy_unsafe(srcfn, dstfn, 0644) ; - byte_copy(srcfn + srcdirlen + len + 2, 9, "nosetsid") ; - if (stat(srcfn, &st) < 0) - { - if (errno != ENOENT) - { - cleanup(compiled) ; - strerr_diefu2sys(111, "stat ", srcfn) ; - } - } - else - { - int fd ; - byte_copy(dstfn + clen + 14 + len, 9, "nosetsid") ; - fd = open_trunc(dstfn) ; - if (fd < 0) - { - cleanup(compiled) ; - strerr_diefu2sys(111, "touch ", dstfn) ; - } - close(fd) ; - } + memcpy(srcfn + srcdirlen + len + 2, "nosetsid", 9) ; + memcpy(dstfn + clen + 14 + len, "nosetsid", 9) ; + filecopy_unsafe(srcfn, dstfn, 0644) ; - byte_copy(dstfn + clen + 14 + len, 5, "data") ; - byte_copy(srcfn + srcdirlen + len + 2, 5, "data") ; + memcpy(srcfn + srcdirlen + len + 2, "data", 5) ; + memcpy(dstfn + clen + 14 + len, "data", 5) ; dircopy(compiled, srcfn, dstfn) ; - byte_copy(dstfn + clen + 14 + len, 4, "env") ; - byte_copy(srcfn + srcdirlen + len + 2, 4, "env") ; + memcpy(srcfn + srcdirlen + len + 2, "env", 4) ; + memcpy(dstfn + clen + 14 + len, "env", 4) ; dircopy(compiled, srcfn, dstfn) ; } } @@ -1320,13 +1297,13 @@ static inline int write_service (buffer *b, s6rc_service_t const *sv, int type) static inline void write_db (char const *compiled, s6rc_db_t const *db) { - size_t clen = str_len(compiled) ; + size_t clen = strlen(compiled) ; buffer b ; int fd ; char buf[4096] ; char dbfn[clen + 4] ; - byte_copy(dbfn, clen, compiled) ; - byte_copy(dbfn + clen, 4, "/db") ; + memcpy(dbfn, compiled, clen) ; + memcpy(dbfn + clen, "/db", 4) ; if (verbosity >= 3) strerr_warni2x("writing ", dbfn) ; fd = open_trunc(dbfn) ; if (fd < 0) @@ -1339,7 +1316,7 @@ static inline void write_db (char const *compiled, s6rc_db_t const *db) cleanup(compiled) ; strerr_diefu2sys(111, "ndelay_off ", dbfn) ; } - buffer_init(&b, &fd_writesv, fd, buf, 4096) ; + buffer_init(&b, &buffer_write, fd, buf, 4096) ; if (buffer_put(&b, S6RC_DB_BANNER_START, S6RC_DB_BANNER_START_LEN) < 0) goto err ; @@ -1382,11 +1359,11 @@ static inline void write_compiled ( char const *const *srcdirs, bundle_t const *bundles, unsigned int nbundles, - uint32 const *bdeps, - uint64 const *uids, - unsigned int uidn, + uint32_t const *bdeps, + uid_t const *uids, + size_t uidn, gid_t const *gids, - unsigned int gidn, + size_t gidn, char const *fdhuser) { if (verbosity >= 2) strerr_warni2x("writing compiled information to ", compiled) ; @@ -1404,20 +1381,20 @@ int main (int argc, char const *const *argv) before_t before = BEFORE_ZERO ; char const *compiled ; char const *fdhuser = 0 ; - unsigned int uidn = 0, gidn = 0 ; - uint64 uids[256] ; + size_t uidn = 0, gidn = 0 ; + uid_t uids[256] ; gid_t gids[256] ; PROG = "s6-rc-compile" ; { subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { - register int opt = subgetopt_r(argc, argv, "v:u:g:h:", &l) ; + int opt = subgetopt_r(argc, argv, "v:u:g:h:", &l) ; if (opt == -1) break ; switch (opt) { case 'v' : if (!uint0_scan(l.arg, &verbosity)) dieusage() ; break ; - case 'u' : if (!uint64_scanlist(uids, 255, l.arg, &uidn)) dieusage() ; break ; + case 'u' : if (!uid_scanlist(uids, 255, l.arg, &uidn)) dieusage() ; break ; case 'g' : if (!gid_scanlist(gids, 255, l.arg, &gidn)) dieusage() ; break ; case 'h' : fdhuser = l.arg ; break ; default : dieusage() ; @@ -1452,7 +1429,7 @@ int main (int argc, char const *const *argv) bundle_t bundles[nbundles] ; unsigned char barray[nbits * nbundles] ; unsigned int nbdeps = resolve_bundles(genalloc_s(bundle_t, &before.bundles), bundles, db.nshort, db.nlong, nbundles, genalloc_s(unsigned int, &before.indices), barray) ; - uint32 bdeps[nbdeps] ; + uint32_t bdeps[nbdeps] ; genalloc_free(bundle_t, &before.bundles) ; flatlist_bundles(bundles, nbundles, nbits, barray, bdeps) ; diff --git a/src/s6-rc/s6-rc-db.c b/src/s6-rc/s6-rc-db.c index 01a0ccc..8e4b92a 100644 --- a/src/s6-rc/s6-rc-db.c +++ b/src/s6-rc/s6-rc-db.c @@ -1,10 +1,9 @@ /* ISC license. */ -#include +#include #include #include #include -#include #include #include #include @@ -25,11 +24,11 @@ static void print_bundle_contents (char const *name) { cdb_t c = CDB_ZERO ; int fd = open_readatb(fdcompiled, "resolve.cdb") ; - register int r ; + int r ; if (fd < 0) strerr_diefu3sys(111, "open ", compiled, "/resolve.cdb") ; if (!cdb_init_map(&c, fd, 1)) strerr_diefu3sys(111, "cdb_init ", compiled, "/resolve.cdb") ; - r = cdb_find(&c, name, str_len(name)) ; + r = cdb_find(&c, name, strlen(name)) ; if (r < 0) strerr_diefu3sys(111, "read ", compiled, "/resolve.cdb") ; if (!r) strerr_dief3x(3, name, " is not a valid identifier in ", compiled) ; if (cdb_datalen(&c) == 4) @@ -41,7 +40,7 @@ static void print_bundle_contents (char const *name) uint32_unpack_big(pack, &x) ; if (x >= db->nshort + db->nlong) strerr_dief2x(4, "invalid database in ", compiled) ; - if (!str_diff(name, db->string + db->services[x].name)) + if (!strcmp(name, db->string + db->services[x].name)) strerr_dief5x(5, "in database ", compiled, ": identifier ", name, " represents an atomic service") ; if (buffer_puts(buffer_1, db->string + db->services[x].name) < 0 || buffer_put(buffer_1, "\n", 1) < 0) @@ -49,9 +48,9 @@ static void print_bundle_contents (char const *name) } else { - unsigned int len = cdb_datalen(&c) >> 2 ; + uint32_t len = cdb_datalen(&c) >> 2 ; char pack[cdb_datalen(&c) + 1] ; - register char const *p = pack ; + char const *p = pack ; if (cdb_datalen(&c) & 3) strerr_dief2x(4, "invalid database in ", compiled) ; if (cdb_read(&c, pack, cdb_datalen(&c), cdb_datapos(&c)) < 0) @@ -63,7 +62,7 @@ static void print_bundle_contents (char const *name) if (x >= db->nshort + db->nlong) strerr_dief2x(4, "invalid database in ", compiled) ; if (buffer_puts(buffer_1, db->string + db->services[x].name) < 0 - || buffer_put(buffer_1, "\n", 1) < 0) + || buffer_put(buffer_1, "\n", 1) < 1) strerr_diefu1sys(111, "write to stdout") ; } } @@ -78,7 +77,7 @@ static void print_services (unsigned int from, unsigned int to) for (; from < to ; from++) { if (buffer_puts(buffer_1, db->string + db->services[from].name) < 0 - || buffer_put(buffer_1, "\n", 1) < 0) + || buffer_put(buffer_1, "\n", 1) < 1) strerr_diefu1sys(111, "write to stdout") ; } if (!buffer_flush(buffer_1)) @@ -96,7 +95,7 @@ static void print_all (int bundlesonly) cdb_traverse_init(&c, &kpos) ; for (;;) { - register int r = cdb_nextkey(&c, &kpos) ; + int r = cdb_nextkey(&c, &kpos) ; char name[cdb_keylen(&c) + 1] ; if (r < 0) strerr_diefu3sys(111, "read ", compiled, "/resolve.cdb") ; if (!r) break ; @@ -111,7 +110,7 @@ static void print_all (int bundlesonly) uint32_unpack_big(pack, &x) ; if (x >= db->nshort + db->nlong) strerr_dief2x(4, "invalid database in ", compiled) ; - if (!byte_diff(name, cdb_keylen(&c), db->string + db->services[x].name) + if (!memcmp(name, db->string + db->services[x].name, cdb_keylen(&c)) && !db->string[db->services[x].name + cdb_keylen(&c)]) continue ; } @@ -131,11 +130,11 @@ static unsigned int resolve_service (char const *name) int fd = open_readatb(fdcompiled, "resolve.cdb") ; uint32_t x ; char pack[4] ; - register int r ; + int r ; if (fd < 0) strerr_diefu3sys(111, "open ", compiled, "/resolve.cdb") ; if (!cdb_init_map(&c, fd, 1)) strerr_diefu3sys(111, "cdb_init ", compiled, "/resolve.cdb") ; - r = cdb_find(&c, name, str_len(name)) ; + r = cdb_find(&c, name, strlen(name)) ; if (r < 0) strerr_diefu3sys(111, "read ", compiled, "/resolve.cdb") ; if (!r) strerr_dief3x(3, name, " is not a valid identifier in ", compiled) ; if (cdb_datalen(&c) != 4) return db->nshort + db->nlong ; @@ -146,7 +145,7 @@ static unsigned int resolve_service (char const *name) close(fd) ; if (x >= db->nshort + db->nlong) strerr_dief2x(4, "invalid database in ", compiled) ; - if (str_diff(name, db->string + db->services[x].name)) + if (strcmp(name, db->string + db->services[x].name)) x = db->nshort + db->nlong ; return x ; } @@ -186,7 +185,7 @@ static void print_script (char const *name, int h) argc = db->services[n].x.oneshot.argc[h] ; while (argc--) if (buffer_puts(buffer_1, *argv++) < 0 - || buffer_put(buffer_1, "\0", 1) < 0) + || buffer_put(buffer_1, "\0", 1) < 1) strerr_diefu1sys(111, "write to stdout") ; if (!buffer_flush(buffer_1)) strerr_diefu1sys(111, "write to stdout") ; @@ -199,13 +198,13 @@ static inline void print_pipeline (char const *name) strerr_dief5x(5, "in database ", compiled, ": identifier ", name, " does not represent a longrun") ; for (;;) { - register unsigned int j = db->services[n].x.longrun.pipeline[0] ; + unsigned int j = db->services[n].x.longrun.pipeline[0] ; if (j >= db->nlong) break ; n = j ; } for (;;) { - register unsigned int j = db->services[n].x.longrun.pipeline[1] ; + unsigned int j = db->services[n].x.longrun.pipeline[1] ; if (buffer_puts(buffer_1, db->string + db->services[n].name) < 0 || buffer_put(buffer_1, "\n", 1) < 0) strerr_diefu1sys(111, "write to stdout") ; @@ -236,16 +235,16 @@ static void print_union (char const *const *argv, int h, int isdeps, int doclosu if (fd < 0) strerr_diefu3sys(111, "open ", compiled, "/resolve.cdb") ; if (!cdb_init_map(&c, fd, 1)) strerr_diefu3sys(111, "cdb_init ", compiled, "/resolve.cdb") ; - byte_zero(state, n) ; + memset(state, 0, n) ; for (; *argv ; argv++) { - register int r = cdb_find(&c, *argv, str_len(*argv)) ; + int r = cdb_find(&c, *argv, strlen(*argv)) ; if (r < 0) strerr_diefu3sys(111, "read ", compiled, "/resolve.cdb") ; if (!r) strerr_dief3x(3, *argv, " is not a valid identifier in ", compiled) ; { - unsigned int len = cdb_datalen(&c) >> 2 ; + uint32_t len = cdb_datalen(&c) >> 2 ; char pack[cdb_datalen(&c) + 1] ; - register char const *p = pack ; + char const *p = pack ; if (cdb_read(&c, pack, cdb_datalen(&c), cdb_datapos(&c)) < 0) strerr_diefu3sys(111, "cdb_read ", compiled, "/resolve.cdb") ; while (len--) @@ -256,8 +255,8 @@ static void print_union (char const *const *argv, int h, int isdeps, int doclosu strerr_dief2x(4, "invalid database in ", compiled) ; if (isdeps) { - register uint32_t ndeps = db->services[x].ndeps[h] ; - register uint32_t const *deps = db->deps + h * db->ndeps + db->services[x].deps[h] ; + uint32_t ndeps = db->services[x].ndeps[h] ; + uint32_t const *deps = db->deps + h * db->ndeps + db->services[x].deps[h] ; while (ndeps--) state[*deps++] |= 1 ; } else state[x] |= 1 ; @@ -296,8 +295,8 @@ static inline void print_help (void) static unsigned int lookup (char const *const *table, char const *command) { - register unsigned int i = 0 ; - for (; table[i] ; i++) if (!str_diff(command, table[i])) break ; + unsigned int i = 0 ; + for (; table[i] ; i++) if (!strcmp(command, table[i])) break ; return i ; } @@ -319,7 +318,7 @@ static inline unsigned int parse_command (char const *command) "all-dependencies", 0 } ; - register unsigned int i = lookup(command_table, command) ; + unsigned int i = lookup(command_table, command) ; if (!command_table[i]) dieusage() ; return i ; } @@ -335,7 +334,7 @@ static inline unsigned int parse_list (char const *command) "bundles", 0 } ; - register unsigned int i = lookup(list_table, command) ; + unsigned int i = lookup(list_table, command) ; if (!list_table[i]) dieusage() ; return i ; } @@ -350,7 +349,7 @@ int main (int argc, char const *const *argv) subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { - register int opt = subgetopt_r(argc, argv, "udl:c:", &l) ; + int opt = subgetopt_r(argc, argv, "udl:c:", &l) ; if (opt == -1) break ; switch (opt) { @@ -375,16 +374,16 @@ int main (int argc, char const *const *argv) if (what == 2) subwhat = 1 + parse_list(argv[1]) ; { - size_t livelen = str_len(live) ; + size_t livelen = strlen(live) ; int compiledlock ; s6rc_db_t dbblob ; - char compiledblob[compiled ? str_len(compiled) : livelen + 10] ; + char compiledblob[compiled ? strlen(compiled) : livelen + 10] ; db = &dbblob ; if (!compiled) { - byte_copy(compiledblob, livelen, live) ; - byte_copy(compiledblob + livelen, 10, "/compiled") ; + memcpy(compiledblob, live, livelen) ; + memcpy(compiledblob + livelen, "/compiled", 10) ; compiled = compiledblob ; } @@ -410,7 +409,7 @@ int main (int argc, char const *const *argv) char const *argvblob[dbblob.nargvs] ; uint32_t depsblob[dbblob.ndeps << 1] ; char stringblob[dbblob.stringlen] ; - register int r ; + int r ; dbblob.services = serviceblob ; dbblob.argvs = argvblob ; diff --git a/src/s6-rc/s6-rc-dryrun.c b/src/s6-rc/s6-rc-dryrun.c index 99c2c62..71ce9da 100644 --- a/src/s6-rc/s6-rc-dryrun.c +++ b/src/s6-rc/s6-rc-dryrun.c @@ -1,6 +1,6 @@ /* ISC license. */ -#include +#include #include #include #include @@ -20,7 +20,7 @@ int main (int argc, char const *const *argv) subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { - register int opt = subgetopt_r(argc, argv, "v:t:", &l) ; + int opt = subgetopt_r(argc, argv, "v:t:", &l) ; if (opt == -1) break ; switch (opt) { diff --git a/src/s6-rc/s6-rc-fdholder-filler.c b/src/s6-rc/s6-rc-fdholder-filler.c index 73283c1..22d93df 100644 --- a/src/s6-rc/s6-rc-fdholder-filler.c +++ b/src/s6-rc/s6-rc-fdholder-filler.c @@ -1,10 +1,9 @@ /* ISC license. */ -#include +#include #include #include -#include -#include +#include #include #include #include @@ -24,7 +23,7 @@ int main (int argc, char const *const *argv) subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { - register int opt = subgetopt_r(argc, argv, "1t:", &l) ; + int opt = subgetopt_r(argc, argv, "1t:", &l) ; if (opt == -1) break ; switch (opt) { @@ -50,7 +49,7 @@ int main (int argc, char const *const *argv) s6_fdholder_fd_t dump[n<<1] ; for (; i < n ; i++) { - size_t len = str_len(argv[i]) ; + size_t len = strlen(argv[i]) ; if (len + 12 > S6_FDHOLDER_ID_SIZE) { errno = ENAMETOOLONG ; @@ -62,12 +61,12 @@ int main (int argc, char const *const *argv) tain_add_g(&dump[i<<1].limit, &tain_infinite_relative) ; offset.nano = i << 1 ; tain_add(&dump[i<<1].limit, &dump[i<<1].limit, &offset) ; - byte_copy(dump[i<<1].id, 12, "pipe:s6rc-r-") ; - byte_copy(dump[i<<1].id + 12, len + 1, argv[i]) ; + memcpy(dump[i<<1].id, "pipe:s6rc-r-", 12) ; + memcpy(dump[i<<1].id + 12, argv[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) ; - byte_copy(dump[(i<<1)+1].id, 13 + len, dump[i<<1].id) ; + memcpy(dump[(i<<1)+1].id, dump[i<<1].id, 13 + len) ; dump[(i<<1)+1].id[10] = 'w' ; } if (!s6_fdholder_setdump_g(&a, dump, n << 1, &deadline)) diff --git a/src/s6-rc/s6-rc-init.c b/src/s6-rc/s6-rc-init.c index e434756..386fbe7 100644 --- a/src/s6-rc/s6-rc-init.c +++ b/src/s6-rc/s6-rc-init.c @@ -1,10 +1,10 @@ /* ISC license. */ -#include +#include +#include #include #include -#include -#include +#include #include #include #include @@ -43,7 +43,7 @@ int main (int argc, char const *const *argv) subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { - register int opt = subgetopt_r(argc, argv, "c:l:t:", &l) ; + int opt = subgetopt_r(argc, argv, "c:l:t:", &l) ; if (opt == -1) break ; switch (opt) { @@ -92,16 +92,16 @@ int main (int argc, char const *const *argv) if (!s6rc_lock(satmp.s, 2, &fdlock, 0, 0, 0)) { char tmp[satmp.len] ; - byte_copy(tmp, satmp.len, satmp.s) ; + memcpy(tmp, satmp.s, satmp.len) ; cleanup() ; strerr_diefu2sys(111, "take lock on ", tmp) ; } - byte_copy(lfn, llen, satmp.s) ; + memcpy(lfn, satmp.s, llen) ; lfn[llen] = 0 ; if (symlink(satmp.s + dirlen, lfn) < 0) { char tmp[satmp.len - dirlen] ; - byte_copy(tmp, satmp.len - dirlen, satmp.s + dirlen) ; + memcpy(tmp, satmp.s + dirlen, satmp.len - dirlen) ; cleanup() ; strerr_diefu4sys(111, "symlink ", tmp, " to ", lfn) ; } @@ -115,7 +115,7 @@ int main (int argc, char const *const *argv) cleanup() ; strerr_diefu2sys(111, "open ", compiled) ; } - byte_copy(lfn + llen, 10, "/compiled") ; + memcpy(lfn + llen, "/compiled", 10) ; if (symlink(compiled, lfn) < 0) { cleanup() ; @@ -125,7 +125,7 @@ int main (int argc, char const *const *argv) /* scandir */ - byte_copy(lfn + llen + 1, 8, "scandir") ; + memcpy(lfn + llen + 1, "scandir", 8) ; if (symlink(argv[0], lfn) < 0) { cleanup() ; @@ -135,9 +135,9 @@ int main (int argc, char const *const *argv) /* state */ - byte_copy(lfn + llen + 1, 6, "state") ; + memcpy(lfn + llen + 1, "state", 6) ; { - register int r = s6rc_db_read_sizes(fdcompiled, &db) ; + int r = s6rc_db_read_sizes(fdcompiled, &db) ; if (r <= 0) { cleanup() ; @@ -148,7 +148,7 @@ int main (int argc, char const *const *argv) n = db.nshort + db.nlong ; { char zero[n] ; - byte_zero(zero, n) ; + memset(zero, 0, n) ; if (!openwritenclose_unsafe(lfn, zero, n)) { cleanup() ; @@ -160,9 +160,9 @@ int main (int argc, char const *const *argv) /* servicedirs */ - byte_copy(lfn + llen + 1, 12, "servicedirs") ; - byte_copy(cfn, llen + 1, lfn) ; - byte_copy(cfn + llen + 1, 21, "compiled/servicedirs") ; + memcpy(lfn + llen + 1, "servicedirs", 12) ; + memcpy(cfn, lfn, llen + 1) ; + memcpy(cfn + llen + 1, "compiled/servicedirs", 21) ; if (!hiercopy(cfn, lfn)) { cleanup() ; diff --git a/src/s6-rc/s6-rc-oneshot-run.c b/src/s6-rc/s6-rc-oneshot-run.c index 6fe7255..3bb38a8 100644 --- a/src/s6-rc/s6-rc-oneshot-run.c +++ b/src/s6-rc/s6-rc-oneshot-run.c @@ -1,9 +1,9 @@ /* ISC license. */ -#include +#include +#include #include -#include -#include +#include #include #include #include @@ -23,7 +23,7 @@ int main (int argc, char const *const *argv, char const *const *envp) subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { - register int opt = subgetopt_r(argc, argv, "l:", &l) ; + int opt = subgetopt_r(argc, argv, "l:", &l) ; if (opt == -1) break ; switch (opt) { @@ -35,18 +35,18 @@ int main (int argc, char const *const *argv, char const *const *envp) } if (argc < 2) dieusage() ; - if (!case_diffs(argv[0], "up")) up = 1 ; - else if (!case_diffs(argv[0], "down")) up = 0 ; + if (!strcasecmp(argv[0], "up")) up = 1 ; + else if (!strcasecmp(argv[0], "down")) up = 0 ; else dieusage() ; if (!uint0_scan(argv[1], &number)) dieusage() ; { - size_t livelen = str_len(live) ; + size_t livelen = strlen(live) ; int fdcompiled, compiledlock ; s6rc_db_t db ; char compiled[livelen + 10] ; - byte_copy(compiled, livelen, live) ; - byte_copy(compiled + livelen, 10, "/compiled") ; + memcpy(compiled, live, livelen) ; + memcpy(compiled + livelen, "/compiled", 10) ; if (!s6rc_lock(0, 0, 0, compiled, 1, &compiledlock)) strerr_diefu2sys(111, "take lock on ", compiled) ; @@ -72,7 +72,7 @@ int main (int argc, char const *const *argv, char const *const *envp) char const *argvblob[db.nargvs] ; uint32_t depsblob[db.ndeps << 1] ; char stringblob[db.stringlen] ; - register int r ; + int r ; db.services = serviceblob ; db.argvs = argvblob ; @@ -90,10 +90,10 @@ int main (int argc, char const *const *argv, char const *const *envp) /* Run the script */ { - register unsigned int sargc = db.services[number].x.oneshot.argc[up] ; + unsigned int sargc = db.services[number].x.oneshot.argc[up] ; char const *const *sargv = db.argvs + db.services[number].x.oneshot.argv[up] ; char const *newargv[sargc + 1] ; - register char const **p = newargv ; + char const **p = newargv ; while (sargc--) *p++ = *sargv++ ; *p = 0 ; pathexec0_run(newargv, envp) ; diff --git a/src/s6-rc/s6-rc-update.c b/src/s6-rc/s6-rc-update.c index 2b37453..4008388 100644 --- a/src/s6-rc/s6-rc-update.c +++ b/src/s6-rc/s6-rc-update.c @@ -1,14 +1,12 @@ /* ISC license. */ -#include +#include #include #include #include #include #include -#include -#include -#include +#include #include #include #include @@ -83,7 +81,7 @@ static inline void parse_line (stralloc *sa, char const *s, size_t slen, unsigne char pack[4] ; uint32_t x ; unsigned int cur ; - register int r = cdb_find(oldc, sa->s + base + slen, str_len(sa->s + base + slen)) ; + int r = cdb_find(oldc, sa->s + base + slen, strlen(sa->s + base + slen)) ; if (r < 0) strerr_diefu3sys(111, "read ", live, "/compiled/resolve.cdb") ; if (!r) strerr_dief5x(3, "unknown identifier in ", live, "/compiled/resolve.cdb", ": ", sa->s + base + slen) ; if (cdb_datalen(oldc) != 4) strerr_dief5x(5, "identifier ", sa->s + base + slen, " does not represent an atomic service in ", live, "/compiled") ; @@ -94,11 +92,11 @@ static inline void parse_line (stralloc *sa, char const *s, size_t slen, unsigne if (oldstate[x] & 64) strerr_dief3x(6, "service ", olddb->string + olddb->services[x].name, " appears more than once in conversion file") ; oldstate[x] |= 64 ; - cur = base + slen + str_len(sa->s + base + slen) + 1 ; - if (n >= 2 && !str_diff(sa->s + cur, "->")) + cur = base + slen + strlen(sa->s + base + slen) + 1 ; + if (n >= 2 && !strcmp(sa->s + cur, "->")) { - register size_t newnamelen = str_len(sa->s + cur + 3) ; - byte_copy(sa->s + sa->len, newnamelen + 1, sa->s + cur + 3) ; + size_t newnamelen = strlen(sa->s + cur + 3) ; + memcpy(sa->s + sa->len, sa->s + cur + 3, newnamelen + 1) ; newnames[x] = sa->len ; oldstate[x] |= 16 ; sa->len += newnamelen + 1 ; cur += newnamelen + 4 ; @@ -106,10 +104,10 @@ static inline void parse_line (stralloc *sa, char const *s, size_t slen, unsigne } while (n--) { - if (!str_diff(sa->s + cur, "restart")) oldstate[x] |= 4 ; + if (!strcmp(sa->s + cur, "restart")) oldstate[x] |= 4 ; else strerr_dief2x(100, "unknown keyword in conversion file: ", sa->s + cur) ; - cur += str_len(sa->s + cur) + 1 ; + cur += strlen(sa->s + cur) + 1 ; } } } @@ -118,13 +116,13 @@ static inline void parse_conversion_file (char const *convfile, stralloc *sa, un { int fd = open_readb(convfile) ; char buf[4096] ; - buffer b = BUFFER_INIT(&fd_readsv, fd, buf, 4096) ; + buffer b = BUFFER_INIT(&buffer_read, fd, buf, 4096) ; size_t base = satmp.len ; if (fd < 0) strerr_diefu2sys(111, "open ", convfile) ; for (;;) { - register int r = skagetln(&b, &satmp, '\n') ; + int r = skagetln(&b, &satmp, '\n') ; if (!r) break ; if (r < 0) { @@ -162,8 +160,8 @@ static inline void fill_convtable_and_flags (unsigned char *conversion_table, un while (i--) { char const *newname = oldstate[i] & 16 ? namedata + oldindex[i] : olddb->string + olddb->services[i].name ; - unsigned int len ; - int r = cdb_find(newc, newname, str_len(newname)) ; + uint32_t len ; + int r = cdb_find(newc, newname, strlen(newname)) ; if (r < 0) strerr_diefu3sys(111, "read ", newfn, "/resolve.cdb") ; if (!r) { @@ -228,7 +226,7 @@ static void compute_transitions (char const *convfile, unsigned char *oldstate, unsigned int newm = bitarray_div8(newn) ; unsigned int oldindex[oldn] ; unsigned char conversion_table[oldn * newm] ; - byte_zero(conversion_table, oldn * newm) ; + memset(conversion_table, 0, oldn * newm) ; stuff_with_oldc(oldstate, fdoldc, olddb, convfile, oldindex, sa) ; stuff_with_newc(fdnewc, newfn, conversion_table, oldstate, newstate, sa->s + sabase, oldindex, invimage, olddb, newdb) ; sa->len = sabase ; @@ -264,7 +262,7 @@ static void compute_transitions (char const *convfile, unsigned char *oldstate, i = oldn ; while (i--) if (oldstate[i] & 1) { - register unsigned int j = newn ; + unsigned int j = newn ; while (j--) if (bitarray_peek(conversion_table + i * newm, j)) newstate[j] |= (oldstate[i] & 32) ? 2 : 33 ; } @@ -297,27 +295,27 @@ static void compute_transitions (char const *convfile, unsigned char *oldstate, static inline void rollback_servicedirs (char const *newlive, unsigned char const *newstate, unsigned int const *invimage, s6rc_db_t const *olddb, s6rc_db_t const *newdb, unsigned int n) { - size_t newllen = str_len(newlive) ; + size_t newllen = strlen(newlive) ; unsigned int i = n ; while (i--) { - size_t newnamelen = str_len(newdb->string + newdb->services[i].name) ; + size_t newnamelen = strlen(newdb->string + newdb->services[i].name) ; char newfn[newllen + 14 + newnamelen] ; - byte_copy(newfn, newllen, newlive) ; - byte_copy(newfn + newllen, 13, "/servicedirs/") ; - byte_copy(newfn + newllen + 13, newnamelen + 1, newdb->string + newdb->services[i].name) ; + memcpy(newfn, newlive, newllen) ; + memcpy(newfn + newllen, "/servicedirs/", 13) ; + memcpy(newfn + newllen + 13, newdb->string + newdb->services[i].name, newnamelen + 1) ; if (newstate[i] & 1) { char const *oldname = newstate[i] & 8 ? olddb->string + olddb->services[invimage[i]].name : newdb->string + newdb->services[i].name ; - size_t oldnamelen = str_len(oldname) ; + size_t oldnamelen = strlen(oldname) ; char oldfn[livelen + 23 + oldnamelen] ; - byte_copy(oldfn, livelen, live) ; - byte_copy(oldfn + livelen, 22, "/compiled/servicedirs/") ; - byte_copy(oldfn + livelen + 22, oldnamelen + 1, oldname) ; + memcpy(oldfn, live, livelen) ; + memcpy(oldfn + livelen, "/compiled/servicedirs/", 22) ; + memcpy(oldfn + livelen + 22, oldname, oldnamelen + 1) ; if (!s6rc_servicedir_copy_online(oldfn, newfn)) strerr_diefu4sys(111, "rollback ", oldfn, " into ", newfn) ; - byte_copy(oldfn + livelen, 13, "/servicedirs/") ; - byte_copy(oldfn + livelen + 13, oldnamelen + 1, oldname) ; + memcpy(oldfn + livelen, "/servicedirs/", 13) ; + memcpy(oldfn + livelen + 13, oldname, oldnamelen + 1) ; if (rename(newfn, oldfn) < 0) strerr_diefu4sys(111, "rollback: can't rename ", newfn, " to ", oldfn) ; } @@ -328,7 +326,7 @@ static inline void make_new_livedir (unsigned char const *oldstate, s6rc_db_t co { size_t tmpbase = satmp.len ; size_t sabase = sa->len ; - size_t newclen = str_len(newcompiled) ; + size_t newclen = strlen(newcompiled) ; size_t dirlen, llen, newlen, sdlen ; int e = 0 ; unsigned int i = 0 ; @@ -342,8 +340,8 @@ static inline void make_new_livedir (unsigned char const *oldstate, s6rc_db_t co size_t tmplen = satmp.len ; char fn[llen - sabase + 9] ; if (!stralloc_cats(sa, "/scandir") || !stralloc_0(sa)) { e = errno ; goto err ; } - byte_copy(fn, llen - sabase, sa->s + sabase) ; - byte_copy(fn + llen - sabase, 9, "/scandir") ; + memcpy(fn, sa->s + sabase, llen - sabase) ; + memcpy(fn + llen - sabase, "/scandir", 9) ; if (sareadlink(&satmp, fn) < 0 || !stralloc_0(&satmp)) { e = errno ; goto err ; } if (symlink(satmp.s + tmplen, sa->s + sabase) < 0) { e = errno ; goto err ; } satmp.len = tmplen ; @@ -367,22 +365,22 @@ static inline void make_new_livedir (unsigned char const *oldstate, s6rc_db_t co for (; i < newdb->nlong ; i++) { - size_t newnamelen = str_len(newdb->string + newdb->services[i].name) ; + size_t newnamelen = strlen(newdb->string + newdb->services[i].name) ; char newfn[newclen + 14 + newnamelen] ; - byte_copy(newfn, newclen, newcompiled) ; - byte_copy(newfn + newclen, 13, "/servicedirs/") ; - byte_copy(newfn + newclen + 13, newnamelen + 1, newdb->string + newdb->services[i].name) ; + memcpy(newfn, newcompiled, newclen) ; + memcpy(newfn + newclen, "/servicedirs/", 13) ; + memcpy(newfn + newclen + 13, newdb->string + newdb->services[i].name, newnamelen + 1) ; sa->len = sdlen ; if (!stralloc_cats(sa, newdb->string + newdb->services[i].name) || !stralloc_0(sa)) { e = errno ; goto rollback ; } if (newstate[i] & 1) { char const *oldname = newstate[i] & 8 ? olddb->string + olddb->services[invimage[i]].name : newdb->string + newdb->services[i].name ; - size_t oldnamelen = str_len(oldname) ; + size_t oldnamelen = strlen(oldname) ; char oldfn[livelen + 14 + oldnamelen] ; - byte_copy(oldfn, livelen, live) ; - byte_copy(oldfn + livelen, 13, "/servicedirs/") ; - byte_copy(oldfn + livelen + 13, oldnamelen + 1, oldname) ; + memcpy(oldfn, live, livelen) ; + memcpy(oldfn + livelen, "/servicedirs/", 13) ; + memcpy(oldfn + livelen + 13, oldname, oldnamelen + 1) ; if (rename(oldfn, sa->s + sabase) < 0) goto rollback ; if (!s6rc_servicedir_copy_online(newfn, sa->s + sabase)) { i++ ; e = errno ; goto rollback ; } } @@ -393,8 +391,8 @@ static inline void make_new_livedir (unsigned char const *oldstate, s6rc_db_t co sa->s[sa->len++] = 0 ; { char tmpfn[llen + 5 - sabase] ; - byte_copy(tmpfn, llen - sabase, sa->s + sabase) ; - byte_copy(tmpfn + llen - sabase, 5, ".new") ; + memcpy(tmpfn, sa->s + sabase, llen - sabase) ; + memcpy(tmpfn + llen - sabase, ".new", 5) ; if (unlink(tmpfn) < 0 && errno != ENOENT) { e = errno ; goto rollback ; } if (symlink(sa->s + dirlen, tmpfn) < 0) { e = errno ; goto rollback ; } @@ -445,10 +443,10 @@ static inline int delete_unused_pipes (s6_fdholder_t *a, s6rc_db_t const *olddb, if (!(oldstate[i] & 8) && olddb->services[i].x.longrun.pipeline[0] < olddb->nlong) { - size_t len = str_len(olddb->string + olddb->services[i].name) ; + size_t len = strlen(olddb->string + olddb->services[i].name) ; char pipename[len + 13] ; - byte_copy(pipename, 12, "pipe:s6rc-w-") ; - byte_copy(pipename + 12, len + 1, olddb->string + olddb->services[i].name) ; + memcpy(pipename, "pipe:s6rc-w-", 12) ; + memcpy(pipename + 12, olddb->string + olddb->services[i].name, len + 1) ; if (!s6_fdholder_delete_g(a, pipename, deadline)) return 0 ; pipename[10] = 'r' ; if (!s6_fdholder_delete_g(a, pipename, deadline)) return 0 ; @@ -467,14 +465,14 @@ static inline int rename_pipes (s6_fdholder_t *a, s6rc_db_t const *olddb, s6rc_d if ((newstate[i] & 20) == 20 && newdb->services[i].x.longrun.pipeline[0] < newdb->nlong) { int fd ; - size_t oldlen = str_len(olddb->string + olddb->services[invimage[i]].name) ; - size_t newlen = str_len(newdb->string + newdb->services[i].name) ; + size_t oldlen = strlen(olddb->string + olddb->services[invimage[i]].name) ; + size_t newlen = strlen(newdb->string + newdb->services[i].name) ; char oldpipename[oldlen + 13] ; char newpipename[newlen + 13] ; - byte_copy(oldpipename, 12, "pipe:s6rc-r-") ; - byte_copy(oldpipename + 12, oldlen + 1, olddb->string + olddb->services[invimage[i]].name) ; - byte_copy(newpipename, 12, "pipe:s6rc-r-") ; - byte_copy(newpipename + 12, newlen + 1, newdb->string + newdb->services[i].name) ; + memcpy(oldpipename, "pipe:s6rc-r-", 12) ; + memcpy(oldpipename + 12, olddb->string + olddb->services[invimage[i]].name, oldlen + 1) ; + memcpy(newpipename, "pipe:s6rc-r-", 12) ; + memcpy(newpipename + 12, newdb->string + newdb->services[i].name, newlen + 1) ; fd = s6_fdholder_retrieve_delete_g(a, oldpipename, deadline) ; if (fd < 0) return 0 ; if (!s6_fdholder_store_g(a, fd, newpipename, &limit, deadline)) @@ -513,10 +511,10 @@ static inline int create_new_pipes (s6_fdholder_t *a, s6rc_db_t const *newdb, un if (!(newstate[i] & 4) && newdb->services[i].x.longrun.pipeline[0] < newdb->nlong) { int p[2] ; - size_t len = str_len(newdb->string + newdb->services[i].name) ; + size_t len = strlen(newdb->string + newdb->services[i].name) ; char pipename[len + 13] ; - byte_copy(pipename, 12, "pipe:s6rc-r-") ; - byte_copy(pipename + 12, len + 1, newdb->string + newdb->services[i].name) ; + memcpy(pipename, "pipe:s6rc-r-", 12) ; + memcpy(pipename + 12, newdb->string + newdb->services[i].name, len + 1) ; if (pipe(p) < 0) return 0 ; if (!s6_fdholder_store_g(a, p[0], pipename, &limit, deadline)) { @@ -556,8 +554,8 @@ static inline void update_fdholder (s6rc_db_t const *olddb, unsigned char const s6_fdholder_t a = S6_FDHOLDER_ZERO ; char fnsocket[livelen + sizeof("/servicedirs/" S6RC_FDHOLDER "/s")] ; if (!(newstate[1] & 1)) return ; - byte_copy(fnsocket, livelen, live) ; - byte_copy(fnsocket + livelen, sizeof("/servicedirs/" S6RC_FDHOLDER "/s"), "/servicedirs/" S6RC_FDHOLDER "/s") ; + memcpy(fnsocket, live, livelen) ; + memcpy(fnsocket + livelen, "/servicedirs/" S6RC_FDHOLDER "/s", sizeof("/servicedirs/" S6RC_FDHOLDER "/s")) ; fdsocket = ipc_stream_nb() ; if (fdsocket < 0) goto hammer ; if (!ipc_timed_connect_g(fdsocket, fnsocket, deadline)) @@ -619,7 +617,7 @@ int main (int argc, char const *const *argv, char const *const *envp) subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { - register int opt = subgetopt_r(argc, argv, "v:t:nl:f:", &l) ; + int opt = subgetopt_r(argc, argv, "v:t:nl:f:", &l) ; if (opt == -1) break ; switch (opt) { @@ -640,7 +638,7 @@ int main (int argc, char const *const *argv, char const *const *envp) strerr_dief2x(100, argv[0], " is not an absolute path") ; if (live[0] != '/') strerr_dief2x(100, live, " is not an absolute path") ; - livelen = str_len(live) ; + livelen = strlen(live) ; if (!random_init()) strerr_diefu1sys(111, "init random generator") ; @@ -658,8 +656,8 @@ int main (int argc, char const *const *argv, char const *const *envp) /* Take the live, old and new locks */ - byte_copy(dbfn, livelen, live) ; - byte_copy(dbfn + livelen, 10, "/compiled") ; + memcpy(dbfn, live, livelen) ; + memcpy(dbfn + livelen, "/compiled", 10) ; if (!s6rc_lock(live, 2, &livelock, dbfn, 1, &oldlock)) strerr_diefu4sys(111, "take lock on ", live, " and ", dbfn) ; if (!s6rc_lock(0, 0, 0, argv[0], 1, &newlock)) @@ -694,7 +692,7 @@ int main (int argc, char const *const *argv, char const *const *envp) char newstringblob[newdb.stringlen] ; unsigned char oldstate[oldn] ; unsigned char newstate[newn] ; - register int r ; + int r ; olddb.services = oldserviceblob ; olddb.argvs = oldargvblob ; @@ -718,14 +716,14 @@ int main (int argc, char const *const *argv, char const *const *envp) /* Initial state */ - byte_copy(dbfn + livelen + 1, 6, "state") ; + memcpy(dbfn + livelen + 1, "state", 6) ; { - register ssize_t rr = openreadnclose(dbfn, (char *)oldstate, oldn) ; + ssize_t rr = openreadnclose(dbfn, (char *)oldstate, oldn) ; if (rr != oldn) strerr_diefu2sys(111, "read ", dbfn) ; } r = oldn ; while (r--) oldstate[r] &= 1 ; - byte_zero(newstate, newn) ; + memset(newstate, 0, newn) ; r = newn ; while (r--) invimage[r] = olddb.nlong + olddb.nshort ; diff --git a/src/s6-rc/s6-rc.c b/src/s6-rc/s6-rc.c index 26ca196..f81d38d 100644 --- a/src/s6-rc/s6-rc.c +++ b/src/s6-rc/s6-rc.c @@ -1,14 +1,12 @@ /* ISC license. */ -#include +#include #include #include #include #include #include -#include -#include -#include +#include #include #include #include @@ -51,8 +49,8 @@ static inline void announce (void) char fn[livelen + 7] ; char tmpstate[n] ; if (dryrun[0]) return ; - byte_copy(fn, livelen, live) ; - byte_copy(fn + livelen, 7, "/state") ; + memcpy(fn, live, livelen) ; + memcpy(fn + livelen, "/state", 7) ; while (i--) tmpstate[i] = !!(state[i] & 1) ; if (!openwritenclose_suffix(fn, tmpstate, n, ".new")) strerr_diefu2sys(111, "write ", fn) ; @@ -60,7 +58,7 @@ static inline void announce (void) static void print_services (void) { - register unsigned int i = 0 ; + unsigned int i = 0 ; for (; i < n ; i++) if (state[i] & 2) { @@ -71,16 +69,16 @@ static void print_services (void) strerr_diefu1sys(111, "write to stdout") ; } -static unsigned int compute_timeout (unsigned int i, int h) +static uint32_t compute_timeout (unsigned int i, int h) { - unsigned int t = db->services[i].timeout[h] ; + uint32_t t = db->services[i].timeout[h] ; int globalt ; tain_t globaltto ; tain_sub(&globaltto, &deadline, &STAMP) ; globalt = tain_to_millisecs(&globaltto) ; if (!globalt) globalt = 1 ; if (globalt > 0 && (!t || (unsigned int)globalt < t)) - t = (unsigned int)globalt ; + t = (uint32_t)globalt ; return t ; } @@ -92,8 +90,8 @@ static pid_t start_oneshot (unsigned int i, int h) char vfmt[UINT_FMT] ; char ifmt[UINT_FMT] ; char socketfn[livelen + S6RC_ONESHOT_RUNNER_LEN + 12] ; - byte_copy(socketfn, livelen, live) ; - byte_copy(socketfn + livelen, 12 + S6RC_ONESHOT_RUNNER_LEN, "/scandir/" S6RC_ONESHOT_RUNNER "/s") ; + memcpy(socketfn, live, livelen) ; + memcpy(socketfn + livelen, "/scandir/" S6RC_ONESHOT_RUNNER "/s", 12 + S6RC_ONESHOT_RUNNER_LEN) ; tfmt[uint32_fmt(tfmt, compute_timeout(i, h))] = 0 ; vfmt[uint_fmt(vfmt, verbosity)] = 0 ; ifmt[uint_fmt(ifmt, i)] = 0 ; @@ -127,18 +125,18 @@ static pid_t start_oneshot (unsigned int i, int h) static pid_t start_longrun (unsigned int i, int h) { - size_t svdlen = str_len(db->string + db->services[i].name) ; + size_t svdlen = strlen(db->string + db->services[i].name) ; unsigned int m = 0 ; char fmt[UINT32_FMT] ; char vfmt[UINT_FMT] ; char servicefn[livelen + svdlen + 26] ; char const *newargv[7 + !!dryrun[0] * 6] ; - byte_copy(servicefn, livelen, live) ; - byte_copy(servicefn + livelen, 9, "/scandir/") ; - byte_copy(servicefn + livelen + 9, svdlen, db->string + db->services[i].name) ; + memcpy(servicefn, live, livelen) ; + memcpy(servicefn + livelen, "/scandir/", 9) ; + memcpy(servicefn + livelen + 9, db->string + db->services[i].name, svdlen) ; if (h) { - byte_copy(servicefn + livelen + 9 + svdlen, 17, "/notification-fd") ; + memcpy(servicefn + livelen + 9 + svdlen, "/notification-fd", 17) ; if (access(servicefn, F_OK) < 0) { h = 2 ; @@ -172,12 +170,12 @@ static void success_longrun (unsigned int i, int h) { if (!dryrun[0]) { - size_t svdlen = str_len(db->string + db->services[i].name) ; + size_t svdlen = strlen(db->string + db->services[i].name) ; char fn[livelen + svdlen + 15] ; - byte_copy(fn, livelen, live) ; - byte_copy(fn + livelen, 9, "/scandir/") ; - byte_copy(fn + livelen + 9, svdlen, db->string + db->services[i].name) ; - byte_copy(fn + livelen + 9 + svdlen, 6, "/down") ; + memcpy(fn, live, livelen) ; + memcpy(fn + livelen, "/scandir/", 9) ; + memcpy(fn + livelen + 9, db->string + db->services[i].name, svdlen) ; + memcpy(fn + livelen + 9 + svdlen, "/down", 6) ; if (h) { if (unlink(fn) < 0 && verbosity) @@ -278,7 +276,7 @@ static int handle_signals (int h) { unsigned int j = 0 ; int wstat ; - register pid_t r = wait_nohang(&wstat) ; + pid_t r = wait_nohang(&wstat) ; if (r < 0) if (errno == ECHILD) break ; else strerr_diefu1sys(111, "wait for children") ; @@ -327,7 +325,7 @@ static int doit (int spfd, int h) while (npids) { - register int r = iopause_g(&x, 1, &deadline) ; + int r = iopause_g(&x, 1, &deadline) ; if (r < 0) strerr_diefu1sys(111, "iopause") ; if (!r) strerr_dief1x(2, "timed out") ; if (!handle_signals(h)) exitcode = 1 ; @@ -337,14 +335,14 @@ static int doit (int spfd, int h) static void invert_selection (void) { - register unsigned int i = n ; + unsigned int i = n ; while (i--) state[i] ^= 2 ; } static inline unsigned int lookup (char const *const *table, char const *command) { - register unsigned int i = 0 ; - for (; table[i] ; i++) if (!str_diff(command, table[i])) break ; + unsigned int i = 0 ; + for (; table[i] ; i++) if (!strcmp(command, table[i])) break ; return i ; } @@ -358,7 +356,7 @@ static inline unsigned int parse_command (char const *command) "change", 0 } ; - register unsigned int i = lookup(command_table, command) ; + unsigned int i = lookup(command_table, command) ; if (!command_table[i]) dieusage() ; return i ; } @@ -384,7 +382,7 @@ int main (int argc, char const *const *argv) subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { - register int opt = subgetopt_r(argc, argv, "v:n:t:l:udpaX", &l) ; + int opt = subgetopt_r(argc, argv, "v:n:t:l:udpaX", &l) ; if (opt == -1) break ; switch (opt) { @@ -418,15 +416,15 @@ int main (int argc, char const *const *argv) return 0 ; } - livelen = str_len(live) ; + livelen = strlen(live) ; { int fdcompiled ; s6rc_db_t dbblob ; char dbfn[livelen + 10] ; db = &dbblob ; - byte_copy(dbfn, livelen, live) ; - byte_copy(dbfn + livelen, 10, "/compiled") ; + memcpy(dbfn, live, livelen) ; + memcpy(dbfn + livelen, "/compiled", 10) ; /* Take the locks on live and compiled */ @@ -471,12 +469,12 @@ int main (int argc, char const *const *argv) /* Read live state in bit 0 of state */ - byte_copy(dbfn + livelen + 1, 6, "state") ; + memcpy(dbfn + livelen + 1, "state", 6) ; { - register ssize_t r = openreadnclose(dbfn, (char *)state, n) ; + ssize_t r = openreadnclose(dbfn, (char *)state, n) ; if (r != n) strerr_diefu2sys(111, "read ", dbfn) ; { - register unsigned int i = n ; + unsigned int i = n ; while (i--) state[i] &= 1 ; } } @@ -484,7 +482,7 @@ int main (int argc, char const *const *argv) /* Read the db from the file */ { - register int r = s6rc_db_read(fdcompiled, &dbblob) ; + int r = s6rc_db_read(fdcompiled, &dbblob) ; if (r < 0) strerr_diefu3sys(111, "read ", dbfn, "/db") ; if (!r) strerr_dief3x(4, "invalid service database in ", dbfn, "/db") ; } @@ -500,8 +498,8 @@ int main (int argc, char const *const *argv) strerr_diefu3sys(111, "cdb_init ", dbfn, "/resolve.cdb") ; for (; *argv ; argv++) { - unsigned int len ; - register int r = cdb_find(&c, *argv, str_len(*argv)) ; + uint32_t len ; + int r = cdb_find(&c, *argv, strlen(*argv)) ; if (r < 0) strerr_diefu3sys(111, "read ", dbfn, "/resolve.cdb") ; if (!r) strerr_dief4x(3, *argv, " is not a recognized identifier in ", dbfn, "/resolve.cdb") ; @@ -535,7 +533,7 @@ int main (int argc, char const *const *argv) if (selectlive) { - register unsigned int i = n ; + unsigned int i = n ; while (i--) if (state[i] & 1) state[i] |= 2 ; } @@ -573,7 +571,7 @@ int main (int argc, char const *const *argv) if (prune) { - register int r ; + int r ; if (up) invert_selection() ; r = doit(spfd, 0) ; if (r) return r ; -- cgit v1.2.3