]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
xsysconf: Only fail on error results and errno set
authorStafford Horne <shorne@gmail.com>
Fri, 24 Sep 2021 02:29:33 +0000 (11:29 +0900)
committerStafford Horne <shorne@gmail.com>
Fri, 24 Sep 2021 08:30:03 +0000 (17:30 +0900)
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.

support/xsysconf.c

index 2607d3a720d2cfa61deb6a1294de4c1557185852..fce77954171e882dbc41bb169f5129d7f9ef27a5 100644 (file)
@@ -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;