Skip to contentSkip to conversation

selftests: filesystems: fix warn_unused_result build warnings

PATCH In review Amer Al Shanawany 3 participants 5 messages Apr 17, 2024 – Jun 11, 2024 Kselftest

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests: filesystems: fix warn_unused_result build warnings

Fix the following warnings by adding return check and error messages.

statmount_test.c: In function ‘cleanup_namespace’:
statmount_test.c:128:9: warning: ignoring return value of ‘fchdir’ declared with attribute ‘warn_unused_result’ [-Wunused-result]

  128 |         fchdir(orig_root);
      |         ^~~~~~~~~~~~~~~~~
statmount_test.c:129:9: warning: ignoring return value of ‘chroot’
declared with attribute ‘warn_unused_result’ [-Wunused-result]
  129 |         chroot(".");
      |         ^~~~~~~~~~~
---
 .../selftests/filesystems/statmount/statmount_test.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
tools/testing/selftests/filesystems/statmount/statmount_test.c +10 -2
index e6d7c4f1c85b..e8c019d72cbf 100644
@@ -125,8 +125,16 @@ static uint32_t old_root_id, old_parent_id;
 
 static void cleanup_namespace(void)
 {
-	fchdir(orig_root);
-	chroot(".");
+	int ret;
+
+	ret = fchdir(orig_root);
+	if (ret == -1)
+		ksft_perror("fchdir to original root");
+
+	ret = chroot(".");
+	if (ret == -1)
+		ksft_perror("chroot to original root");
+
 	umount2(root_mntpoint, MNT_DETACH);
 	rmdir(root_mntpoint);
 }
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Amer Al Shanawany

Fix the following warnings by adding return check and error messages.

statmount_test.c: In function ‘cleanup_namespace’:
statmount_test.c:128:9: warning: ignoring return value of ‘fchdir’ declared with attribute ‘warn_unused_result’ [-Wunused-result]

Quoted 8 lines
  128 |         fchdir(orig_root);
      |         ^~~~~~~~~~~~~~~~~
statmount_test.c:129:9: warning: ignoring return value of ‘chroot’
declared with attribute ‘warn_unused_result’ [-Wunused-result]
  129 |         chroot(".");
      |         ^~~~~~~~~~~
Quoted 27 lines
---
 .../selftests/filesystems/statmount/statmount_test.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
tools/testing/selftests/filesystems/statmount/statmount_test.c +10 -2
index e6d7c4f1c85b..e8c019d72cbf 100644
@@ -125,8 +125,16 @@ static uint32_t old_root_id, old_parent_id;
 
 static void cleanup_namespace(void)
 {
-	fchdir(orig_root);
-	chroot(".");
+	int ret;
+
+	ret = fchdir(orig_root);
+	if (ret == -1)
+		ksft_perror("fchdir to original root");
+
+	ret = chroot(".");
+	if (ret == -1)
+		ksft_perror("chroot to original root");
+
 	umount2(root_mntpoint, MNT_DETACH);
 	rmdir(root_mntpoint);
 }
Signature · 2 lines
BR,
Muhammad Usama Anjum
#2 lore raw
Quoted 35 lines · Muhammad Usama Anjum
Quoted 5 lines · Amer Al Shanawany

Fix the following warnings by adding return check and error messages.

statmount_test.c: In function ‘cleanup_namespace’:
statmount_test.c:128:9: warning: ignoring return value of ‘fchdir’ declared with attribute ‘warn_unused_result’ [-Wunused-result]

Quoted 8 lines
  128 |         fchdir(orig_root);
      |         ^~~~~~~~~~~~~~~~~
statmount_test.c:129:9: warning: ignoring return value of ‘chroot’
declared with attribute ‘warn_unused_result’ [-Wunused-result]
  129 |         chroot(".");
      |         ^~~~~~~~~~~
Quoted 19 lines
---
 .../selftests/filesystems/statmount/statmount_test.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
tools/testing/selftests/filesystems/statmount/statmount_test.c +5 -2
index e6d7c4f1c85b..e8c019d72cbf 100644
@@ -125,8 +125,16 @@ static uint32_t old_root_id, old_parent_id;
 
 static void cleanup_namespace(void)
 {
-	fchdir(orig_root);
-	chroot(".");
+	int ret;
+
+	ret = fchdir(orig_root);
+	if (ret == -1)
+		ksft_perror("fchdir to original root");
Quoted 8 lines

tools/testing/selftests/filesystems/statmount/statmount_test.c static uint32_t old_root_id, old_parent_id; · line 140

Quoted 8 lines
tools/testing/selftests/filesystems/statmount/statmount_test.c +5 -0
+
+	ret = chroot(".");
+	if (ret == -1)
+		ksft_perror("chroot to original root");
+
 	umount2(root_mntpoint, MNT_DETACH);
 	rmdir(root_mntpoint);
 }

