From: Alejandro Colomar Date: Sat, 2 Dec 2023 00:21:01 +0000 (+0100) Subject: lib/: get_pid(): Use the usual -1 as an error code X-Git-Tag: 4.15.0-rc1~50 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4c0c7c52f14382f7b6f7e36337d28c4460923db4;p=thirdparty%2Fshadow.git lib/: get_pid(): Use the usual -1 as an error code Signed-off-by: Alejandro Colomar --- diff --git a/lib/commonio.c b/lib/commonio.c index 2783e20b5..01a26c964 100644 --- a/lib/commonio.c +++ b/lib/commonio.c @@ -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", diff --git a/lib/get_pid.c b/lib/get_pid.c index 27c84581b..61caa7aa2 100644 --- a/lib/get_pid.c +++ b/lib/get_pid.c @@ -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; } /* @@ -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 */ diff --git a/lib/user_busy.c b/lib/user_busy.c index c73e7bf3b..3ab26f6f2 100644 --- a/lib/user_busy.c +++ b/lib/user_busy.c @@ -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; } @@ -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) {