Skip to content

Commit

Permalink
launch/service: delay service-start
Browse files Browse the repository at this point in the history
Delay the actual start of the systemd service until the correct matches
are installed. Otherwise, we might miss a PropertiesChanged signal,
because the scheduler happened to prefer scheduling all systemd jobs
before installing the D-Bus matches.

Reported-by: Stefan Agner <[email protected]>
Signed-off-by: David Rheinsberg <[email protected]>
  • Loading branch information
dvdhrm authored and teg committed Jan 30, 2023
1 parent 25b59bd commit e1a592f
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions src/launch/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,19 @@ static int service_watch_unit_load_handler(sd_bus_message *message, void *userda
if (r < 0)
return error_origin(r);

/*
* With the correct `PropertiesChanged` match installed, we can start
* the service. For classic activation, we use transient units. For
* systemd activation, we just spawn the specified unit.
*/

if (service->is_transient)
r = service_start_transient_unit(service);
else
r = service_start_unit(service);
if (r)
return error_fold(r);

return 1;
}

Expand Down Expand Up @@ -852,29 +865,6 @@ static int service_watch_unit(Service *service, const char *unit) {
return 0;
}

static int service_start(Service *service) {
int r;

if (service->active_unit) {
r = service_watch_jobs(service);
if (r)
return error_trace(r);

r = service_watch_unit(service, service->active_unit);
if (r)
return error_trace(r);

if (service->is_transient)
r = service_start_transient_unit(service);
else
r = service_start_unit(service);
if (r)
return error_trace(r);
}

return 0;
}

/**
* service_activate() - trigger a service activation
* @service: service to activate
Expand Down Expand Up @@ -976,9 +966,20 @@ int service_activate(Service *service, uint64_t serial) {
*/
}

r = service_start(service);
if (r)
return error_fold(r);
if (service->active_unit) {
r = service_watch_jobs(service);
if (r)
return error_fold(r);

r = service_watch_unit(service, service->active_unit);
if (r)
return error_fold(r);

/*
* Actual start of the service unit is delayed until all the
* correct D-Bus matches are configured.
*/
}

return 0;
}
Expand Down

0 comments on commit e1a592f

Please sign in to comment.