From: Alejandro Colomar Date: Tue, 9 Jan 2024 16:05:43 +0000 (+0100) Subject: lib/get_pid.c: get_pidfd_from_fd(): Don't open-code get_fd() X-Git-Tag: 4.17.0-rc1~213 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b198c1e78203c5485bc4b5c26bc750e039b72be1;p=thirdparty%2Fshadow.git lib/get_pid.c: get_pidfd_from_fd(): Don't open-code get_fd() Reviewed-by: "Serge E. Hallyn" Signed-off-by: Alejandro Colomar --- diff --git a/lib/get_pid.c b/lib/get_pid.c index 80e1336c3..f090a2651 100644 --- a/lib/get_pid.c +++ b/lib/get_pid.c @@ -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 +// SPDX-License-Identifier: BSD-3-Clause + #include @@ -25,20 +24,12 @@ */ 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)