Skip to contentSkip to conversation

prlimit: fix diagnostic when setting current PIDs resources fails

PATCH Applied Bernhard Voelker 2 participants 2 messages Nov 14, 2011 – Nov 16, 2011 Util-Linux package

lore
Share & tools
lore
#0 lore raw

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
---
 sys-utils/prlimit.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
sys-utils/prlimit.c +6 -2
index 525351a..6943d11 100644
@@ -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)
maintainer
#1 lore raw
Quoted 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 current  

process"));

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