[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
access tests: fix test failure when run as root
From: |
Bruno Haible |
Subject: |
access tests: fix test failure when run as root |
Date: |
Mon, 07 Oct 2019 01:44:23 +0200 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-159-generic; KDE/5.18.0; x86_64; ; ) |
One of the gnulib tests, test-access, fails when running as root.
This patch fixes it.
2019-10-06 Bruno Haible <address@hidden>
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.
diff --git a/modules/access-tests b/modules/access-tests
index 082aeb5..4b35c21 100644
--- a/modules/access-tests
+++ b/modules/access-tests
@@ -5,8 +5,10 @@ tests/macros.h
Depends-on:
creat
+root-uid
configure.ac:
+AC_CHECK_FUNCS_ONCE([geteuid])
Makefile.am:
TESTS += test-access
diff --git a/tests/test-access.c b/tests/test-access.c
index 7af7f9a..1488d55 100644
--- a/tests/test-access.c
+++ b/tests/test-access.c
@@ -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;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- access tests: fix test failure when run as root,
Bruno Haible <=