Skip to contentSkip to conversation

prlimit: fix displaying of modified limits

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 15/15 prlimit: fix displaying of modified limits

[PATCH 15/15] prlimit: fix displaying of modified limits

When a limit is to be modified and shown, e.g. in

  $ prlimit -p$$  -n1000 -n
then the prlimit syscall has overwritten lims[i].rlim with the old value.
For such cases, copy the new values afterwards again.
---
 sys-utils/prlimit.c |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)
sys-utils/prlimit.c +1 -0
index 69440a5..bfe8005 100644
@@ -333,6 +333,7 @@ static void do_prlimit(struct prlimit lims[], int tt_flags)
 
 	for (i = 0; i < MAX_RESOURCES; i++) {
 		struct rlimit *new = NULL;
+		struct rlimit new_rlim;
 
 		if (lims[i].modify) {
 			if (!pid)
@@ -348,7 +349,9 @@ static void do_prlimit(struct prlimit lims[], int tt_flags)
 				 lims[i].rlim.rlim_max != RLIM_INFINITY))
 				errx(EXIT_FAILURE, _("the soft limit cannot exceed the ceiling 

value"));

- new = &lims[i].rlim;
+ new_rlim.rlim_cur = lims[i].rlim.rlim_cur;
+ new_rlim.rlim_max = lims[i].rlim.rlim_max;
+ new = &new_rlim;
} else if (!(lims[i].show)) {
continue;
}
@@ -383,6 +386,15 @@ static void do_prlimit(struct prlimit lims[], int tt_flags)
lims[i].desc->name);
}
}
+ if (lims[i].modify && new) {
+ /*
+ * prlimit has overwritten lims[i].rlim with the old value.
+ * In the case we have to display the new value, we have to
+ * copy it from new_rlim again.
+ */
+ lims[i].rlim.rlim_cur = new_rlim.rlim_cur;
+ lims[i].rlim.rlim_max = new_rlim.rlim_max;
+ }
}
}

maintainer
#1 lore raw
Quoted 6 lines · Bernhard Voelker

[PATCH 15/15] prlimit: fix displaying of modified limits

When a limit is to be modified and shown, e.g. in

  $ prlimit -p$$  -n1000 -n
then the prlimit syscall has overwritten lims[i].rlim with the old value.
For such cases, copy the new values afterwards again.

This is also unnecessary now, but I have a little improved this thing, so the syscall is not called with the same pointer for new and old argument now.

Thanks.

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com