diff options
author | Bruno Haible <bruno@clisp.org> | 2019-10-07 01:42:11 +0200 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2019-10-07 01:42:11 +0200 |
commit | 1eb7b25df1976fa852ddd7ea0ae26ec670146ce7 (patch) | |
tree | 686ef04b50fdfc070819cf36ee01508f5ac3a529 | |
parent | 4f027501ea35f8075192e360ac45c641ebad18dc (diff) | |
download | gnulib-1eb7b25df1976fa852ddd7ea0ae26ec670146ce7.tar.gz |
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.
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | modules/access-tests | 2 | ||||
-rw-r--r-- | tests/test-access.c | 19 |
3 files changed, 28 insertions, 3 deletions
@@ -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 diff --git a/modules/access-tests b/modules/access-tests index 082aeb58b1..4b35c21150 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 7af7f9a239..1488d55b50 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; } |