From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-3.7 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id BD27A1F4BD for ; Sun, 6 Oct 2019 23:44:37 +0000 (UTC) Received: from localhost ([::1]:37498 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHGCa-0007tX-Cu for normalperson@yhbt.net; Sun, 06 Oct 2019 19:44:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51701) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHGCS-0007re-27 for bug-gnulib@gnu.org; Sun, 06 Oct 2019 19:44:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iHGCR-0001f8-0G for bug-gnulib@gnu.org; Sun, 06 Oct 2019 19:44:27 -0400 Received: from mo6-p00-ob.smtp.rzone.de ([2a01:238:20a:202:5300::8]:15423) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iHGCQ-0001cx-AL for bug-gnulib@gnu.org; Sun, 06 Oct 2019 19:44:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1570405463; s=strato-dkim-0002; d=clisp.org; h=Message-ID:Date:Subject:To:From:X-RZG-CLASS-ID:X-RZG-AUTH:From: Subject:Sender; bh=YtElOr9lDlFJQFnfJS8M2GA46QwaRAZ7FP21bN0nCXg=; b=qKQMW8nskQkxpKo6GGIVRLaT9jsJYnxOY1LLIruFZPem1HGG0c4sh9HgRYgbpFTp4S D5YS4V4llM9DScg9yR7LpHXXIu4xJaiYfbElvwfj6gbXRk1Nc/s8GHuTkLJ5uQOueGK/ RP1qpWfQDwagXEX6kU9MxzMAmExWysac8uRYkm72TwtHglYTwPU7ij0QDeZVNgmQcuiA KZtfBFvhPAvXXWKHmMFZQ/6VVUJk8YiV+AhozqdQhGV5WnsRjj5desB+gB3Hrqo0aeX7 X/MdLu/oaq4k8iQdcBNuZO56Yu1Wkzs5kiRoPGWzhx5XGI0/3H6ssMzDaq7WDcP1ZhgN HUIA== X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH+AHjwLuWOGaf0zJZW" X-RZG-CLASS-ID: mo00 Received: from bruno.haible.de by smtp.strato.de (RZmta 44.28.0 DYNA|AUTH) with ESMTPSA id N06099v96NiNCTr (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Mon, 7 Oct 2019 01:44:23 +0200 (CEST) From: Bruno Haible To: bug-gnulib@gnu.org Subject: access tests: fix test failure when run as root Date: Mon, 07 Oct 2019 01:44:23 +0200 Message-ID: <5867345.KNtYe3x8ii@omega> User-Agent: KMail/5.1.3 (Linux/4.4.0-159-generic; KDE/5.18.0; x86_64; ; ) MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a01:238:20a:202:5300::8 X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" One of the gnulib tests, test-access, fails when running as root. This patch fixes it. 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. 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 #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; }