* [LTP] [PATCH 1/1] tst_fd: Add runtime check for missing .needs_tmpdir
@ 2026-11-09 18:32 Petr Vorel
2026-11-10 9:35 ` Cyril Hrubis
0 siblings, 1 reply; 3+ messages in thread
From: Petr Vorel @ 2026-11-09 18:32 UTC (permalink / raw)
To: ltp; +Cc: Stephen Bertram
Although it'd be possible to write sparse check for this,
which would be better, runtime check is simpler.
Follow-up: 07a9023085 ("accept03/tst_fd: Harden parallel runs against shared path races")
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
Also see
[RFC,1/1] sparse: LTP-006: Detect files created in the current directory
https://patchwork.kernel.org/project/ltp/patch/20261104182800.421758-1-pvorel@suse.cz/
Kind regards,
Petr
lib/tst_fd.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/lib/tst_fd.c b/lib/tst_fd.c
index 6538a098c7..7cc5501fae 100644
--- a/lib/tst_fd.c
+++ b/lib/tst_fd.c
@@ -22,6 +22,8 @@
#include "lapi/bpf.h"
#include "lapi/fsmount.h"
+#include "tso_tmpdir.h"
+
#include "tst_fd.h"
struct tst_fd_desc {
@@ -30,8 +32,18 @@ struct tst_fd_desc {
const char *desc;
};
+static void require_tmpdir(struct tst_fd *fd)
+{
+ if (tst_tmpdir_created())
+ return;
+
+ tst_brk(TBROK, "%s fd requires .needs_tmpdir = 1 (test bug, report to LTP ML)",
+ tst_fd_desc(fd));
+}
+
static void open_file(struct tst_fd *fd)
{
+ require_tmpdir(fd);
fd->fd = SAFE_OPEN("fd_file", O_RDWR | O_CREAT, 0666);
SAFE_UNLINK("fd_file");
}
@@ -40,6 +52,7 @@ static void open_path(struct tst_fd *fd)
{
int tfd;
+ require_tmpdir(fd);
tfd = SAFE_CREAT("fd_file", 0666);
SAFE_CLOSE(tfd);
@@ -50,6 +63,7 @@ static void open_path(struct tst_fd *fd)
static void open_dir(struct tst_fd *fd)
{
+ require_tmpdir(fd);
SAFE_MKDIR("fd_dir", 0700);
fd->fd = SAFE_OPEN("fd_dir", O_DIRECTORY);
SAFE_RMDIR("fd_dir");
--
2.56.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-10 11:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-09 18:32 [LTP] [PATCH 1/1] tst_fd: Add runtime check for missing .needs_tmpdir Petr Vorel
2026-11-10 9:35 ` Cyril Hrubis
2026-11-10 11:19 ` Petr Vorel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox