[PATCH 08/15] prlimit: give better diagnostic for illegal hard limit case Give better diagnostic in cases where the user only specifies a new hard limit, but when that is lower than the current hard limit. Example: $ prlimit -n -p7852 --noheadings NOFILE max amount of open files 1024 8192 Previous message: $ prlimit -n:1000 -p7852 prlimit: the soft limit cannot exceed the ceiling value New message: $ prlimit -n:1000 -p7852 prlimit: current soft limit NOFILE is greater than new hard limit Signed-off-by: Bernhard Voelker <mail@xxxxxxxxxxxxxxxxxxx> --- sys-utils/prlimit.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-) diff --git a/sys-utils/prlimit.c b/sys-utils/prlimit.c index 622a318..4124faa 100644 --- a/sys-utils/prlimit.c +++ b/sys-utils/prlimit.c @@ -313,6 +313,17 @@ static void get_unknown_hardsoft(struct prlimit *lim) lim->rlim.rlim_cur = old.rlim_cur; else if (!(lim->found & PRLIMIT_HARD)) lim->rlim.rlim_max = old.rlim_max; + + /* give better diagnostic in cases where the new hard limit + * would be lower than the current soft limit, and the user + * did not give a new soft limit. + */ + if (!(lim->found & PRLIMIT_SOFT) && + (lim->rlim.rlim_cur > lim->rlim.rlim_max)) { + errx(EXIT_FAILURE, + _("current soft limit %s is greater than new hard limit"), + lim->desc->name); + } } } -- 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