Merge pull request #6975 from sourcejedi/logind_pid_0_v2

Selectively revert "tree-wide: use pid_is_valid() at more places"
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2017-10-04 21:33:52 +02:00 committed by GitHub
commit 03d4358277
6 changed files with 11 additions and 11 deletions

View File

@ -475,7 +475,7 @@ static int get_process_id(pid_t pid, const char *field, uid_t *uid) {
assert(field);
assert(uid);
if (!pid_is_valid(pid))
if (pid < 0)
return -EINVAL;
p = procfs_file_alloca(pid, "status");
@ -787,7 +787,7 @@ int getenv_for_pid(pid_t pid, const char *field, char **_value) {
bool pid_is_unwaited(pid_t pid) {
/* Checks whether a PID is still valid at all, including a zombie */
if (!pid_is_valid(pid))
if (pid < 0)
return false;
if (pid <= 1) /* If we or PID 1 would be dead and have been waited for, this code would not be running */
@ -807,7 +807,7 @@ bool pid_is_alive(pid_t pid) {
/* Checks whether a PID is still valid and not a zombie */
if (!pid_is_valid(pid))
if (pid < 0)
return false;
if (pid <= 1) /* If we or PID 1 would be a zombie, this code would not be running */
@ -826,7 +826,7 @@ bool pid_is_alive(pid_t pid) {
int pid_from_same_root_fs(pid_t pid) {
const char *root;
if (!pid_is_valid(pid))
if (pid < 0)
return false;
if (pid == 0 || pid == getpid_cached())

View File

@ -446,7 +446,7 @@ static int method_get_unit_by_pid(sd_bus_message *message, void *userdata, sd_bu
r = sd_bus_message_read(message, "u", &pid);
if (r < 0)
return r;
if (!pid_is_valid((pid_t) pid))
if (pid < 0)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid PID " PID_FMT, pid);
if (pid == 0) {

View File

@ -287,7 +287,7 @@ int manager_get_session_by_pid(Manager *m, pid_t pid, Session **session) {
assert(m);
if (pid < 1)
if (!pid_is_valid(pid))
return -EINVAL;
r = cg_pid_get_unit(pid, &unit);
@ -311,7 +311,7 @@ int manager_get_user_by_pid(Manager *m, pid_t pid, User **user) {
assert(m);
assert(user);
if (pid < 1)
if (!pid_is_valid(pid))
return -EINVAL;
r = cg_pid_get_slice(pid, &unit);

View File

@ -344,7 +344,7 @@ static int method_get_session_by_pid(sd_bus_message *message, void *userdata, sd
r = sd_bus_message_read(message, "u", &pid);
if (r < 0)
return r;
if (!pid_is_valid((pid_t) pid))
if (pid < 0)
return -EINVAL;
if (pid == 0) {
@ -407,7 +407,7 @@ static int method_get_user_by_pid(sd_bus_message *message, void *userdata, sd_bu
r = sd_bus_message_read(message, "u", &pid);
if (r < 0)
return r;
if (!pid_is_valid((pid_t) pid))
if (pid < 0)
return -EINVAL;
if (pid == 0) {

View File

@ -199,7 +199,7 @@ static int method_get_machine_by_pid(sd_bus_message *message, void *userdata, sd
if (r < 0)
return r;
if (!pid_is_valid((pid_t) pid))
if (pid < 0)
return -EINVAL;
if (pid == 0) {

View File

@ -3376,7 +3376,7 @@ static int logind_check_inhibitors(enum action a) {
return log_oom();
if (!pid_is_valid((pid_t) pid)) {
log_error("Invalid PID %" PRIu32 ".", pid);
log_error("Invalid PID "PID_FMT".", (pid_t) pid);
return -ERANGE;
}