}
static int service_set_main_pid(Service *s, pid_t pid) {
+ pid_t ppid;
+
assert(s);
if (pid <= 1)
if (pid == getpid())
return -EINVAL;
+ if (get_parent_of_pid(pid, &ppid) >= 0 && ppid != getpid())
+ log_warning("%s: Supervising process %lu which is not our child. We'll most likely not notice when it exits.",
+ s->meta.id, (unsigned long) pid);
+
s->main_pid = pid;
s->main_pid_known = true;
return 0;
}
-static int service_set_control_pid(Service *s, pid_t pid) {
- assert(s);
-
- if (pid <= 1)
- return -EINVAL;
-
- if (pid == getpid())
- return -EINVAL;
-
- s->control_pid = pid;
-
- return 0;
-}
-
static void service_close_socket_fd(Service *s) {
assert(s);
static void service_enter_stop(Service *s, bool success) {
int r;
- pid_t pid;
assert(s);
false,
!s->permissions_start_only,
!s->root_directory_start_only,
- &pid)) < 0)
+ &s->control_pid)) < 0)
goto fail;
- service_set_control_pid(s, pid);
service_set_state(s, SERVICE_STOP);
} else
service_enter_signal(s, SERVICE_STOP_SIGTERM, true);
static void service_enter_start_post(Service *s) {
int r;
- pid_t pid;
assert(s);
service_unwatch_control_pid(s);
false,
!s->permissions_start_only,
!s->root_directory_start_only,
- &pid)) < 0)
+ &s->control_pid)) < 0)
goto fail;
- service_set_control_pid(s, pid);
service_set_state(s, SERVICE_START_POST);
} else
service_enter_running(s, true);
s->control_command_id = SERVICE_EXEC_START;
s->control_command = s->exec_command[SERVICE_EXEC_START];
- service_set_control_pid(s, pid);
+ s->control_pid = pid;
service_set_state(s, SERVICE_START);
} else if (s->type == SERVICE_FINISH ||
static void service_enter_start_pre(Service *s) {
int r;
- pid_t pid;
assert(s);
false,
!s->permissions_start_only,
!s->root_directory_start_only,
- &pid)) < 0)
+ &s->control_pid)) < 0)
goto fail;
- service_set_control_pid(s, pid);
service_set_state(s, SERVICE_START_PRE);
} else
service_enter_start(s);
static void service_enter_reload(Service *s) {
int r;
- pid_t pid;
assert(s);
false,
!s->permissions_start_only,
!s->root_directory_start_only,
- &pid)) < 0)
+ &s->control_pid)) < 0)
goto fail;
- service_set_control_pid(s, pid);
service_set_state(s, SERVICE_RELOAD);
} else
service_enter_running(s, true);
static void service_run_next(Service *s, bool success) {
int r;
- pid_t pid;
assert(s);
assert(s->control_command);
false,
!s->permissions_start_only,
!s->root_directory_start_only,
- &pid)) < 0)
+ &s->control_pid)) < 0)
goto fail;
- service_set_control_pid(s, pid);
return;
fail:
if ((r = parse_pid(value, &pid)) < 0)
log_debug("Failed to parse control-pid value %s", value);
else
- service_set_control_pid(s, pid);
+ s->control_pid = pid;
} else if (streq(key, "main-pid")) {
pid_t pid;