[LTP] [PATCH] pipe/pipe15.c: Adjust fd check for pipe creation
Wenjie Xu
xuwenjie04@baidu.com
Tue Mar 5 08:20:14 CET 2024
> HI Wenjie, Marius,
>
> > A pipe occupies 2 fds, and considering 3 standard fds,
> > we should compare rlim_max with such *2+3 calculated value
> > to verify whether the maximum file descriptor configuration
> > of the current machine is sufficient.
>
> Indeed, 1024*2+3 is the lowest number which passes with non-default ulimit:
>
> ulimit -n $((1024*2+3)) && ./pipe15
>
> Therefore I merged, thank you!
>
> BTW I wonder how did you encounter this?
In my test case, the system ulimit is set to 10240,
and the calculated pipe_count is also 10240, causing
the EMFILE failure when creating the pipe below.
> @Marius FYI I also fixed SIGSEGV when low ulimit, see
> https://github.com/linux-test-project/ltp/commit/fc6adb8454df34fa87b462844b740cc3a0b84caa
>
> > Signed-off-by: Wenjie Xu <xuwenjie04@baidu.com>
> > ---
> > testcases/kernel/syscalls/pipe/pipe15.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> > diff --git a/testcases/kernel/syscalls/pipe/pipe15.c b/testcases/kernel/syscalls/pipe/pipe15.c
> > index c85ad1820..9e02fe2eb 100644
> > --- a/testcases/kernel/syscalls/pipe/pipe15.c
> > +++ b/testcases/kernel/syscalls/pipe/pipe15.c
> > @@ -59,7 +59,7 @@ static void setup(void)
> > tst_res(TINFO, "Creating %i pipes", pipe_count);
>
> > SAFE_GETRLIMIT(RLIMIT_NOFILE, &nfd);
> > - if (nfd.rlim_max < (unsigned long)pipe_count)
> > + if (nfd.rlim_max < (unsigned long)pipe_count * 2 + 3)
> nit: you mixed tabs with spaces or broke indent. And patch was not applicable
> (even before my changes), therefore I needed to do the changes myself and thus I
> put my fix fc6adb845 ("pipe15: Avoid SIGSEGV in cleanup") before.
>
> Kind regards,
> Petr
>
> > tst_brk(TCONF, "NOFILE limit max too low: %lu < %i", nfd.rlim_max, pipe_count);
> > if (nfd.rlim_cur < nfd.rlim_max) {
> > nfd.rlim_cur = nfd.rlim_max;
More information about the ltp
mailing list