[LTP] [PATCH 1/1] tst_fd: Add runtime check for missing .needs_tmpdir

Petr Vorel pvorel@suse.cz
Mon Nov 9 19:32:22 CET 2026


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



More information about the ltp mailing list