From: Bruno Haible Date: Sun, 6 Oct 2019 23:42:11 +0000 (+0200) Subject: access tests: Fix test failure when run as root. X-Git-Tag: v1.0~4637 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1eb7b25df1976fa852ddd7ea0ae26ec670146ce7;p=thirdparty%2Fgnulib.git 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/ChangeLog b/ChangeLog index 983dcf4c81..0fbb2d4391 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2019-10-06 Bruno Haible + + 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 (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 #include #include +#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; }