conf: generate runtime .conf files in the block format

Finit's own generated services -- watchdogd, keventd, runparts, and
the dbus plugin -- still went through conf_save_service() as legacy
one-liners, so `initctl show keventd` taught the old format on a
system otherwise converted to the new one.

conf_save_service() now takes the block title and a printf-style body
and writes the file itself:

    # Generated by finit:conf_save_service()
    service keventd {
            description = "Finit kernel event daemon"
            runlevel    = "S12345789"
            notify      = "none"
            cgroup init {}
            command     = "/libexec/finit/keventd"
    }

vfprintf() into the file also removes the fixed-size staging buffers
in the callers, where a long dbus pidfile path could truncate inside
a quoted string and take the whole generated file with it.

Semantics preserved: watch-only pid:! maps to pidfile without
pidfile-create, the watchdog keeps its watchdog:finit identity, and
log:console becomes log { file = "/dev/console" }.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2026-08-01 11:25:39 +02:00
1 parent 5aa7daf708
commit 9360c8e9b9
3 files changed
+45 -21

No files matched your search

+12 -8
View File
@@ -100,7 +100,7 @@ static void setup(void *arg)
{
char *group = DBUS_DAEMONGROUP;
char *user = DBUS_DAEMONUSER;
char line[256];
char pid[300];
char *pidfn;
mode_t prev;
char *cmd;
@@ -151,15 +151,19 @@ static void setup(void *arg)
* Register service with Finit
* Note: dbus drops privs after starting up.
*/
pid[0] = 0;
if (pidfn) {
snprintf(line, sizeof(line), "[S123456789] cgroup.system notify:none name:dbus pid:!%s %s %s -- %s",
pidfn, cmd, DBUS_ARGS, DBUS_DESC);
snprintf(pid, sizeof(pid), "\tpidfile = \"%s\"\n", pidfn);
free(pidfn);
} else
snprintf(line, sizeof(line), "[S123456789] cgroup.system notify:none name:dbus %s %s -- %s",
cmd, DBUS_ARGS, DBUS_DESC);
conf_save_service(SVC_TYPE_SERVICE, line, "dbus.conf");
}
conf_save_service(SVC_TYPE_SERVICE, "dbus", "dbus.conf",
"\tdescription = \"" DBUS_DESC "\"\n"
"\trunlevel = \"S123456789\"\n"
"\tnotify = \"none\"\n"
"\tcgroup system {}\n"
"%s"
"\tcommand = \"%s " DBUS_ARGS "\"\n",
pid, cmd);
free(cmd);
}