[v6,6/7] tests: Replace various function calls with their x variant

Message ID 20230602152812.108497-7-fberat@redhat.com
State Committed
Commit f6a532fbd0f430dc4ded254d713d89fcbafc1b7e
Delegated to: Siddhesh Poyarekar
Headers
Series Fix warn unused result |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_glibc_check--master-arm pending Patch applied
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 pending Patch applied

Commit Message

Frederic Berat June 2, 2023, 3:28 p.m. UTC
  With fortification enabled, few function calls return result need to be
checked, has they get the __wur macro enabled.
---
Changes since v5:
 - Actually replace functions with their x variant as described

 misc/tst-error1.c    | 4 +++-
 nss/tst-reload2.c    | 2 +-
 posix/tst-chmod.c    | 7 +++++--
 posix/wordexp-test.c | 2 +-
 stdlib/test-canon.c  | 4 +++-
 5 files changed, 13 insertions(+), 6 deletions(-)
  

Comments

Siddhesh Poyarekar June 6, 2023, 12:20 p.m. UTC | #1
On 2023-06-02 11:28, Frédéric Bérat wrote:
> With fortification enabled, few function calls return result need to be
> checked, has they get the __wur macro enabled.
> ---
> Changes since v5:
>   - Actually replace functions with their x variant as described

LGTM.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>

> 
>   misc/tst-error1.c    | 4 +++-
>   nss/tst-reload2.c    | 2 +-
>   posix/tst-chmod.c    | 7 +++++--
>   posix/wordexp-test.c | 2 +-
>   stdlib/test-canon.c  | 4 +++-
>   5 files changed, 13 insertions(+), 6 deletions(-)
> 
> diff --git a/misc/tst-error1.c b/misc/tst-error1.c
> index 9c4a62fbd0..75d4edf476 100644
> --- a/misc/tst-error1.c
> +++ b/misc/tst-error1.c
> @@ -5,11 +5,13 @@
>   #include <wchar.h>
>   #include <libc-diag.h>
>   
> +#include <support/xstdio.h>
> +
>   static int
>   do_test (int argc, char *argv[])
>   {
>     mtrace ();
> -  (void) freopen (argc == 1 ? "/dev/stdout" : argv[1], "a", stderr);
> +  xfreopen (argc == 1 ? "/dev/stdout" : argv[1], "a", stderr);
>     /* Orient the stream.  */
>     fwprintf (stderr, L"hello world\n");
>     char buf[20000];
> diff --git a/nss/tst-reload2.c b/nss/tst-reload2.c
> index ba9b5b7687..89cc9ea242 100644
> --- a/nss/tst-reload2.c
> +++ b/nss/tst-reload2.c
> @@ -121,7 +121,7 @@ do_test (void)
>     /* Change the root dir.  */
>   
>     TEST_VERIFY (chroot ("/subdir") == 0);
> -  chdir ("/");
> +  xchdir ("/");
>   
>     /* Check we're NOT using the "inner" nsswitch.conf.  */
>   
> diff --git a/posix/tst-chmod.c b/posix/tst-chmod.c
> index b98a05a265..470a696fe5 100644
> --- a/posix/tst-chmod.c
> +++ b/posix/tst-chmod.c
> @@ -27,6 +27,8 @@
>   #include <unistd.h>
>   #include <sys/stat.h>
>   
> +#include <support/xunistd.h>
> +
>   
>   #define OUT_OF_MEMORY \
>     do {									      \
> @@ -229,7 +231,8 @@ do_test (int argc, char *argv[])
>     close (fd);
>   
>     snprintf (buf, buflen, "%s/..", testdir);
> -  chdir (buf);
> +  xchdir (buf);
> +
>     /* We are now in the directory above the one we create the test
>        directory in.  */
>   
> @@ -349,7 +352,7 @@ do_test (int argc, char *argv[])
>       }
>   
>    fail:
> -  chdir (startdir);
> +  xchdir (startdir);
>   
>     /* Remove all the files.  */
>     chmod (testdir, 0700);
> diff --git a/posix/wordexp-test.c b/posix/wordexp-test.c
> index 524597d96b..28d1d1509b 100644
> --- a/posix/wordexp-test.c
> +++ b/posix/wordexp-test.c
> @@ -336,7 +336,7 @@ do_test (int argc, char *argv[])
>     if (cwd == NULL)
>       cwd = "..";
>   
> -  chdir (cwd);
> +  xchdir (cwd);
>     rmdir (tmpdir);
>   
>     return 0;
> diff --git a/stdlib/test-canon.c b/stdlib/test-canon.c
> index bf19b1f1b1..2874258722 100644
> --- a/stdlib/test-canon.c
> +++ b/stdlib/test-canon.c
> @@ -27,6 +27,8 @@
>   #include <sys/param.h>
>   #include <sys/stat.h>
>   
> +#include <support/xunistd.h>
> +
>   /* Prototype for our test function.  */
>   extern int do_test (int argc, char *argv[]);
>   #include <test-skeleton.c>
> @@ -159,7 +161,7 @@ do_test (int argc, char ** argv)
>       }
>   
>     for (i = 0; i < (int) (sizeof (symlinks) / sizeof (symlinks[0])); ++i)
> -    symlink (symlinks[i].value, symlinks[i].name);
> +    xsymlink (symlinks[i].value, symlinks[i].name);
>   
>     int has_dir = mkdir ("doesExist", 0777) == 0;
>
  

