]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/: get_pid(): Use the usual -1 as an error code
authorAlejandro Colomar <alx@kernel.org>
Sat, 2 Dec 2023 00:21:01 +0000 (01:21 +0100)
committerSerge Hallyn <serge@hallyn.com>
Fri, 5 Jan 2024 22:54:55 +0000 (16:54 -0600)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/commonio.c
lib/get_pid.c
lib/user_busy.c

index 2783e20b5aee3c47dd82d8c14f276b7166a19bbd..01a26c96423bd691a9ea66ecc3a160c4590a9f2e 100644 (file)
@@ -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",
index 27c84581b25fd6c44c67cc3d4d11c70f50a06f3e..61caa7aa2912544b578c7452081a60324e0c8537 100644 (file)
@@ -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 */
index c73e7bf3bed88632f3ad7df54e89849d9a81b31e..3ab26f6f2c61722b399f32adde8f9a08a1f6f3e1 100644 (file)
@@ -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) {