bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: supersede: Avoid a failure when writing to /dev/null in Solaris zone


From: Bruno Haible
Subject: Re: supersede: Avoid a failure when writing to /dev/null in Solaris zones
Date: Sun, 20 Sep 2020 21:31:37 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-189-generic; KDE/5.18.0; x86_64; ; )

On 2020-08-23 I did:
> 2020-08-23  Bruno Haible  <bruno@clisp.org>
> 
>       supersede: Avoid a failure when writing to /dev/null in Solaris zones.
>       Reported by Jörg Sonnenberger <joerg@netbsd.org>
>       via Thomas Klausner <tk@giga.or.at> in
>       
> <https://pkgsrc.se/files.php?messageId=20200812233110.30230FB28@cvs.NetBSD.org>.
>       * lib/supersede.c (open_supersede): When opening an existing non-regular
>       file on Solaris, use O_CREAT although it should not be necessary.

The same workaround is also needed on native Windows (mingw and MSVC).


2020-09-20  Bruno Haible  <bruno@clisp.org>

        supersede: Fix test failures on native Windows.
        * lib/supersede.c (open_supersede): Handle non-regular files on native
        Windows like on Solaris.
        * tests/test-supersede-open.h (test_open_supersede): Use O_BINARY flag.

diff --git a/lib/supersede.c b/lib/supersede.c
index a03cc6d..a3dfa4f 100644
--- a/lib/supersede.c
+++ b/lib/supersede.c
@@ -80,10 +80,12 @@ open_supersede (const char *filename, int flags, mode_t 
mode,
   int fd;
   /* Extra flags for existing devices.  */
   int extra_flags =
-    #if defined __sun
+    #if defined __sun || (defined _WIN32 && !defined __CYGWIN__)
     /* open ("/dev/null", O_TRUNC | O_WRONLY) fails with error EINVAL on 
Solaris
-       zones.  See <https://www.illumos.org/issues/13035>.  As a workaround, 
add
-       the O_CREAT flag, although it ought not to be necessary.  */
+       zones.  See <https://www.illumos.org/issues/13035>.
+       Likewise for open ("NUL", O_TRUNC | O_RDWR) on native Windows.
+       As a workaround, add the O_CREAT flag, although it ought not to be
+       necessary.  */
     O_CREAT;
     #else
     0;
@@ -207,8 +209,8 @@ open_supersede (const char *filename, int flags, mode_t 
mode,
               action->final_rename_temp = NULL;
               action->final_rename_dest = NULL;
             }
-          #if defined __sun
-          /* Work around <https://www.illumos.org/issues/13035>.  */
+          #if defined __sun || (defined _WIN32 && !defined __CYGWIN__)
+          /* See the comment regarding extra_flags, above.  */
           else if (errno == EINVAL)
             {
               struct stat statbuf;
diff --git a/tests/test-supersede-open.h b/tests/test-supersede-open.h
index f3b9b15..74a56d8 100644
--- a/tests/test-supersede-open.h
+++ b/tests/test-supersede-open.h
@@ -30,7 +30,7 @@ test_open_supersede (bool supersede_if_exists, bool 
supersede_if_does_not_exist)
     ASSERT (stat (filename, &statbuf) < 0);
 
     struct supersede_final_action action;
-    int fd = open_supersede (filename, O_RDWR | O_TRUNC, 0666,
+    int fd = open_supersede (filename, O_RDWR | O_BINARY | O_TRUNC, 0666,
                              supersede_if_exists, supersede_if_does_not_exist,
                              &action);
     ASSERT (fd >= 0);
@@ -56,7 +56,7 @@ test_open_supersede (bool supersede_if_exists, bool 
supersede_if_does_not_exist)
     ino_t orig_ino = statbuf.st_ino;
 
     struct supersede_final_action action;
-    int fd = open_supersede (filename, O_RDWR | O_TRUNC, 0666,
+    int fd = open_supersede (filename, O_RDWR | O_BINARY | O_TRUNC, 0666,
                              supersede_if_exists, supersede_if_does_not_exist,
                              &action);
     ASSERT (fd >= 0);
@@ -101,7 +101,7 @@ test_open_supersede (bool supersede_if_exists, bool 
supersede_if_does_not_exist)
     ASSERT (stat (DEV_NULL, &statbuf) == 0);
 
     struct supersede_final_action action;
-    int fd = open_supersede (DEV_NULL, O_RDWR | O_TRUNC, 0666,
+    int fd = open_supersede (DEV_NULL, O_RDWR | O_BINARY | O_TRUNC, 0666,
                              supersede_if_exists, supersede_if_does_not_exist,
                              &action);
     ASSERT (fd >= 0);
@@ -125,7 +125,7 @@ test_open_supersede (bool supersede_if_exists, bool 
supersede_if_does_not_exist)
 
         struct supersede_final_action action;
         int fd =
-          open_supersede (linkname, O_RDWR | O_TRUNC, 0666,
+          open_supersede (linkname, O_RDWR | O_BINARY | O_TRUNC, 0666,
                           supersede_if_exists, supersede_if_does_not_exist,
                           &action);
         ASSERT (fd >= 0);
@@ -180,7 +180,7 @@ test_open_supersede (bool supersede_if_exists, bool 
supersede_if_does_not_exist)
 
         struct supersede_final_action action;
         int fd =
-          open_supersede (linkname, O_RDWR | O_TRUNC, 0666,
+          open_supersede (linkname, O_RDWR | O_BINARY | O_TRUNC, 0666,
                           supersede_if_exists, supersede_if_does_not_exist,
                           &action);
         ASSERT (fd >= 0);
@@ -209,7 +209,7 @@ test_open_supersede (bool supersede_if_exists, bool 
supersede_if_does_not_exist)
 
         struct supersede_final_action action;
         int fd =
-          open_supersede (linkname, O_RDWR | O_TRUNC, 0666,
+          open_supersede (linkname, O_RDWR | O_BINARY | O_TRUNC, 0666,
                           supersede_if_exists, supersede_if_does_not_exist,
                           &action);
         ASSERT (fd >= 0);
@@ -243,7 +243,7 @@ test_open_supersede (bool supersede_if_exists, bool 
supersede_if_does_not_exist)
 
         struct supersede_final_action action;
         int fd =
-          open_supersede (linkname, O_RDWR | O_TRUNC, 0666,
+          open_supersede (linkname, O_RDWR | O_BINARY | O_TRUNC, 0666,
                           supersede_if_exists, supersede_if_does_not_exist,
                           &action);
         ASSERT (fd < 0);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]