return 1; /* We have a pidfd and it still points to the PID we have, hence all is *really* OK → return 1 */
}
+bool pidref_is_self(const PidRef *pidref) {
+ if (!pidref)
+ return false;
+
+ return pidref->pid == getpid_cached();
+}
+
static void pidref_hash_func(const PidRef *pidref, struct siphash *state) {
siphash24_compress(&pidref->pid, sizeof(pidref->pid), state);
}
return pidref_set_pid(pidref, 0);
}
+bool pidref_is_self(const PidRef *pidref);
+
void pidref_done(PidRef *pidref);
PidRef *pidref_free(PidRef *pidref);
DEFINE_TRIVIAL_CLEANUP_FUNC(PidRef*, pidref_free);
if (!pidref_is_set(pid))
return NULL;
- if (pid->pid == getpid_cached())
+ if (pidref_is_self(pid))
return hashmap_get(m->units, SPECIAL_INIT_SCOPE);
if (pid->pid == 1)
return NULL;
if (pidref->pid <= 1)
return -EINVAL;
- if (pidref->pid == getpid_cached())
+ if (pidref_is_self(pidref))
return -EINVAL;
if (pidref_equal(&s->main_pid, pidref) && s->main_pid_known) {
* PID is questionnable but should be accepted if the source of configuration is trusted. > 0 if the PID is
* good */
- if (pid->pid == getpid_cached() || pid->pid == 1)
+ if (pidref_is_self(pid) || pid->pid == 1)
return log_unit_full_errno(UNIT(s), prio, SYNTHETIC_ERRNO(EPERM), "New main PID "PID_FMT" is the manager, refusing.", pid->pid);
if (pidref_equal(pid, &s->control_pid))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Process identifier is not valid.");
/* Some extra safety check */
- if (pid->pid == 1 || pid->pid == getpid_cached())
+ if (pid->pid == 1 || pidref_is_self(pid))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Process " PID_FMT " is a manager process, refusing.", pid->pid);
/* Don't even begin to bother with kernel threads */