Re: [LTP] [PATCH 2/2] close: add test for double close EBADF

Petr Vorel
2026-04-09T08:16:15Z

> Verify that calling close() on an already closed file descriptor fails
> with EBADF.

> The existing close tests cover:
> - close01: successful close on valid file descriptors
> - close02: invalid file descriptor (-1)

> This test adds coverage for a common state transition case where a
> previously valid file descriptor becomes invalid after close().

IMHO it'd make sense to add this errno check to close02.c (using .tcnt).

...
> --- /dev/null
> +++ b/testcases/kernel/syscalls/close/close03.c
> @@ -0,0 +1,26 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (C) 2026 Jinseok Kim <always.starving0@gmail.com>
> + */
> +
> +/*\
> + * Verify that calling close() twice on the same fd returns EBADF on

Please instead of close() use:
:manpage:`close(2)`

That will provide link to man page
https://man7.org/linux/man-pages/man2/close.2.html

in our test catalog:
https://linux-test-project.readthedocs.io/en/latest/users/test_catalog.html

Kind regards,
Petr

> + * the second call.
> + */
> +
> +#include <errno.h>
> +#include <fcntl.h>
> +#include "tst_test.h"
> +
> +static void run(void)
> +{
> + int fd = SAFE_OPEN("close03", O_CREAT, 0600);
> +
> + TST_EXP_PASS(close(fd));
> + TST_EXP_FAIL(close(fd), EBADF);
> +}
> +
> +static struct tst_test test = {
> + .needs_tmpdir = 1,
> + .test_all = run,
> +};