glibc/sysdeps
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
..
aarch64 AArch64: Define TLS_DEFINE_INIT_TP 2014-06-11 12:23:01 -07:00
alpha Alpha: Define TLS_DEFINE_INIT_TP 2014-06-11 12:23:35 -07:00
arm ARM: Define TLS_DEFINE_INIT_TP 2014-06-09 12:53:16 -07:00
generic Remove second argument from TLS_INIT_TP macro 2014-05-27 14:48:46 +02:00
gnu Silence a missing-noreturn warning for _Unwind_Resume. 2014-05-09 10:06:20 -07:00
hppa HPPA: Define TLS_DEFINE_INIT_TP 2014-06-09 14:04:45 -07:00
i386 Move i386 code out of nptl/ subdirectory. 2014-06-12 10:08:24 -07:00
ia64 Remove second argument from TLS_INIT_TP macro 2014-05-27 14:48:46 +02:00
ieee754 Fix log2 (1) in round-downward mode (bug 17042). 2014-06-10 12:07:15 +00:00
init_array Update copyright notices with scripts/update-copyrights 2014-01-01 22:00:23 +10:00
m68k m68k: Define TLS_DEFINE_INIT_TP 2014-06-09 15:54:19 -07:00
mach Remove second argument from TLS_INIT_TP macro 2014-05-27 14:48:46 +02:00
microblaze Remove second argument from TLS_INIT_TP macro 2014-05-27 14:48:46 +02:00
mips MIPS: Define TLS_DEFINE_INIT_TP 2014-06-09 13:47:38 -07:00
nptl Get rid of nptl/sysdeps/pthread/ subdirectory 2014-06-12 13:48:47 -07:00
posix Return EAI_AGAIN for AF_UNSPEC when herrno is TRY_AGAIN (BZ #16849) 2014-05-15 12:33:11 +05:30
powerpc Update powerpc-fpu ULPs. 2014-06-11 21:22:49 -05:00
pthread Use list.h in posix-timer code. 2014-06-12 14:17:14 -07:00
s390 Remove redundant C locale settings. 2014-06-07 19:58:36 +00:00
sh Move SH code out of nptl/ subdirectory. 2014-06-12 09:05:54 -07:00
sparc Move SPARC public headers out of nptl/ 2014-06-12 15:04:34 -07:00
tile Tile: Define TLS_DEFINE_INIT_TP 2014-06-11 12:25:27 -07:00
unix get_nprocs: Only return explictly set cache values (BZ #16996) 2014-06-13 14:02:04 +05:30
wordsize-32 Update copyright notices with scripts/update-copyrights 2014-01-01 22:00:23 +10:00
wordsize-64 Update copyright notices with scripts/update-copyrights 2014-01-01 22:00:23 +10:00
x86 Move NPTL public ABI headers for x86 to sysdeps/x86/nptl/. 2014-05-14 09:44:56 -07:00
x86_64 Move i386 code out of nptl/ subdirectory. 2014-06-12 10:08:24 -07:00