[LTP] [PATCH v4] close02: add test for double close EBADF
Petr Vorel
pvorel@suse.cz
Fri Apr 17 13:56:48 CEST 2026
Hi Jinseok,
...
> -static void run(void)
> +static struct tcase {
> + const char *desc;
> + int fd;
> + int exp_errno;
> +} tcases[] = {
> + { "close(-1)", -1, EBADF },
> + { "close same fd twice", -1, EBADF },
> +};
> +
> +static void verify_close(unsigned int i)
> +{
> + struct tcase *tc = &tcases[i];
> +
> + TST_EXP_FAIL(close(tc->fd), tc->exp_errno, "%s", tc->desc);
> +}
> +
> +static void setup(void)
> {
> - TST_EXP_FAIL(close(-1), EBADF);
> + int fd = SAFE_OPEN("close02", O_CREAT | O_RDWR, 0600);
> +
> + SAFE_CLOSE(fd);
> + tcases[1].fd = fd;
Depending on index is error-prone. I know that test array has only 2 members,
but could you please use our usual approach to use file descriptors as static?
See fd_ebadf and fd_enotdir in testcases/kernel/syscalls/bind/bind01.c.
Kind regards,
Petr
More information about the ltp
mailing list