diff options
author | Lennart Poettering <lennart@poettering.net> | 2017-07-14 18:57:54 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2017-07-31 18:01:42 +0200 |
commit | 54191eb3e74a8fa8bdd049471e630541c65e4f25 (patch) | |
tree | e4e97ae7abe730440f11584746f29e16b4f04427 /src/basic | |
parent | cad93f2996f18c987b3b4b62a5ede762c11338c8 (diff) | |
download | systemd-54191eb3e74a8fa8bdd049471e630541c65e4f25.tar.gz systemd-54191eb3e74a8fa8bdd049471e630541c65e4f25.tar.bz2 systemd-54191eb3e74a8fa8bdd049471e630541c65e4f25.zip |
parse-util: introduce pid_is_valid()
Checking for validity of a PID is relatively easy, but let's add a
helper cal for this too, in order to make things more readable and more
similar to uid_is_valid(), gid_is_valid() and friends.
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/parse-util.c | 2 | ||||
-rw-r--r-- | src/basic/process-util.h | 4 |
2 files changed, 5 insertions, 1 deletions
diff --git a/src/basic/parse-util.c b/src/basic/parse-util.c index 4532f222c8..89bb667c5f 100644 --- a/src/basic/parse-util.c +++ b/src/basic/parse-util.c @@ -59,7 +59,7 @@ int parse_pid(const char *s, pid_t* ret_pid) { if ((unsigned long) pid != ul) return -ERANGE; - if (pid <= 0) + if (!pid_is_valid(pid)) return -ERANGE; *ret_pid = pid; diff --git a/src/basic/process-util.h b/src/basic/process-util.h index 17746b4ebf..b45d60dbd1 100644 --- a/src/basic/process-util.h +++ b/src/basic/process-util.h @@ -118,6 +118,10 @@ static inline bool ioprio_priority_is_valid(int i) { return i >= 0 && i < IOPRIO_BE_NR; } +static inline bool pid_is_valid(pid_t p) { + return p > 0; +} + int ioprio_parse_priority(const char *s, int *ret); pid_t getpid_cached(void); |