From: Christian Goeschel Ndjomouo Date: Sun, 29 Mar 2026 18:55:17 +0000 (-0400) Subject: prlimit: support 'PID:inode' process address format X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=47b2e9193973d1bc8cd80fc779f6291d73e0f4cd;p=thirdparty%2Futil-linux.git prlimit: support 'PID:inode' process address format Signed-off-by: Christian Goeschel Ndjomouo --- diff --git a/sys-utils/prlimit.1.adoc b/sys-utils/prlimit.1.adoc index fbfbc9f0a..c4808936d 100644 --- a/sys-utils/prlimit.1.adoc +++ b/sys-utils/prlimit.1.adoc @@ -20,7 +20,7 @@ prlimit - get and set process resource limits == SYNOPSIS -*prlimit* [options] [**--**_resource_[**=**_limits_]] [*--pid* _PID_] +*prlimit* [options] [**--**_resource_[**=**_limits_]] [*--pid* _PID_[:_inode_]] *prlimit* [options] [**--**_resource_[**=**_limits_]] _command_ [_argument_...] @@ -48,9 +48,9 @@ Do not print a header line. *-o*, *--output* _list_:: Define the output columns to use. If no output arrangement is specified, then a default set is used. Use *--help* to get a list of all supported columns. -*-p*, *--pid* _PID_:: -Specify the process ID. Without this option (and without a _command_), -the running process will be used. +*-p*, *--pid* _PID_[:_inode_]:: +Specify the process ID. Without this option (and without a _command_), the running process will be used. +The _inode_ uniquely identifies the process identity in the pidfs. To retrieve a process's inode number you can use the *getino*(1) utility. *--raw*:: Use the raw output format. @@ -138,7 +138,8 @@ mailto:dave@gnu.org[Davidlohr Bueso] - In memory of Dennis M. Ritchie. == SEE ALSO *ulimit*(1p), -*prlimit*(2) +*prlimit*(2), +*getino*(1) include::man-common/bugreports.adoc[] diff --git a/sys-utils/prlimit.c b/sys-utils/prlimit.c index 72390bb3d..8d118a8f5 100644 --- a/sys-utils/prlimit.c +++ b/sys-utils/prlimit.c @@ -32,6 +32,8 @@ #include "closestream.h" #include "path.h" #include "pathnames.h" +#include "pidutils.h" +#include "pidfd-utils.h" #ifndef RLIMIT_RTTIME # define RLIMIT_RTTIME 15 @@ -156,11 +158,18 @@ static void __attribute__((__noreturn__)) usage(void) { FILE *out = stdout; size_t i; + char *pid_arg = NULL; + +#ifdef USE_PIDFD_INO_SUPPORT + pid_arg = "PID[:inode]"; +#else + pid_arg = "PID"; +#endif fputs(USAGE_HEADER, out); fprintf(out, - _(" %s [options] [--=] [-p PID]\n"), program_invocation_short_name); + _(" %s [options] [--=] [-p %s]\n"), program_invocation_short_name, pid_arg); fprintf(out, _(" %s [options] [--=] COMMAND\n"), program_invocation_short_name); @@ -505,9 +514,21 @@ static int add_prlim(char *ops, struct list_head *lims, size_t id) return 0; } +static int parse_pid_str(char *pidstr, pid_t *pidnum) +{ + int pfd = -1; + uint64_t pidfd_ino = 0; + + ul_parse_pid_str_or_err(pidstr, pidnum, &pidfd_ino); + if (pidfd_ino) + pfd = ul_get_valid_pidfd_or_err(*pidnum, pidfd_ino); + + return pfd; +} + int main(int argc, char **argv) { - int opt; + int opt, pid_fd = -1; struct list_head lims; enum { @@ -612,7 +633,8 @@ int main(int argc, char **argv) case 'p': if (pid) errx(EXIT_FAILURE, _("option --pid may be specified only once")); - pid = strtopid_or_err(optarg, _("invalid PID argument")); + + pid_fd = parse_pid_str(optarg, &pid); break; case 'o': ncolumns = string_to_idarray(optarg, @@ -671,5 +693,7 @@ int main(int argc, char **argv) errexec(argv[optind]); } + if (pid_fd >= 0) + close(pid_fd); return EXIT_SUCCESS; }