From: Jinseok Kim <always.starving0@gmail.com>
To: pvorel@suse.cz
Cc: ltp@lists.linux.it
Subject: [LTP] [PATCH v6] close02: add test for double close EBADF
Date: Wed, 29 Apr 2026 23:20:14 +0900 [thread overview]
Message-ID: <20260429142016.1483-1-always.starving0@gmail.com> (raw)
In-Reply-To: <20260422114126.GD402660@pevik>
Verify that calling close() on an already closed file descriptor fails
with EBADF.
This test adds coverage for a common state transition case where a
previously valid file descriptor becomes invalid after close().
Signed-off-by: Jinseok Kim <always.starving0@gmail.com>
---
Changes in v6:
- Use a pointer for fd, referencing the bind01.c approach
- Link to v5 : https://lore.kernel.org/ltp/20260421144246.2046-1-always.starving0@gmail.com
Changes in v5:
- Change file descriptor as static
- Link to v4 : https://lore.kernel.org/ltp/20260416125554.2920-1-always.starving0@gmail.com
Changes in v4:
- Remove enum, add fd/expected errno in tcases, and move preparation
to setup().
- Link to v3: https://lore.kernel.org/ltp/20260413165457.1349-1-always.starving0@gmail.com
Changes in v3:
- Add O_RDWR flag to SAFE_OPEN
- Link to v2: https://lore.kernel.org/ltp/20260411110405.7330-1-always.starving0@gmail.com
Changes in v2:
- Add additional test coverage to close02 instead of creating a separate
close03 test.
- Link to v1: https://lore.kernel.org/ltp/20260406133134.17238-2-always.starving0@gmail.com
---
testcases/kernel/syscalls/close/close02.c | 36 ++++++++++++++++++++---
1 file changed, 32 insertions(+), 4 deletions(-)
diff --git a/testcases/kernel/syscalls/close/close02.c b/testcases/kernel/syscalls/close/close02.c
index 617c48237..c54789e7e 100644
--- a/testcases/kernel/syscalls/close/close02.c
+++ b/testcases/kernel/syscalls/close/close02.c
@@ -5,17 +5,45 @@
*/
/*\
- * Call close(-1) and expects it to return EBADF.
+ * Verify :manpage:`close(2)` failure cases:
+ *
+ * 1) close(-1) returns EBADF.
+ * 2) closing the same fd twice returns EBADF on the second call.
*/
#include <errno.h>
+#include <fcntl.h>
+
#include "tst_test.h"
-static void run(void)
+static int fd_invalid = -1;
+static int fd_closed = -1;
+
+static struct tcase {
+ const char *desc;
+ int *fd;
+ int exp_errno;
+} tcases[] = {
+ { "close(-1)", &fd_invalid, EBADF },
+ { "close same fd twice", &fd_closed, 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);
+ fd_closed = SAFE_OPEN("close02", O_CREAT | O_RDWR, 0600);
+ SAFE_CLOSE(fd_closed);
}
static struct tst_test test = {
- .test_all = run,
+ .needs_tmpdir = 1,
+ .setup = setup,
+ .tcnt = ARRAY_SIZE(tcases),
+ .test = verify_close,
};
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2026-04-29 14:21 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-06 13:30 [LTP] [PATCH 1/2] close: remove unused headers and fix minor style issues Jinseok Kim
2026-04-06 13:31 ` [LTP] [PATCH 2/2] close: add test for double close EBADF Jinseok Kim
2026-04-09 8:15 ` Petr Vorel
2026-04-11 11:04 ` [LTP] [PATCH v2] " Jinseok Kim
2026-04-13 4:33 ` Li Wang
2026-04-13 11:30 ` Petr Vorel
2026-04-13 16:52 ` [LTP] [PATCH v3] " Jinseok Kim
2026-04-13 18:04 ` [LTP] " linuxtestproject.agent
2026-04-13 20:45 ` [LTP] [PATCH v3] " Petr Vorel
2026-04-16 12:55 ` [LTP] [PATCH v4] close02: " Jinseok Kim
2026-04-16 13:44 ` [LTP] " linuxtestproject.agent
2026-04-17 0:01 ` [LTP] [PATCH v4] " Li Wang
2026-04-17 11:56 ` Petr Vorel
2026-04-21 14:42 ` [LTP] [PATCH v5] " Jinseok Kim
2026-04-21 15:16 ` [LTP] " linuxtestproject.agent
2026-04-22 11:41 ` [LTP] [PATCH v5] " Petr Vorel
2026-04-29 14:20 ` Jinseok Kim [this message]
2026-04-29 15:18 ` [LTP] " linuxtestproject.agent
2026-05-06 12:10 ` Andrea Cervesato via ltp
2026-05-12 15:25 ` [LTP] [PATCH v7] " Jinseok Kim
2026-05-12 17:15 ` [LTP] " linuxtestproject.agent
2026-05-13 7:07 ` Andrea Cervesato via ltp
2026-05-13 10:47 ` [LTP] [PATCH v7] " Petr Vorel
2026-04-09 8:08 ` [LTP] [PATCH 1/2] close: remove unused headers and fix minor style issues Petr Vorel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260429142016.1483-1-always.starving0@gmail.com \
--to=always.starving0@gmail.com \
--cc=ltp@lists.linux.it \
--cc=pvorel@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.