[PATCH] Fix incorrect setrlimit return value checks in tests
Collin Funk
collin.funk1@gmail.com
Tue Oct 28 21:05:41 GMT 2025
Osama Abdelkader <osama.abdelkader@gmail.com> writes:
> The setrlimit(2) function returns 0 on success and -1 on error, but
> several test files were incorrectly checking for a return value of 1
> to detect errors. This means the error checks would never trigger,
> causing tests to continue silently even when setrlimit() failed.
>
> This commit fixes the error checks in five files to correctly test
> for -1, matching both the documented behavior and the pattern used
> correctly in other parts of the codebase.
>
> Files affected:
> * debug/tst-sprintf-fortify-rdonly.c
> * io/tst-closefrom.c
> * posix/tst-spawn3.c
> * support/support-open-dev-null-range.c
> * support/tst-support-open-dev-null-range.c
>
> Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
> ---
> debug/tst-sprintf-fortify-rdonly.c | 2 +-
> io/tst-closefrom.c | 2 +-
> posix/tst-spawn3.c | 2 +-
> support/support-open-dev-null-range.c | 2 +-
> support/tst-support-open-dev-null-range.c | 2 +-
> 5 files changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/debug/tst-sprintf-fortify-rdonly.c b/debug/tst-sprintf-fortify-rdonly.c
> index fafc8340ea..33a22f5d87 100644
> --- a/debug/tst-sprintf-fortify-rdonly.c
> +++ b/debug/tst-sprintf-fortify-rdonly.c
> @@ -94,7 +94,7 @@ do_test (void)
> max_fd = (rl.rlim_cur < max_fd ? rl.rlim_cur : max_fd);
> rl.rlim_cur = max_fd;
>
> - if (setrlimit (RLIMIT_NOFILE, &rl) == 1)
> + if (setrlimit (RLIMIT_NOFILE, &rl) == -1)
> FAIL_EXIT1 ("setrlimit (RLIMIT_NOFILE): %m");
>
> /* Exhaust the file descriptor limit with temporary files. */
> diff --git a/io/tst-closefrom.c b/io/tst-closefrom.c
> index 81011644fd..6dc3000207 100644
> --- a/io/tst-closefrom.c
> +++ b/io/tst-closefrom.c
> @@ -103,7 +103,7 @@ closefrom_test_file_desc_limit (void)
> max_fd = (rl.rlim_cur < max_fd ? rl.rlim_cur : max_fd);
> rl.rlim_cur = max_fd;
>
> - if (setrlimit (RLIMIT_NOFILE, &rl) == 1)
> + if (setrlimit (RLIMIT_NOFILE, &rl) == -1)
> FAIL_EXIT1 ("setrlimit (RLIMIT_NOFILE): %m");
> }
>
> diff --git a/posix/tst-spawn3.c b/posix/tst-spawn3.c
> index 3d637e8de6..d17b6d2a06 100644
> --- a/posix/tst-spawn3.c
> +++ b/posix/tst-spawn3.c
> @@ -62,7 +62,7 @@ do_test (void)
> max_fd = (rl.rlim_cur < max_fd ? rl.rlim_cur : max_fd);
> rl.rlim_cur = max_fd;
>
> - if (setrlimit (RLIMIT_NOFILE, &rl) == 1)
> + if (setrlimit (RLIMIT_NOFILE, &rl) == -1)
> FAIL_EXIT1 ("setrlimit (RLIMIT_NOFILE): %m");
>
> /* Exhauste the file descriptor limit with temporary files. */
> diff --git a/support/support-open-dev-null-range.c b/support/support-open-dev-null-range.c
> index 812d579583..baf70b4118 100644
> --- a/support/support-open-dev-null-range.c
> +++ b/support/support-open-dev-null-range.c
> @@ -33,7 +33,7 @@ increase_nofile (void)
>
> rl.rlim_cur += 128;
>
> - if (setrlimit (RLIMIT_NOFILE, &rl) == 1)
> + if (setrlimit (RLIMIT_NOFILE, &rl) == -1)
> FAIL_EXIT1 ("setrlimit (RLIMIT_NOFILE): %m");
> }
>
> diff --git a/support/tst-support-open-dev-null-range.c b/support/tst-support-open-dev-null-range.c
> index 6db20f0703..545e22242d 100644
> --- a/support/tst-support-open-dev-null-range.c
> +++ b/support/tst-support-open-dev-null-range.c
> @@ -121,7 +121,7 @@ do_test (void)
>
> rl.rlim_cur = number_of_opened_files ();
>
> - if (setrlimit (RLIMIT_NOFILE, &rl) == 1)
> + if (setrlimit (RLIMIT_NOFILE, &rl) == -1)
> FAIL_EXIT1 ("setrlimit (RLIMIT_NOFILE): %m");
> }
Nice catch.
Reviewed-by: Collin Funk <collin.funk1@gmail.com>
Collin
More information about the Libc-alpha
mailing list