libink: a brokerless D-Bus implementation for Finit

Finit had no way to answer the question every service manager gets
asked: what is running, and change it.  D-Bus is how the rest of
userspace asks, but linking libdbus, sd-bus or GIO into PID 1 buys a
dependency, an allocator and a main loop we do not control.

So libink: the wire format, an object tree, and a bus of Finit's own
at /run/finit/bus, gated like INIT_SOCKET.  It speaks the standard
org.freedesktop.DBus, .Peer, .Introspectable interfaces, and Finit's
own Manager1, Service1 and Cond1 on top.  Methods that change
something are marked privileged and answered only for a caller the
kernel vouched for, via SO_PEERCRED.

Server and client both, since initctl is the first thing that needs
to talk to it, and its Start/Stop/Restart/Reload now go over the bus
rather than the legacy socket.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2026-08-13 09:28:14 +02:00
1 parent ae9a24f44f
commit 0a269f3298
39 files changed
+5530 -49

No files matched your search

+59 -7
View File
@@ -1443,17 +1443,65 @@ int service_stop(svc_t *svc)
}
/**
* service_reload - Reload a service
* service_reload - Request reload of a service, driven by the state machine
* @svc: Service to reload
*
* This function does some basic checks of the runtime state of Finit
* and a sanity check of the @svc before sending %SIGHUP or calling
* the reload:script command.
* Mark a service dirty so the state machine will (re-)apply its
* configuration, then advance the state machine. For services that
* don't handle SIGHUP this also clears the readiness condition and
* the pidfile/none-notify readiness flag so dependents are properly
* notified once the service comes back.
*
* Returns:
* POSIX OK(0) on success, non-zero if @svc is NULL.
*/
int service_reload(svc_t *svc)
{
if (!svc)
return 1;
if (svc_is_blocked(svc))
svc_start(svc);
else
service_timeout_cancel(svc);
/*
* Clear conditions before reload to ensure dependent services
* are properly updated. Only needed when the service does NOT
* support SIGHUP (noreload), because then it will be stopped
* and restarted, so conditions genuinely go away. When the
* service handles SIGHUP, its PID and pidfile persist, so the
* condition stays valid and dependents should not be disrupted.
*
* Note: only clear 'ready' for services where the pidfile
* inotify handler reasserts it (pid/none). For s6/systemd
* services readiness relies on their respective notification
* mechanism which may not re-trigger on SIGHUP.
*/
if (svc_is_noreload(svc)) {
svc_cond_clear(svc);
if (svc->notify == SVC_NOTIFY_PID || svc->notify == SVC_NOTIFY_NONE)
service_ready(svc, 0);
}
svc_mark_dirty(svc);
service_step(svc);
return 0;
}
/**
* service_reload_apply - Perform the actual reload of a running service
* @svc: Service to reload
*
* Low-level reload step: sends %SIGHUP or runs the reload:script
* command. Called by the state machine when a service marked
* reload-pending by service_reload() reaches the right state.
*
* Returns:
* POSIX OK(0) or non-zero on error.
*/
static int service_reload(svc_t *svc)
static int service_reload_apply(svc_t *svc)
{
const char *id = svc_ident(svc, NULL, 0);
int do_progress = 1;
@@ -3015,6 +3063,10 @@ static void svc_set_state(svc_t *svc, svc_state_t new_state)
return;
*state = new_state;
#ifdef HAVE_DBUS
dbus_notify_service_state(svc, old_state, new_state);
#endif
/*
* The unit has stopped: HALTED comes after any post:/cleanup:
* script, DONE is a completed run/task, where remain-after-exit
@@ -3384,7 +3436,7 @@ restart:
if (sm_in_reload())
break;
service_reload(svc);
service_reload_apply(svc);
}
svc_mark_clean(svc);
@@ -3422,7 +3474,7 @@ restart:
if (svc_is_noreload(svc))
service_stop(svc);
else
service_reload(svc);
service_reload_apply(svc);
break;
}