Skip to content
This repository was archived by the owner on Jun 2, 2023. It is now read-only.
This repository was archived by the owner on Jun 2, 2023. It is now read-only.

It is not possible to read /proc/loadavg on Archlinux using gcc 10.1.0 and Qt 5.15.0 #7

@JunioCalu

Description

@JunioCalu

patch:

diff --git a/utils/system_stat.cpp b/utils/system_stat.cpp
index 90395fb..00c0d24 100644
--- a/utils/system_stat.cpp
+++ b/utils/system_stat.cpp
@@ -52,25 +52,27 @@ auto print_err = [](decltype(errno) e, const QString &msg)
 bool SystemStat::readLoadAvg(qreal &loadAvg1, qreal &loadAvg5, qreal &loadAvg15) {
     bool b = false;
     FILE *fp;
-    char buf[128];
-    int rc;
-    double avg1, avg5, avg15;
-
+    char buf[256];
+    double load[3];
+    int i;
     errno = 0;
-    if ((fp = fopen(PROC_PATH_LOADAVG, "r")) == nullptr) {
-        print_err(errno, QString("open %1 failed").arg(PROC_PATH_LOADAVG));
-        return b;
-    }
 
-    if (fgets(buf, sizeof(buf), fp)) {
-        rc = sscanf(buf, "%lf %lf %lf", &avg1, &avg5, &avg15);
-        if (rc == 3) {
-            loadAvg1 = avg1;
-            loadAvg5 = avg5;
-            loadAvg15 = avg15;
+    if ((fp = fopen(PROC_PATH_LOADAVG, "r")) != nullptr) {
+    	if((fgets(buf, sizeof(buf), fp)) != nullptr) {
+    		load[0] = strtod(strtok(buf, " \n"), NULL);
+    		for(i=1;i<3;i++){
+            	load[i] = strtod(strtok(NULL, " \n"), NULL);
+    		}
+    		loadAvg1 = load[0];
+    		loadAvg5 = load[1];
+    		loadAvg15 = load[2];
             b = true;
         }
-    }
+        else {
+        	print_err(errno, QString("open %1 failed").arg(PROC_PATH_LOADAVG));
+        	return b;
+    	}
+  	}
     fclose(fp);
     if (!b) {
         print_err(errno, QString("read %1 failed").arg(PROC_PATH_LOADAVG));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions