[v4,12/15] tests: replace ftruncate by xftruncate

Message ID 20230428122142.928135-13-fberat@redhat.com
State Committed
Commit 32043daaafcd59793b9addf7af1bcedb3b666f09
Delegated to: Siddhesh Poyarekar
Headers
Series Fix warn unused result |

Commit Message

Frederic Berat April 28, 2023, 12:21 p.m. UTC
  With fortification enabled, ftruncate calls return result needs to be
checked, has it gets the __wur macro enabled.
---
 io/tst-copy_file_range.c  | 2 +-
 posix/tst-getopt-cancel.c | 3 ++-
 stdio-common/tst-perror.c | 3 ++-
 3 files changed, 5 insertions(+), 3 deletions(-)
  

Comments

Siddhesh Poyarekar May 25, 2023, 1:25 a.m. UTC | #1
On 2023-04-28 08:21, Frédéric Bérat wrote:
> With fortification enabled, ftruncate calls return result needs to be
> checked, has it gets the __wur macro enabled.
> ---
>   io/tst-copy_file_range.c  | 2 +-
>   posix/tst-getopt-cancel.c | 3 ++-
>   stdio-common/tst-perror.c | 3 ++-
>   3 files changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/io/tst-copy_file_range.c b/io/tst-copy_file_range.c
> index d1f3aaa5a9..bd64e9c42b 100644
> --- a/io/tst-copy_file_range.c
> +++ b/io/tst-copy_file_range.c
> @@ -166,7 +166,7 @@ short_copy (void)
>             inoff = 3;
>             xlseek (infd, shift, SEEK_SET);
>           }
> -      ftruncate (outfd, 0);
> +      xftruncate (outfd, 0);
>         xlseek (outfd, 0, SEEK_SET);
>         outoff = 0;
>   
> diff --git a/posix/tst-getopt-cancel.c b/posix/tst-getopt-cancel.c
> index 7167d1a914..6f49391690 100644
> --- a/posix/tst-getopt-cancel.c
> +++ b/posix/tst-getopt-cancel.c
> @@ -33,6 +33,7 @@
>   #include <support/support.h>
>   #include <support/temp_file.h>
>   #include <support/xthread.h>
> +#include <support/xunistd.h>
>   
>   static bool
>   check_stderr (bool expect_errmsg, FILE *stderr_trapped)
> @@ -48,7 +49,7 @@ check_stderr (bool expect_errmsg, FILE *stderr_trapped)
>         fputs (lineptr, stdout);
>       }
>     rewind (stderr_trapped);
> -  ftruncate (fileno (stderr_trapped), 0);
> +  xftruncate (fileno (stderr_trapped), 0);
>     return got_errmsg == expect_errmsg;
>   }
>   
> diff --git a/stdio-common/tst-perror.c b/stdio-common/tst-perror.c
> index 57835e0c59..b4ab583462 100644
> --- a/stdio-common/tst-perror.c
> +++ b/stdio-common/tst-perror.c

This one needs to be ported to use support/test-driver.  The patch is OK 
otherwise.

