]> Savannah Git Hosting - gnulib.git/commitdiff
access tests: Fix test failure when run as root.
authorBruno Haible <bruno@clisp.org>
Sun, 6 Oct 2019 23:42:11 +0000 (01:42 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 6 Oct 2019 23:42:11 +0000 (01:42 +0200)
* tests/test-access.c: Include root-uid.h.
(geteuid): Define fallback.
(main): Don't expect that writing to a read-only file would fail when
running as root. Also, remove the created files at the end.
* modules/access-tests (Depends-on): Add root-uid.
(configure.ac): Test whether geteuid exists.

ChangeLog
modules/access-tests
tests/test-access.c

index 983dcf4c815e9f3e74a9ddf3858273a43340cdf5..0fbb2d43912b46d73e32c2e58bcbfde98c1c940b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2019-10-06  Bruno Haible  <bruno@clisp.org>
+
+       access tests: Fix test failure when run as root.
+       * tests/test-access.c: Include root-uid.h.
+       (geteuid): Define fallback.
+       (main): Don't expect that writing to a read-only file would fail when
+       running as root. Also, remove the created files at the end.
+       * modules/access-tests (Depends-on): Add root-uid.
+       (configure.ac): Test whether geteuid exists.
+
 2019-10-06  Benno Schulenberg  <bensberg@telfort.nl>  (tiny change)
 
        users.txt: add GNU nano
index 082aeb58b1a6095569fe21948ba87fed2749f51e..4b35c21150073a1eec2ffc477c26a1088724ebbe 100644 (file)
@@ -5,8 +5,10 @@ tests/macros.h
 
 Depends-on:
 creat
+root-uid
 
 configure.ac:
+AC_CHECK_FUNCS_ONCE([geteuid])
 
 Makefile.am:
 TESTS += test-access
index 7af7f9a23926313ea3d5f00799cac2be38364b0a..1488d55b505ce380b98c68705a1d717584a8a2d3 100644 (file)
@@ -24,8 +24,14 @@ SIGNATURE_CHECK (access, int, (const char *, int));
 #include <errno.h>
 #include <fcntl.h>
 #include <sys/stat.h>
+#include "root-uid.h"
 #include "macros.h"
 
+/* mingw and MSVC 9 lack geteuid, so setup a dummy value.  */
+#if !HAVE_GETEUID
+# define geteuid() ROOT_UID
+#endif
+
 #define BASE "test-access.t"
 
 int
@@ -62,9 +68,12 @@ main ()
 
     ASSERT (access (BASE "f2", R_OK) == 0);
 
-    errno = 0;
-    ASSERT (access (BASE "f2", W_OK) == -1);
-    ASSERT (errno == EACCES);
+    if (geteuid () != ROOT_UID)
+      {
+        errno = 0;
+        ASSERT (access (BASE "f2", W_OK) == -1);
+        ASSERT (errno == EACCES);
+      }
 
 #if defined _WIN32 && !defined __CYGWIN__
     /* X_OK works like R_OK.  */
@@ -76,5 +85,9 @@ main ()
 #endif
   }
 
+  /* Cleanup.  */
+  unlink (BASE "f1");
+  unlink (BASE "f2");
+
   return 0;
 }