selftests/filesystems/mount-notify: fix unused unused result warning
PATCH v2 1/1 selftests/filesystems/mount-notify: fix unused unused result warning
When running make kselftest, the following compilation warning was encountered:
mount-notify_test.c: In function ‘fanotify_rmdir’:
mount-notify_test.c:490:17: warning: ignoring return value of ‘chdir’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
490 | chdir("/");
| ^~~~~~~~~~---
Changes in v2:
- Apply changes suggested by Shuah Khan
- Link to v1: https://lore.kernel.org/all/[email protected]/
--- .../filesystems/mount-notify/mount-notify_test.c | 15 ++++++++++----- .../mount-notify/mount-notify_test_ns.c | 15 ++++++++++----- 2 files changed, 20 insertions(+), 10 deletions(-)
tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c +10 -5
@@ -458,12 +458,17 @@ TEST_F(fanotify, rmdir)ASSERT_GE (ret,0 );if (ret ==0 ) { -chdir ("/" ); -unshare (CLONE_NEWNS ); -mount ("" ,"/" ,NULL ,MS_REC |MS_PRIVATE ,NULL ); -umount2 ("/a" ,MNT_DETACH ); +if (chdir ("/" )) +exit (-1 ); +if (unshare (CLONE_NEWNS )) +exit (-1 ); +if (mount ("" ,"/" ,NULL ,MS_REC |MS_PRIVATE ,NULL )) +exit (-1 ); +if (umount2 ("/a" ,MNT_DETACH )) +exit (-1 );// This triggers a detach in the other namespace -rmdir ("/a" ); +if (rmdir ("/a" )) +exit (-1 );exit (0 ); }wait (NULL );
tools/testing/selftests/filesystems/mount-notify/mount-notify_test_ns.c +10 -5
@@ -486,12 +486,17 @@ TEST_F(fanotify, rmdir)ASSERT_GE (ret,0 );if (ret ==0 ) { -chdir ("/" ); -unshare (CLONE_NEWNS ); -mount ("" ,"/" ,NULL ,MS_REC |MS_PRIVATE ,NULL ); -umount2 ("/a" ,MNT_DETACH ); +if (chdir ("/" )) +exit (-1 ); +if (unshare (CLONE_NEWNS )) +exit (-1 ); +if (mount ("" ,"/" ,NULL ,MS_REC |MS_PRIVATE ,NULL )) +exit (-1 ); +if (umount2 ("/a" ,MNT_DETACH )) +exit (-1 );// This triggers a detach in the other namespace -rmdir ("/a" ); +if (rmdir ("/a" )) +exit (-1 );exit (0 ); }wait (NULL );
Signature · 1 line
2.43.0
Quoted 22 lines · Chen Linxuan
When running
make kselftest, the following compilation warning was encountered:
mount-notify_test.c: In function ‘fanotify_rmdir’:
mount-notify_test.c:490:17: warning: ignoring return value of ‘chdir’ declared with attribute ‘warn_unused_result’ [-Wunused-result]490 | chdir("/"); | ^~~~~~~~~~Signed-off-by Chen Linxuan <[email protected]>---
Changes in v2:
- Apply changes suggested by Shuah Khan
- Link to v1: https://lore.kernel.org/all/[email protected]/--- .../filesystems/mount-notify/mount-notify_test.c | 15 ++++++++++----- .../mount-notify/mount-notify_test_ns.c | 15 ++++++++++----- 2 files changed, 20 insertions(+), 10 deletions(-)tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c +0
-0
tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c TEST_F(fanotify, rmdir) · line 461
Quoted 8 lines
tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c +1
-4@@ -458,12 +458,17 @@ TEST_F(fanotify, rmdir)ASSERT_GE (ret,0 );if (ret ==0 ) { -chdir ("/" ); -unshare (CLONE_NEWNS ); -mount ("" ,"/" ,NULL ,MS_REC |MS_PRIVATE ,NULL ); -umount2 ("/a" ,MNT_DETACH ); +if (chdir ("/" ))
Please use the APIs provided by the kselftest_harness.h instead of checking return types manually. For example:
use ASSERT_EQ(chdir("/", 0)).
Quoted 41 lines
tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c +9
-1+exit (-1 ); +if (unshare (CLONE_NEWNS )) +exit (-1 ); +if (mount ("" ,"/" ,NULL ,MS_REC |MS_PRIVATE ,NULL )) +exit (-1 ); +if (umount2 ("/a" ,MNT_DETACH )) +exit (-1 );// This triggers a detach in the other namespace -rmdir ("/a" ); +if (rmdir ("/a" )) +exit (-1 );exit (0 ); }wait (NULL );tools/testing/selftests/filesystems/mount-notify/mount-notify_test_ns.c +10
-5@@ -486,12 +486,17 @@ TEST_F(fanotify, rmdir)ASSERT_GE (ret,0 );if (ret ==0 ) { -chdir ("/" ); -unshare (CLONE_NEWNS ); -mount ("" ,"/" ,NULL ,MS_REC |MS_PRIVATE ,NULL ); -umount2 ("/a" ,MNT_DETACH ); +if (chdir ("/" )) +exit (-1 ); +if (unshare (CLONE_NEWNS )) +exit (-1 ); +if (mount ("" ,"/" ,NULL ,MS_REC |MS_PRIVATE ,NULL )) +exit (-1 ); +if (umount2 ("/a" ,MNT_DETACH )) +exit (-1 );// This triggers a detach in the other namespace -rmdir ("/a" ); +if (rmdir ("/a" )) +exit (-1 );exit (0 ); }wait (NULL );
Quoted 26 lines · Muhammad Usama Anjum
Quoted 24 lines · Chen Linxuan
When running
make kselftest, the following compilation warning was encountered:
mount-notify_test.c: In function ‘fanotify_rmdir’:
mount-notify_test.c:490:17: warning: ignoring return value of ‘chdir’ declared with attribute ‘warn_unused_result’ [-Wunused-result]490 | chdir("/"); | ^~~~~~~~~~Signed-off-by Chen Linxuan <[email protected]>---
Changes in v2:
- Apply changes suggested by Shuah Khan
- Link to v1: https://lore.kernel.org/all/[email protected]/--- .../filesystems/mount-notify/mount-notify_test.c | 15 ++++++++++----- .../mount-notify/mount-notify_test_ns.c | 15 ++++++++++----- 2 files changed, 20 insertions(+), 10 deletions(-)tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c +0
-0@@ -458,12 +458,17 @@ TEST_F(fanotify, rmdir)ASSERT_GE (ret,0 );
Quoted 9 lines
tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c TEST_F(fanotify, rmdir) · line 461
Quoted 6 lines
tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c +1
-4if (ret ==0 ) { -chdir ("/" ); -unshare (CLONE_NEWNS ); -mount ("" ,"/" ,NULL ,MS_REC |MS_PRIVATE ,NULL ); -umount2 ("/a" ,MNT_DETACH ); +if (chdir ("/" ))Please use the APIs provided by the
kselftest_harness.hinstead of checking return types manually. For example:
useASSERT_EQ(chdir("/", 0)).
Are you sure?We're in a forked sub process here.
Quoted 45 lines
Quoted 42 lines
tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c +9
-1+exit (-1 ); +if (unshare (CLONE_NEWNS )) +exit (-1 ); +if (mount ("" ,"/" ,NULL ,MS_REC |MS_PRIVATE ,NULL )) +exit (-1 ); +if (umount2 ("/a" ,MNT_DETACH )) +exit (-1 );// This triggers a detach in the other namespace -rmdir ("/a" ); +if (rmdir ("/a" )) +exit (-1 );exit (0 ); }wait (NULL );tools/testing/selftests/filesystems/mount-notify/mount-notify_test_ns.c +10
-5@@ -486,12 +486,17 @@ TEST_F(fanotify, rmdir)ASSERT_GE (ret,0 );if (ret ==0 ) { -chdir ("/" ); -unshare (CLONE_NEWNS ); -mount ("" ,"/" ,NULL ,MS_REC |MS_PRIVATE ,NULL ); -umount2 ("/a" ,MNT_DETACH ); +if (chdir ("/" )) +exit (-1 ); +if (unshare (CLONE_NEWNS )) +exit (-1 ); +if (mount ("" ,"/" ,NULL ,MS_REC |MS_PRIVATE ,NULL )) +exit (-1 ); +if (umount2 ("/a" ,MNT_DETACH )) +exit (-1 );// This triggers a detach in the other namespace -rmdir ("/a" ); +if (rmdir ("/a" )) +exit (-1 );exit (0 ); }wait (NULL );
Quoted 38 lines · Chen Linxuan
Quoted 26 lines · Muhammad Usama Anjum
Quoted 24 lines · Chen Linxuan
When running
make kselftest, the following compilation warning was encountered:
mount-notify_test.c: In function ‘fanotify_rmdir’:
mount-notify_test.c:490:17: warning: ignoring return value of ‘chdir’ declared with attribute ‘warn_unused_result’ [-Wunused-result]490 | chdir("/"); | ^~~~~~~~~~Signed-off-by Chen Linxuan <[email protected]>---
Changes in v2:
- Apply changes suggested by Shuah Khan
- Link to v1: https://lore.kernel.org/all/[email protected]/--- .../filesystems/mount-notify/mount-notify_test.c | 15 ++++++++++----- .../mount-notify/mount-notify_test_ns.c | 15 ++++++++++----- 2 files changed, 20 insertions(+), 10 deletions(-)tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c +0
-0@@ -458,12 +458,17 @@ TEST_F(fanotify, rmdir)ASSERT_GE (ret,0 );Quoted 9 lines
tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c TEST_F(fanotify, rmdir) · line 461
Quoted 6 lines
tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c +1
-4if (ret ==0 ) { -chdir ("/" ); -unshare (CLONE_NEWNS ); -mount ("" ,"/" ,NULL ,MS_REC |MS_PRIVATE ,NULL ); -umount2 ("/a" ,MNT_DETACH ); +if (chdir ("/" ))Please use the APIs provided by the
kselftest_harness.hinstead of checking return types manually. For example:
useASSERT_EQ(chdir("/", 0)).
Quoted 1 line
Are you sure?We're in a forked sub process here.
ASSERT_* are macros. They can be used anywhere. Please give it a try.
Quoted 46 lines
Quoted 46 lines
Quoted 43 lines
tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c +9
-1+exit (-1 ); +if (unshare (CLONE_NEWNS )) +exit (-1 ); +if (mount ("" ,"/" ,NULL ,MS_REC |MS_PRIVATE ,NULL )) +exit (-1 ); +if (umount2 ("/a" ,MNT_DETACH )) +exit (-1 );// This triggers a detach in the other namespace -rmdir ("/a" ); +if (rmdir ("/a" )) +exit (-1 );exit (0 ); }wait (NULL );tools/testing/selftests/filesystems/mount-notify/mount-notify_test_ns.c +10
-5@@ -486,12 +486,17 @@ TEST_F(fanotify, rmdir)ASSERT_GE (ret,0 );if (ret ==0 ) { -chdir ("/" ); -unshare (CLONE_NEWNS ); -mount ("" ,"/" ,NULL ,MS_REC |MS_PRIVATE ,NULL ); -umount2 ("/a" ,MNT_DETACH ); +if (chdir ("/" )) +exit (-1 ); +if (unshare (CLONE_NEWNS )) +exit (-1 ); +if (mount ("" ,"/" ,NULL ,MS_REC |MS_PRIVATE ,NULL )) +exit (-1 ); +if (umount2 ("/a" ,MNT_DETACH )) +exit (-1 );// This triggers a detach in the other namespace -rmdir ("/a" ); +if (rmdir ("/a" )) +exit (-1 );exit (0 ); }wait (NULL );
Quoted 40 lines · Muhammad Usama Anjum
Quoted 38 lines · Chen Linxuan
Quoted 35 lines · Muhammad Usama Anjum
Quoted 22 lines · Chen Linxuan
When running
make kselftest, the following compilation warning was encountered:
mount-notify_test.c: In function ‘fanotify_rmdir’:
mount-notify_test.c:490:17: warning: ignoring return value of ‘chdir’ declared with attribute ‘warn_unused_result’ [-Wunused-result]490 | chdir("/"); | ^~~~~~~~~~Signed-off-by Chen Linxuan <[email protected]>---
Changes in v2:
- Apply changes suggested by Shuah Khan
- Link to v1: https://lore.kernel.org/all/[email protected]/--- .../filesystems/mount-notify/mount-notify_test.c | 15 ++++++++++----- .../mount-notify/mount-notify_test_ns.c | 15 ++++++++++----- 2 files changed, 20 insertions(+), 10 deletions(-)tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c +0
-0tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c TEST_F(fanotify, rmdir) · line 461
Quoted 8 lines
tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c +1
-4@@ -458,12 +458,17 @@ TEST_F(fanotify, rmdir)ASSERT_GE (ret,0 );if (ret ==0 ) { -chdir ("/" ); -unshare (CLONE_NEWNS ); -mount ("" ,"/" ,NULL ,MS_REC |MS_PRIVATE ,NULL ); -umount2 ("/a" ,MNT_DETACH ); +if (chdir ("/" ))Please use the APIs provided by the
kselftest_harness.hinstead of checking return types manually. For example:
useASSERT_EQ(chdir("/", 0)).
Quoted 2 lines
Quoted 1 line
Are you sure?We're in a forked sub process here.
ASSERT_* are macros. They can be used anywhere. Please give it a try.
V3: https://lore.kernel.org/all/[email protected]/
Quoted 50 lines
Quoted 47 lines
Quoted 47 lines
Quoted 44 lines
tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c +9
-1+exit (-1 ); +if (unshare (CLONE_NEWNS )) +exit (-1 ); +if (mount ("" ,"/" ,NULL ,MS_REC |MS_PRIVATE ,NULL )) +exit (-1 ); +if (umount2 ("/a" ,MNT_DETACH )) +exit (-1 );// This triggers a detach in the other namespace -rmdir ("/a" ); +if (rmdir ("/a" )) +exit (-1 );exit (0 ); }wait (NULL );tools/testing/selftests/filesystems/mount-notify/mount-notify_test_ns.c +10
-5@@ -486,12 +486,17 @@ TEST_F(fanotify, rmdir)ASSERT_GE (ret,0 );if (ret ==0 ) { -chdir ("/" ); -unshare (CLONE_NEWNS ); -mount ("" ,"/" ,NULL ,MS_REC |MS_PRIVATE ,NULL ); -umount2 ("/a" ,MNT_DETACH ); +if (chdir ("/" )) +exit (-1 ); +if (unshare (CLONE_NEWNS )) +exit (-1 ); +if (mount ("" ,"/" ,NULL ,MS_REC |MS_PRIVATE ,NULL )) +exit (-1 ); +if (umount2 ("/a" ,MNT_DETACH )) +exit (-1 );// This triggers a detach in the other namespace -rmdir ("/a" ); +if (rmdir ("/a" )) +exit (-1 );exit (0 ); }wait (NULL );