Fix parsing of /sys/devices/system/cpu/online (bug 25859)
authorAndreas Schwab <schwab@linux-m68k.org>
Tue, 8 Dec 2020 18:17:41 +0000 (19:17 +0100)
committerAndreas Schwab <schwab@linux-m68k.org>
Wed, 9 Dec 2020 14:32:29 +0000 (15:32 +0100)
The file contains comma-separated ranges, not spaces.

sysdeps/unix/sysv/linux/getsysstats.c

index 1ef077f..a9069b7 100644 (file)
@@ -143,6 +143,7 @@ __get_nprocs (void)
   char *re = buffer_end;
 
   const int flags = O_RDONLY | O_CLOEXEC;
+  /* This file contains comma-separated ranges.  */
   int fd = __open_nocancel ("/sys/devices/system/cpu/online", flags);
   char *l;
   int result = 0;
@@ -175,10 +176,10 @@ __get_nprocs (void)
            result += m - n + 1;
 
            l = endp;
-           while (l < re && isspace (*l))
+           if (l < re && *l == ',')
              ++l;
          }
-       while (l < re);
+       while (l < re && *l != '\n');
 
       __close_nocancel_nostatus (fd);