Skip to contentSkip to conversation

selftests: filesystems: add return value checks

PATCH In review Abhinav Jain 2 participants 2 messages Jun 10, 2024 – Jun 11, 2024 Kselftest

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests: filesystems: add return value checks

Add ksft_exit_fail_msg() return value checks for fchdir() & chroot() to address the selftests statmount test compile warnings

statmount_test.c:127:2: warning: ignoring return value of ‘fchdir’, declared with attribute warn_unused_result [-Wunused-result]

  127 |  fchdir(orig_root);
      |  ^~~~~~~~~~~~~~~~~
statmount_test.c:128:2: warning: ignoring return value of ‘chroot’,
declared with attribute warn_unused_result [-Wunused-result]
  128 |  chroot(".");
      |  ^~~~~~~~~~~
---
 .../filesystems/statmount/statmount_test.c          | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
tools/testing/selftests/filesystems/statmount/statmount_test.c +11 -2
index e6d7c4f1c85b..b5e1247233b6 100644
@@ -125,8 +125,17 @@ 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_exit_fail_msg("changing current directory: %s\n",
+				strerror(errno));
+
+	ret = chroot(".");
+	if (ret == -1)
+		ksft_exit_fail_msg("chroot: %s\n", strerror(errno));
+
 	umount2(root_mntpoint, MNT_DETACH);
 	rmdir(root_mntpoint);
 }
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 31 lines · Abhinav Jain

Add ksft_exit_fail_msg() return value checks for fchdir() & chroot() to address the selftests statmount test compile warnings

statmount_test.c:127:2: warning: ignoring return value of ‘fchdir’, declared with attribute warn_unused_result [-Wunused-result]

   127 |  fchdir(orig_root);
       |  ^~~~~~~~~~~~~~~~~
statmount_test.c:128:2: warning: ignoring return value of ‘chroot’,
declared with attribute warn_unused_result [-Wunused-result]
   128 |  chroot(".");
       |  ^~~~~~~~~~~
---
  .../filesystems/statmount/statmount_test.c          | 13 +++++++++++--
  1 file changed, 11 insertions(+), 2 deletions(-)
tools/testing/selftests/filesystems/statmount/statmount_test.c +4 -2
index e6d7c4f1c85b..b5e1247233b6 100644
@@ -125,8 +125,17 @@ 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)

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

Quoted 10 lines
tools/testing/selftests/filesystems/statmount/statmount_test.c +7 -0
+		ksft_exit_fail_msg("changing current directory: %s\n",
+				strerror(errno));
+
+	ret = chroot(".");
+	if (ret == -1)
+		ksft_exit_fail_msg("chroot: %s\n", strerror(errno));
+
  	umount2(root_mntpoint, MNT_DETACH);
  	rmdir(root_mntpoint);
  }

There is another prior patch that fixes the problem
https://patchwork.kernel.org/project/linux-kselftest/patch/[email protected]/

thanks,
-- Shuah