[SERVICE_AUTO_RESTART] = UNIT_ACTIVATING,
};
+static void service_unwatch_control_pid(Service *s) {
+ assert(s);
+
+ if (s->control_pid <= 0)
+ return;
+
+ unit_unwatch_pid(UNIT(s), s->control_pid);
+ s->control_pid = 0;
+}
+
+static void service_unwatch_main_pid(Service *s) {
+ assert(s);
+
+ if (s->main_pid <= 0)
+ return;
+
+ unit_unwatch_pid(UNIT(s), s->main_pid);
+ s->main_pid = 0;
+}
+
static void service_done(Unit *u) {
Service *s = SERVICE(u);
/* This will leak a process, but at least no memory or any of
* our resources */
- if (s->main_pid > 0) {
- unit_unwatch_pid(u, s->main_pid);
- s->main_pid = 0;
- }
-
- if (s->control_pid > 0) {
- unit_unwatch_pid(u, s->control_pid);
- s->control_pid = 0;
- }
+ service_unwatch_main_pid(s);
+ service_unwatch_control_pid(s);
unit_unwatch_timer(u, &s->timer_watch);
}
if (s->main_pid_known)
return 0;
+ assert(s->main_pid <= 0);
+
if (!s->pid_file)
return -ENOENT;
state != SERVICE_STOP &&
state != SERVICE_STOP_SIGTERM &&
state != SERVICE_STOP_SIGKILL)
- if (s->main_pid > 0) {
- unit_unwatch_pid(UNIT(s), s->main_pid);
- s->main_pid = 0;
- }
+ service_unwatch_main_pid(s);
if (state != SERVICE_START_PRE &&
state != SERVICE_START &&
state != SERVICE_STOP_POST &&
state != SERVICE_FINAL_SIGTERM &&
state != SERVICE_FINAL_SIGKILL) {
- if (s->control_pid > 0) {
- unit_unwatch_pid(UNIT(s), s->control_pid);
- s->control_pid = 0;
- }
-
+ service_unwatch_control_pid(s);
s->control_command = NULL;
}
if (!success)
s->failure = true;
+ service_unwatch_control_pid(s);
+
if ((s->control_command = s->exec_command[SERVICE_EXEC_STOP_POST]))
if ((r = service_spawn(s,
s->control_command,
if (!success)
s->failure = true;
+ service_unwatch_control_pid(s);
+
if ((s->control_command = s->exec_command[SERVICE_EXEC_STOP]))
if ((r = service_spawn(s,
s->control_command,
int r;
assert(s);
+ service_unwatch_control_pid(s);
+
if ((s->control_command = s->exec_command[SERVICE_EXEC_START_POST]))
if ((r = service_spawn(s,
s->control_command,
/* For simple services we immediately start
* the START_POST binaries. */
+ service_unwatch_main_pid(s);
+
s->main_pid = pid;
s->main_pid_known = true;
service_enter_start_post(s);
/* For forking services we wait until the start
* process exited. */
+ service_unwatch_control_pid(s);
+
s->control_pid = pid;
s->control_command = s->exec_command[SERVICE_EXEC_START];
} else if (s->type == SERVICE_FINISH) {
/* For finishing services we wait until the start
* process exited, too, but it is our main process. */
+ service_unwatch_main_pid(s);
+
s->main_pid = pid;
+ s->main_pid_known = true;
s->control_command = s->exec_command[SERVICE_EXEC_START];
} else
assert_not_reached("Unknown service type");
assert(s);
+ service_unwatch_control_pid(s);
+
if ((s->control_command = s->exec_command[SERVICE_EXEC_START_PRE]))
if ((r = service_spawn(s,
s->control_command,
assert(s);
+ service_unwatch_control_pid(s);
+
if ((s->control_command = s->exec_command[SERVICE_EXEC_RELOAD]))
if ((r = service_spawn(s,
s->control_command,
s->control_command = s->control_command->command_next;
+ service_unwatch_control_pid(s);
+
if ((r = service_spawn(s,
s->control_command,
true,