1 diff --git a/sysdeps/unix/sysv/linux/getsysstats.c b/sysdeps/unix/sysv/linux/getsysstats.c
2 index af454b6..249bd19 100644
3 --- a/sysdeps/unix/sysv/linux/getsysstats.c
4 +++ b/sysdeps/unix/sysv/linux/getsysstats.c
8 #include <not-cancel.h>
9 +#include <kernel-features.h>
12 /* How we can determine the number of available processors depends on
14 But not all systems have support for the /proc filesystem. If it
15 is not available we simply return 1 since there is no way. */
17 -#include <not-cancel.h>
20 /* Other architectures use different formats for /proc/cpuinfo. This
21 provides a hook for alternative parsers. */
22 @@ -128,6 +126,15 @@ next_line (int fd, char *const buffer, char **cp, char **re,
26 + static int cached_result;
27 + static time_t timestamp;
29 + time_t now = time (NULL);
30 + time_t prev = timestamp;
31 + atomic_read_barrier ();
33 + return cached_result;
35 /* XXX Here will come a test for the new system call. */
37 const size_t buffer_size = __libc_use_alloca (8192) ? 8192 : 512;
38 @@ -135,20 +142,65 @@ __get_nprocs ()
39 char *buffer_end = buffer + buffer_size;
40 char *cp = buffer_end;
41 char *re = buffer_end;
45 const int flags = O_RDONLY | O_CLOEXEC;
47 const int flags = O_RDONLY;
49 + int fd = open_not_cancel_2 ("/sys/devices/system/cpu/online", flags);
54 + l = next_line (fd, buffer, &cp, &re, buffer_end);
59 + unsigned long int n = strtoul (l, &endp, 10);
66 + unsigned long int m = n;
70 + m = strtoul (l, &endp, 10);
78 + result += m - n + 1;
81 + while (l < re && isspace (*l))
86 + close_not_cancel_no_status (fd);
96 /* The /proc/stat format is more uniform, use it by default. */
97 - int fd = open_not_cancel_2 ("/proc/stat", flags);
98 + fd = open_not_cancel_2 ("/proc/stat", flags);
104 while ((l = next_line (fd, buffer, &cp, &re, buffer_end)) != NULL)
105 /* The current format of /proc/stat has all the cpu* entries
106 at the front. We assume here that stays this way. */
107 @@ -169,6 +221,11 @@ __get_nprocs ()
112 + cached_result = result;
113 + atomic_write_barrier ();
118 weak_alias (__get_nprocs, get_nprocs)
119 @@ -236,7 +293,7 @@ phys_pages_info (const char *format)
120 long int result = -1;
122 /* If we haven't found an appropriate entry return 1. */
123 - FILE *fp = fopen ("/proc/meminfo", "rc");
124 + FILE *fp = fopen ("/proc/meminfo", "rce");
127 /* No threads use this stream. */