diff options
| author | Laurent Bercot <ska-skaware@skarnet.org> | 2025-08-04 16:30:18 +0000 |
|---|---|---|
| committer | Laurent Bercot <ska@appnovation.com> | 2025-08-04 16:30:18 +0000 |
| commit | 984dbc024561cc4f7b6974c9836b4862d73d13a9 (patch) | |
| tree | c493d1cd84956f02cd12b2086ad3cfddc0df0803 /src/libs6rc | |
| parent | 0f4be56abd8fc87e1c68f652f56051c6779db4e1 (diff) | |
| download | s6-rc-984dbc024561cc4f7b6974c9836b4862d73d13a9.tar.gz | |
More utilities: s6rc_nlto0, s6rc_repo_set_listdeps
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libs6rc')
| -rw-r--r-- | src/libs6rc/deps-lib/s6rc | 2 | ||||
| -rw-r--r-- | src/libs6rc/s6rc_nlto0.c | 33 | ||||
| -rw-r--r-- | src/libs6rc/s6rc_repo_set_listdeps.c | 77 |
3 files changed, 112 insertions, 0 deletions
diff --git a/src/libs6rc/deps-lib/s6rc b/src/libs6rc/deps-lib/s6rc index b57ca05..f56fd56 100644 --- a/src/libs6rc/deps-lib/s6rc +++ b/src/libs6rc/deps-lib/s6rc @@ -12,10 +12,12 @@ s6rc_livedir_create.o s6rc_livedir_prefix.o s6rc_livedir_prefixsize.o s6rc_lock.o +s6rc_nlto0.o s6rc_read_uint.o s6rc_repo_cleanup.o s6rc_repo_lock.o s6rc_repo_set_compile.o +s6rc_repo_set_listdeps.o s6rc_repo_sync.o s6rc_sanitize_dir.o s6rc_servicedir_internal.o diff --git a/src/libs6rc/s6rc_nlto0.c b/src/libs6rc/s6rc_nlto0.c new file mode 100644 index 0000000..6436cdb --- /dev/null +++ b/src/libs6rc/s6rc_nlto0.c @@ -0,0 +1,33 @@ +/* ISC license. */ + +#include <stdint.h> + +#include <skalibs/genalloc.h> + +#include <s6-rc/s6rc-utils.h> + +int s6rc_nlto0 (char *s, size_t start, size_t len, genalloc *indices) +{ + size_t origlen = genalloc_len(size_t, indices) ; + size_t pos = start ; + int wasnull = !indices->s ; + int inword = 0 ; + + for (size_t i = start ; i < len ; i++) + { + if (s[i] == '\n') + { + s[i] = 0 ; + if (!genalloc_append(size_t, indices, &pos)) goto err ; + inword = 0 ; + } + else if (!inword) { pos = i ; inword = 1 ; } + } + if (inword) goto err ; + return 1 ; + + err: + if (wasnull) genalloc_free(size_t, indices) ; + else genalloc_setlen(size_t, indices, origlen) ; + return 0 ; +} diff --git a/src/libs6rc/s6rc_repo_set_listdeps.c b/src/libs6rc/s6rc_repo_set_listdeps.c new file mode 100644 index 0000000..9a98d5f --- /dev/null +++ b/src/libs6rc/s6rc_repo_set_listdeps.c @@ -0,0 +1,77 @@ +/* ISC license. */ + +#include <sys/wait.h> +#include <string.h> +#include <unistd.h> +#include <errno.h> + +#include <skalibs/posixplz.h> +#include <skalibs/types.h> +#include <skalibs/strerr.h> +#include <skalibs/stralloc.h> +#include <skalibs/genalloc.h> +#include <skalibs/cspawn.h> +#include <skalibs/djbunix.h> + +#include <s6-rc/config.h> +#include <s6-rc/s6rc-utils.h> +#include <s6-rc/repo.h> + +int s6rc_repo_set_listdeps (char const *repo, char const *service, uint32_t options, stralloc *storage, genalloc *indices) +{ + int swasnull = !storage->s ; + int gwasnull = !indices->s ; + size_t sstart = storage->len ; + + { + size_t m = 0 ; + size_t repolen = strlen(repo) ; + char const *argv[9] ; + pid_t pid ; + int fd ; + int wstat ; + char refdb[repolen + 22] ; + memcpy(refdb, repo, repolen) ; + memcpy(refdb + repolen, "/compiled/.everything", 22) ; + argv[m++] = S6RC_BINPREFIX "s6-rc-db" ; + argv[m++] = "-c"; + argv[m++] = refdb ; + argv[m++] = "-b" ; + argv[m++] = options & 1 ? "-u" : "-d" ; + argv[m++] = "--" ; + argv[m++] = "dependencies" ; + argv[m++] = service ; + argv[m++] = 0 ; + pid = child_spawn1_pipe(argv[0], argv, (char const *const *)environ, &fd, 1) ; + if (!pid) { strerr_warnfu2sys("spawn ", argv[0]) ; return -1 ; } + if (!slurpn(fd, storage, 0)) { strerr_warnfu2sys("read output from ", argv[0]) ; return -1 ; } + fd_close(fd) ; + if (wait_pid(pid, &wstat) == -1) + { + strerr_warnfu2sys("wait for ", argv[0]) ; + return -1 ; + } + if (WIFSIGNALED(wstat)) + { + char fmt[UINT_FMT] ; + fmt[uint_fmt(fmt, WTERMSIG(wstat))] = 0 ; + strerr_warnf3x(argv[0], " crashed with signal ", fmt) ; + return -1 ; + } + if (WEXITSTATUS(wstat)) + { + char fmt[UINT_FMT] ; + fmt[uint_fmt(fmt, WEXITSTATUS(wstat))] = 0 ; + strerr_warnf3x(argv[0], " exited with code ", fmt) ; + return (WEXITSTATUS(wstat) < 99) - 1 ; + } + } + + if (!s6rc_nlto0(storage->s + sstart, sstart, storage->len, indices)) goto err ; + return 1 ; + + err: + if (gwasnull) genalloc_free(size_t, indices) ; + if (swasnull) stralloc_free(storage) ; + return -1 ; +} |
