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:
parent
cad93f2996
commit
54191eb3e7
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue