From 97ca450966fb11273868a49cefa8d575bc34a13f Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Mon, 27 Feb 2023 23:00:54 +0100 Subject: [PATCH] Add support for static services in /lib/finit/system/*.conf Slowly migrating away from hard-coded services in plugins. This way it's possible for the user to both inspect and override as needed. Signed-off-by: Joachim Wiberg --- configure.ac | 5 +++++ src/conf.c | 25 +++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 14907fa2..6de02767 100644 --- a/configure.ac +++ b/configure.ac @@ -14,6 +14,7 @@ AC_CONFIG_FILES([Makefile man/Makefile plugins/Makefile src/Makefile + system/Makefile tmpfiles.d/Makefile test/test.env test/Makefile test/lib/Makefile test/src/Makefile]) @@ -289,6 +290,10 @@ AC_EXPAND_DIR(finit_tmpfiles, "$pkglibdir/tmpfiles.d") AC_SUBST(finit_tmpfiles) AC_DEFINE_UNQUOTED(FINIT_TMPFILES, "$finit_tmpfiles", [Finit tmpfiles.d/ .conf path]) +AC_EXPAND_DIR(system_path, "$pkglibdir/system") +AC_SUBST(system_path) +AC_DEFINE_UNQUOTED(FINIT_SYSPATH, "$system_path", [Static services, previously generated at runtime by plugins]) + AC_EXPAND_DIR(rescue_conf, "$pkglibdir/rescue.conf") AC_DEFINE_UNQUOTED(RESCUE_CONF, "$rescue_conf", [Finit rescue mode .conf]) AC_EXPAND_DIR(sample_conf, "$pkglibdir/sample.conf") diff --git a/src/conf.c b/src/conf.c index a8ce00f4..7ed855f4 100644 --- a/src/conf.c +++ b/src/conf.c @@ -941,9 +941,17 @@ int conf_reload(void) rlim2str(i), lim2str(&global_rlimit[i])); } - /* Next, read all *.conf in /etc/finit.d/ */ + /* + * Next, read all *.conf in /lib/finit/system and /etc/finit.d/ + * The system files were previously created at runtime by plugins + * but are now regular files that can be overridden by files in + * /etc/finit.d -- similar to how tmfiles.d(5) work. E.g., add + * an override .conf, or an ignore by symlinking to /dev/null + */ snprintf(path, sizeof(path), "%s/*.conf", finit_rcsd); glob(path, 0, NULL, &gl); + snprintf(path, sizeof(path), "%s/*.conf", FINIT_SYSPATH); + glob(path, GLOB_APPEND, NULL, &gl); snprintf(path, sizeof(path), "%s/enabled/*.conf", finit_rcsd); glob(path, GLOB_APPEND, NULL, &gl); @@ -951,7 +959,20 @@ int conf_reload(void) char *path = gl.gl_pathv[i]; char *rp = NULL; struct stat st; - size_t len; + size_t j, len; + + /* check for FINIT_SYSPATH overrides */ + for (j = i + 1; j < gl.gl_pathc; j++) { + if (strncmp(path, FINIT_SYSPATH, strlen(FINIT_SYSPATH))) + continue; + if (strcmp(basename(path), basename(gl.gl_pathv[j]))) + continue; + path = NULL; /* replacement later in list, skip this */ + break; + } + + if (!path) + continue; /* skip, override exists */ /* Check that it's an actual file ... beyond any symlinks */ if (lstat(path, &st)) {