public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/maskray/unnest] xsysconf: Only fail on error results and errno set
@ 2021-09-24 20:12 Fangrui Song
  0 siblings, 0 replies; only message in thread
From: Fangrui Song @ 2021-09-24 20:12 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=2efca218b56b0ef32289ad448c05b8f482a2e759

commit 2efca218b56b0ef32289ad448c05b8f482a2e759
Author: Stafford Horne <shorne@gmail.com>
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;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-09-24 20:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-24 20:12 [glibc/maskray/unnest] xsysconf: Only fail on error results and errno set Fangrui Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).