]> granicus.if.org Git - procps-ng/commitdiff
library: Cygwin only has 4 cpu numbers
authorCraig Small <csmall@dropbear.xyz>
Thu, 26 May 2022 07:53:43 +0000 (17:53 +1000)
committerCraig Small <csmall@dropbear.xyz>
Thu, 26 May 2022 07:53:43 +0000 (17:53 +1000)
Old library never checked how many matches there were meaning that
both 8-number and 4-number cpu lines would work.

proc/stat.c

index 147a4224416df10143d62bcac099783c6fb80cdb..ac0c2156d4690eae9cf88aa8a0baf98fdde697fd 100644 (file)
@@ -601,7 +601,11 @@ static int stat_read_failed (
     sum_ptr->numa_node = STAT_NODE_INVALID;     // mark as invalid
 
     // now value the cpu summary tics from line #1
+#ifdef __CYGWIN__
+    if (4 > sscanf(bp, "cpu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu"
+#else
     if (8 > sscanf(bp, "cpu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu"
+#endif
         , &sum_ptr->new.user,  &sum_ptr->new.nice,   &sum_ptr->new.system
         , &sum_ptr->new.idle,  &sum_ptr->new.iowait, &sum_ptr->new.irq
         , &sum_ptr->new.sirq,  &sum_ptr->new.stolen
@@ -630,7 +634,11 @@ reap_em_again:
         cpu_ptr->numa_node = STAT_NODE_INVALID;
         cpu_ptr->count = 1;
 
+#ifdef __CYGWIN__
+        if (4 > (rc = sscanf(bp, "cpu%d %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu"
+#else
         if (8 > (rc = sscanf(bp, "cpu%d %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu"
+#endif
             , &cpu_ptr->id
             , &cpu_ptr->new.user,  &cpu_ptr->new.nice,   &cpu_ptr->new.system
             , &cpu_ptr->new.idle,  &cpu_ptr->new.iowait, &cpu_ptr->new.irq