aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2026-10-15 08:19:48 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2026-10-15 08:19:48 +0000
commitdb3fb428599c9c8fe105dcf4ba8d1c914c54cc26 (patch)
treef83ab9920c39916777a35e5034a4cb9f43614da8 /src
parent91a0655557e707977f583b2142bda898ee599fd8 (diff)
downloads6-rc-main.tar.gz
More work on format-upgrade inclusion: real meta-information storageHEADmain
If a db format upgrade is necessary, we need to compile the snapshot with the new s6-rc-compile. There's data we need to pass to it that isn't stored (options passed when committing the original set), so we store it in the db itself (patching s6-rc-compile). We modify the s6-rc-compile wrappers to pass all this metadata. Next, we will compile the snapshot.
Diffstat (limited to 'src')
-rw-r--r--src/include/s6-rc/repo.h1
-rw-r--r--src/repo/deps-lib/s6rcrepo1
-rw-r--r--src/repo/s6rc_repo_compile.c14
-rw-r--r--src/repo/s6rc_repo_read_major.c15
-rw-r--r--src/repo/s6rc_repo_setcompile.c2
-rw-r--r--src/s6-rc/s6-rc-compile.c41
6 files changed, 45 insertions, 29 deletions
diff --git a/src/include/s6-rc/repo.h b/src/include/s6-rc/repo.h
index 6ecec15..6c9b17b 100644
--- a/src/include/s6-rc/repo.h
+++ b/src/include/s6-rc/repo.h
@@ -26,6 +26,7 @@ extern int s6rc_repo_ls (char const *, stralloc *, genalloc *) ;
extern char const s6rc_repo_rxnames[4][7] ;
extern uint32_t s6rc_repo_read_major (char const *) ; /* the major a db was compiled with */
+extern int s6rc_repo_install_needs_upgrade (char const *) ;
extern int s6rc_repo_makestores (char const *, char const *const *, uint16_t, char *) ;
diff --git a/src/repo/deps-lib/s6rcrepo b/src/repo/deps-lib/s6rcrepo
index aee5f34..eb1ead9 100644
--- a/src/repo/deps-lib/s6rcrepo
+++ b/src/repo/deps-lib/s6rcrepo
@@ -7,6 +7,7 @@ s6rc_repo_fillset.o
s6rc_repo_fixset.o
s6rc_repo_flattenservices.o
s6rc_repo_getserviceflags.o
+s6rc_repo_install_needs_upgrade.o
s6rc_repo_list_sets.o
s6rc_repo_listalldeps.o
s6rc_repo_listcontents.o
diff --git a/src/repo/s6rc_repo_compile.c b/src/repo/s6rc_repo_compile.c
index f89a65a..fc7d8ea 100644
--- a/src/repo/s6rc_repo_compile.c
+++ b/src/repo/s6rc_repo_compile.c
@@ -16,12 +16,13 @@
#include <s6-rc/config.h>
#include <s6-rc/repo.h>
-int s6rc_repo_compile (char const *repo, char const *set, char const *const *rxs, uint8_t nrxs, char *oldc, unsigned int verbosity, char const *fdhuser, char const *catchall)
+int s6rc_repo_compile (char const *repo, char const *set, char const *const *rxs, uint8_t nrxs, char *oldc, unsigned int verbosity, char const *fdhuser, char const *catchall, char const *defbundle)
{
size_t repolen = strlen(repo) ;
size_t setlen = strlen(set) ;
size_t totrxlen = 0 ;
int needprefix = strcmp(set, ".ref") ;
+ int needsnapshot = needprefix && memcmp(set, ".snapshot.", 10) ;
char snap[setlen + 44] ;
char newc[repolen + setlen + 45] ;
memcpy(newc, repo, repolen) ;
@@ -38,7 +39,7 @@ int s6rc_repo_compile (char const *repo, char const *set, char const *const *rxs
pid_t pid ;
size_t m = 0 ;
int wstat ;
- char const *argv[11 + nrxs] ;
+ char const *argv[13 + nrxs] ;
char fmtv[UINT_FMT] ;
char src[nrxs * (repolen + 10 + (needprefix ? setlen + 1 : 0)) + totrxlen] ;
char *w = src ;
@@ -57,6 +58,11 @@ int s6rc_repo_compile (char const *repo, char const *set, char const *const *rxs
argv[m++] = "-L" ;
argv[m++] = catchall ;
}
+ if (defbundle)
+ {
+ argv[m++] = "-D" ;
+ argv[m++] = defbundle ;
+ }
argv[m++] = "--" ;
argv[m++] = newc ;
for (uint8_t i = 0 ; i < nrxs ; i++)
@@ -96,7 +102,7 @@ int s6rc_repo_compile (char const *repo, char const *set, char const *const *rxs
}
}
- if (needprefix)
+ if (needsnapshot)
{
int e ;
memcpy(snap, ".snapshot", 9) ;
@@ -124,7 +130,7 @@ int s6rc_repo_compile (char const *repo, char const *set, char const *const *rxs
{
int e = errno ;
rm_rf(newc) ;
- if (needprefix) s6rc_repo_setdelete(repo, snap) ;
+ if (needsnapshot) s6rc_repo_setdelete(repo, snap) ;
errno = e ;
strerr_warnfu4sys("atomically symlink ", newc + repolen + 10, " to ", fn) ;
return -1 ;
diff --git a/src/repo/s6rc_repo_read_major.c b/src/repo/s6rc_repo_read_major.c
index 08d646b..1501fe2 100644
--- a/src/repo/s6rc_repo_read_major.c
+++ b/src/repo/s6rc_repo_read_major.c
@@ -16,15 +16,12 @@ uint32_t s6rc_repo_read_major (char const *compiled)
size_t clen = strlen(compiled) ;
ssize_t r ;
uint32_t res ;
- char tmp[UINT32_FMT] ;
- char fn[clen + 7] ;
+ char pack[5] ;
+ char fn[clen + 16] ;
memcpy(fn, compiled, clen) ;
- memcpy(fn + clen, "/major", 7) ;
- r = openreadnclose(fn, tmp, UINT32_FMT) ;
- if (r == -1) return errno == ENOENT ? 7 : 0 ; /* up to 0.7.0.0 doesn't have db/major */
- if (!r) return 0 ;
- if (tmp[r] != '\n') return (errno = EPROTO, 0) ;
- tmp[r] = 0 ;
- if (uint320_scan(tmp, &res) != r) return (errno = EPROTO, 0) ;
+ memcpy(fn + clen, "/metainfo/major", 16) ;
+ r = openreadnclose(fn, pack, 5) ;
+ if (r != 4) return r == -1 && errno == ENOENT ? 7 : 0 ; /* up to 0.7.0.0 doesn't have metainfo */
+ uint32_unpack_big(pack, &res) ;
return res ;
}
diff --git a/src/repo/s6rc_repo_setcompile.c b/src/repo/s6rc_repo_setcompile.c
index 1bdbea8..f894f64 100644
--- a/src/repo/s6rc_repo_setcompile.c
+++ b/src/repo/s6rc_repo_setcompile.c
@@ -13,7 +13,7 @@ int s6rc_repo_setcompile (char const *repo, char const *set, char const *defbund
int r ;
if (!s6rc_repo_makesetbundles(repo, set, verbosity)) return -1 ;
if (!s6rc_repo_makedefbundle(repo, set, defbundle)) return -1 ;
- r = s6rc_repo_compile(repo, set, rxs, 4, oldc, verbosity, fdhuser, catchall) ;
+ r = s6rc_repo_compile(repo, set, rxs, 4, oldc, verbosity, fdhuser, catchall, defbundle) ;
{
int e = errno ;
diff --git a/src/s6-rc/s6-rc-compile.c b/src/s6-rc/s6-rc-compile.c
index 0bfe4d7..8e9af59 100644
--- a/src/s6-rc/s6-rc-compile.c
+++ b/src/s6-rc/s6-rc-compile.c
@@ -21,7 +21,7 @@
#include <s6-rc/config.h>
#include <s6-rc/s6rc.h>
-#define USAGE "s6-rc-compile [ -v verbosity ] [ -h fdholder-user ] [ -L catchall-logger ] [ -b ] destdir sources..."
+#define USAGE "s6-rc-compile [ -v verbosity ] [ -h fdholder-user ] [ -L catchall-logger ] [ -D default-bundle ] [ -b ] destdir sources..."
#define dieusage() strerr_dieusage(100, USAGE)
#define dienomem() strerr_dief(111, "out of memory") ;
@@ -37,6 +37,7 @@ enum gola_e
GOLA_VERBOSITY,
GOLA_FDHUSER,
GOLA_CATCHALL,
+ GOLA_DEFBUNDLE,
GOLA_N
} ;
@@ -1604,19 +1605,26 @@ static inline void write_db (char const *compiled, s6rc_db_t const *db)
strerr_diefusys(111, "write to ", dbfn) ;
}
-static inline void write_major (char const *compiled)
+static inline void write_meta (char const *compiled, char const *fdhuser, char const *catchall)
{
- uint32_t version = s6rc_get_major(S6RC_VERSION) ;
- size_t len ;
- char fmt[UINT32_FMT] ;
- if (!version)
- {
- cleanup(compiled) ;
- strerr_dief(101, "invalid software version: ", S6RC_VERSION) ;
- }
- len = uint32_fmt(fmt, version) ;
- fmt[len++] = '\n' ;
- auto_file(compiled, "major", fmt, len) ;
+ char pack[4] ;
+ char fn[19] ;
+
+ memcpy(fn, "metainfo", 9) ;
+ auto_dir(compiled, fn) ;
+
+ memcpy(fn + 8, "/major", 7) ;
+ uint32_pack_big(pack, s6rc_get_major(S6RC_VERSION)) ;
+ auto_file(compiled, fn, pack, 4) ;
+
+ memcpy(fn + 9, "fdhuser", 8) ;
+ auto_file(compiled, fn, fdhuser ? fdhuser : "", fdhuser ? strlen(fdhuser) : 0) ;
+
+ memcpy(fn + 9, "catchall", 9) ;
+ auto_file(compiled, fn, catchall ? catchall : "", catchall ? strlen(catchall) : 0) ;
+
+ memcpy(fn + 9, "defbundle", 10) ;
+ auto_file(compiled, fn, defbundle ? defbundle : "", defbundle ? strlen(defbundle) : 0) ;
}
static inline void write_compiled (
@@ -1628,11 +1636,12 @@ static inline void write_compiled (
uint32_t const *bdeps,
char const *fdhuser,
char const *catchall,
+ char const *defbundle,
int blocking)
{
if (verbosity >= 2) strerr_warni("writing compiled information to ", compiled) ;
init_compiled(compiled) ;
- write_major(compiled) ;
+ write_meta(compiled, fdhuser, catchall, defbundle) ;
write_sizes(compiled, db) ;
write_resolve(compiled, db, bundles, nbundles, bdeps) ;
stralloc_free(&data) ;
@@ -1653,6 +1662,7 @@ int main (int argc, char const *const *argv)
{ .so = 'v', .lo = "verbosity", .i = GOLA_VERBOSITY },
{ .so = 'h', .lo = "fdholder-user", .i = GOLA_FDHUSER },
{ .so = 'L', .lo = "catchall-logger", .i = GOLA_CATCHALL },
+ { .so = 'D', .lo = "default-bundle", .i = GOLA_DEFBUNDLE },
} ;
before_t before = BEFORE_ZERO ;
uint64_t wgolb = 0 ;
@@ -1660,6 +1670,7 @@ int main (int argc, char const *const *argv)
char const *compiled ;
unsigned int golc ;
PROG = "s6-rc-compile" ;
+ wgola[GOLA_DEFBUNDLE] = S6RC_DEFBUNDLE ;
golc = GOL_main(argc, argv, rgolb, rgola, &wgolb, wgola) ;
argc -= golc ; argv += golc ;
@@ -1722,7 +1733,7 @@ int main (int argc, char const *const *argv)
db.deps = deps ;
flatlist_services(&db, sarray) ;
propagate_bundle_flags(&db, bundles, nbundles, bdeps) ;
- write_compiled(compiled, &db, srcdirs, bundles, nbundles, bdeps, wgola[GOLA_FDHUSER], wgola[GOLA_CATCHALL], wgolb & GOLB_BLOCK) ;
+ write_compiled(compiled, &db, srcdirs, bundles, nbundles, bdeps, wgola[GOLA_FDHUSER], wgola[GOLA_CATCHALL], wgola[GOLA_DEFBUNDLE], wgolb & GOLB_BLOCK) ;
}
}