diff --git a/configure.ac b/configure.ac index 7f20eae6..218736a9 100644 --- a/configure.ac +++ b/configure.ac @@ -298,6 +298,7 @@ pkglibdir=$libdir/finit AC_SUBST(pkglibexecdir) AC_EXPAND_DIR(pkglibexecdir, "$libexecdir/finit") AC_DEFINE_UNQUOTED(FINIT_EXECPATH_, "$pkglibexecdir", [Finit libexec path]) +AC_DEFINE_UNQUOTED(FINIT_RUNPATH_, "/run/finit/system", [Finit runtime dynamic system services]) AC_EXPAND_DIR(plugin_path, "$pkglibdir/plugins") AC_SUBST(plugin_path) @@ -313,7 +314,7 @@ AC_DEFINE_UNQUOTED(FINIT_TMPFILES, "$finit_tmpfiles", [Finit tmpfiles.d/ .conf p 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_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]) diff --git a/doc/config.md b/doc/config.md index 0ac0bbe5..9182610b 100644 --- a/doc/config.md +++ b/doc/config.md @@ -68,10 +68,18 @@ the following layout is recommended: | : `- another-static.conf | : | `- finit.conf - `- lib/ + |- lib + | `- finit/ + | `- system/ + | |- 10-hotplug.conf + | `- ... + `- run/ `- finit/ `- system/ - |- 10-hotplug.conf + |- dbus.conf + |- keventd.conf + |- runparts.conf + |- watchdogd.conf `- ... Configuration files in `/etc` are provided by the user, or projects like @@ -85,6 +93,11 @@ the hard-coded services provided by plugins before. All .conf files in this directory be either replaced by a system administrator or overridden by a file with the same name in `/etc/finit.d/`. +The files in `/run/finit/system/*.conf` are created by plugins and Finit +bundled services like runparts, the [watchdog](#watchdog), and `keventd` +if they are enabled. Like `/lib/finit/system/*.conf`, these files can + be overridden by file with the same name in `/etc/finit.d/`. + Services in the `available/` and `enabled/` sub-directories are called dynamic services, in contrast to static services -- the only difference being where they are installed and if the `initctl` tool can manage them @@ -100,6 +113,8 @@ unique group, where files within each group are sorted alphabetically. /lib/finit/system/10-hotplug.conf /lib/finit/system/90-testserv.conf + /run/finit/system/dbus.conf + /run/finit/system/runparts.conf /etc/finit.d/10-abc.conf /etc/finit.d/20-abc.conf /etc/finit.d/enabled/1-aaa.conf diff --git a/plugins/dbus.c b/plugins/dbus.c index 5cc523ba..b7b92082 100644 --- a/plugins/dbus.c +++ b/plugins/dbus.c @@ -157,9 +157,7 @@ static void setup(void *arg) snprintf(line, sizeof(line), "[S123456789] cgroup.system name:dbus %s %s -- %s", cmd, DBUS_ARGS, DBUS_DESC); - if (service_register(SVC_TYPE_SERVICE, line, global_rlimit, NULL)) - err(1, "Failed registering %s", DBUS_DAEMON); - + conf_save_service(SVC_TYPE_SERVICE, line, "dbus.conf"); free(cmd); } diff --git a/src/conf.c b/src/conf.c index b9b3a221..d7cb0fec 100644 --- a/src/conf.c +++ b/src/conf.c @@ -462,6 +462,30 @@ void conf_save_exec_order(svc_t *svc, char *cmdline, int result) fclose(fp); } +/* + * Called by plugins and similar that dynamically generate system services + */ +void conf_save_service(int type, char *cfg, char *file) +{ + char fn[256]; + svc_t foo; + FILE *fp; + + snprintf(fn, sizeof(fn), "%s/%s", FINIT_RUNPATH_, file); + if (fexist(fn)) + warn("File %s already exists, overwriting.", fn); + fp = fopen(fn, "w"); + if (!fp) { + err(1, "Failed creating %s", fn); + return; + } + + foo.type = type; + fprintf(fp, "# Generated by finit:%s()\n", __func__); + fprintf(fp, "%s %s\n", svc_typestr(&foo), cfg); + fclose(fp); +} + /* * Sets, and makes a note of, all KEY=VALUE lines in a given .conf line * from finit.conf, or other .conf file. Note, PATH is always reset in @@ -1207,13 +1231,16 @@ int conf_reload(void) * * /lib/finit/system/10-hotplug.conf * /lib/finit/system/90-testserv.conf + * /run/finit/system/dbus.conf + * /run/finit/system/tty.conf * /etc/finit.d/10-abc.conf * /etc/finit.d/20-abc.conf * /etc/finit.d/enabled/1-aaa.conf * /etc/finit.d/enabled/1-abc.conf * /etc/finit.d/enabled/2-aaa.conf */ - glob_append(&gl, 0, "%s/*.conf", FINIT_SYSPATH); + glob_append(&gl, 0, "%s/*.conf", FINIT_SYSPATH_); + glob_append(&gl, 1, "%s/*.conf", FINIT_RUNPATH_); glob_append(&gl, 1, "%s/*.conf", finit_rcsd); glob_append(&gl, 1, "%s/enabled/*.conf", finit_rcsd); @@ -1238,9 +1265,10 @@ int conf_reload(void) struct stat st; size_t j, len; - /* check for FINIT_SYSPATH overrides */ + /* check for FINIT_SYSPATH_ or FINIT_RUNPATH_ overrides */ for (j = i + 1; j < gl.gl_pathc; j++) { - if (strncmp(path, FINIT_SYSPATH, strlen(FINIT_SYSPATH))) + if (strncmp(path, FINIT_SYSPATH_, strlen(FINIT_SYSPATH_)) && + strncmp(path, FINIT_RUNPATH_, strlen(FINIT_RUNPATH_))) continue; if (strcmp(basename(path), basename(gl.gl_pathv[j]))) continue; @@ -1300,6 +1328,9 @@ done: /* Drop record of all .conf changes */ drop_changes(); + if (bootstrap) + wdog = svc_find("watchdog", "finit"); + /* Override configured runlevel, user said 'S' on /proc/cmdline */ if (BOOTSTRAP && single) cfglevel = 1; @@ -1536,15 +1567,16 @@ int conf_init(uev_ctx_t *ctx) */ #ifdef WDT_DEVNODE if (whichp(FINIT_EXECPATH_ "/watchdogd") && fexist(WDT_DEVNODE)) { - service_register(SVC_TYPE_SERVICE, "[S0123456789] cgroup.init name:watchdog :finit " FINIT_EXECPATH_ "/watchdogd -- Finit watchdog daemon", global_rlimit, NULL); - wdog = svc_find("watchdog", "finit"); + conf_save_service(SVC_TYPE_SERVICE, "[S0123456789] cgroup.init name:watchdog :finit " + FINIT_EXECPATH_ "/watchdogd -- Finit watchdog daemon", "watchdogd.conf"); } #endif /* * Start kernel event daemon as soon as possible, if enabled */ if (whichp(FINIT_EXECPATH_ "/keventd")) - service_register(SVC_TYPE_SERVICE, "[S0123456789] cgroup.init " FINIT_EXECPATH_ "/keventd -- Finit kernel event daemon", global_rlimit, NULL); + conf_save_service(SVC_TYPE_SERVICE, "[S0123456789] cgroup.init " + FINIT_EXECPATH_ "/keventd -- Finit kernel event daemon", "keventd.conf"); dbg("Allow plugins to register early runlevel 1 run/task/services ..."); plugin_run_hooks(HOOK_SVC_PLUGIN); @@ -1580,7 +1612,7 @@ int conf_init(uev_ctx_t *ctx) snprintf(conf, sizeof(conf), "[S] log:console %s %s %s" " -- Calling runparts %s in the background", _PATH_RUNPARTS, args, runparts, runparts); - service_register(SVC_TYPE_TASK, conf, global_rlimit, NULL); + conf_save_service(SVC_TYPE_TASK, conf, "runparts.conf"); } return 0; diff --git a/src/conf.h b/src/conf.h index 58025ce5..769f538c 100644 --- a/src/conf.h +++ b/src/conf.h @@ -45,6 +45,7 @@ int conf_monitor (void); void conf_reset_env (void); void conf_saverc (void); void conf_save_exec_order (svc_t *svc, char *cmdline, int result); +void conf_save_service (int type, char *cfg, char *file); void conf_parse_cmdline (int argc, char *argv[]); int conf_parse_runlevels (char *runlevels); void conf_parse_cond (svc_t *svc, char *cond); diff --git a/tmpfiles.d/finit.conf b/tmpfiles.d/finit.conf index dc5988fb..81f2ceb7 100644 --- a/tmpfiles.d/finit.conf +++ b/tmpfiles.d/finit.conf @@ -11,4 +11,4 @@ d /run/finit/cond 0755 - - - d /run/finit/cond/pid 0755 - - - d /run/finit/cond/sys 0755 - - - d /run/finit/cond/usr 0755 - - - - +d /run/finit/system 0755 - - -