]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/get_pid.c: get_pidfd_from_fd(): Don't open-code get_fd()
authorAlejandro Colomar <alx@kernel.org>
Tue, 9 Jan 2024 16:05:43 +0000 (17:05 +0100)
committerAlejandro Colomar <alx@kernel.org>
Sat, 29 Jun 2024 18:00:18 +0000 (20:00 +0200)
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/get_pid.c

index 80e1336c3b33b12d5c300e17d3f9e1f11f7357b8..f090a265137e651f88e6ca6d5079c4a171f8a9c3 100644 (file)
@@ -1,8 +1,7 @@
-/*
- * SPDX-FileCopyrightText: 2009       , Nicolas François
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
+// SPDX-FileCopyrightText: 2009, Nicolas François
+// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
 
 #include <config.h>
 
  */
 int get_pidfd_from_fd(const char *pidfdstr)
 {
-       char         *end;
-       long long    val;
+       int          pidfd;
        struct stat  st;
        dev_t proc_st_dev, proc_st_rdev;
 
-       errno = 0;
-       val = strtoll(pidfdstr, &end, 10);
-       if (   ('\0' == *pidfdstr)
-           || ('\0' != *end)
-           || (0 != errno)
-           || (val < 0)
-           || (/*@+longintegral@*/val != (int)val)/*@=longintegral@*/) {
+       if (get_fd(pidfdstr, &pidfd) == -1)
                return -1;
-       }
 
        if (stat("/proc/self/uid_map", &st) < 0) {
                return -1;
@@ -47,7 +38,7 @@ int get_pidfd_from_fd(const char *pidfdstr)
        proc_st_dev = st.st_dev;
        proc_st_rdev = st.st_rdev;
 
-       if (fstat(val, &st) < 0) {
+       if (fstat(pidfd, &st) < 0) {
                return -1;
        }
 
@@ -55,7 +46,7 @@ int get_pidfd_from_fd(const char *pidfdstr)
                return -1;
        }
 
-       return (int)val;
+       return pidfd;
 }
 
 int open_pidfd(const char *pidstr)