> @@ -9,6 +9,7 @@
>   #include <unistd.h>
>   #include <wchar.h>
>   
> +#include <support/xunistd.h>
>   
>   #define MB_EXP \
>     "null mode test 1: Invalid or incomplete multibyte or wide character\n" \
> @@ -94,7 +95,7 @@ do_test (void)
>       puts ("multibyte test succeeded");
>   
>     lseek (fd, 0, SEEK_SET);
> -  ftruncate (fd, 0);
> +  xftruncate (fd, 0);
>   
>     if (dup2 (fd, 2) == -1)
>       {
  
Siddhesh Poyarekar June 1, 2023, 4:42 p.m. UTC | #2
On 2023-05-24 21:25, Siddhesh Poyarekar wrote:
> 
> 
> On 2023-04-28 08:21, Frédéric Bérat wrote:
>> With fortification enabled, ftruncate calls return result needs to be
>> checked, has it gets the __wur macro enabled.
>> ---
>>   io/tst-copy_file_range.c  | 2 +-
>>   posix/tst-getopt-cancel.c | 3 ++-
>>   stdio-common/tst-perror.c | 3 ++-
>>   3 files changed, 5 insertions(+), 3 deletions(-)

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

Some tests need to be ported to test-driver.c but that could become a 
separate exercise.

Thanks,
Sid

>>
>> diff --git a/io/tst-copy_file_range.c b/io/tst-copy_file_range.c
>> index d1f3aaa5a9..bd64e9c42b 100644
>> --- a/io/tst-copy_file_range.c
>> +++ b/io/tst-copy_file_range.c
>> @@ -166,7 +166,7 @@ short_copy (void)
>>             inoff = 3;
>>             xlseek (infd, shift, SEEK_SET);
>>           }
>> -      ftruncate (outfd, 0);
>> +      xftruncate (outfd, 0);
>>         xlseek (outfd, 0, SEEK_SET);
>>         outoff = 0;
>> diff --git a/posix/tst-getopt-cancel.c b/posix/tst-getopt-cancel.c
>> index 7167d1a914..6f49391690 100644
>> --- a/posix/tst-getopt-cancel.c
>> +++ b/posix/tst-getopt-cancel.c
>> @@ -33,6 +33,7 @@
>>   #include <support/support.h>
>>   #include <support/temp_file.h>
>>   #include <support/xthread.h>
>> +#include <support/xunistd.h>
>>   static bool
>>   check_stderr (bool expect_errmsg, FILE *stderr_trapped)
>> @@ -48,7 +49,7 @@ check_stderr (bool expect_errmsg, FILE *stderr_trapped)
>>         fputs (lineptr, stdout);
>>       }
>>     rewind (stderr_trapped);
>> -  ftruncate (fileno (stderr_trapped), 0);
>> +  xftruncate (fileno (stderr_trapped), 0);
>>     return got_errmsg == expect_errmsg;
>>   }
>> diff --git a/stdio-common/tst-perror.c b/stdio-common/tst-perror.c
>> index 57835e0c59..b4ab583462 100644
>> --- a/stdio-common/tst-perror.c
>> +++ b/stdio-common/tst-perror.c
> 
> This one needs to be ported to use support/test-driver.  The patch is OK 
> otherwise.
> 
>> @@ -9,6 +9,7 @@
>>   #include <unistd.h>
>>   #include <wchar.h>
>> +#include <support/xunistd.h>
>>   #define MB_EXP \
>>     "null mode test 1: Invalid or incomplete multibyte or wide 
>> character\n" \
>> @@ -94,7 +95,7 @@ do_test (void)
>>       puts ("multibyte test succeeded");
>>     lseek (fd, 0, SEEK_SET);
>> -  ftruncate (fd, 0);
>> +  xftruncate (fd, 0);
>>     if (dup2 (fd, 2) == -1)
>>       {
>
  

Patch

diff --git a/io/tst-copy_file_range.c b/io/tst-copy_file_range.c
index d1f3aaa5a9..bd64e9c42b 100644
--- a/io/tst-copy_file_range.c
+++ b/io/tst-copy_file_range.c
@@ -166,7 +166,7 @@  short_copy (void)
           inoff = 3;
           xlseek (infd, shift, SEEK_SET);
         }
-      ftruncate (outfd, 0);
+      xftruncate (outfd, 0);
       xlseek (outfd, 0, SEEK_SET);
       outoff = 0;
 
diff --git a/posix/tst-getopt-cancel.c b/posix/tst-getopt-cancel.c
index 7167d1a914..6f49391690 100644
--- a/posix/tst-getopt-cancel.c
+++ b/posix/tst-getopt-cancel.c
@@ -33,6 +33,7 @@ 
 #include <support/support.h>
 #include <support/temp_file.h>
 #include <support/xthread.h>
+#include <support/xunistd.h>
 
 static bool
 check_stderr (bool expect_errmsg, FILE *stderr_trapped)
@@ -48,7 +49,7 @@  check_stderr (bool expect_errmsg, FILE *stderr_trapped)
       fputs (lineptr, stdout);
     }
   rewind (stderr_trapped);
-  ftruncate (fileno (stderr_trapped), 0);
+  xftruncate (fileno (stderr_trapped), 0);
   return got_errmsg == expect_errmsg;
 }
 
diff --git a/stdio-common/tst-perror.c b/stdio-common/tst-perror.c
index 57835e0c59..b4ab583462 100644
--- a/stdio-common/tst-perror.c
+++ b/stdio-common/tst-perror.c
@@ -9,6 +9,7 @@ 
 #include <unistd.h>
 #include <wchar.h>
 
+#include <support/xunistd.h>
 
 #define MB_EXP \
   "null mode test 1: Invalid or incomplete multibyte or wide character\n" \
@@ -94,7 +95,7 @@  do_test (void)
     puts ("multibyte test succeeded");
 
   lseek (fd, 0, SEEK_SET);
-  ftruncate (fd, 0);
+  xftruncate (fd, 0);
 
   if (dup2 (fd, 2) == -1)
     {