From 0ea45c6552010c36e4718542db759ec6cdfce58a Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Mon, 6 Oct 2025 02:27:38 +0000 Subject: Add s6-rc-set-install, repodefs page --- .gitignore | 4 +- doc/repodefs.html | 259 ++++++++++++++++++++++++++++++++ package/deps.mak | 19 ++- package/modes | 3 +- package/targets.mak | 3 +- src/include/s6-rc/repo.h | 2 + src/libs6rc/deps-lib/s6rc | 2 + src/libs6rc/s6rc_repo_checkset.c | 40 +++++ src/libs6rc/s6rc_repo_compile.c | 2 +- src/libs6rc/s6rc_repo_setuptodate.c | 45 ++++++ src/repo/deps-exe/s6-rc-set-change | 3 + src/repo/deps-exe/s6-rc-set-changestate | 3 - src/repo/deps-exe/s6-rc-set-install | 3 + src/repo/s6-rc-set-change.c | 217 ++++++++++++++++++++++++++ src/repo/s6-rc-set-changestate.c | 217 -------------------------- src/repo/s6-rc-set-commit.c | 64 ++------ src/repo/s6-rc-set-install.c | 205 +++++++++++++++++++++++++ 17 files changed, 806 insertions(+), 285 deletions(-) create mode 100644 doc/repodefs.html create mode 100644 src/libs6rc/s6rc_repo_checkset.c create mode 100644 src/libs6rc/s6rc_repo_setuptodate.c create mode 100644 src/repo/deps-exe/s6-rc-set-change delete mode 100644 src/repo/deps-exe/s6-rc-set-changestate create mode 100644 src/repo/deps-exe/s6-rc-set-install create mode 100644 src/repo/s6-rc-set-change.c delete mode 100644 src/repo/s6-rc-set-changestate.c create mode 100644 src/repo/s6-rc-set-install.c diff --git a/.gitignore b/.gitignore index 6531dc2..b3b976b 100644 --- a/.gitignore +++ b/.gitignore @@ -17,9 +17,9 @@ /s6-rc-format-upgrade /s6-rc-repo-init /s6-rc-repo-sync -/s6-rc-repo-populate /s6-rc-set-new /s6-rc-set-copy /s6-rc-set-delete -/s6-rc-set-changestate +/s6-rc-set-change /s6-rc-set-commit +/s6-rc-set-install diff --git a/doc/repodefs.html b/doc/repodefs.html new file mode 100644 index 0000000..ff2bd32 --- /dev/null +++ b/doc/repodefs.html @@ -0,0 +1,259 @@ + + + + + + s6-rc: the "repo" subset of commands: definitions and concepts + + + + + + +

+s6-rc
+Software
+skarnet.org +

+ +

The repo subset of s6-rc commands: management of source definition directories

+ +

+ s6-rc commands such as +s6-rc, +s6-rc-compile, or +s6-rc-db, implement pure mechanism, and +leave all the burden of policy, i.e. how to organize source files, +when to compile a service database, etc., to the user. This is on purpose, but +does not make it easy to integrate s6-rc in a distribution, where service +files are provided by packages installed by a package manager, and where the +user wants to be able to easily define which services start at boot time and +which do not, etc. +

+ +

+ The solution to this conundrum is the high-level user interface to s6-rc +(and more generally to the s6 ecosystem) named +s6-frontend (currently +in development). But in order for +s6-frontend to be a +user interface and not a whole engine in its own right, some +stepping stones are in order: intermediary-level helpers to manage s6-rc +source definition directories in a way that maps better to the way that +distributions work than just the raw s6-rc-compile. +

+ +

+ These intermediary-level helpers made their appearance in version 0.6.0.0 +of s6-rc, and they're collectively known as repo commands — +simply because they manage a repository of services. +

+ +

Definitions

+ +
+

Repository

+
+ +

+ An s6-rc repository is a place in the filesystem where the +repo commands perform their work and store their data. It +is made of hierarchies of symlinks (lots and lots of symlinks), that +ultimately point to source definition directories in the +stores, as well as several compiled databases: +the reference database, and the compiled databases +made of the sets you have +committed, including the one you will eventually +install. +

+ +

+ A repository is where offline work on +services happens. It must be located on a read-write filesystem, but +that filesystem does not need to be accessible during the early boot. +The default repository is located in /var/lib/s6-rc/repository +(configurable at build-time). Other repositories can be created and +used at will, typically by non-root users who want to manage their own +sets of services. +

+ +
+

Store

+
+ +

+ A service store is a place in the filesystem where source +definition directories are written by the package manager or the +user, where you can find the real contents of the services (instead +of just symlinks), as in, source definition directories that are +processed by s6-rc-compile. +A repository will typically link to several stores: one provided by +the package manager, and one — or more — provided locally +by the admin. No s6-rc command will ever write to a store, but most +repo commands read from all the stores. +

+ +

+ The location of the stores is entirely determined by distribution +policy, and s6-rc hardcodes no default for them. A good place to +host service definition directories installed by a package manager +could be, for instance, /usr/lib/s6-rc/sources. A good +place to host local service definition directories managed by +an administrator could be /etc/s6-rc/sources. +

+ +
+

Reference database

+
+ +

+ When a repository is created or updated, the list of all services +defined in all the stores used by this repository +is analyzed, and all these services are automatically compiled into a +reference database, stored in the repository. The reference +database is never meant to be installed or go live in any way; its +purpose is mainly to give repo commands access to the full dependency +graph of all the services in the store. Additionally, compiling this +reference database ensures that the whole set of services defined +in all the used stores is consistent: if not, the initialization fails, +so the problem is reported as early as possible. +

+ +
+

Set

+
+ +

+ Inside a repository, a set is the fundamental unit of operation, +and what users will interact the most with. A set is a map associating +each service contained in the reference database +(so, each service listed in all the stores used by the +repository) to a given state that the user wants this service in when +booting the system. This target state is also called a +sub, because target states are implemented by +subdirectories of the directory holding a set. +

+ +

+ The idea is that the user can work on a set, making modifications to +the target states as they see fit; the repo commands always ensure that +the set will be consistent, i.e. that dependencies will be respected and +target states are reachable. When satisfied with the states, the user +can commit the set, then install it. +

+ +
+

Subs

+
+ +

+ A sub is the target state for every service in a set. At all times, +each service is in one and only one sub. The list of subs the service can be in +is the following: +

+ + + +

+ Working on a set basically means moving services from one of these subs to +another, mostly choosing what services you will enable or disable, and sometimes +masking services you don't want to see at all. And once you are happy with a set, +you can commit it. +

+ +
+

Commit

+
+ +

+ Committing a set means assembling a subset of all the source +definition directories in the set and compiling them into a +set database, replacing any previous database for the same +set. This set database can then be installed. +

+ +
+

Install

+
+ +

+ Installing a committed set means copying the compiled set +database to the place (defined by policy distribution) where it can be +used as a live database, i.e. booted on, and then switching +the live database to it. In other words: making the set database into +the new live database. +

+ +

Workflow

+ + + +

+ Note that all these steps will be made easier in the near future by the higher-level +user interface provided by +s6-frontend. +

