[PATCH 05/15] prlimit: fix diagnostic when setting a limit fails
As the prlimit() combines setting and getting the limit of a process,
prlimit must care about issueing the correct error message. This
fixes this wrong diagnostic:
$./prlimit --nofile=10000000
prlimit: failed to get resource limits of the current process: Operation
not permitted
Signed-off-by: Bernhard Voelker <mail@xxxxxxxxxxxxxxxxxxx>
---
sys-utils/prlimit.c | 15 +++++++++++----
1 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/sys-utils/prlimit.c b/sys-utils/prlimit.c
index 9a52b81..d668fba 100644
--- a/sys-utils/prlimit.c
+++ b/sys-utils/prlimit.c
@@ -324,10 +324,17 @@ static void do_prlimit(struct prlimit lims[],
size_t n, int tt_flags)
}
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 (pid) {
+ if (lims[i].modify)
+ err(EXIT_FAILURE, _("failed to set resource limits for PID %d"), pid);
+ else
+ err(EXIT_FAILURE, _("failed to get resource limits for PID %d"), pid);
+ } else {
+ if (lims[i].modify)
+ err(EXIT_FAILURE, _("failed to set resource limits of the current
process"));
+ else
+ err(EXIT_FAILURE, _("failed to get resource limits of the current
process"));
+ }
}
}
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html