From: Christian Goeschel Ndjomouo Date: Tue, 13 Jan 2026 20:18:27 +0000 (-0500) Subject: lib: (pidutils) add a routine to parse pids and err() on failure X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=82fc20e3087a187dc787664186721d1499a6c142;p=thirdparty%2Futil-linux.git lib: (pidutils) add a routine to parse pids and err() on failure Signed-off-by: Christian Goeschel Ndjomouo --- diff --git a/include/pidutils.h b/include/pidutils.h index b2c575c19..979ec0590 100644 --- a/include/pidutils.h +++ b/include/pidutils.h @@ -10,5 +10,6 @@ #include extern int ul_parse_pid_str(char *pidstr, pid_t *pid_num, uint64_t *pfd_ino); +extern void ul_parse_pid_str_or_err(char *pidstr, pid_t *pid_num, uint64_t *pfd_ino); #endif /* UTIL_LINUX_PIDUTILS_H */ diff --git a/lib/pidutils.c b/lib/pidutils.c index 3998816d6..245cbb452 100644 --- a/lib/pidutils.c +++ b/lib/pidutils.c @@ -8,6 +8,7 @@ #include #include +#include "nls.h" #include "strutils.h" #include "pidutils.h" @@ -62,3 +63,22 @@ int ul_parse_pid_str(char *pidstr, pid_t *pid_num, uint64_t *pfd_ino) } return 0; } + +/* + * ul_parse_pid_str_or_err() - Parse a string and store the found pid + * and pidfd inode, or exit on error. + * + * @pidstr: string in format `pid[:pidfd_inode]` that is to be parsed + * @pid_num: stores pid number + * @pfd_ino: stores pidfd inode number + * + * If @pfd_ino is not destined to be set, pass it as NULL. + * + * On failure, err() is called with an error message to indicate the issue. + */ +void ul_parse_pid_str_or_err(char *pidstr, pid_t *pid_num, uint64_t *pfd_ino) +{ + if (ul_parse_pid_str(pidstr, pid_num, pfd_ino) < 0) { + err(EXIT_FAILURE, N_("failed to parse PID argument '%s'"), pidstr); + } +}