From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7814) id 1A3213858003; Fri, 24 Sep 2021 20:12:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1A3213858003 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Fangrui Song To: glibc-cvs@sourceware.org Subject: [glibc/maskray/unnest] xsysconf: Only fail on error results and errno set X-Act-Checkin: glibc X-Git-Author: Stafford Horne X-Git-Refname: refs/heads/maskray/unnest X-Git-Oldrev: 54ff4f1e39067bfd04fb2141710637a11ef88862 X-Git-Newrev: 2efca218b56b0ef32289ad448c05b8f482a2e759 Message-Id: <20210924201221.1A3213858003@sourceware.org> Date: Fri, 24 Sep 2021 20:12:21 +0000 (GMT) X-BeenThere: glibc-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Sep 2021 20:12:21 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=2efca218b56b0ef32289ad448c05b8f482a2e759 commit 2efca218b56b0ef32289ad448c05b8f482a2e759 Author: Stafford Horne Date: Fri Sep 24 11:29:33 2021 +0900 xsysconf: Only fail on error results and errno set When testing nptl/tst-pthread-attr-affinity-fail fails with: error: xsysconf.c:33: sysconf (83): Cannot allocate memory error: 1 test failures This happens as xsysconf checks the errno after running sysconf. Internally the sysconf request for _SC_NPROCESSORS_CONF on linux allocates memory. But there is a problem, even though malloc succeeds errno is getting set to ENOMEM. POSIX allows successful calls to clobber errno. So xsysconf just checking errno is wrong. Fix xsysconf by only failing if we have an error result and errno is set. Diff: --- support/xsysconf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support/xsysconf.c b/support/xsysconf.c index 2607d3a720..fce7795417 100644 --- a/support/xsysconf.c +++ b/support/xsysconf.c @@ -29,7 +29,7 @@ xsysconf (int name) int old_errno = errno; errno = 0; long result = sysconf (name); - if (errno != 0) + if (result == -1 && errno != 0) FAIL_EXIT1 ("sysconf (%d): %m", name); errno = old_errno; return result;