mbox series

[0/3] tools/nolibc: rlimit support

Message ID 20231123-nolibc-rlimit-v1-0-a428b131de2a@weissschuh.net
Headers show
Series tools/nolibc: rlimit support | expand

Message

Thomas Weißschuh Nov. 22, 2023, 11:21 p.m. UTC
The series adds support for setrlimit/getrlimit.
Mainly to avoid spurious coredumps when running the tests under
qemu-user.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
Thomas Weißschuh (3):
      tools/nolibc: drop custom definition of struct rusage
      tools/nolibc: add support for getrlimit/setrlimit
      selftests/nolibc: disable coredump via setrlimit

 tools/include/nolibc/sys.h                   | 38 ++++++++++++++++++++++++++++
 tools/include/nolibc/types.h                 | 21 +--------------
 tools/testing/selftests/nolibc/nolibc-test.c | 31 +++++++++++++++++++++++
 3 files changed, 70 insertions(+), 20 deletions(-)
---
base-commit: 0dbd4651f3f80151910a36416fa0df28a10c3b0a
change-id: 20231122-nolibc-rlimit-bb5b1f264fc4

Best regards,

Comments

Thomas Weißschuh Nov. 26, 2023, 10:42 a.m. UTC | #1
On 2023-11-26 10:28:28+0100, Willy Tarreau wrote:
> Hi Thomas,
> 
> > +int test_rlimit(void)
> > +{
> > +	struct rlimit rlim = {
> > +		.rlim_cur = 1 << 20,
> > +		.rlim_max = 1 << 20,
> > +	};
> > +	int ret;
> > +
> > +	ret = setrlimit(RLIMIT_CORE, &rlim);
> > +	if (ret)
> > +		return -1;
> > +
> > +	rlim.rlim_cur = 0;
> > +	rlim.rlim_max = 0;
> > +
> > +	ret = getrlimit(RLIMIT_CORE, &rlim);
> > +	if (ret)
> > +		return -1;
> > +
> > +	if (rlim.rlim_cur != 1 << 20)
> > +		return -1;
> > +	if (rlim.rlim_max != 1 << 20)
> > +		return -1;
> 
> I think you should used two different values here for cur and max so
> that you can also detect stupid API bugs such as a union being used
> instead of a struct, or copy-pastes in the implementation etc. For
> example using 1<<20 and 1<<21 should do the trick.

Good point, I incorporated the suggestion.

> Otherwise Ack-by me for the whole series, of course.

Thanks!

FYI I retested and pushed the series.


Thomas