service: one owner for user-requested start/stop/restart

The D-Bus methods carried byte-for-byte copies of api.c's static
start/stop/restart helpers.  Promote them to service.c alongside
service_reload(), which already serves both callers, and reduce both
sides to svc_parse_jobstr-style adapters.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2026-08-16 22:03:39 +02:00
1 parent 3efa9d6f41
commit 9d4cc8e933
4 files changed
+90 -75

No files matched your search

+12 -37
View File
@@ -314,46 +314,24 @@ static int manager_get_service(link_call_t *call, void *userdata)
return 0;
}
/* Service-control helpers used by Start/Stop/Restart/Reload. These
* mirror the static helpers in api.c — kept private here so api.c
* stays untouched in this increment. */
/* svc_parse_jobstr-style adapters over the shared service helpers */
static int dbus_apply_stop(svc_t *svc, void *user_data)
{
(void)user_data;
if (!svc)
return 1;
service_timeout_cancel(svc);
svc_stop(svc);
service_step(svc);
if (!IS_RESERVED_RUNLEVEL(runlevel))
service_step_all(SVC_TYPE_ANY);
return 0;
return service_stop_now(svc);
}
static int dbus_apply_start(svc_t *svc, void *user_data)
{
(void)user_data;
if (!svc)
return 1;
service_timeout_cancel(svc);
svc_start(svc);
service_step(svc);
if (!IS_RESERVED_RUNLEVEL(runlevel))
service_step_all(SVC_TYPE_ANY);
return 0;
return service_start_now(svc);
}
static int dbus_apply_restart(svc_t *svc, void *user_data)
{
if (!svc)
return 1;
if (!svc_is_running(svc))
return dbus_apply_start(svc, user_data);
service_timeout_cancel(svc);
service_stop(svc);
service_step(svc);
return 0;
(void)user_data;
return service_restart_now(svc);
}
struct dispatch_ctx {
@@ -685,18 +663,15 @@ static int service1_start (link_call_t *c, void *u) { return service_action_met
static int service1_stop (link_call_t *c, void *u) { return service_action_method(c, u, dbus_apply_stop); }
static int service1_restart(link_call_t *c, void *u) { return service_action_method(c, u, dbus_apply_restart); }
static int service1_reload(link_call_t *call, void *userdata)
static int dbus_apply_reload(svc_t *svc, void *user_data)
{
svc_t *svc = userdata;
(void)user_data;
return service_reload(svc);
}
if (!svc)
return link_call_reply_error(call,
"org.finit.Error.NoSuchService",
"Service object no longer valid");
service_reload(svc);
(void)link_call_reply(call);
return 0;
static int service1_reload(link_call_t *c, void *u)
{
return service_action_method(c, u, dbus_apply_reload);
}
static const link_method_t service_methods[] = {