Patch

diff --git a/misc/tst-error1.c b/misc/tst-error1.c
index 9c4a62fbd0..75d4edf476 100644
--- a/misc/tst-error1.c
+++ b/misc/tst-error1.c
@@ -5,11 +5,13 @@ 
 #include <wchar.h>
 #include <libc-diag.h>
 
+#include <support/xstdio.h>
+
 static int
 do_test (int argc, char *argv[])
 {
   mtrace ();
-  (void) freopen (argc == 1 ? "/dev/stdout" : argv[1], "a", stderr);
+  xfreopen (argc == 1 ? "/dev/stdout" : argv[1], "a", stderr);
   /* Orient the stream.  */
   fwprintf (stderr, L"hello world\n");
   char buf[20000];
diff --git a/nss/tst-reload2.c b/nss/tst-reload2.c
index ba9b5b7687..89cc9ea242 100644
--- a/nss/tst-reload2.c
+++ b/nss/tst-reload2.c
@@ -121,7 +121,7 @@  do_test (void)
   /* Change the root dir.  */
 
   TEST_VERIFY (chroot ("/subdir") == 0);
-  chdir ("/");
+  xchdir ("/");
 
   /* Check we're NOT using the "inner" nsswitch.conf.  */
 
diff --git a/posix/tst-chmod.c b/posix/tst-chmod.c
index b98a05a265..470a696fe5 100644
--- a/posix/tst-chmod.c
+++ b/posix/tst-chmod.c
@@ -27,6 +27,8 @@ 
 #include <unistd.h>
 #include <sys/stat.h>
 
+#include <support/xunistd.h>
+
 
 #define OUT_OF_MEMORY \
   do {									      \
@@ -229,7 +231,8 @@  do_test (int argc, char *argv[])
   close (fd);
 
   snprintf (buf, buflen, "%s/..", testdir);
-  chdir (buf);
+  xchdir (buf);
+
   /* We are now in the directory above the one we create the test
      directory in.  */
 
@@ -349,7 +352,7 @@  do_test (int argc, char *argv[])
     }
 
  fail:
-  chdir (startdir);
+  xchdir (startdir);
 
   /* Remove all the files.  */
   chmod (testdir, 0700);
diff --git a/posix/wordexp-test.c b/posix/wordexp-test.c
index 524597d96b..28d1d1509b 100644
--- a/posix/wordexp-test.c
+++ b/posix/wordexp-test.c
@@ -336,7 +336,7 @@  do_test (int argc, char *argv[])
   if (cwd == NULL)
     cwd = "..";
 
-  chdir (cwd);
+  xchdir (cwd);
   rmdir (tmpdir);
 
   return 0;
diff --git a/stdlib/test-canon.c b/stdlib/test-canon.c
index bf19b1f1b1..2874258722 100644
--- a/stdlib/test-canon.c
+++ b/stdlib/test-canon.c
@@ -27,6 +27,8 @@ 
 #include <sys/param.h>
 #include <sys/stat.h>
 
+#include <support/xunistd.h>
+
 /* Prototype for our test function.  */
 extern int do_test (int argc, char *argv[]);
 #include <test-skeleton.c>
@@ -159,7 +161,7 @@  do_test (int argc, char ** argv)
     }
 
   for (i = 0; i < (int) (sizeof (symlinks) / sizeof (symlinks[0])); ++i)
-    symlink (symlinks[i].value, symlinks[i].name);
+    xsymlink (symlinks[i].value, symlinks[i].name);
 
   int has_dir = mkdir ("doesExist", 0777) == 0;