Skip to contentSkip to conversation

quotactl06: Fix tmpdir cleanup if setup() exits early

PATCH In review Martin Doucha 2 participants 3 messages Mar 4, 2022 – Mar 10, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 quotactl06: Fix tmpdir cleanup if setup() exits early

When setup() exits with TCONF before USRPATH or TESTDIR1 get created, cleanup() will trigger TWARN when it tries to delete them. Check whether the file and directory exists before removing them.

---

Changes since v1:
- Also check whether USRPATH exists before deleting it

 testcases/kernel/syscalls/quotactl/quotactl06.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/quotactl/quotactl06.c +5 -2
index 8e9a17393..87715237f 100644
@@ -206,8 +206,11 @@ static void setup(void)
 
 static void cleanup(void)
 {
-	SAFE_UNLINK(USRPATH);
-	SAFE_RMDIR(TESTDIR1);
+	if (!access(USRPATH, F_OK))
+		SAFE_UNLINK(USRPATH);
+
+	if (!access(TESTDIR1, F_OK))
+		SAFE_RMDIR(TESTDIR1);
 }
 
 static struct tst_test test = {
Signature · 5 lines
2.35.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v2 1/1
#1 lore raw

Hi Martin

Looks good to me,

Best Regards
Yang Xu

Quoted 31 lines

When setup() exits with TCONF before USRPATH or TESTDIR1 get created, cleanup() will trigger TWARN when it tries to delete them. Check whether the file and directory exists before removing them.

---

Changes since v1:
- Also check whether USRPATH exists before deleting it

  testcases/kernel/syscalls/quotactl/quotactl06.c | 7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/quotactl/quotactl06.c +5 -2
index 8e9a17393..87715237f 100644
@@ -206,8 +206,11 @@ static void setup(void)
 
  static void cleanup(void)
  {
-	SAFE_UNLINK(USRPATH);
-	SAFE_RMDIR(TESTDIR1);
+	if (!access(USRPATH, F_OK))
+		SAFE_UNLINK(USRPATH);
+
+	if (!access(TESTDIR1, F_OK))
+		SAFE_RMDIR(TESTDIR1);
  }
 
  static struct tst_test test = {
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

Hi Martin

Merged this patchset, thanks.

Best Regards
Yang Xu

Quoted 39 lines

Hi Martin

Looks good to me,

Best Regards
Yang Xu

Quoted 31 lines

When setup() exits with TCONF before USRPATH or TESTDIR1 get created, cleanup() will trigger TWARN when it tries to delete them. Check whether the file and directory exists before removing them.

---

Changes since v1:
- Also check whether USRPATH exists before deleting it

   testcases/kernel/syscalls/quotactl/quotactl06.c | 7 +++++--
   1 file changed, 5 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/quotactl/quotactl06.c +5 -2
index 8e9a17393..87715237f 100644
@@ -206,8 +206,11 @@ static void setup(void)
 
   static void cleanup(void)
   {
-	SAFE_UNLINK(USRPATH);
-	SAFE_RMDIR(TESTDIR1);
+	if (!access(USRPATH, F_OK))
+		SAFE_UNLINK(USRPATH);
+
+	if (!access(TESTDIR1, F_OK))
+		SAFE_RMDIR(TESTDIR1);
   }
 
   static struct tst_test test = {
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp