From: Lennart Poettering Date: Thu, 31 Aug 2017 08:25:06 +0000 (+0200) Subject: tree-wide: use pid_is_valid() at more places X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=9fc8db12dbccc9e71f2c0761030eb5dbb9c1ff7a;p=elogind.git tree-wide: use pid_is_valid() at more places --- diff --git a/src/basic/process-util.c b/src/basic/process-util.c index 4dcb93f2d..98f5a38ae 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -478,7 +478,7 @@ static int get_process_id(pid_t pid, const char *field, uid_t *uid) { assert(field); assert(uid); - if (pid < 0) + if (!pid_is_valid(pid)) return -EINVAL; p = procfs_file_alloca(pid, "status"); @@ -794,7 +794,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 < 0) + if (!pid_is_valid(pid)) return false; if (pid <= 1) /* If we or PID 1 would be dead and have been waited for, this code would not be running */ @@ -814,7 +814,7 @@ bool pid_is_alive(pid_t pid) { /* Checks whether a PID is still valid and not a zombie */ - if (pid < 0) + if (!pid_is_valid(pid)) return false; if (pid <= 1) /* If we or PID 1 would be a zombie, this code would not be running */ @@ -834,7 +834,7 @@ bool pid_is_alive(pid_t pid) { int pid_from_same_root_fs(pid_t pid) { const char *root; - if (pid < 0) + if (!pid_is_valid(pid)) return false; if (pid == 0 || pid == getpid_cached()) diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 8da2eb63f..e80b778cf 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -348,7 +348,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 < 0) + if (!pid_is_valid((pid_t) pid)) return -EINVAL; if (pid == 0) { @@ -411,7 +411,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 < 0) + if (!pid_is_valid((pid_t) pid)) return -EINVAL; if (pid == 0) {