On the first call to the cpu_freq|cpu_iowait user may see an initial n/a result
because NULL is returned but the value has been parsed correctly.

Example:

[CPU n/a%] [RAM 52%] [ 2018-04-16 15:55:19 ]
[CPU  16%] [RAM 52%] [ 2018-04-16 15:55:20 ]
[CPU   2%] [RAM 52%] [ 2018-04-16 15:55:21 ]
---
 components/cpu.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/components/cpu.c b/components/cpu.c
index a001d14..646cdad 100644
--- a/components/cpu.c
+++ b/components/cpu.c
@@ -28,10 +28,8 @@ cpu_perc(void)
                   &a[3], &a[4], &a[5], &a[6]) != 7) {
                return NULL;
        }
-       if (!valid) {
+       if (!valid)
                valid = 1;
-               return NULL;
-       }
 
        perc = 100 * ((b[0]+b[1]+b[2]+b[5]+b[6]) - (a[0]+a[1]+a[2]+a[5]+a[6])) /
               ((b[0]+b[1]+b[2]+b[3]+b[4]+b[5]+b[6]) - 
(a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+a[6]));
@@ -52,10 +50,8 @@ cpu_iowait(void)
                   &a[3], &a[4], &a[5], &a[6]) != 7) {
                return NULL;
        }
-       if (!valid) {
+       if (!valid)
                valid = 1;
-               return NULL;
-       }
 
        perc = 100 * ((b[4]) - (a[4])) /
               ((b[0]+b[1]+b[2]+b[3]+b[4]+b[5]+b[6]) - 
(a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+a[6]));
-- 
2.14.3


Reply via email to