exec_context_done(&s->exec_context);
exec_command_free_array(s->exec_command, _SERVICE_EXEC_COMMAND_MAX);
s->control_command = NULL;
+ s->main_command = NULL;
/* This will leak a process, but at least no memory or any of
* our resources */
state != SERVICE_RELOAD &&
state != SERVICE_STOP &&
state != SERVICE_STOP_SIGTERM &&
- state != SERVICE_STOP_SIGKILL)
+ state != SERVICE_STOP_SIGKILL) {
service_unwatch_main_pid(s);
+ s->main_command = NULL;
+ }
if (state != SERVICE_START_PRE &&
state != SERVICE_START &&
service_unwatch_control_pid(s);
- s->control_command_id = SERVICE_EXEC_STOP_POST;
if ((s->control_command = s->exec_command[SERVICE_EXEC_STOP_POST])) {
+ s->control_command_id = SERVICE_EXEC_STOP_POST;
+
if ((r = service_spawn(s,
s->control_command,
true,
service_unwatch_control_pid(s);
- s->control_command_id = SERVICE_EXEC_STOP;
if ((s->control_command = s->exec_command[SERVICE_EXEC_STOP])) {
+ s->control_command_id = SERVICE_EXEC_STOP;
+
if ((r = service_spawn(s,
s->control_command,
true,
service_unwatch_control_pid(s);
- s->control_command_id = SERVICE_EXEC_START_POST;
if ((s->control_command = s->exec_command[SERVICE_EXEC_START_POST])) {
+ s->control_command_id = SERVICE_EXEC_START_POST;
+
if ((r = service_spawn(s,
s->control_command,
true,
static void service_enter_start(Service *s) {
pid_t pid;
int r;
+ ExecCommand *c;
assert(s);
else
service_unwatch_main_pid(s);
- s->control_command_id = SERVICE_EXEC_START;
- s->control_command = s->exec_command[SERVICE_EXEC_START];
+ if (s->type == SERVICE_FORKING) {
+ s->control_command_id = SERVICE_EXEC_START;
+ c = s->control_command = s->exec_command[SERVICE_EXEC_START];
+
+ s->main_command = NULL;
+ } else {
+ s->control_command_id = _SERVICE_EXEC_COMMAND_INVALID;
+ s->control_command = NULL;
+
+ c = s->main_command = s->exec_command[SERVICE_EXEC_START];
+ }
if ((r = service_spawn(s,
- s->control_command,
+ c,
s->type == SERVICE_FORKING || s->type == SERVICE_DBUS || s->type == SERVICE_NOTIFY,
true,
true,
service_unwatch_control_pid(s);
- s->control_command_id = SERVICE_EXEC_START_PRE;
if ((s->control_command = s->exec_command[SERVICE_EXEC_START_PRE])) {
+ s->control_command_id = SERVICE_EXEC_START_PRE;
+
if ((r = service_spawn(s,
s->control_command,
true,
service_unwatch_control_pid(s);
- s->control_command_id = SERVICE_EXEC_RELOAD;
if ((s->control_command = s->exec_command[SERVICE_EXEC_RELOAD])) {
+ s->control_command_id = SERVICE_EXEC_RELOAD;
+
if ((r = service_spawn(s,
s->control_command,
true,
int r;
assert(s);
- assert(s->control_command);
- assert(s->control_command->command_next);
+ assert(s->main_command);
+ assert(s->main_command->command_next);
+ assert(s->type == SERVICE_ONESHOT);
if (!success)
s->failure = true;
- assert(s->control_command_id == SERVICE_EXEC_START);
- assert(s->type == SERVICE_ONESHOT);
-
- s->control_command = s->control_command->command_next;
+ s->main_command = s->main_command->command_next;
service_unwatch_main_pid(s);
if ((r = service_spawn(s,
- s->control_command,
+ s->main_command,
false,
true,
true,
s->main_pid = 0;
exec_status_exit(&s->main_exec_status, pid, code, status, s->exec_context.utmp_id);
- if (s->type != SERVICE_FORKING && s->control_command) {
- s->control_command->exec_status = s->main_exec_status;
+ /* If this is not a forking service than the main
+ * process got started and hence we copy the exit
+ * status so that it is recorded both as main and as
+ * control process exit status */
+ if (s->main_command) {
+ s->main_command->exec_status = s->main_exec_status;
- if (s->control_command->ignore)
+ if (s->main_command->ignore)
success = true;
}
"%s: main process exited, code=%s, status=%i", u->meta.id, sigchld_code_to_string(code), status);
s->failure = s->failure || !success;
- if (s->control_command &&
- s->control_command->command_next &&
+ if (s->main_command &&
+ s->main_command->command_next &&
success) {
/* There is another command to *
/* The service exited, so the service is officially
* gone. */
-
- s->control_command = NULL;
- s->control_command_id = _SERVICE_EXEC_COMMAND_INVALID;
+ s->main_command = NULL;
switch (s->state) {