prlimit: fix diagnostic when setting current PIDs resources fails
PATCH 3/15 prlimit: fix diagnostic when setting current PIDs resources fails
[PATCH 03/15] prlimit: fix diagnostic when setting current PIDs resources fails
Avoids wrong message:
$ prlimit --nofile=16000 prlimit: failed to get resource limits for PID 0: Operation not permitted
Signed-off-by Bernhard Voelker <[email protected]>
--- sys-utils/prlimit.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-)
sys-utils/prlimit.c +6 -2
@@ -320,8 +320,12 @@ static void do_prlimit(struct prlimit lims[], size_t n, int tt_flags)printf (":%ju>\n" , new->rlim_max); } -if (prlimit (pid, lims[i].desc->resource, new, &lims[i].rlim) ==-1 ) -err (EXIT_FAILURE ,_ ("failed to get resource limits for PID %d" ), pid); +if (prlimit (pid, lims[i].desc->resource, new, &lims[i].rlim) ==-1 ) { +if (pid) +err (EXIT_FAILURE ,_ ("failed to get resource limits for PID %d" ), pid); +else +err (EXIT_FAILURE ,_ ("failed to get resource limits of the current process" )); + } }if (nshows)
Karel Zak
maintainerQuoted 2 lines · Bernhard Voelker
[PATCH 03/15] prlimit: fix diagnostic when setting current PIDs resources fails
Not applied, but I have improved the error messages according to your 5-8 patches.
Quoted 7 lines
sys-utils/prlimit.c +5
-1-err (EXIT_FAILURE ,_ ("failed to get resource limits for PID %d" ), pid); +if (prlimit (pid, lims[i].desc->resource, new, &lims[i].rlim) ==-1 ) { +if (pid) +err (EXIT_FAILURE ,_ ("failed to get resource limits for PID %d" ), pid); +else + err(EXIT_FAILURE, _("failed to get resource limits of the currentprocess"));
I think we don't have to care about the PID in the error message at all. The util works always with one PID only.
"failed to set the %s resource limit"
or
"failed to get the %s resource limit"
seems enough :-)
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com