[LTP] [PATCH v3 2/2] open: replace getdtablesize with getrlimit

Petr Vorel pvorel@suse.cz
Fri Mar 13 17:42:58 CET 2026


Hi Jinseok,

> The test currently uses getdtablesize() to determine the maximum
> number of file descriptors for the process. This interface is
> considered legacy and is not specified by POSIX.

> Use getrlimit() instead, which provides a well-defined
> and portable way to obtain the per-process file descriptor limit.

Hm, it's still supported by all libc on Linux including musl [1] and bionic [2],
and we even test getdomainname [3], but ok, let's move beyond POSIX 2004.

[1] https://git.musl-libc.org/cgit/musl/tree/src/legacy/getdtablesize.c
[2] https://android.googlesource.com/platform/bionic.git/+/refs/heads/main/libc/bionic/ndk_cruft.cpp#288
[3] testcases/kernel/syscalls/getdomainname/getdomainname01.c

...
> +++ b/testcases/kernel/syscalls/open/open04.c
> @@ -11,6 +11,7 @@

>  #include <stdio.h>
>  #include <stdlib.h>
> +#include <sys/resource.h>
nit: I removed this before merge (header included by other headers).

Merged this patch only (not the first one).

Kind regards,
Petr

>  #include "tst_test.h"

>  #define FNAME "open04"
> @@ -23,8 +24,10 @@ static char fname[20];
>  static void setup(void)
>  {
>  	int fd;
> +	struct rlimit rlim;

> -	fds_limit = getdtablesize();
> +	SAFE_GETRLIMIT(RLIMIT_NOFILE, &rlim);
> +	fds_limit = rlim.rlim_cur;
>  	first = SAFE_OPEN(FNAME, O_RDWR | O_CREAT, 0777);

>  	fds = SAFE_MALLOC(sizeof(int) * (fds_limit - first));


More information about the ltp mailing list