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)
commit2efca218b56b0ef32289ad448c05b8f482a2e759
tree55e9620d1d77c169f45167c299303ed5affbab1d
parent54ff4f1e39067bfd04fb2141710637a11ef88862
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.
support/xsysconf.c