Hi,

Can you please consider this patch?

Thank  you

Amer

#3 lore raw
Quoted 46 lines · Amer Al Shanawany
Quoted 35 lines · Muhammad Usama Anjum
Quoted 5 lines · Amer Al Shanawany

Fix the following warnings by adding return check and error messages.

statmount_test.c: In function ‘cleanup_namespace’:
statmount_test.c:128:9: warning: ignoring return value of ‘fchdir’ declared with attribute ‘warn_unused_result’ [-Wunused-result]

Quoted 8 lines
  128 |         fchdir(orig_root);
      |         ^~~~~~~~~~~~~~~~~
statmount_test.c:129:9: warning: ignoring return value of ‘chroot’
declared with attribute ‘warn_unused_result’ [-Wunused-result]
  129 |         chroot(".");
      |         ^~~~~~~~~~~
Quoted 19 lines
---
 .../selftests/filesystems/statmount/statmount_test.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
tools/testing/selftests/filesystems/statmount/statmount_test.c +5 -2
index e6d7c4f1c85b..e8c019d72cbf 100644
@@ -125,8 +125,16 @@ static uint32_t old_root_id, old_parent_id;
 
 static void cleanup_namespace(void)
 {
-	fchdir(orig_root);
-	chroot(".");
+	int ret;
+
+	ret = fchdir(orig_root);
+	if (ret == -1)
+		ksft_perror("fchdir to original root");
Quoted 8 lines

tools/testing/selftests/filesystems/statmount/statmount_test.c static uint32_t old_root_id, old_parent_id; · line 140

Quoted 8 lines
tools/testing/selftests/filesystems/statmount/statmount_test.c +5 -0
+
+	ret = chroot(".");
+	if (ret == -1)
+		ksft_perror("chroot to original root");
+
 	umount2(root_mntpoint, MNT_DETACH);
 	rmdir(root_mntpoint);
 }

Hi,

Quoted 8 lines

Can you please consider this patch?

Thank  you

Amer

Hello,

Could you please consider this simple patch for fixing build warnings for kselftest ?

Thank you

Amer

maintainer
#4 lore raw
Quoted 55 lines · Amer Al Shanawany
Quoted 46 lines · Amer Al Shanawany
Quoted 35 lines · Muhammad Usama Anjum
Quoted 5 lines · Amer Al Shanawany

Fix the following warnings by adding return check and error messages.

statmount_test.c: In function ‘cleanup_namespace’:
statmount_test.c:128:9: warning: ignoring return value of ‘fchdir’ declared with attribute ‘warn_unused_result’ [-Wunused-result]

Quoted 8 lines
   128 |         fchdir(orig_root);
       |         ^~~~~~~~~~~~~~~~~
statmount_test.c:129:9: warning: ignoring return value of ‘chroot’
declared with attribute ‘warn_unused_result’ [-Wunused-result]
   129 |         chroot(".");
       |         ^~~~~~~~~~~
Quoted 19 lines
---
  .../selftests/filesystems/statmount/statmount_test.c | 12 ++++++++++--
  1 file changed, 10 insertions(+), 2 deletions(-)
tools/testing/selftests/filesystems/statmount/statmount_test.c +5 -2
index e6d7c4f1c85b..e8c019d72cbf 100644
@@ -125,8 +125,16 @@ static uint32_t old_root_id, old_parent_id;
 
  static void cleanup_namespace(void)
  {
-	fchdir(orig_root);
-	chroot(".");
+	int ret;
+
+	ret = fchdir(orig_root);
+	if (ret == -1)
+		ksft_perror("fchdir to original root");
Quoted 8 lines

tools/testing/selftests/filesystems/statmount/statmount_test.c static uint32_t old_root_id, old_parent_id; · line 140

Quoted 8 lines
tools/testing/selftests/filesystems/statmount/statmount_test.c +5 -0
+
+	ret = chroot(".");
+	if (ret == -1)
+		ksft_perror("chroot to original root");
+
  	umount2(root_mntpoint, MNT_DETACH);
  	rmdir(root_mntpoint);
  }

Hi,

Quoted 8 lines

Can you please consider this patch?

Thank  you

Amer

Quoted 7 lines

Hello,

Could you please consider this simple patch for fixing build warnings for kselftest ?

Thank you

Amer

Applied to linux-kselftest fixes branch for the next rc.

thanks,
-- Shuah