diff options
| author | Laurent Bercot <ska-skaware@skarnet.org> | 2025-08-19 16:29:18 +0000 |
|---|---|---|
| committer | Laurent Bercot <ska-skaware@skarnet.org> | 2025-08-19 16:29:18 +0000 |
| commit | bfdfb6e54738a6a26d146eadf025646fa65c7b0c (patch) | |
| tree | 34ff6e5d263cdf9d3115c6f6aa4667f4d0ee8db0 /src/libs6rc | |
| parent | a92aa0997e0d367e396b02dc2d55d0c0a3cbbc38 (diff) | |
| download | s6-rc-bfdfb6e54738a6a26d146eadf025646fa65c7b0c.tar.gz | |
Almost got a full sync, still need the adjustment heuristic
Diffstat (limited to 'src/libs6rc')
| -rw-r--r-- | src/libs6rc/deps-lib/s6rc | 1 | ||||
| -rw-r--r-- | src/libs6rc/s6rc_repo_fillset.c | 7 | ||||
| -rw-r--r-- | src/libs6rc/s6rc_repo_makesetbundles.c | 10 | ||||
| -rw-r--r-- | src/libs6rc/s6rc_repo_sync.c | 12 | ||||
| -rw-r--r-- | src/libs6rc/s6rc_strrefcmp.c | 10 |
5 files changed, 25 insertions, 15 deletions
diff --git a/src/libs6rc/deps-lib/s6rc b/src/libs6rc/deps-lib/s6rc index 6107d4b..4af4acb 100644 --- a/src/libs6rc/deps-lib/s6rc +++ b/src/libs6rc/deps-lib/s6rc @@ -38,6 +38,7 @@ s6rc_servicedir_copy_offline.o s6rc_servicedir_copy_online.o s6rc_servicedir_manage.o s6rc_servicedir_unsupervise.o +s6rc_strrefcmp.o s6rc_type_check.o -ls6 -lskarnet diff --git a/src/libs6rc/s6rc_repo_fillset.c b/src/libs6rc/s6rc_repo_fillset.c index 9548c19..50c0156 100644 --- a/src/libs6rc/s6rc_repo_fillset.c +++ b/src/libs6rc/s6rc_repo_fillset.c @@ -2,14 +2,16 @@ #include <string.h> #include <unistd.h> +#include <stdlib.h> #include <errno.h> #include <skalibs/direntry.h> #include <skalibs/strerr.h> +#include <s6-rc/s6rc-utils.h> #include <s6-rc/repo.h> -int s6rc_repo_fillset (char const *repo, char const *set) +int s6rc_repo_fillset (char const *repo, char const *set, char const *const *existing, size_t n) { size_t repolen = strlen(repo) ; size_t setlen = strlen(set) ; @@ -42,7 +44,8 @@ int s6rc_repo_fillset (char const *repo, char const *set) char src[len + 30] ; char dst[repolen + 18 + setlen + len] ; memcpy(src, "../.atomics/", 12) ; - memcpy(src + 12, d->d_name, len) ; + memcpy(src + 12, d->d_name, len+1) ; + if (n && bsearch(&d->d_name, existing, n, sizeof(char const *), &s6rc_strrefcmp)) continue ; memcpy(src + 12 + len, "/flag-essential", 16) ; if (access(src, F_OK) == -1) { diff --git a/src/libs6rc/s6rc_repo_makesetbundles.c b/src/libs6rc/s6rc_repo_makesetbundles.c index 30ff29e..8fcf979 100644 --- a/src/libs6rc/s6rc_repo_makesetbundles.c +++ b/src/libs6rc/s6rc_repo_makesetbundles.c @@ -14,13 +14,9 @@ #include <skalibs/genalloc.h> #include <skalibs/djbunix.h> +#include <s6-rc/s6rc-utils.h> #include <s6-rc/repo.h> -static int str_ref_cmp (void const *a, void const *b) -{ - return strcmp(*(char const *const *)a, *(char const *const *)b) ; -} - int s6rc_repo_makesetbundles (char const *repo, char const *set, unsigned int verbosity) { size_t repolen = strlen(repo) ; @@ -49,7 +45,7 @@ int s6rc_repo_makesetbundles (char const *repo, char const *set, unsigned int ve for (size_t i = 0 ; i < n ; i++) masked[i] = maskedstorage + genalloc_s(size_t, &ga)[i] ; sa.len = 0 ; genalloc_setlen(size_t, &ga, 0) ; - qsort(masked, n, sizeof(char const *), &str_ref_cmp) ; + qsort(masked, n, sizeof(char const *), &s6rc_strrefcmp) ; if (mkdir(dst, 02755) == -1) { @@ -83,7 +79,7 @@ int s6rc_repo_makesetbundles (char const *repo, char const *set, unsigned int ve for (; i < m ; i++) { char const *x = sa.s + genalloc_s(size_t, &ga)[i] ; - if (bsearch(x, masked, n, sizeof(char const *), &str_ref_cmp)) + if (bsearch(x, masked, n, sizeof(char const *), &s6rc_strrefcmp)) { if (verbosity >= 3) strerr_warni4x("skipping bundle ", d->d_name, " containing e.g. masked service ", x) ; diff --git a/src/libs6rc/s6rc_repo_sync.c b/src/libs6rc/s6rc_repo_sync.c index 8ff1137..e3d71fd 100644 --- a/src/libs6rc/s6rc_repo_sync.c +++ b/src/libs6rc/s6rc_repo_sync.c @@ -27,7 +27,7 @@ static inline void cleanup (char const *ato, char const *bun) errno = e ; } -static int s6rc_repo_syncsub (char const *repo, char const *set, char const *sub, uint32_t where, stralloc *sa, genalloc *ga, unsigned int verbosity) +static int unlink_stales_in_sub (char const *repo, char const *set, char const *sub, uint32_t where, stralloc *sa, genalloc *ga, unsigned int verbosity) { size_t repolen = strlen(repo) ; size_t setlen = strlen(set) ; @@ -91,14 +91,14 @@ static int s6rc_repo_syncsub (char const *repo, char const *set, char const *sub static inline int s6rc_repo_syncset (char const *repo, size_t repolen, char const *set, stralloc *sa, genalloc *ga, unsigned int verbosity) { - static char const subs[3][7] = { "masked", "active", "onboot" } ; for (unsigned int i = 0 ; i < 3 ; i++) - if (s6rc_repo_syncsub(repo, set, subs[i], i, sa, ga, verbosity)) goto err ; + if (unlink_stales_in_sub(repo, set, s6rc_repo_sublist[i], i, sa, ga, verbosity)) goto err ; - size_t n = genalloc_len(size_t, ga) ; - if (!n) { - if (!s6rc_repo_fillset(repo, set)) goto err ; + size_t n = genalloc_len(size_t, ga) ; + char const *stillhere[n + !n] ; + for (size_t i = 0 ; i < n ; i++) stillhere[i] = sa->s + genalloc_s(size_t, ga)[i] ; + if (!s6rc_repo_fillset(repo, set, stillhere, n)) goto err ; } sa->len = 0 ; diff --git a/src/libs6rc/s6rc_strrefcmp.c b/src/libs6rc/s6rc_strrefcmp.c new file mode 100644 index 0000000..e4732df --- /dev/null +++ b/src/libs6rc/s6rc_strrefcmp.c @@ -0,0 +1,10 @@ +/* ISC license. */ + +#include <string.h> + +#include <s6-rc/s6rc-utils.h> + +int s6rc_strrefcmp (void const *a, void const *b) +{ + return strcmp(*(char const *const *)a, *(char const *const *)b) ; +} |
