about summary refs log tree commit diff
path: root/ChangeLog
diff options
context:
space:
mode:
authorMeador Inge <meadori@codesourcery.com>2014-06-13 14:02:04 +0530
committerSiddhesh Poyarekar <siddhesh@redhat.com>2014-06-13 14:02:04 +0530
commit995a46bbfba9964e328e3947130919d8bd3cd62a (patch)
treec36f1da1cc528a8cfc1d891310be2599c0507532 /ChangeLog
parentfebf6cc58c36cd5a978b8b5faedb5a932eb44c98 (diff)
downloadglibc-995a46bbfba9964e328e3947130919d8bd3cd62a.tar.gz
glibc-995a46bbfba9964e328e3947130919d8bd3cd62a.tar.xz
glibc-995a46bbfba9964e328e3947130919d8bd3cd62a.zip
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.
Diffstat (limited to 'ChangeLog')
-rw-r--r--ChangeLog6
1 files changed, 6 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 83764a5840..d5474af375 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2014-06-13  Meador Inge  <meadori@codesourcery.com>
+
+	[BZ #16996]
+	sysdeps/unix/sysv/linux/getsysstats.c (__get_nprocs): Ensure
+	that the cached result has been set before returning it.
+
 2014-06-12  Roland McGrath  <roland@hack.frob.com>
 
 	* nptl/sysdeps/unix/sysv/linux/sparc/bits/pthreadtypes.h: Moved ...