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.
This commit is contained in:
Lennart Poettering 2017-07-14 18:57:54 +02:00
parent cad93f2996
commit 54191eb3e7
3 changed files with 7 additions and 2 deletions

View File

@ -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;

View File

@ -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);

View File

@ -45,6 +45,7 @@
#include "terminal-util.h"
#include "user-util.h"
#include "util.h"
#include "process-util.h"
#define RELEASE_USEC (20*USEC_PER_SEC)
@ -281,7 +282,7 @@ int session_save(Session *s) {
if (!s->vtnr)
fprintf(f, "POSITION=%u\n", s->position);
if (s->leader > 0)
if (pid_is_valid(s->leader))
fprintf(f, "LEADER="PID_FMT"\n", s->leader);
if (audit_session_is_valid(s->audit_id))