Skip to content

Commit

Permalink
lib/: get_pid(): Use the usual -1 as an error code
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Colomar <[email protected]>
  • Loading branch information
alejandro-colomar authored and hallyn committed Jan 5, 2024
1 parent 18c428a commit 4c0c7c5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/commonio.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ static int do_lock_file (const char *file, const char *lock, bool log)
return 0;
}
buf[len] = '\0';
if (get_pid (buf, &pid) == 0) {
if (get_pid(buf, &pid) == -1) {
if (log) {
(void) fprintf (shadow_logfd,
"%s: existing lock file %s with an invalid PID '%s'\n",
Expand Down
6 changes: 3 additions & 3 deletions lib/get_pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ int get_pid (const char *pidstr, pid_t *pid)
|| (0 != errno)
|| (val < 1)
|| (/*@+longintegral@*/val != (pid_t)val)/*@=longintegral@*/) {
return 0;
return -1;
}

*pid = val;
return 1;
return 0;
}

/*
Expand Down Expand Up @@ -82,7 +82,7 @@ int open_pidfd(const char *pidstr)
char proc_dir_name[32];
pid_t target;

if (get_pid(pidstr, &target) == 0)
if (get_pid(pidstr, &target) == -1)
return -ENOENT;

/* max string length is 6 + 10 + 1 + 1 = 18, allocate 32 bytes */
Expand Down
4 changes: 2 additions & 2 deletions lib/user_busy.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ static int user_busy_processes (const char *name, uid_t uid)
}

/* Check if this is a valid PID */
if (get_pid (tmp_d_name, &pid) == 0) {
if (get_pid(tmp_d_name, &pid) == -1) {
continue;
}

Expand Down Expand Up @@ -232,7 +232,7 @@ static int user_busy_processes (const char *name, uid_t uid)
if (task_dir != NULL) {
while ((ent = readdir (task_dir)) != NULL) {
pid_t tid;
if (get_pid (ent->d_name, &tid) == 0) {
if (get_pid(ent->d_name, &tid) == -1) {
continue;
}
if (tid == pid) {
Expand Down

0 comments on commit 4c0c7c5

Please sign in to comment.