+ + + diff --git a/package/deps.mak b/package/deps.mak index 2f7e0f0..73bb12d 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -22,6 +22,7 @@ src/libs6rc/s6rc_ls.o src/libs6rc/s6rc_ls.lo: src/libs6rc/s6rc_ls.c src/include/ src/libs6rc/s6rc_nlto0.o src/libs6rc/s6rc_nlto0.lo: src/libs6rc/s6rc_nlto0.c src/include/s6-rc/s6rc-utils.h src/libs6rc/s6rc_read_uint.o src/libs6rc/s6rc_read_uint.lo: src/libs6rc/s6rc_read_uint.c src/include/s6-rc/s6rc-utils.h src/libs6rc/s6rc_repo_badsub.o src/libs6rc/s6rc_repo_badsub.lo: src/libs6rc/s6rc_repo_badsub.c src/include/s6-rc/repo.h +src/libs6rc/s6rc_repo_checkset.o src/libs6rc/s6rc_repo_checkset.lo: src/libs6rc/s6rc_repo_checkset.c src/include/s6-rc/repo.h src/include/s6-rc/s6rc-utils.h src/libs6rc/s6rc_repo_cleanup.o src/libs6rc/s6rc_repo_cleanup.lo: src/libs6rc/s6rc_repo_cleanup.c src/include/s6-rc/repo.h src/libs6rc/s6rc_repo_compile.o src/libs6rc/s6rc_repo_compile.lo: src/libs6rc/s6rc_repo_compile.c src/include/s6-rc/config.h src/include/s6-rc/repo.h src/libs6rc/s6rc_repo_fillset.o src/libs6rc/s6rc_repo_fillset.lo: src/libs6rc/s6rc_repo_fillset.c src/include/s6-rc/repo.h src/include/s6-rc/s6rc-utils.h @@ -43,6 +44,7 @@ src/libs6rc/s6rc_repo_makesvlist_byname.o src/libs6rc/s6rc_repo_makesvlist_bynam src/libs6rc/s6rc_repo_moveservices.o src/libs6rc/s6rc_repo_moveservices.lo: src/libs6rc/s6rc_repo_moveservices.c src/include/s6-rc/repo.h src/libs6rc/s6rc_repo_refcompile.o src/libs6rc/s6rc_repo_refcompile.lo: src/libs6rc/s6rc_repo_refcompile.c src/include/s6-rc/repo.h src/libs6rc/s6rc_repo_setcompile.o src/libs6rc/s6rc_repo_setcompile.lo: src/libs6rc/s6rc_repo_setcompile.c src/include/s6-rc/repo.h +src/libs6rc/s6rc_repo_setuptodate.o src/libs6rc/s6rc_repo_setuptodate.lo: src/libs6rc/s6rc_repo_setuptodate.c src/include/s6-rc/repo.h src/include/s6-rc/s6rc-utils.h src/libs6rc/s6rc_repo_subnames.o src/libs6rc/s6rc_repo_subnames.lo: src/libs6rc/s6rc_repo_subnames.c src/include/s6-rc/repo.h src/libs6rc/s6rc_repo_sv_bcmpr.o src/libs6rc/s6rc_repo_sv_bcmpr.lo: src/libs6rc/s6rc_repo_sv_bcmpr.c src/include/s6-rc/repo.h src/libs6rc/s6rc_repo_sv_cmpr.o src/libs6rc/s6rc_repo_sv_cmpr.lo: src/libs6rc/s6rc_repo_sv_cmpr.c src/include/s6-rc/repo.h @@ -63,10 +65,11 @@ src/libs6rc/s6rc_strrefcmp.o src/libs6rc/s6rc_strrefcmp.lo: src/libs6rc/s6rc_str src/libs6rc/s6rc_type_check.o src/libs6rc/s6rc_type_check.lo: src/libs6rc/s6rc_type_check.c src/include/s6-rc/s6rc-utils.h src/repo/s6-rc-repo-init.o src/repo/s6-rc-repo-init.lo: src/repo/s6-rc-repo-init.c src/include/s6-rc/config.h src/include/s6-rc/s6rc.h src/repo/s6-rc-repo-sync.o src/repo/s6-rc-repo-sync.lo: src/repo/s6-rc-repo-sync.c src/include/s6-rc/config.h src/include/s6-rc/s6rc.h -src/repo/s6-rc-set-changestate.o src/repo/s6-rc-set-changestate.lo: src/repo/s6-rc-set-changestate.c src/include/s6-rc/config.h src/include/s6-rc/s6rc.h +src/repo/s6-rc-set-change.o src/repo/s6-rc-set-change.lo: src/repo/s6-rc-set-change.c src/include/s6-rc/config.h src/include/s6-rc/s6rc.h src/repo/s6-rc-set-commit.o src/repo/s6-rc-set-commit.lo: src/repo/s6-rc-set-commit.c src/include/s6-rc/config.h src/include/s6-rc/s6rc.h src/repo/s6-rc-set-copy.o src/repo/s6-rc-set-copy.lo: src/repo/s6-rc-set-copy.c src/include/s6-rc/config.h src/include/s6-rc/s6rc.h src/repo/s6-rc-set-delete.o src/repo/s6-rc-set-delete.lo: src/repo/s6-rc-set-delete.c src/include/s6-rc/config.h src/include/s6-rc/s6rc.h +src/repo/s6-rc-set-install.o src/repo/s6-rc-set-install.lo: src/repo/s6-rc-set-install.c src/include/s6-rc/config.h src/include/s6-rc/s6rc.h src/repo/s6-rc-set-new.o src/repo/s6-rc-set-new.lo: src/repo/s6-rc-set-new.c src/include/s6-rc/config.h src/include/s6-rc/s6rc.h src/s6-rc/s6-rc-bundle.o src/s6-rc/s6-rc-bundle.lo: src/s6-rc/s6-rc-bundle.c src/include/s6-rc/config.h src/include/s6-rc/s6rc.h src/s6-rc/s6-rc-compile.o src/s6-rc/s6-rc-compile.lo: src/s6-rc/s6-rc-compile.c src/include/s6-rc/config.h src/include/s6-rc/s6rc.h @@ -80,27 +83,29 @@ src/s6-rc/s6-rc-update.o src/s6-rc/s6-rc-update.lo: src/s6-rc/s6-rc-update.c src src/s6-rc/s6-rc.o src/s6-rc/s6-rc.lo: src/s6-rc/s6-rc.c src/include/s6-rc/config.h src/include/s6-rc/s6rc.h ifeq ($(strip $(STATIC_LIBS_ARE_PIC)),) -libs6rc.a.xyzzy: src/libs6rc/s6rc_db_check_depcycles.o src/libs6rc/s6rc_db_check_pipelines.o src/libs6rc/s6rc_db_check_revdeps.o src/libs6rc/s6rc_db_read.o src/libs6rc/s6rc_db_read_sizes.o src/libs6rc/s6rc_db_read_uint32.o src/libs6rc/s6rc_graph_closure.o src/libs6rc/s6rc_live_state_size.o src/libs6rc/s6rc_live_state_read.o src/libs6rc/s6rc_livedir_canon.o src/libs6rc/s6rc_livedir_create.o src/libs6rc/s6rc_livedir_prefix.o src/libs6rc/s6rc_livedir_prefixsize.o src/libs6rc/s6rc_lock.o src/libs6rc/s6rc_ls.o src/libs6rc/s6rc_nlto0.o src/libs6rc/s6rc_read_uint.o src/libs6rc/s6rc_repo_badsub.o src/libs6rc/s6rc_repo_cleanup.o src/libs6rc/s6rc_repo_compile.o src/libs6rc/s6rc_repo_fillset.o src/libs6rc/s6rc_repo_fixset.o src/libs6rc/s6rc_repo_flattenservices.o src/libs6rc/s6rc_repo_list_sets.o src/libs6rc/s6rc_repo_listalldeps.o src/libs6rc/s6rc_repo_listcontents.o src/libs6rc/s6rc_repo_listdeps.o src/libs6rc/s6rc_repo_listdeps_internal.o src/libs6rc/s6rc_repo_listsub.o src/libs6rc/s6rc_repo_lock.o src/libs6rc/s6rc_repo_makedefbundle.o src/libs6rc/s6rc_repo_makesetbundles.o src/libs6rc/s6rc_repo_makestores.o src/libs6rc/s6rc_repo_makesvlist.o src/libs6rc/s6rc_repo_makesvlist_byname.o src/libs6rc/s6rc_repo_moveservices.o src/libs6rc/s6rc_repo_refcompile.o src/libs6rc/s6rc_repo_setcompile.o src/libs6rc/s6rc_repo_subnames.o src/libs6rc/s6rc_repo_sv_bcmpr.o src/libs6rc/s6rc_repo_sv_cmpr.o src/libs6rc/s6rc_repo_sync.o src/libs6rc/s6rc_repo_syncset.o src/libs6rc/s6rc_repo_syncset_tmp.o src/libs6rc/s6rc_repo_touch.o src/libs6rc/s6rc_repo_touchset.o src/libs6rc/s6rc_sanitize_dir.o src/libs6rc/s6rc_servicedir_internal.o src/libs6rc/s6rc_servicedir_block.o src/libs6rc/s6rc_servicedir_unblock.o src/libs6rc/s6rc_servicedir_copy_offline.o src/libs6rc/s6rc_servicedir_copy_online.o src/libs6rc/s6rc_servicedir_manage.o src/libs6rc/s6rc_servicedir_unsupervise.o src/libs6rc/s6rc_strrefcmp.o src/libs6rc/s6rc_type_check.o +libs6rc.a.xyzzy: src/libs6rc/s6rc_db_check_depcycles.o src/libs6rc/s6rc_db_check_pipelines.o src/libs6rc/s6rc_db_check_revdeps.o src/libs6rc/s6rc_db_read.o src/libs6rc/s6rc_db_read_sizes.o src/libs6rc/s6rc_db_read_uint32.o src/libs6rc/s6rc_graph_closure.o src/libs6rc/s6rc_live_state_size.o src/libs6rc/s6rc_live_state_read.o src/libs6rc/s6rc_livedir_canon.o src/libs6rc/s6rc_livedir_create.o src/libs6rc/s6rc_livedir_prefix.o src/libs6rc/s6rc_livedir_prefixsize.o src/libs6rc/s6rc_lock.o src/libs6rc/s6rc_ls.o src/libs6rc/s6rc_nlto0.o src/libs6rc/s6rc_read_uint.o src/libs6rc/s6rc_repo_badsub.o src/libs6rc/s6rc_repo_checkset.o src/libs6rc/s6rc_repo_cleanup.o src/libs6rc/s6rc_repo_compile.o src/libs6rc/s6rc_repo_fillset.o src/libs6rc/s6rc_repo_fixset.o src/libs6rc/s6rc_repo_flattenservices.o src/libs6rc/s6rc_repo_list_sets.o src/libs6rc/s6rc_repo_listalldeps.o src/libs6rc/s6rc_repo_listcontents.o src/libs6rc/s6rc_repo_listdeps.o src/libs6rc/s6rc_repo_listdeps_internal.o src/libs6rc/s6rc_repo_listsub.o src/libs6rc/s6rc_repo_lock.o src/libs6rc/s6rc_repo_makedefbundle.o src/libs6rc/s6rc_repo_makesetbundles.o src/libs6rc/s6rc_repo_makestores.o src/libs6rc/s6rc_repo_makesvlist.o src/libs6rc/s6rc_repo_makesvlist_byname.o src/libs6rc/s6rc_repo_moveservices.o src/libs6rc/s6rc_repo_refcompile.o src/libs6rc/s6rc_repo_setcompile.o src/libs6rc/s6rc_repo_setuptodate.o src/libs6rc/s6rc_repo_subnames.o src/libs6rc/s6rc_repo_sv_bcmpr.o src/libs6rc/s6rc_repo_sv_cmpr.o src/libs6rc/s6rc_repo_sync.o src/libs6rc/s6rc_repo_syncset.o src/libs6rc/s6rc_repo_syncset_tmp.o src/libs6rc/s6rc_repo_touch.o src/libs6rc/s6rc_repo_touchset.o src/libs6rc/s6rc_sanitize_dir.o src/libs6rc/s6rc_servicedir_internal.o src/libs6rc/s6rc_servicedir_block.o src/libs6rc/s6rc_servicedir_unblock.o src/libs6rc/s6rc_servicedir_copy_offline.o src/libs6rc/s6rc_servicedir_copy_online.o src/libs6rc/s6rc_servicedir_manage.o src/libs6rc/s6rc_servicedir_unsupervise.o src/libs6rc/s6rc_strrefcmp.o src/libs6rc/s6rc_type_check.o else -libs6rc.a.xyzzy:src/libs6rc/s6rc_db_check_depcycles.lo src/libs6rc/s6rc_db_check_pipelines.lo src/libs6rc/s6rc_db_check_revdeps.lo src/libs6rc/s6rc_db_read.lo src/libs6rc/s6rc_db_read_sizes.lo src/libs6rc/s6rc_db_read_uint32.lo src/libs6rc/s6rc_graph_closure.lo src/libs6rc/s6rc_live_state_size.lo src/libs6rc/s6rc_live_state_read.lo src/libs6rc/s6rc_livedir_canon.lo src/libs6rc/s6rc_livedir_create.lo src/libs6rc/s6rc_livedir_prefix.lo src/libs6rc/s6rc_livedir_prefixsize.lo src/libs6rc/s6rc_lock.lo src/libs6rc/s6rc_ls.lo src/libs6rc/s6rc_nlto0.lo src/libs6rc/s6rc_read_uint.lo src/libs6rc/s6rc_repo_badsub.lo src/libs6rc/s6rc_repo_cleanup.lo src/libs6rc/s6rc_repo_compile.lo src/libs6rc/s6rc_repo_fillset.lo src/libs6rc/s6rc_repo_fixset.lo src/libs6rc/s6rc_repo_flattenservices.lo src/libs6rc/s6rc_repo_list_sets.lo src/libs6rc/s6rc_repo_listalldeps.lo src/libs6rc/s6rc_repo_listcontents.lo src/libs6rc/s6rc_repo_listdeps.lo src/libs6rc/s6rc_repo_listdeps_internal.lo src/libs6rc/s6rc_repo_listsub.lo src/libs6rc/s6rc_repo_lock.lo src/libs6rc/s6rc_repo_makedefbundle.lo src/libs6rc/s6rc_repo_makesetbundles.lo src/libs6rc/s6rc_repo_makestores.lo src/libs6rc/s6rc_repo_makesvlist.lo src/libs6rc/s6rc_repo_makesvlist_byname.lo src/libs6rc/s6rc_repo_moveservices.lo src/libs6rc/s6rc_repo_refcompile.lo src/libs6rc/s6rc_repo_setcompile.lo src/libs6rc/s6rc_repo_subnames.lo src/libs6rc/s6rc_repo_sv_bcmpr.lo src/libs6rc/s6rc_repo_sv_cmpr.lo src/libs6rc/s6rc_repo_sync.lo src/libs6rc/s6rc_repo_syncset.lo src/libs6rc/s6rc_repo_syncset_tmp.lo src/libs6rc/s6rc_repo_touch.lo src/libs6rc/s6rc_repo_touchset.lo src/libs6rc/s6rc_sanitize_dir.lo src/libs6rc/s6rc_servicedir_internal.lo src/libs6rc/s6rc_servicedir_block.lo src/libs6rc/s6rc_servicedir_unblock.lo src/libs6rc/s6rc_servicedir_copy_offline.lo src/libs6rc/s6rc_servicedir_copy_online.lo src/libs6rc/s6rc_servicedir_manage.lo src/libs6rc/s6rc_servicedir_unsupervise.lo src/libs6rc/s6rc_strrefcmp.lo src/libs6rc/s6rc_type_check.lo +libs6rc.a.xyzzy:src/libs6rc/s6rc_db_check_depcycles.lo src/libs6rc/s6rc_db_check_pipelines.lo src/libs6rc/s6rc_db_check_revdeps.lo src/libs6rc/s6rc_db_read.lo src/libs6rc/s6rc_db_read_sizes.lo src/libs6rc/s6rc_db_read_uint32.lo src/libs6rc/s6rc_graph_closure.lo src/libs6rc/s6rc_live_state_size.lo src/libs6rc/s6rc_live_state_read.lo src/libs6rc/s6rc_livedir_canon.lo src/libs6rc/s6rc_livedir_create.lo src/libs6rc/s6rc_livedir_prefix.lo src/libs6rc/s6rc_livedir_prefixsize.lo src/libs6rc/s6rc_lock.lo src/libs6rc/s6rc_ls.lo src/libs6rc/s6rc_nlto0.lo src/libs6rc/s6rc_read_uint.lo src/libs6rc/s6rc_repo_badsub.lo src/libs6rc/s6rc_repo_checkset.lo src/libs6rc/s6rc_repo_cleanup.lo src/libs6rc/s6rc_repo_compile.lo src/libs6rc/s6rc_repo_fillset.lo src/libs6rc/s6rc_repo_fixset.lo src/libs6rc/s6rc_repo_flattenservices.lo src/libs6rc/s6rc_repo_list_sets.lo src/libs6rc/s6rc_repo_listalldeps.lo src/libs6rc/s6rc_repo_listcontents.lo src/libs6rc/s6rc_repo_listdeps.lo src/libs6rc/s6rc_repo_listdeps_internal.lo src/libs6rc/s6rc_repo_listsub.lo src/libs6rc/s6rc_repo_lock.lo src/libs6rc/s6rc_repo_makedefbundle.lo src/libs6rc/s6rc_repo_makesetbundles.lo src/libs6rc/s6rc_repo_makestores.lo src/libs6rc/s6rc_repo_makesvlist.lo src/libs6rc/s6rc_repo_makesvlist_byname.lo src/libs6rc/s6rc_repo_moveservices.lo src/libs6rc/s6rc_repo_refcompile.lo src/libs6rc/s6rc_repo_setcompile.lo src/libs6rc/s6rc_repo_setuptodate.lo src/libs6rc/s6rc_repo_subnames.lo src/libs6rc/s6rc_repo_sv_bcmpr.lo src/libs6rc/s6rc_repo_sv_cmpr.lo src/libs6rc/s6rc_repo_sync.lo src/libs6rc/s6rc_repo_syncset.lo src/libs6rc/s6rc_repo_syncset_tmp.lo src/libs6rc/s6rc_repo_touch.lo src/libs6rc/s6rc_repo_touchset.lo src/libs6rc/s6rc_sanitize_dir.lo src/libs6rc/s6rc_servicedir_internal.lo src/libs6rc/s6rc_servicedir_block.lo src/libs6rc/s6rc_servicedir_unblock.lo src/libs6rc/s6rc_servicedir_copy_offline.lo src/libs6rc/s6rc_servicedir_copy_online.lo src/libs6rc/s6rc_servicedir_manage.lo src/libs6rc/s6rc_servicedir_unsupervise.lo src/libs6rc/s6rc_strrefcmp.lo src/libs6rc/s6rc_type_check.lo endif libs6rc.pc: EXTRA_LIBS := -ls6 -lskarnet ${SPAWN_LIB} libs6rc.so.xyzzy: EXTRA_LIBS := -ls6 -lskarnet ${SPAWN_LIB} -libs6rc.so.xyzzy:src/libs6rc/s6rc_db_check_depcycles.lo src/libs6rc/s6rc_db_check_pipelines.lo src/libs6rc/s6rc_db_check_revdeps.lo src/libs6rc/s6rc_db_read.lo src/libs6rc/s6rc_db_read_sizes.lo src/libs6rc/s6rc_db_read_uint32.lo src/libs6rc/s6rc_graph_closure.lo src/libs6rc/s6rc_live_state_size.lo src/libs6rc/s6rc_live_state_read.lo src/libs6rc/s6rc_livedir_canon.lo src/libs6rc/s6rc_livedir_create.lo src/libs6rc/s6rc_livedir_prefix.lo src/libs6rc/s6rc_livedir_prefixsize.lo src/libs6rc/s6rc_lock.lo src/libs6rc/s6rc_ls.lo src/libs6rc/s6rc_nlto0.lo src/libs6rc/s6rc_read_uint.lo src/libs6rc/s6rc_repo_badsub.lo src/libs6rc/s6rc_repo_cleanup.lo src/libs6rc/s6rc_repo_compile.lo src/libs6rc/s6rc_repo_fillset.lo src/libs6rc/s6rc_repo_fixset.lo src/libs6rc/s6rc_repo_flattenservices.lo src/libs6rc/s6rc_repo_list_sets.lo src/libs6rc/s6rc_repo_listalldeps.lo src/libs6rc/s6rc_repo_listcontents.lo src/libs6rc/s6rc_repo_listdeps.lo src/libs6rc/s6rc_repo_listdeps_internal.lo src/libs6rc/s6rc_repo_listsub.lo src/libs6rc/s6rc_repo_lock.lo src/libs6rc/s6rc_repo_makedefbundle.lo src/libs6rc/s6rc_repo_makesetbundles.lo src/libs6rc/s6rc_repo_makestores.lo src/libs6rc/s6rc_repo_makesvlist.lo src/libs6rc/s6rc_repo_makesvlist_byname.lo src/libs6rc/s6rc_repo_moveservices.lo src/libs6rc/s6rc_repo_refcompile.lo src/libs6rc/s6rc_repo_setcompile.lo src/libs6rc/s6rc_repo_subnames.lo src/libs6rc/s6rc_repo_sv_bcmpr.lo src/libs6rc/s6rc_repo_sv_cmpr.lo src/libs6rc/s6rc_repo_sync.lo src/libs6rc/s6rc_repo_syncset.lo src/libs6rc/s6rc_repo_syncset_tmp.lo src/libs6rc/s6rc_repo_touch.lo src/libs6rc/s6rc_repo_touchset.lo src/libs6rc/s6rc_sanitize_dir.lo src/libs6rc/s6rc_servicedir_internal.lo src/libs6rc/s6rc_servicedir_block.lo src/libs6rc/s6rc_servicedir_unblock.lo src/libs6rc/s6rc_servicedir_copy_offline.lo src/libs6rc/s6rc_servicedir_copy_online.lo src/libs6rc/s6rc_servicedir_manage.lo src/libs6rc/s6rc_servicedir_unsupervise.lo src/libs6rc/s6rc_strrefcmp.lo src/libs6rc/s6rc_type_check.lo +libs6rc.so.xyzzy:src/libs6rc/s6rc_db_check_depcycles.lo src/libs6rc/s6rc_db_check_pipelines.lo src/libs6rc/s6rc_db_check_revdeps.lo src/libs6rc/s6rc_db_read.lo src/libs6rc/s6rc_db_read_sizes.lo src/libs6rc/s6rc_db_read_uint32.lo src/libs6rc/s6rc_graph_closure.lo src/libs6rc/s6rc_live_state_size.lo src/libs6rc/s6rc_live_state_read.lo src/libs6rc/s6rc_livedir_canon.lo src/libs6rc/s6rc_livedir_create.lo src/libs6rc/s6rc_livedir_prefix.lo src/libs6rc/s6rc_livedir_prefixsize.lo src/libs6rc/s6rc_lock.lo src/libs6rc/s6rc_ls.lo src/libs6rc/s6rc_nlto0.lo src/libs6rc/s6rc_read_uint.lo src/libs6rc/s6rc_repo_badsub.lo src/libs6rc/s6rc_repo_checkset.lo src/libs6rc/s6rc_repo_cleanup.lo src/libs6rc/s6rc_repo_compile.lo src/libs6rc/s6rc_repo_fillset.lo src/libs6rc/s6rc_repo_fixset.lo src/libs6rc/s6rc_repo_flattenservices.lo src/libs6rc/s6rc_repo_list_sets.lo src/libs6rc/s6rc_repo_listalldeps.lo src/libs6rc/s6rc_repo_listcontents.lo src/libs6rc/s6rc_repo_listdeps.lo src/libs6rc/s6rc_repo_listdeps_internal.lo src/libs6rc/s6rc_repo_listsub.lo src/libs6rc/s6rc_repo_lock.lo src/libs6rc/s6rc_repo_makedefbundle.lo src/libs6rc/s6rc_repo_makesetbundles.lo src/libs6rc/s6rc_repo_makestores.lo src/libs6rc/s6rc_repo_makesvlist.lo src/libs6rc/s6rc_repo_makesvlist_byname.lo src/libs6rc/s6rc_repo_moveservices.lo src/libs6rc/s6rc_repo_refcompile.lo src/libs6rc/s6rc_repo_setcompile.lo src/libs6rc/s6rc_repo_setuptodate.lo src/libs6rc/s6rc_repo_subnames.lo src/libs6rc/s6rc_repo_sv_bcmpr.lo src/libs6rc/s6rc_repo_sv_cmpr.lo src/libs6rc/s6rc_repo_sync.lo src/libs6rc/s6rc_repo_syncset.lo src/libs6rc/s6rc_repo_syncset_tmp.lo src/libs6rc/s6rc_repo_touch.lo src/libs6rc/s6rc_repo_touchset.lo src/libs6rc/s6rc_sanitize_dir.lo src/libs6rc/s6rc_servicedir_internal.lo src/libs6rc/s6rc_servicedir_block.lo src/libs6rc/s6rc_servicedir_unblock.lo src/libs6rc/s6rc_servicedir_copy_offline.lo src/libs6rc/s6rc_servicedir_copy_online.lo src/libs6rc/s6rc_servicedir_manage.lo src/libs6rc/s6rc_servicedir_unsupervise.lo src/libs6rc/s6rc_strrefcmp.lo src/libs6rc/s6rc_type_check.lo libs6rc.dylib.xyzzy: EXTRA_LIBS := -ls6 -lskarnet ${SPAWN_LIB} -libs6rc.dylib.xyzzy:src/libs6rc/s6rc_db_check_depcycles.lo src/libs6rc/s6rc_db_check_pipelines.lo src/libs6rc/s6rc_db_check_revdeps.lo src/libs6rc/s6rc_db_read.lo src/libs6rc/s6rc_db_read_sizes.lo src/libs6rc/s6rc_db_read_uint32.lo src/libs6rc/s6rc_graph_closure.lo src/libs6rc/s6rc_live_state_size.lo src/libs6rc/s6rc_live_state_read.lo src/libs6rc/s6rc_livedir_canon.lo src/libs6rc/s6rc_livedir_create.lo src/libs6rc/s6rc_livedir_prefix.lo src/libs6rc/s6rc_livedir_prefixsize.lo src/libs6rc/s6rc_lock.lo src/libs6rc/s6rc_ls.lo src/libs6rc/s6rc_nlto0.lo src/libs6rc/s6rc_read_uint.lo src/libs6rc/s6rc_repo_badsub.lo src/libs6rc/s6rc_repo_cleanup.lo src/libs6rc/s6rc_repo_compile.lo src/libs6rc/s6rc_repo_fillset.lo src/libs6rc/s6rc_repo_fixset.lo src/libs6rc/s6rc_repo_flattenservices.lo src/libs6rc/s6rc_repo_list_sets.lo src/libs6rc/s6rc_repo_listalldeps.lo src/libs6rc/s6rc_repo_listcontents.lo src/libs6rc/s6rc_repo_listdeps.lo src/libs6rc/s6rc_repo_listdeps_internal.lo src/libs6rc/s6rc_repo_listsub.lo src/libs6rc/s6rc_repo_lock.lo src/libs6rc/s6rc_repo_makedefbundle.lo src/libs6rc/s6rc_repo_makesetbundles.lo src/libs6rc/s6rc_repo_makestores.lo src/libs6rc/s6rc_repo_makesvlist.lo src/libs6rc/s6rc_repo_makesvlist_byname.lo src/libs6rc/s6rc_repo_moveservices.lo src/libs6rc/s6rc_repo_refcompile.lo src/libs6rc/s6rc_repo_setcompile.lo src/libs6rc/s6rc_repo_subnames.lo src/libs6rc/s6rc_repo_sv_bcmpr.lo src/libs6rc/s6rc_repo_sv_cmpr.lo src/libs6rc/s6rc_repo_sync.lo src/libs6rc/s6rc_repo_syncset.lo src/libs6rc/s6rc_repo_syncset_tmp.lo src/libs6rc/s6rc_repo_touch.lo src/libs6rc/s6rc_repo_touchset.lo src/libs6rc/s6rc_sanitize_dir.lo src/libs6rc/s6rc_servicedir_internal.lo src/libs6rc/s6rc_servicedir_block.lo src/libs6rc/s6rc_servicedir_unblock.lo src/libs6rc/s6rc_servicedir_copy_offline.lo src/libs6rc/s6rc_servicedir_copy_online.lo src/libs6rc/s6rc_servicedir_manage.lo src/libs6rc/s6rc_servicedir_unsupervise.lo src/libs6rc/s6rc_strrefcmp.lo src/libs6rc/s6rc_type_check.lo +libs6rc.dylib.xyzzy:src/libs6rc/s6rc_db_check_depcycles.lo src/libs6rc/s6rc_db_check_pipelines.lo src/libs6rc/s6rc_db_check_revdeps.lo src/libs6rc/s6rc_db_read.lo src/libs6rc/s6rc_db_read_sizes.lo src/libs6rc/s6rc_db_read_uint32.lo src/libs6rc/s6rc_graph_closure.lo src/libs6rc/s6rc_live_state_size.lo src/libs6rc/s6rc_live_state_read.lo src/libs6rc/s6rc_livedir_canon.lo src/libs6rc/s6rc_livedir_create.lo src/libs6rc/s6rc_livedir_prefix.lo src/libs6rc/s6rc_livedir_prefixsize.lo src/libs6rc/s6rc_lock.lo src/libs6rc/s6rc_ls.lo src/libs6rc/s6rc_nlto0.lo src/libs6rc/s6rc_read_uint.lo src/libs6rc/s6rc_repo_badsub.lo src/libs6rc/s6rc_repo_checkset.lo src/libs6rc/s6rc_repo_cleanup.lo src/libs6rc/s6rc_repo_compile.lo src/libs6rc/s6rc_repo_fillset.lo src/libs6rc/s6rc_repo_fixset.lo src/libs6rc/s6rc_repo_flattenservices.lo src/libs6rc/s6rc_repo_list_sets.lo src/libs6rc/s6rc_repo_listalldeps.lo src/libs6rc/s6rc_repo_listcontents.lo src/libs6rc/s6rc_repo_listdeps.lo src/libs6rc/s6rc_repo_listdeps_internal.lo src/libs6rc/s6rc_repo_listsub.lo src/libs6rc/s6rc_repo_lock.lo src/libs6rc/s6rc_repo_makedefbundle.lo src/libs6rc/s6rc_repo_makesetbundles.lo src/libs6rc/s6rc_repo_makestores.lo src/libs6rc/s6rc_repo_makesvlist.lo src/libs6rc/s6rc_repo_makesvlist_byname.lo src/libs6rc/s6rc_repo_moveservices.lo src/libs6rc/s6rc_repo_refcompile.lo src/libs6rc/s6rc_repo_setcompile.lo src/libs6rc/s6rc_repo_setuptodate.lo src/libs6rc/s6rc_repo_subnames.lo src/libs6rc/s6rc_repo_sv_bcmpr.lo src/libs6rc/s6rc_repo_sv_cmpr.lo src/libs6rc/s6rc_repo_sync.lo src/libs6rc/s6rc_repo_syncset.lo src/libs6rc/s6rc_repo_syncset_tmp.lo src/libs6rc/s6rc_repo_touch.lo src/libs6rc/s6rc_repo_touchset.lo src/libs6rc/s6rc_sanitize_dir.lo src/libs6rc/s6rc_servicedir_internal.lo src/libs6rc/s6rc_servicedir_block.lo src/libs6rc/s6rc_servicedir_unblock.lo src/libs6rc/s6rc_servicedir_copy_offline.lo src/libs6rc/s6rc_servicedir_copy_online.lo src/libs6rc/s6rc_servicedir_manage.lo src/libs6rc/s6rc_servicedir_unsupervise.lo src/libs6rc/s6rc_strrefcmp.lo src/libs6rc/s6rc_type_check.lo s6-rc-repo-init: EXTRA_LIBS := ${SYSCLOCK_LIB} s6-rc-repo-init: src/repo/s6-rc-repo-init.o ${LIBS6RC} -lskarnet s6-rc-repo-sync: EXTRA_LIBS := ${SYSCLOCK_LIB} s6-rc-repo-sync: src/repo/s6-rc-repo-sync.o ${LIBS6RC} -lskarnet -s6-rc-set-changestate: EXTRA_LIBS := ${SYSCLOCK_LIB} -s6-rc-set-changestate: src/repo/s6-rc-set-changestate.o ${LIBS6RC} -lskarnet +s6-rc-set-change: EXTRA_LIBS := ${SYSCLOCK_LIB} +s6-rc-set-change: src/repo/s6-rc-set-change.o ${LIBS6RC} -lskarnet s6-rc-set-commit: EXTRA_LIBS := ${SYSCLOCK_LIB} s6-rc-set-commit: src/repo/s6-rc-set-commit.o ${LIBS6RC} -lskarnet s6-rc-set-copy: EXTRA_LIBS := ${SYSCLOCK_LIB} s6-rc-set-copy: src/repo/s6-rc-set-copy.o ${LIBS6RC} -lskarnet s6-rc-set-delete: EXTRA_LIBS := ${SYSCLOCK_LIB} s6-rc-set-delete: src/repo/s6-rc-set-delete.o ${LIBS6RC} -lskarnet +s6-rc-set-install: EXTRA_LIBS := ${SYSCLOCK_LIB} +s6-rc-set-install: src/repo/s6-rc-set-install.o ${LIBS6RC} -lskarnet s6-rc-set-new: EXTRA_LIBS := ${SYSCLOCK_LIB} s6-rc-set-new: src/repo/s6-rc-set-new.o ${LIBS6RC} -lskarnet s6-rc: EXTRA_LIBS := ${SYSCLOCK_LIB} ${SPAWN_LIB} diff --git a/package/modes b/package/modes index f565295..a940c7a 100644 --- a/package/modes +++ b/package/modes @@ -13,5 +13,6 @@ s6-rc-repo-sync 0755 s6-rc-set-new 0755 s6-rc-set-copy 0755 s6-rc-set-delete 0755 -s6-rc-set-changestate 0755 +s6-rc-set-change 0755 s6-rc-set-commit 0755 +s6-rc-set-install 0755 diff --git a/package/targets.mak b/package/targets.mak index feffc92..08f564b 100644 --- a/package/targets.mak +++ b/package/targets.mak @@ -12,8 +12,9 @@ s6-rc-repo-sync \ s6-rc-set-new \ s6-rc-set-copy \ s6-rc-set-delete \ -s6-rc-set-changestate \ +s6-rc-set-change \ s6-rc-set-commit \ +s6-rc-set-install \ LIBEXEC_TARGETS := \ s6-rc-fdholder-filler \ diff --git a/src/include/s6-rc/repo.h b/src/include/s6-rc/repo.h index 5d0426a..f611059 100644 --- a/src/include/s6-rc/repo.h +++ b/src/include/s6-rc/repo.h @@ -32,6 +32,8 @@ extern int s6rc_repo_syncset_tmp (char const *, char const *, stralloc *, genall extern int s6rc_repo_lock (char const *, int) ; extern int s6rc_repo_touch (char const *) ; extern int s6rc_repo_touchset (char const *, char const *) ; +extern int s6rc_repo_checkset (char const *, char const *) ; +extern int s6rc_repo_setuptodate (char const *, char const *) ; extern int s6rc_repo_makesetbundles (char const *, char const *, unsigned int) ; extern int s6rc_repo_makedefbundle (char const *, char const *, char const *) ; diff --git a/src/libs6rc/deps-lib/s6rc b/src/libs6rc/deps-lib/s6rc index 79c2909..02797a8 100644 --- a/src/libs6rc/deps-lib/s6rc +++ b/src/libs6rc/deps-lib/s6rc @@ -16,6 +16,7 @@ s6rc_ls.o s6rc_nlto0.o s6rc_read_uint.o s6rc_repo_badsub.o +s6rc_repo_checkset.o s6rc_repo_cleanup.o s6rc_repo_compile.o s6rc_repo_fillset.o @@ -36,6 +37,7 @@ s6rc_repo_makesvlist_byname.o s6rc_repo_moveservices.o s6rc_repo_refcompile.o s6rc_repo_setcompile.o +s6rc_repo_setuptodate.o s6rc_repo_subnames.o s6rc_repo_sv_bcmpr.o s6rc_repo_sv_cmpr.o diff --git a/src/libs6rc/s6rc_repo_checkset.c b/src/libs6rc/s6rc_repo_checkset.c new file mode 100644 index 0000000..adf8674 --- /dev/null +++ b/src/libs6rc/s6rc_repo_checkset.c @@ -0,0 +1,40 @@ +/* ISC license. */ + +#include +#include + +#include +#include + +#include +#include + +int s6rc_repo_checkset (char const *repo, char const *set) +{ + struct stat st ; + size_t repolen = strlen(repo) ; + size_t setlen = strlen(set) ; + char fn[repolen + 10 + setlen] ; + memcpy(fn, repo, repolen) ; + memcpy(fn + repolen, "/sources/", 9) ; + memcpy(fn + repolen + 9, set, setlen + 1) ; + if (stat(fn, &st) == -1) + { + if (errno == ENOENT) + { + strerr_warnf4x("set ", set, " does not exist in repository ", repo) ; + return 3 ; + } + else + { + strerr_warnfu2sys("stat ", fn) ; + return 111 ; + } + } + if (!S_ISDIR(st.st_mode)) + { + strerr_warnf3x("file ", fn, " is not a directory") ; + return 102 ; + } + return 0 ; +} diff --git a/src/libs6rc/s6rc_repo_compile.c b/src/libs6rc/s6rc_repo_compile.c index b31a981..ac4207d 100644 --- a/src/libs6rc/s6rc_repo_compile.c +++ b/src/libs6rc/s6rc_repo_compile.c @@ -93,7 +93,7 @@ int s6rc_repo_compile (char const *repo, char const *set, char const *const *sub char fn[repolen + setlen + 11] ; memcpy(fn, newc, repolen + 10) ; memcpy(fn + repolen + 10, set, setlen + 1) ; - if (!atomic_symlink4(newc + repolen + 10, fn, oldc + repolen + 10, repolen + setlen + 45)) + if (!atomic_symlink4(newc + repolen + 10, fn, oldc + repolen + 10, setlen + 35)) { int e = errno ; rm_rf(newc) ; diff --git a/src/libs6rc/s6rc_repo_setuptodate.c b/src/libs6rc/s6rc_repo_setuptodate.c new file mode 100644 index 0000000..9e9fe58 --- /dev/null +++ b/src/libs6rc/s6rc_repo_setuptodate.c @@ -0,0 +1,45 @@ +/* ISC license. */ + +#include + +#include +#include + +#include +#include + +#include +#include + +int s6rc_repo_setuptodate (char const *repo, char const *set) +{ + struct stat stsource ; + struct stat stcompiled ; + size_t repolen = strlen(repo) ; + size_t setlen = strlen(set) ; + char srcfn[repolen + 17 + setlen] ; + char dstfn[repolen + 11 + setlen] ; + memcpy(srcfn, repo, repolen) ; + memcpy(srcfn + repolen, "/sources/", 9) ; + memcpy(srcfn + repolen + 9, set, setlen) ; + memcpy(srcfn + repolen + 9 + setlen, "/.stamp", 8) ; + memcpy(dstfn, repo, repolen) ; + memcpy(dstfn + repolen, "/compiled/", 10) ; + memcpy(dstfn + repolen + 10, set, setlen + 1) ; + if (stat(srcfn, &stsource) == -1) + { + strerr_warnfu2sys("stat ", srcfn) ; + return -1 ; + } + if (stat(dstfn, &stcompiled) == -1) + { + if (errno == ENOENT) return 0 ; + strerr_warnfu2sys("stat ", dstfn) ; + return -1 ; + } + return + stsource.st_atim.tv_sec < stcompiled.st_atim.tv_sec ? 1 : + stsource.st_atim.tv_sec > stcompiled.st_atim.tv_sec ? 0 : + stsource.st_atim.tv_nsec < stcompiled.st_atim.tv_nsec ; +} + diff --git a/src/repo/deps-exe/s6-rc-set-change b/src/repo/deps-exe/s6-rc-set-change new file mode 100644 index 0000000..6dd7af7 --- /dev/null +++ b/src/repo/deps-exe/s6-rc-set-change @@ -0,0 +1,3 @@ +${LIBS6RC} +-lskarnet +${SYSCLOCK_LIB} diff --git a/src/repo/deps-exe/s6-rc-set-changestate b/src/repo/deps-exe/s6-rc-set-changestate deleted file mode 100644 index 6dd7af7..0000000 --- a/src/repo/deps-exe/s6-rc-set-changestate +++ /dev/null @@ -1,3 +0,0 @@ -${LIBS6RC} --lskarnet -${SYSCLOCK_LIB} diff --git a/src/repo/deps-exe/s6-rc-set-install b/src/repo/deps-exe/s6-rc-set-install new file mode 100644 index 0000000..6dd7af7 --- /dev/null +++ b/src/repo/deps-exe/s6-rc-set-install @@ -0,0 +1,3 @@ +${LIBS6RC} +-lskarnet +${SYSCLOCK_LIB} diff --git a/src/repo/s6-rc-set-change.c b/src/repo/s6-rc-set-change.c new file mode 100644 index 0000000..c659471 --- /dev/null +++ b/src/repo/s6-rc-set-change.c @@ -0,0 +1,217 @@ +/* ISC license. */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#define USAGE "s6-rc-set-change [ -v verbosity ] [ -r repo ] [ -E ] [ -f | -I fail|pull|warn ] [ -n ] set newstate services..." +#define dieusage() strerr_dieusage(100, USAGE) + +enum golb_e +{ + GOLB_FORCE_ESSENTIAL = 0x01, + GOLB_IGNORE_DEPENDENCIES = 0x02, + GOLB_DRYRUN = 0x04 +} ; + +enum gola_e +{ + GOLA_VERBOSITY, + GOLA_REPODIR, + GOLA_FORCELEVEL, + GOLA_N +} ; + +struct subname_s +{ + char const *name ; + uint8_t sub ; +} ; + +static gol_bool const rgolb[] = +{ + { .so = 'E', .lo = "force-essential", .clear = 0, .set = GOLB_FORCE_ESSENTIAL }, + { .so = 'f', .lo = "ignore-dependencies", .clear = 0, .set = GOLB_IGNORE_DEPENDENCIES }, + { .so = 'n', .lo = "dry-run", .clear = 0, .set = GOLB_DRYRUN } +} ; + +static gol_arg const rgola[] = +{ + { .so = 'v', .lo = "verbosity", .i = GOLA_VERBOSITY }, + { .so = 'r', .lo = "repodir", .i = GOLA_REPODIR }, + { .so = 'I', .lo = "if-dependencies-found", .i = GOLA_FORCELEVEL } +} ; + +static struct subname_s const accepted_forcelevels[] = +{ + { .name = "fail", .sub = 0 }, + { .name = "pull", .sub = 2 }, + { .name = "warn", .sub = 1 } +} ; + +static uint64_t wgolb = 0 ; + +static struct subname_s const accepted_subs[] = +{ + { .name = "active", .sub = 1 }, + { .name = "always", .sub = 3 }, + { .name = "disable", .sub = 1 }, + { .name = "disabled", .sub = 1 }, + { .name = "enable", .sub = 2 }, + { .name = "enabled", .sub = 2 }, + { .name = "essential", .sub = 3 }, + { .name = "make-essential", .sub = 3 }, + { .name = "mask", .sub = 0 }, + { .name = "masked", .sub = 0 }, + { .name = "onboot", .sub = 2 }, + { .name = "unmask", .sub = 1 }, + { .name = "unmasked", .sub = 1 } +} ; + +static int subname_cmp (void const *a, void const *b) +{ + return strcmp((char const *)a, ((struct subname_s const *)b)->name) ; +} + +int main (int argc, char const *const *argv) +{ + stralloc storage = STRALLOC_ZERO ; + genalloc svlist = GENALLOC_ZERO ; /* s6rc_repo_sv */ + genalloc indices = GENALLOC_ZERO ; /* size_t then uint32_t */ + int fdlock ; + unsigned int verbosity = 1 ; + unsigned int forcelevel = 1 ; + char const *wgola[GOLA_N] = { 0 } ; + unsigned int golc ; + struct subname_s *newsub ; + size_t max = 0, sabase ; + s6rc_repo_sv *list ; + uint32_t listn, n ; + + PROG = "s6-rc-set-change" ; + wgola[GOLA_REPODIR] = S6RC_REPO_BASE ; + + golc = GOL_main(argc, argv, rgolb, rgola, &wgolb, wgola) ; + argc -= golc ; argv += golc ; + if (wgola[GOLA_VERBOSITY] && !uint0_scan(wgola[GOLA_VERBOSITY], &verbosity)) + strerr_dief1x(100, "verbosity needs to be an unsigned integer") ; + if (wgola[GOLA_FORCELEVEL]) + { + struct subname_s *p = bsearch(wgola[GOLA_FORCELEVEL], accepted_forcelevels, sizeof(accepted_forcelevels)/sizeof(struct subname_s), sizeof(struct subname_s), &subname_cmp) ; + if (!p) strerr_dief1x(100, "if-dependencies-found needs to be fail, warn or pull") ; + forcelevel = p->sub ; + } + if (argc < 3) dieusage() ; + if (strchr(argv[0], '/') || strchr(argv[0], '\n')) + strerr_dief1x(100, "set names cannot contain / or newlines") ; + + newsub = bsearch(argv[1], accepted_subs, sizeof(accepted_subs)/sizeof(struct subname_s), sizeof(struct subname_s), &subname_cmp) ; + if (!newsub) strerr_dief2x(100, "unrecognized state change directive:", argv[1]) ; + if (newsub->sub == 3 && !(wgolb & GOLB_FORCE_ESSENTIAL)) + strerr_dief1x(100, " artificially mark a service as essential without --force-essential") ; + + fdlock = s6rc_repo_lock(wgola[GOLA_REPODIR], 1) ; + if (fdlock == -1) strerr_diefu2sys(111, "lock ", wgola[GOLA_REPODIR]) ; + + if (!s6rc_repo_makesvlist_byname(wgola[GOLA_REPODIR], argv[0], &storage, &svlist)) _exit(111) ; + list = genalloc_s(s6rc_repo_sv, &svlist) ; + listn = genalloc_len(s6rc_repo_sv, &svlist) ; + sabase = storage.len ; + { + int r = s6rc_repo_flattenservices(wgola[GOLA_REPODIR], argv + 2, argc - 2, &storage, &indices) ; + if (r) _exit(r) ; + } + n = genalloc_len(size_t, &indices) ; + if (!n) strerr_dief1x(101, "can't happen: 0 services in flattened list!") ; + + s6rc_repo_sv starting[n] ; + uint32_t ind[n] ; + + for (uint32_t i = 0 ; i < n ; i++) + { + char const *s = storage.s + genalloc_s(size_t, &indices)[i] ; + s6rc_repo_sv *p = bsearchr(s, list, listn, sizeof(s6rc_repo_sv), &s6rc_repo_sv_bcmpr, storage.s) ; + if (!p) strerr_dief7x(102, "inconsistent view in set ", argv[0], " of repository ", wgola[GOLA_REPODIR], ": service ", s, " is defined in the reference database but not in the textual representation of the set") ; + starting[i] = *p ; + ind[i] = p - list ; + max += strlen(s) + 1 ; + } + + storage.len = sabase ; + genalloc_setlen(size_t, &indices, 0) ; + + if (!(wgolb & GOLB_IGNORE_DEPENDENCIES)) + { + size_t m = 0 ; + char const *tmpstart[n] ; + char tmpstore[max] ; + + for (uint32_t i = 0 ; i < n ; i++) + { + size_t len ; + list[ind[i]].sub = newsub->sub ; + tmpstart[i] = tmpstore + m ; + len = strlen(storage.s + list[ind[i]].pos) + 1 ; + memcpy(tmpstore + m, storage.s + list[ind[i]].pos, len) ; + m += len ; + } + + if (!s6rc_repo_badsub(wgola[GOLA_REPODIR], argv[0], tmpstart, n, newsub->sub, 3, list, listn, &storage, &indices)) _exit(111) ; + if (genalloc_len(uint32_t, &indices)) + { + uint32_t const *bads = genalloc_s(uint32_t, &indices) ; + uint32_t badn = genalloc_len(uint32_t, &indices) ; + if (verbosity) + { + char const *arg[10 + (badn << 1)] ; + arg[0] = PROG ; + arg[1] = ": " ; + arg[2] = !forcelevel ? "fatal" : "warning" ; + arg[3] = ": the following services (" ; + arg[4] = newsub->sub >= 2 ? "dependencies of" : "depending on" ; + arg[5] = " the ones given as arguments) " ; + arg[6] = forcelevel == 2 ? "are also being" : "also need to be" ; + arg[7] = " changed to \"" ; + arg[8] = s6rc_repo_subnames[newsub->sub] ; + arg[9] = "\": " ; + for (uint32_t i = 0 ; i < badn ; i++) + { + arg[10 + (i << 1)] = storage.s + list[bads[i]].pos ; + arg[11 + (i << 1)] = i < badn ? " " : "" ; + } + strerr_warnv(arg, 10 + (badn << 1)) ; + } + if (!forcelevel) _exit(1) ; + if (wgolb & GOLB_DRYRUN) _exit(0) ; + if (forcelevel == 2) + { + s6rc_repo_sv full[n + badn] ; + for (uint32_t i = 0 ; i < n ; i++) full[i] = starting[i] ; + for (uint32_t i = 0 ; i < badn ; i++) full[n + i] = list[bads[i]] ; + if (!s6rc_repo_moveservices(wgola[GOLA_REPODIR], argv[0], full, n + badn, newsub->sub, storage.s, verbosity)) _exit(111) ; + _exit(0) ; + } + } + } + genalloc_free(uint32_t, &indices) ; + stralloc_free(&storage) ; + + if (!(wgolb & GOLB_DRYRUN)) + { + if (!s6rc_repo_moveservices(wgola[GOLA_REPODIR], argv[0], starting, n, newsub->sub, storage.s, verbosity)) _exit(111) ; + } + _exit(0) ; +} diff --git a/src/repo/s6-rc-set-changestate.c b/src/repo/s6-rc-set-changestate.c deleted file mode 100644 index 1064051..0000000 --- a/src/repo/s6-rc-set-changestate.c +++ /dev/null @@ -1,217 +0,0 @@ -/* ISC license. */ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#define USAGE "s6-rc-set-changestate [ -v verbosity ] [ -r repo ] [ -E ] [ -f | -I fail|pull|warn ] [ -n ] set newstate services..." -#define dieusage() strerr_dieusage(100, USAGE) - -enum golb_e -{ - GOLB_FORCE_ESSENTIAL = 0x01, - GOLB_IGNORE_DEPENDENCIES = 0x02, - GOLB_DRYRUN = 0x04 -} ; - -enum gola_e -{ - GOLA_VERBOSITY, - GOLA_REPODIR, - GOLA_FORCELEVEL, - GOLA_N -} ; - -struct subname_s -{ - char const *name ; - uint8_t sub ; -} ; - -static gol_bool const rgolb[] = -{ - { .so = 'E', .lo = "force-essential", .clear = 0, .set = GOLB_FORCE_ESSENTIAL }, - { .so = 'f', .lo = "ignore-dependencies", .clear = 0, .set = GOLB_IGNORE_DEPENDENCIES }, - { .so = 'n', .lo = "dry-run", .clear = 0, .set = GOLB_DRYRUN } -} ; - -static gol_arg const rgola[] = -{ - { .so = 'v', .lo = "verbosity", .i = GOLA_VERBOSITY }, - { .so = 'r', .lo = "repodir", .i = GOLA_REPODIR }, - { .so = 'I', .lo = "if-dependencies-found", .i = GOLA_FORCELEVEL } -} ; - -static struct subname_s const accepted_forcelevels[] = -{ - { .name = "fail", .sub = 0 }, - { .name = "pull", .sub = 2 }, - { .name = "warn", .sub = 1 } -} ; - -static uint64_t wgolb = 0 ; - -static struct subname_s const accepted_subs[] = -{ - { .name = "active", .sub = 1 }, - { .name = "always", .sub = 3 }, - { .name = "disable", .sub = 1 }, - { .name = "disabled", .sub = 1 }, - { .name = "enable", .sub = 2 }, - { .name = "enabled", .sub = 2 }, - { .name = "essential", .sub = 3 }, - { .name = "make-essential", .sub = 3 }, - { .name = "mask", .sub = 0 }, - { .name = "masked", .sub = 0 }, - { .name = "onboot", .sub = 2 }, - { .name = "unmask", .sub = 1 }, - { .name = "unmasked", .sub = 1 } -} ; - -static int subname_cmp (void const *a, void const *b) -{ - return strcmp((char const *)a, ((struct subname_s const *)b)->name) ; -} - -int main (int argc, char const *const *argv) -{ - stralloc storage = STRALLOC_ZERO ; - genalloc svlist = GENALLOC_ZERO ; /* s6rc_repo_sv */ - genalloc indices = GENALLOC_ZERO ; /* size_t then uint32_t */ - int fdlock ; - unsigned int verbosity = 1 ; - unsigned int forcelevel = 1 ; - char const *wgola[GOLA_N] = { 0 } ; - unsigned int golc ; - struct subname_s *newsub ; - size_t max = 0, sabase ; - s6rc_repo_sv *list ; - uint32_t listn, n ; - - PROG = "s6-rc-set-changestate" ; - wgola[GOLA_REPODIR] = S6RC_REPO_BASE ; - - golc = GOL_main(argc, argv, rgolb, rgola, &wgolb, wgola) ; - argc -= golc ; argv += golc ; - if (wgola[GOLA_VERBOSITY] && !uint0_scan(wgola[GOLA_VERBOSITY], &verbosity)) - strerr_dief1x(100, "verbosity needs to be an unsigned integer") ; - if (wgola[GOLA_FORCELEVEL]) - { - struct subname_s *p = bsearch(wgola[GOLA_FORCELEVEL], accepted_forcelevels, sizeof(accepted_forcelevels)/sizeof(struct subname_s), sizeof(struct subname_s), &subname_cmp) ; - if (!p) strerr_dief1x(100, "if-dependencies-found needs to be fail, warn or pull") ; - forcelevel = p->sub ; - } - if (argc < 3) dieusage() ; - if (strchr(argv[0], '/') || strchr(argv[0], '\n')) - strerr_dief1x(100, "set names cannot contain / or newlines") ; - - newsub = bsearch(argv[1], accepted_subs, sizeof(accepted_subs)/sizeof(struct subname_s), sizeof(struct subname_s), &subname_cmp) ; - if (!newsub) strerr_dief2x(100, "unrecognized state change directive:", argv[1]) ; - if (newsub->sub == 3 && !(wgolb & GOLB_FORCE_ESSENTIAL)) - strerr_dief1x(100, " artificially mark a service as essential without --force-essential") ; - - fdlock = s6rc_repo_lock(wgola[GOLA_REPODIR], 1) ; - if (fdlock == -1) strerr_diefu2sys(111, "lock ", wgola[GOLA_REPODIR]) ; - - if (!s6rc_repo_makesvlist_byname(wgola[GOLA_REPODIR], argv[0], &storage, &svlist)) _exit(111) ; - list = genalloc_s(s6rc_repo_sv, &svlist) ; - listn = genalloc_len(s6rc_repo_sv, &svlist) ; - sabase = storage.len ; - { - int r = s6rc_repo_flattenservices(wgola[GOLA_REPODIR], argv + 2, argc - 2, &storage, &indices) ; - if (r) _exit(r) ; - } - n = genalloc_len(size_t, &indices) ; - if (!n) strerr_dief1x(101, "can't happen: 0 services in flattened list!") ; - - s6rc_repo_sv starting[n] ; - uint32_t ind[n] ; - - for (uint32_t i = 0 ; i < n ; i++) - { - char const *s = storage.s + genalloc_s(size_t, &indices)[i] ; - s6rc_repo_sv *p = bsearchr(s, list, listn, sizeof(s6rc_repo_sv), &s6rc_repo_sv_bcmpr, storage.s) ; - if (!p) strerr_dief7x(102, "inconsistent view in set ", argv[0], " of repository ", wgola[GOLA_REPODIR], ": service ", s, " is defined in the reference database but not in the textual representation of the set") ; - starting[i] = *p ; - ind[i] = p - list ; - max += strlen(s) + 1 ; - } - - storage.len = sabase ; - genalloc_setlen(size_t, &indices, 0) ; - - if (!(wgolb & GOLB_IGNORE_DEPENDENCIES)) - { - size_t m = 0 ; - char const *tmpstart[n] ; - char tmpstore[max] ; - - for (uint32_t i = 0 ; i < n ; i++) - { - size_t len ; - list[ind[i]].sub = newsub->sub ; - tmpstart[i] = tmpstore + m ; - len = strlen(storage.s + list[ind[i]].pos) + 1 ; - memcpy(tmpstore + m, storage.s + list[ind[i]].pos, len) ; - m += len ; - } - - if (!s6rc_repo_badsub(wgola[GOLA_REPODIR], argv[0], tmpstart, n, newsub->sub, 3, list, listn, &storage, &indices)) _exit(111) ; - if (genalloc_len(uint32_t, &indices)) - { - uint32_t const *bads = genalloc_s(uint32_t, &indices) ; - uint32_t badn = genalloc_len(uint32_t, &indices) ; - if (verbosity) - { - char const *arg[10 + (badn << 1)] ; - arg[0] = PROG ; - arg[1] = ": " ; - arg[2] = !forcelevel ? "fatal" : "warning" ; - arg[3] = ": the following services (" ; - arg[4] = newsub->sub >= 2 ? "dependencies of" : "depending on" ; - arg[5] = " the ones given as arguments) " ; - arg[6] = forcelevel == 2 ? "are also being" : "also need to be" ; - arg[7] = " changed to \"" ; - arg[8] = s6rc_repo_subnames[newsub->sub] ; - arg[9] = "\": " ; - for (uint32_t i = 0 ; i < badn ; i++) - { - arg[10 + (i << 1)] = storage.s + list[bads[i]].pos ; - arg[11 + (i << 1)] = i < badn ? " " : "" ; - } - strerr_warnv(arg, 10 + (badn << 1)) ; - } - if (!forcelevel) _exit(1) ; - if (wgolb & GOLB_DRYRUN) _exit(0) ; - if (forcelevel == 2) - { - s6rc_repo_sv full[n + badn] ; - for (uint32_t i = 0 ; i < n ; i++) full[i] = starting[i] ; - for (uint32_t i = 0 ; i < badn ; i++) full[n + i] = list[bads[i]] ; - if (!s6rc_repo_moveservices(wgola[GOLA_REPODIR], argv[0], full, n + badn, newsub->sub, storage.s, verbosity)) _exit(111) ; - _exit(0) ; - } - } - } - genalloc_free(uint32_t, &indices) ; - stralloc_free(&storage) ; - - if (!(wgolb & GOLB_DRYRUN)) - { - if (!s6rc_repo_moveservices(wgola[GOLA_REPODIR], argv[0], starting, n, newsub->sub, storage.s, verbosity)) _exit(111) ; - } - _exit(0) ; -} diff --git a/src/repo/s6-rc-set-commit.c b/src/repo/s6-rc-set-commit.c index 908f307..efdb2a9 100644 --- a/src/repo/s6-rc-set-commit.c +++ b/src/repo/s6-rc-set-commit.c @@ -51,60 +51,12 @@ static gol_arg const rgola[] = { .so = 'h', .lo = "fdholder-user", .i = GOLA_FDHUSER } } ; -static uint64_t wgolb = 0 ; - -static inline void check_set (char const *repo, char const *set) -{ - struct stat st ; - size_t repolen = strlen(repo) ; - size_t setlen = strlen(set) ; - char fn[repolen + 10 + setlen] ; - memcpy(fn, repo, repolen) ; - memcpy(fn + repolen, "/sources/", 9) ; - memcpy(fn + repolen + 9, set, setlen + 1) ; - if (stat(fn, &st) == -1) - { - if (errno == ENOENT) - strerr_dief4x(3, "set ", set, " does not exist in repository ", repo) ; - else strerr_diefu2sys(111, "stat ", fn) ; - } - if (!S_ISDIR(st.st_mode)) - strerr_dief3x(102, "file ", fn, " is not a directory") ; -} - -static inline int uptodate (char const *repo, char const *set) -{ - struct stat stsource ; - struct stat stcompiled ; - size_t repolen = strlen(repo) ; - size_t setlen = strlen(set) ; - char srcfn[repolen + 17 + setlen] ; - char dstfn[repolen + 11 + setlen] ; - memcpy(srcfn, repo, repolen) ; - memcpy(srcfn + repolen, "/sources/", 9) ; - memcpy(srcfn + repolen + 9, set, setlen) ; - memcpy(srcfn + repolen + 9 + setlen, "/.stamp", 8) ; - memcpy(dstfn, repo, repolen) ; - memcpy(dstfn + repolen, "/compiled/", 10) ; - memcpy(dstfn + repolen + 10, set, setlen + 1) ; - if (stat(srcfn, &stsource) == -1) - strerr_diefu2sys(111, "stat ", srcfn) ; - if (stat(dstfn, &stcompiled) == -1) - { - if (errno == ENOENT) return 0 ; - else strerr_diefu2sys(111, "stat ", dstfn) ; - } - return - stsource.st_atim.tv_sec < stcompiled.st_atim.tv_sec ? 1 : - stsource.st_atim.tv_sec > stcompiled.st_atim.tv_sec ? 0 : - stsource.st_atim.tv_nsec < stcompiled.st_atim.tv_nsec ; -} - int main (int argc, char const *const *argv) { int fdlock ; unsigned int verbosity = 1 ; char const *wgola[GOLA_N] = { 0 } ; + uint64_t wgolb = 0 ; unsigned int golc ; int r ; @@ -122,11 +74,17 @@ int main (int argc, char const *const *argv) fdlock = s6rc_repo_lock(wgola[GOLA_REPODIR], 1) ; if (fdlock == -1) strerr_diefu2sys(111, "lock ", wgola[GOLA_REPODIR]) ; - check_set(wgola[GOLA_REPODIR], argv[0]) ; - if (!(wgolb & GOLB_FORCE) && uptodate(wgola[GOLA_REPODIR], argv[0])) + r = s6rc_repo_checkset(wgola[GOLA_REPODIR], argv[0]) ; + if (r) _exit(r) ; + if (!(wgolb & GOLB_FORCE)) { - if (verbosity >= 2) strerr_warni3x("set ", argv[0], " is already up-to-date.") ; - _exit(0) ; + r = s6rc_repo_setuptodate(wgola[GOLA_REPODIR], argv[0]) ; + if (r == -1) _exit(111) ; + if (r) + { + if (verbosity >= 2) strerr_warni3x("set ", argv[0], " is already up-to-date.") ; + _exit(0) ; + } } size_t oldclen = S6RC_REPO_COMPILE_BUFLEN(strlen(wgola[GOLA_REPODIR]), strlen(argv[0])) ; diff --git a/src/repo/s6-rc-set-install.c b/src/repo/s6-rc-set-install.c new file mode 100644 index 0000000..2e0b7a0 --- /dev/null +++ b/src/repo/s6-rc-set-install.c @@ -0,0 +1,205 @@ +/* ISC license. */ + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#define USAGE "s6-rc-set-install [ -v verbosity ] [ -l livedir ] [ -r repo ] [ -f convfile ] [ -b ] [ -K ] set bootdbdir" +#define dieusage() strerr_dieusage(100, USAGE) + +enum golb_e +{ + GOLB_BLOCK = 0x01, + GOLB_KEEPOLD = 0x02 +} ; + +enum gola_e +{ + GOLA_VERBOSITY, + GOLA_LIVEDIR, + GOLA_REPODIR, + GOLA_CONVFILE, + GOLA_N +} ; + +static gol_bool const rgolb[] = +{ + { .so = 'b', .lo = "block", .clear = 0, .set = GOLB_BLOCK }, + { .so = 'K', .lo = "keep-old", .clear = 0, .set = GOLB_KEEPOLD } +} ; + +static gol_arg const rgola[] = +{ + { .so = 'v', .lo = "verbosity", .i = GOLA_VERBOSITY }, + { .so = 'l', .lo = "livedir", .i = GOLA_LIVEDIR }, + { .so = 'r', .lo = "repodir", .i = GOLA_REPODIR }, + { .so = 'f', .lo = "conversion-file", .i = GOLA_CONVFILE } +} ; + +int main (int argc, char const *const *argv) +{ + int fdlock ; + unsigned int verbosity = 1 ; + char const *wgola[GOLA_N] = { 0 } ; + uint64_t wgolb = 0 ; + unsigned int golc ; + int r ; + + PROG = "s6-rc-set-install" ; + wgola[GOLA_LIVEDIR] = S6RC_LIVE_BASE ; + wgola[GOLA_REPODIR] = S6RC_REPO_BASE ; + + golc = GOL_main(argc, argv, rgolb, rgola, &wgolb, wgola) ; + argc -= golc ; argv += golc ; + if (wgola[GOLA_VERBOSITY] && !uint0_scan(wgola[GOLA_VERBOSITY], &verbosity)) + strerr_dief1x(100, "verbosity needs to be an unsigned integer") ; + if (argc < 2) dieusage() ; + if (strchr(argv[0], '/') || strchr(argv[0], '\n')) + strerr_dief1x(100, "set names cannot contain / or newlines") ; + + fdlock = s6rc_repo_lock(wgola[GOLA_REPODIR], 0) ; + if (fdlock == -1) strerr_diefu2sys(111, "lock ", wgola[GOLA_REPODIR]) ; + r = s6rc_repo_checkset(wgola[GOLA_REPODIR], argv[0]) ; + if (r) _exit(r) ; + + r = s6rc_repo_setuptodate(wgola[GOLA_REPODIR], argv[0]) ; + if (r == -1) _exit(111) ; + if (!r) strerr_dief3x(1, "set ", argv[0], " is not up-to-date; commit it first") ; + + { + size_t repolen = strlen(wgola[GOLA_REPODIR]) ; + size_t setlen = strlen(argv[0]) ; + size_t clen = S6RC_REPO_COMPILE_BUFLEN(repolen, setlen) ; + size_t dstlen = strlen(argv[1]) ; + ssize_t l ; + pid_t pid ; + int wstat ; + char *olddb = 0 ; + char const *uargv[11] ; + char fmtv[UINT_FMT] ; + char clink[repolen + setlen + 11] ; + char cfull[clen] ; + char dstfn[dstlen + setlen + 36] ; + fmtv[uint_fmt(fmtv, verbosity)] = 0 ; + memcpy(clink, wgola[GOLA_REPODIR], repolen) ; + memcpy(clink + repolen, "/compiled/", 10) ; + memcpy(clink + repolen + 10, argv[0], setlen + 1) ; + memcpy(cfull, clink, repolen + 10) ; + memcpy(dstfn, argv[1], dstlen) ; + dstfn[dstlen] = '/' ; + l = readlink(clink, cfull + repolen + 10, setlen + 35) ; + if (l == -1) strerr_diefu2sys(111, "readlink ", clink) ; + if (l >= setlen + 35) strerr_diefu2x(102, "incorrect/unexpected link contents for ", clink) ; + cfull[repolen + 10 + l] = 0 ; + memcpy(dstfn + dstlen + 1, cfull + repolen + 10, l+1) ; + l = 0 ; + { + struct stat st ; + if (stat(argv[1], &st) == -1) + strerr_diefu2sys(111, "stat ", argv[1]) ; + if (!S_ISDIR(st.st_mode)) + strerr_dief2x(100, argv[1], " is not a directory") ; + if (stat(dstfn, &st) == -1) + { + if (errno != ENOENT) + strerr_diefu2sys(111, "stat ", dstfn) ; + } + else strerr_dief2x(102, dstfn, " already exists!?") ; + } + { + size_t llen = strlen(wgola[GOLA_LIVEDIR]) ; + char cfn[llen + 10] ; + memcpy(cfn, wgola[GOLA_LIVEDIR], llen) ; + memcpy(cfn + llen, "/compiled", 10) ; + olddb = realpath(cfn, 0) ; + if (!olddb && errno != ENOENT) strerr_diefu2sys(111, "realpath ", cfn) ; + } + + if (!hiercopy(cfull, dstfn)) + { + int e = errno ; + rm_rf(dstfn) ; + errno = e ; + strerr_diefu4sys(111, "recursively copy ", cfull, " to ", dstfn) ; + } + + uargv[l++] = S6RC_BINPREFIX "s6-rc-update" ; + if (wgolb & GOLB_BLOCK) uargv[l++] = "-b" ; + uargv[l++] = "-v" ; + uargv[l++] = fmtv ; + uargv[l++] = "-l" ; + uargv[l++] = wgola[GOLA_LIVEDIR] ; + if (wgola[GOLA_CONVFILE]) + { + uargv[l++] = "-f" ; + uargv[l++] = wgola[GOLA_CONVFILE] ; + } + uargv[l++] = "--" ; + uargv[l++] = dstfn ; + uargv[l++] = 0 ; + + pid = cspawn(uargv[0], uargv, (char const *const *)environ, 0, 0, 0) ; + if (!pid) + { + int e = errno ; + rm_rf(dstfn) ; + errno = e ; + strerr_diefu2sys(111, "spawn ", uargv[0]) ; + } + r = wait_pid(pid, &wstat) ; + if (r == -1) strerr_diefu3sys(111, "wait for the ", uargv[0], " process (updating may yet succeed)") ; + if (WIFSIGNALED(wstat)) + { + char fmt[INT_FMT] ; + fmt[int_fmt(fmt, WTERMSIG(wstat))] = 0 ; + strerr_dief3x(wait_estatus(wstat), uargv[0], " crashed with signal ", fmt) ; + } + r = WEXITSTATUS(wstat) ; + if (r == 111) + strerr_dief2x(111, uargv[0], " exited 111, unable to know the state of the live db or clean up") ; + if ((r >= 3 && r <= 10) || r == 100) + { + int e = errno ; + char fmt[INT_FMT] ; + fmt[int_fmt(fmt, r)] = 0 ; + rm_rf(dstfn) ; + errno = e ; + strerr_dief4x(r, uargv[0], " exited with code ", fmt, ": live database switch NOT performed") ; + } + if (olddb) + { + if (wgolb & GOLB_KEEPOLD) + { + if (buffer_puts(buffer_1small, olddb) == -1 + || !buffer_putflush(buffer_1small, "\n", 1)) + strerr_diefu1sys(111, "write to stdout (live database switch performed)") ; + } + else rm_rf(olddb) ; + } + if (r) + { + char fmt[INT_FMT] ; + fmt[int_fmt(fmt, r)] = 0 ; + strerr_dief4x(r, uargv[0], " exited with code ", fmt, ", but the live database switch was performed") ; + } + } + _exit(0) ; +} -- cgit v1.3.1