Skip to contentSkip to conversation

lib/tst_checkpoint.c: Replace SAFE_CLOSE with SAFE_UNLINK

PATCH New Zhao Gongyi 2 participants 2 messages Apr 29, 2021 – Apr 30, 2021 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/tst_checkpoint.c: Replace SAFE_CLOSE with SAFE_UNLINK

When we call tst_checkpoint_init and set the cleanup_fn to NULL, the file checkpoint_futex_base_file might be left over.

---
 lib/tst_checkpoint.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/tst_checkpoint.c +1 -1
index 9e9dcf9e6..3360ab07b 100644
@@ -78,7 +78,7 @@ void tst_checkpoint_init(const char *file, const int lineno,
 
 	tst_max_futexes = page_size / sizeof(uint32_t);
 
-	SAFE_CLOSE(cleanup_fn, fd);
+	SAFE_UNLINK(cleanup_fn, "checkpoint_futex_base_file");
 }
 
 int tst_checkpoint_wait(unsigned int id, unsigned int msec_timeout)

--
2.17.1

#1 lore raw

PATCH 1/1 lib/tst_checkpoint.c: Replace SAFE_CLOSE with SAFE_UNLINK

Hi!

Quoted 13 lines

When we call tst_checkpoint_init and set the cleanup_fn to NULL, the file checkpoint_futex_base_file might be left over.

---
 lib/tst_checkpoint.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/tst_checkpoint.c +0 -0
index 9e9dcf9e6..3360ab07b 100644

lib/tst_checkpoint.c void tst_checkpoint_init(const char *file, const int lineno, · line 81

Quoted 5 lines
lib/tst_checkpoint.c +1 -1
@@ -78,7 +78,7 @@ void tst_checkpoint_init(const char *file, const int lineno,
 
 	tst_max_futexes = page_size / sizeof(uint32_t);
 
-	SAFE_CLOSE(cleanup_fn, fd);
+	SAFE_UNLINK(cleanup_fn, "checkpoint_futex_base_file");

We ensure that the file is created in the test temporary directory and we do check that the test created a temporary directory with the tst_tmpdir_created() before we attempt to open the file, so the file is removed at the end of the test along with rest of the files the test has created.

Also we have to close the fd, we keep reference to the file only via the mmaped() pages, there is no point in keeping it open.

Signature · 2 lines
Cyril Hrubis
[email protected]