glibc/sysdeps/unix
Meador Inge 995a46bbfb get_nprocs: Only return explictly set cache values (BZ #16996)
The implementation of __get_nprocs uses a stactic variable to cache
the value of the current number of processors.  The caching breaks when
'time (NULL) == 0':

  $ cat nproc.c
  #include <stdio.h>
  #include <time.h>
  #include <sys/time.h>

  int main(int argc, char *argv[])
  {
    time_t t;
    struct timeval tv = {0, 0};
    printf("settimeofday({0, 0}, NULL) = %d\n", settimeofday(&tv, NULL));
    t = time(NULL);
    printf("Time: %d, CPUs: %d\n", (unsigned int)t, get_nprocs());
    return 0;
  }
  $ gcc -O3 nproc.c
  $ ./a.out
  settimeofday({0, 0}, NULL) = -1
  Time: 1401311578, CPUs: 4
  $ sudo ./a.out
  settimeofday({0, 0}, NULL) = 0
  Time: 0, CPUs: 0

The problem is with the condition used to check whether a cached
value should be returned or not:

  static int cached_result;
  static time_t timestamp;

  time_t now = time (NULL);
  time_t prev = timestamp;
  atomic_read_barrier ();
  if (now == prev)
    return cached_result;

This patch fixes the problem by ensuring that 'cached_result' has
been set at least once before returning it.
2014-06-13 14:02:04 +05:30
..
alpha alpha: Fix __pointer_chk_guard definition for the testsuite 2014-04-16 21:35:27 -07:00
arm Move arm from ports to libc. 2014-02-08 01:49:39 +00:00
bsd Update copyright notices with scripts/update-copyrights 2014-01-01 22:00:23 +10:00
i386 Update copyright notices with scripts/update-copyrights 2014-01-01 22:00:23 +10:00
inet Move nss directory into sysdeps Subdirs. 2013-02-05 14:32:48 -08:00
mips Move mips from ports to libc. 2014-02-10 23:30:21 +00:00
powerpc Update copyright notices with scripts/update-copyrights 2014-01-01 22:00:23 +10:00
sh Update copyright notices with scripts/update-copyrights 2014-01-01 22:00:23 +10:00
sysv/linux get_nprocs: Only return explictly set cache values (BZ #16996) 2014-06-13 14:02:04 +05:30
x86_64 Update copyright notices with scripts/update-copyrights 2014-01-01 22:00:23 +10:00
clock_gettime.c Use glibc_likely instead __builtin_expect. 2014-02-10 15:07:12 +01:00
clock_nanosleep.c Update copyright notices with scripts/update-copyrights 2014-01-01 22:00:23 +10:00
clock_settime.c Use glibc_likely instead __builtin_expect. 2014-02-10 15:07:12 +01:00
confstr.h
get_child_max.c Update copyright notices with scripts/update-copyrights 2014-01-01 22:00:23 +10:00
getlogin_r.c Update copyright notices with scripts/update-copyrights 2014-01-01 22:00:23 +10:00
getlogin.c Update copyright notices with scripts/update-copyrights 2014-01-01 22:00:23 +10:00
getpagesize.c Update copyright notices with scripts/update-copyrights 2014-01-01 22:00:23 +10:00
grantpt.c Fix macro warning on HAVE_PT_CHOWN 2014-05-14 09:46:54 +02:00
ifreq.c Update copyright notices with scripts/update-copyrights 2014-01-01 22:00:23 +10:00
Implies
make-syscalls.sh don't use Bash-specific ${parameter/pattern/string} expansion 2013-09-28 23:03:09 -04:00
Makefile Update copyright notices with scripts/update-copyrights 2014-01-01 22:00:23 +10:00
s-proto-cancel.S
s-proto.S
setxid.h
sockatmark.c Update copyright notices with scripts/update-copyrights 2014-01-01 22:00:23 +10:00
stime.c Update copyright notices with scripts/update-copyrights 2014-01-01 22:00:23 +10:00
Subdirs
syscall-template.S Update copyright notices with scripts/update-copyrights 2014-01-01 22:00:23 +10:00
syscall.S Update copyright notices with scripts/update-copyrights 2014-01-01 22:00:23 +10:00
syscalls.list Name space hygeine for madvise. 2012-10-04 16:31:43 -07:00
sysdep.h Update copyright notices with scripts/update-copyrights 2014-01-01 22:00:23 +10:00