[MOUNT_MAINTAINANCE] = "maintainance"
};
+static void service_unwatch_control_pid(Mount *m) {
+ assert(m);
+
+ if (m->control_pid <= 0)
+ return;
+
+ unit_unwatch_pid(UNIT(m), m->control_pid);
+ m->control_pid = 0;
+}
+
static void mount_parameters_done(MountParameters *p) {
assert(p);
exec_command_done_array(m->exec_command, _MOUNT_EXEC_COMMAND_MAX);
m->control_command = NULL;
- if (m->control_pid > 0) {
- unit_unwatch_pid(u, m->control_pid);
- m->control_pid = 0;
- }
+ service_unwatch_control_pid(m);
unit_unwatch_timer(u, &m->timer_watch);
}
state != MOUNT_REMOUNTING_SIGTERM &&
state != MOUNT_REMOUNTING_SIGKILL) {
unit_unwatch_timer(UNIT(m), &m->timer_watch);
-
- if (m->control_pid > 0) {
- unit_unwatch_pid(UNIT(m), m->control_pid);
- m->control_pid = 0;
- }
-
+ service_unwatch_control_pid(m);
m->control_command = NULL;
}
NULL)) < 0)
goto fail;
+ service_unwatch_control_pid(m);
+
if ((r = mount_spawn(m, c, &m->control_pid)) < 0)
goto fail;
if (r < 0)
goto fail;
+ service_unwatch_control_pid(m);
+
if ((r = mount_spawn(m, c, &m->control_pid)) < 0)
goto fail;
goto fail;
}
+ service_unwatch_control_pid(m);
+
if ((r = mount_spawn(m, c, &m->control_pid)) < 0)
goto fail;
[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,
[SOCKET_MAINTAINANCE] = "maintainance"
};
+static void socket_unwatch_control_pid(Socket *s) {
+ assert(s);
+
+ if (s->control_pid <= 0)
+ return;
+
+ unit_unwatch_pid(UNIT(s), s->control_pid);
+ s->control_pid = 0;
+}
+
static void socket_done(Unit *u) {
Socket *s = SOCKET(u);
SocketPort *p;
exec_command_free_array(s->exec_command, _SOCKET_EXEC_COMMAND_MAX);
s->control_command = NULL;
- if (s->control_pid > 0) {
- unit_unwatch_pid(u, s->control_pid);
- s->control_pid = 0;
- }
+ socket_unwatch_control_pid(s);
s->service = NULL;
state != SOCKET_STOP_POST_SIGTERM &&
state != SOCKET_STOP_POST_SIGKILL) {
unit_unwatch_timer(UNIT(s), &s->timer_watch);
-
- if (s->control_pid > 0) {
- unit_unwatch_pid(UNIT(s), s->control_pid);
- s->control_pid = 0;
- }
-
+ socket_unwatch_control_pid(s);
s->control_command = NULL;
}
if (!success)
s->failure = true;
+ socket_unwatch_control_pid(s);
+
if ((s->control_command = s->exec_command[SOCKET_EXEC_STOP_POST]))
if ((r = socket_spawn(s, s->control_command, &s->control_pid)) < 0)
goto fail;
if (!success)
s->failure = true;
+ socket_unwatch_control_pid(s);
+
if ((s->control_command = s->exec_command[SOCKET_EXEC_STOP_PRE]))
if ((r = socket_spawn(s, s->control_command, &s->control_pid)) < 0)
goto fail;
goto fail;
}
+ socket_unwatch_control_pid(s);
+
if ((s->control_command = s->exec_command[SOCKET_EXEC_START_POST]))
if ((r = socket_spawn(s, s->control_command, &s->control_pid)) < 0) {
log_warning("%s failed to run start-post executable: %s", unit_id(UNIT(s)), strerror(-r));
int r;
assert(s);
+ socket_unwatch_control_pid(s);
+
if ((s->control_command = s->exec_command[SOCKET_EXEC_START_PRE]))
if ((r = socket_spawn(s, s->control_command, &s->control_pid)) < 0)
goto fail;
if (!success)
s->failure = true;
+ socket_unwatch_control_pid(s);
+
s->control_command = s->control_command->command_next;
if ((r = socket_spawn(s, s->control_command, &s->control_pid)) < 0)