netstar pushed a commit to branch master.

http://git.enlightenment.org/apps/evisum.git/commit/?id=d82aa24eb47d19b38febac4b7548f43ba2ea3905

commit d82aa24eb47d19b38febac4b7548f43ba2ea3905
Author: Alastair Poole <m...@alastairpoole.com>
Date:   Thu Nov 11 19:27:38 2021 +0000

    next: up-to-date.
---
 src/bin/next/{filesystems.c => file_systems.c} |  58 ++++----
 src/bin/next/{filesystems.h => file_systems.h} |  18 +--
 src/bin/next/machine.c                         |   3 +
 src/bin/next/machine.h                         |  78 +++++++----
 src/bin/next/machine/cpu.x                     |  91 ++++---------
 src/bin/next/machine/sensors.x                 | 177 ++++++++++++++++---------
 src/bin/next/meson.build                       |   7 +-
 src/bin/next/process.c                         |  66 +++++----
 src/bin/next/process.h                         |   6 +-
 9 files changed, 275 insertions(+), 229 deletions(-)

diff --git a/src/bin/next/filesystems.c b/src/bin/next/file_systems.c
similarity index 59%
rename from src/bin/next/filesystems.c
rename to src/bin/next/file_systems.c
index 35b6499..0efc016 100644
--- a/src/bin/next/filesystems.c
+++ b/src/bin/next/file_systems.c
@@ -1,4 +1,4 @@
-#include "filesystems.h"
+#include "file_systems.h"
 
 #include <stdio.h>
 #include <limits.h>
@@ -29,7 +29,7 @@
 #endif
 
 Eina_List *
-file_system_info_all_get(void)
+file_systems_find(void)
 {
    Eina_List *list = NULL;
 # if defined(__linux__)
@@ -45,7 +45,7 @@ file_system_info_all_get(void)
      {
         mount = strchr(buf, ' ') + 1;
         if (!mount) continue;
-        dev = strndup(buf, mount - buf);
+        dev = strndup(buf, mount - buf - 1);
         cp = strchr(mount, ' ');
         if (!cp) continue;
         end = cp;
@@ -55,7 +55,7 @@ file_system_info_all_get(void)
         if (!end) continue;
         type_name = strndup(cp, end - cp);
 
-        if ((strstr(cp, "nodev")) || (statfs(mount, &stats) < 0) ||
+        if ((statfs(mount, &stats) < 0) ||
             (stats.f_blocks == 0 && stats.f_bfree == 0))
           {
              free(dev);
@@ -64,12 +64,16 @@ file_system_info_all_get(void)
           }
 
         File_System *fs = calloc(1, sizeof(File_System));
-        fs->mount = strdup(mount);
-        fs->path = dev;
-        fs->type_name = type_name;
-        fs->usage.total = stats.f_bsize * stats.f_blocks;
-        fs->usage.used  = fs->usage.total - (stats.f_bsize * stats.f_bfree);
-        list = eina_list_append(list, fs);
+        if (fs)
+          {
+             snprintf(fs->mount, sizeof(fs->mount), "%s", mount);
+             snprintf(fs->path, sizeof(fs->path), "%s", dev);
+             snprintf(fs->type_name, sizeof(fs->type_name), "%s", type_name);
+             fs->usage.total = stats.f_bsize * stats.f_blocks;
+             fs->usage.used  = fs->usage.total - (stats.f_bsize * 
stats.f_bfree);
+             free(dev); free(type_name);
+             list = eina_list_append(list, fs);
+          }
      }
    fclose(f);
 # else
@@ -80,32 +84,26 @@ file_system_info_all_get(void)
    for (i = 0; i < count; i++)
      {
         File_System *fs = calloc(1, sizeof(File_System));
-        fs->mount = strdup(mounts[i].f_mntonname);
-        fs->path  = strdup(mounts[i].f_mntfromname);
+        if (fs)
+          {
+             snprintf(fs->mount, sizeof(fs->mount), "%s", 
mounts[i].f_mntonname);
+             snprintf(fs->path, sizeof(fs->path), "%s", 
mounts[i].f_mntfromname);
 #if defined(__OpenBSD__)
 #else
-        fs->type  = mounts[i].f_type;
+             fs->type  = mounts[i].f_type;
 #endif
-        fs->type_name = strdup(mounts[i].f_fstypename);
-        fs->usage.total = mounts[i].f_bsize * mounts[i].f_blocks;
-        fs->usage.used  = fs->usage.total - (mounts[i].f_bsize * 
mounts[i].f_bfree);
+             snprintf(fs->type_name, sizeof(fs->type_name), "%s", 
mounts[i].f_fstypename);
+
+             fs->usage.total = mounts[i].f_bsize * mounts[i].f_blocks;
+             fs->usage.used  = fs->usage.total - (mounts[i].f_bsize * 
mounts[i].f_bfree);
 
-        list = eina_list_append(list, fs);
+             list = eina_list_append(list, fs);
+          }
      }
 # endif
    return list;
 }
 
-void
-file_system_info_free(File_System *fs)
-{
-   free(fs->mount);
-   free(fs->path);
-   if (fs->type_name)
-     free(fs->type_name);
-   free(fs);
-}
-
 Eina_Bool
 file_system_in_use(const char *name)
 {
@@ -115,13 +113,13 @@ file_system_in_use(const char *name)
 
    if (!name) return 0;
 
-   list = file_system_info_all_get();
+   list = file_systems_find();
    EINA_LIST_FREE(list, fs)
      {
-        if (fs->type_name && (!strcasecmp(fs->type_name, name)))
+        if ((fs->type_name[0]) && (!strcasecmp(fs->type_name, name)))
           mounted = 1;
 
-        file_system_info_free(fs);
+        free(fs);
      }
 
    return mounted;
diff --git a/src/bin/next/filesystems.h b/src/bin/next/file_systems.h
similarity index 53%
rename from src/bin/next/filesystems.h
rename to src/bin/next/file_systems.h
index 897c10b..93af33e 100644
--- a/src/bin/next/filesystems.h
+++ b/src/bin/next/file_systems.h
@@ -4,20 +4,22 @@
 #include <Eina.h>
 
 typedef struct {
-   unsigned long long total;
-   unsigned long long used;
+   uint64_t total;
+   uint64_t used;
 } _Usage;
 
 typedef struct _File_System {
-   char         *path;
-   char         *mount;
-   char         *type_name;
-   unsigned int  type;
-   _Usage        usage;
+   char         path[PATH_MAX];
+   char         mount[PATH_MAX];
+   char         type_name[64];
+   unsigned int type;
+   _Usage       usage;
+
+   int          unique_id;
 } File_System;
 
 Eina_List *
-file_system_info_all_get(void);
+file_systems_find(void);
 
 void
 file_system_info_free(File_System *fs);
diff --git a/src/bin/next/machine.c b/src/bin/next/machine.c
index a0de59c..285a67c 100644
--- a/src/bin/next/machine.c
+++ b/src/bin/next/machine.c
@@ -63,6 +63,9 @@
 # include <sys/resource.h>
 #endif
 
+#include <Ecore.h>
+#include <Ecore_File.h>
+
 #include "macros.h"
 #include "machine.h"
 #include "machine/machine.x"
diff --git a/src/bin/next/machine.h b/src/bin/next/machine.h
index d43166a..317803f 100644
--- a/src/bin/next/machine.h
+++ b/src/bin/next/machine.h
@@ -2,18 +2,22 @@
 #define MACHINE_H
 
 #include <Eina.h>
-#include <Ecore.h>
-#include <Ecore_File.h>
 #include <stdint.h>
 #include <stdbool.h>
 
+#define CPUFREQ_INVALID -1
+
 typedef struct
 {
+   char          name[16];
    unsigned long total;
    unsigned long idle;
-   float         percent;
-   int           id;
-   int           top_id;
+   int8_t        percent;
+   uint16_t      id;
+   uint16_t      top_id;
+   int           freq;
+   int           temp;
+   int           unique_id;
 } Cpu_Core;
 
 #define MEM_VIDEO_CARD_MAX 8
@@ -40,6 +44,8 @@ typedef struct
    Meminfo_Video   video[MEM_VIDEO_CARD_MAX];
 } Meminfo;
 
+#define THERMAL_INVALID -999
+
 typedef enum
 {
    THERMAL = 0,
@@ -48,10 +54,10 @@ typedef enum
 
 typedef struct
 {
-   char       *name;
-   char       *child_name;
+   char        name[255];
+   char        child_name[255];
 #if defined(__linux__)
-   char       *path;
+   char        path[PATH_MAX];
 #elif defined(__OpenBSD__)
    int         mibs[5];
 #endif
@@ -59,37 +65,43 @@ typedef struct
    bool        invalid;
    int         id;
    Sensor_Type type;
+   int         unique_id;
 } Sensor;
 
 typedef struct
 {
-   char   *name;
-   char   *vendor;
-   char   *model;
-   double  charge_full;
-   double  charge_current;
-   double  percent;
-   bool    present;
+   char      name[255];
+   char      vendor[64];
+   char      model[64];
+   uint32_t  charge_full;
+   uint32_t  charge_current;
+   float     percent;
+   bool      present;
 #if defined(__OpenBSD__)
-   int     mibs[5];
+   int       mibs[5];
 #elif defined(__FreeBSD__) || defined(__DragonFly__)
-   char    unit;
+   char      unit;
 #endif
+   int       unique_id;
 } Battery;
 
 typedef struct
 {
-   char     name[255];
-   uint64_t total_in;
-   uint64_t total_out;
+   char          name[255];
+   uint64_t      total_in;
+   uint64_t      total_out;
 
-   uint64_t peak_in;
-   uint64_t peak_out;
+   uint64_t      peak_in;
+   uint64_t      peak_out;
 
-   uint64_t in;
-   uint64_t out;
+   uint64_t      in;
+   uint64_t      out;
+
+   int           unique_id;
 } Network_Interface;
 
+// Power
+
 Eina_Bool
 power_ac_present(void);
 
@@ -97,26 +109,34 @@ Eina_List *
 batteries_find(void);
 
 void
-battery_free(Battery *bat);
+batteries_update(Eina_List *batteries);
 
 void
 battery_update(Battery *bat);
 
+// Sensors
+
 Eina_List *
 sensors_find(void);
 
 void
-memory_info(Meminfo *memory);
-
-void
-sensor_free(Sensor *sensor);
+sensors_update(Eina_List *sensors);
 
 Eina_Bool
 sensor_update(Sensor *sensor);
 
+// Network
+
 Eina_List *
 network_interfaces_find(void);
 
+// Memory
+
+void
+memory_info(Meminfo *memory);
+
+// CPU Cores
+
 Eina_List *
 cores_find(void);
 
diff --git a/src/bin/next/machine/cpu.x b/src/bin/next/machine/cpu.x
index a500722..8e67d8d 100644
--- a/src/bin/next/machine/cpu.x
+++ b/src/bin/next/machine/cpu.x
@@ -48,10 +48,7 @@ int
 cores_online_count(void)
 {
 #if defined(__OpenBSD__)
-   static int cores = 0;
-
-   if (cores != 0) return cores;
-
+   int cores = 0;
    size_t len;
    int mib[2] = { CTL_HW, HW_NCPUONLINE };
 
@@ -68,9 +65,7 @@ cores_online_count(void)
 void
 cores_update(Eina_List *cores)
 {
-   int diff_total, diff_idle;
-   double ratio, percent;
-   unsigned long total, idle, used;
+   unsigned long total, idle;
    Cpu_Core *core;
    int ncpu = eina_list_count(cores);
    if (!ncpu) return;
@@ -96,21 +91,10 @@ cores_update(Eina_List *cores)
 
         idle = cpu[CP_IDLE];
 
-        diff_total = total - core->total;
-        diff_idle = idle - core->idle;
-        if (diff_total == 0) diff_total = 1;
-
-        ratio = diff_total / 100.0;
-        used = diff_total - diff_idle;
-        percent = used / ratio;
-
-        if (percent > 100) percent = 100;
-        else if (percent < 0)
-          percent = 0;
-
-        core->percent = percent;
         core->total = total;
         core->idle = idle;
+        core->freq = core_id_frequency(core->id);
+        core->temp = core_id_temperature(core->id);
      }
 #elif defined(__OpenBSD__)
    static struct cpustats cpu_times[CPU_STATES];
@@ -134,21 +118,10 @@ cores_update(Eina_List *cores)
 
         idle = cpu_times[i].cs_time[CP_IDLE];
 
-        diff_total = total - core->total;
-        if (diff_total == 0) diff_total = 1;
-
-        diff_idle = idle - core->idle;
-        ratio = diff_total / 100.0;
-        used = diff_total - diff_idle;
-        percent = used / ratio;
-
-        if (percent > 100) percent = 100;
-        else if (percent < 0)
-          percent = 0;
-
-        core->percent = percent;
         core->total = total;
         core->idle = idle;
+        core->freq = core_id_frequency(core->id);
+        core->temp = core_id_temperature(core->id);
      }
 #elif defined(__linux__)
    char *buf, name[128];
@@ -173,21 +146,11 @@ cores_update(Eina_List *cores)
 
              total = cpu_times[0] + cpu_times[1] + cpu_times[2] + cpu_times[3];
              idle = cpu_times[3];
-             diff_total = total - core->total;
-             if (diff_total == 0) diff_total = 1;
-
-             diff_idle = idle - core->idle;
-             ratio = diff_total / 100.0;
-             used = diff_total - diff_idle;
-             percent = used / ratio;
 
-             if (percent > 100) percent = 100;
-             else if (percent < 0)
-               percent = 0;
-
-             core->percent = percent;
              core->total = total;
              core->idle = idle;
+             core->freq = core_id_frequency(core->id);
+             core->temp = core_id_temperature(core->id);
           }
      }
    free(buf);
@@ -216,18 +179,6 @@ cores_update(Eina_List *cores)
            load[i].cpu_ticks[CPU_STATE_NICE];
         idle = load[i].cpu_ticks[CPU_STATE_IDLE];
 
-        diff_total = total - core->total;
-        if (diff_total == 0) diff_total = 1;
-        diff_idle = idle - core->idle;
-        ratio = diff_total / 100.0;
-        used = diff_total - diff_idle;
-        percent = used / ratio;
-
-        if (percent > 100) percent = 100;
-        else if (percent < 0)
-          percent = 0;
-
-        core->percent = percent;
         core->total = total;
         core->idle = idle;
      }
@@ -246,6 +197,7 @@ cores_find(void)
      {
         core = calloc(1, sizeof(Cpu_Core));
         core->id = i;
+        snprintf(core->name, sizeof(core->name), "cpu%i", i);
         cores = eina_list_append(cores, core);
      }
    cores_topology(cores);
@@ -260,7 +212,7 @@ static char _hwmon_path[256];
 int
 _core_n_temperature_read(int n)
 {
-   int temp = -1;
+   int temp = THERMAL_INVALID;
 #if defined(__linux__)
 
    char *b = file_contents(_core_temps[n]);
@@ -357,7 +309,7 @@ core_id_temperature(int id)
         if (!dir)
           {
              init = 1;
-             return -1;
+             return THERMAL_INVALID;
           }
 
         while ((dh = readdir(dir)) != NULL)
@@ -389,7 +341,7 @@ core_id_temperature(int id)
         init = 1;
      }
 
-   if (!_hwmon_path[0]) return -1;
+   if (!_hwmon_path[0]) return THERMAL_INVALID;
 
    return _core_n_temperature_read(id);
 #elif defined(__FreeBSD__) || defined(__DragonFly__)
@@ -403,7 +355,7 @@ core_id_temperature(int id)
 
     return _core_n_temperature_read(id);
 #endif
-   return -1;
+   return THERMAL_INVALID;
 }
 
 int
@@ -420,7 +372,7 @@ int
 core_id_frequency(int id)
 {
 #if defined(__linux__)
-   int freq = -1;
+   int freq = CPUFREQ_INVALID;
    FILE *f;
    char buf[4096];
    int tmp;
@@ -436,7 +388,7 @@ core_id_frequency(int id)
                freq = tmp;
           }
         fclose(f);
-        if (freq != -1) return freq;
+        if (freq != CPUFREQ_INVALID) return freq;
      }
 
    return freq;
@@ -444,7 +396,7 @@ core_id_frequency(int id)
    return cores_frequency();
 #endif
 
-   return -1;
+   return CPUFREQ_INVALID;
 }
 
 int
@@ -534,7 +486,7 @@ cores_frequency_min_max(int *min, int *max)
 int
 cores_frequency(void)
 {
-   int freq = -1;
+   int freq = CPUFREQ_INVALID;
 
 #if defined(__FreeBSD__) || defined(__DragonFly__)
    size_t len = sizeof(freq);
@@ -560,7 +512,7 @@ cores_frequency(void)
                freq = tmp;
           }
         fclose(f);
-        if (freq != -1) return freq;
+        if (freq != CPUFREQ_INVALID) return freq;
      }
 
    f = fopen("/proc/cpuinfo", "r");
@@ -635,5 +587,12 @@ cores_topology(Eina_List *cores)
         core->top_id = cores_top[i].id;
      }
    free(cores_top);
+#else
+   Cpu_Core *core;
+   Eina_List *l;
+
+   EINA_LIST_FOREACH(cores, l, core)
+     core->top_id = core->id;
 #endif
+
 }
diff --git a/src/bin/next/machine/sensors.x b/src/bin/next/machine/sensors.x
index b142d1a..7d0d2d7 100644
--- a/src/bin/next/machine/sensors.x
+++ b/src/bin/next/machine/sensors.x
@@ -1,17 +1,3 @@
-void
-sensor_free(Sensor *sensor)
-{
-   if (sensor->name)
-     free(sensor->name);
-   if (sensor->child_name)
-     free(sensor->child_name);
-#if defined(__linux__)
-   if (sensor->path)
-     free(sensor->path);
-#endif
-   free(sensor);
-}
-
 Eina_Bool
 sensor_update(Sensor *sensor)
 {
@@ -70,7 +56,6 @@ sensors_find(void)
    struct sensordev snsrdev;
    size_t slen = sizeof(struct sensor);
    size_t sdlen = sizeof(struct sensordev);
-   char buf[32];
    enum sensor_type type;
 
    for (devn = 0;; devn++)
@@ -99,13 +84,17 @@ sensors_find(void)
                   sensor = calloc(1, sizeof(Sensor));
                   if (sensor)
                     {
-                       sensor->name = strdup(snsrdev.xname);
-                       snprintf(buf, sizeof(buf), "%i", n);
-                       sensor->child_name = strdup(buf);
+                       strlcpy(sensor->name, snsrdev.xname, 
sizeof(sensor->name));
                        if (snsr.type == SENSOR_TEMP)
-                         sensor->type = THERMAL;
+                         {
+                            snprintf(sensor->child_name, 
sizeof(sensor->child_name), "temp%i", n);
+                            sensor->type = THERMAL;
+                         }
                        else if (snsr.type == SENSOR_FANRPM)
-                         sensor->type = FANRPM;
+                         {
+                            snprintf(sensor->child_name, 
sizeof(sensor->child_name), "fan%i", n);
+                            sensor->type = FANRPM;
+                         }
                        memcpy(sensor->mibs, &mibs, sizeof(mibs));
 
                        sensors = eina_list_append(sensors, sensor);
@@ -124,7 +113,8 @@ sensors_find(void)
         sensor = calloc(1, sizeof(Sensor));
         if (sensor)
           {
-             sensor->name = strdup("hw.acpi.thermal.tz0.temperature");
+             strlcpy(sensor->name, "hw.acpi.thermal.tz0.temperature", 
sizeof(sensor->name));
+             strlcpy(sensor->child_name, "0", sizeof(sensor->child_name));
              sensor->value = (float) (value -  2732) / 10;
              sensors = eina_list_append(sensors, sensor);
           }
@@ -141,7 +131,8 @@ sensors_find(void)
              sensor = calloc(1, sizeof(Sensor));
              if (sensor)
                {
-                  sensor->name = strdup(buf);
+                  strlcpy(sensor->name, buf, sizeof(sensor->name));
+                  snprintf(sensor->child_name, sizeof(sensor->child_name), 
"%i", i);
                   sensor->value = (float) (value - 2732) / 10;
                   sensors = eina_list_append(sensors, sensor);
                }
@@ -198,18 +189,29 @@ sensors_find(void)
                        sensor = calloc(1, sizeof(Sensor));
                        if (sensor)
                          {
+                            char *d;
                             sensor->type = FANRPM;
-                            sensor->path = strdup(buf);
+                            eina_strlcpy(sensor->path, buf, 
sizeof(sensor->path));
                             snprintf(buf, sizeof(buf), "%s/name", link);
-                            sensor->name = file_contents(buf);
+                            d = file_contents(buf);
+                            if (d)
+                              {
+                                 eina_strlcpy(sensor->name, d, 
sizeof(sensor->name));
+                                 free(d);
+                              }
                             snprintf(buf, sizeof(buf), "%s/fan%i_label", link, 
id);
                             if (ecore_file_exists(buf))
-                              sensor->child_name = file_contents(buf);
-                            else
                               {
-                                 snprintf(buf, sizeof(buf), "fan%i", id);
-                                 sensor->child_name = strdup(buf);
+                                 d = file_contents(buf);
+                                 if (d)
+                                   {
+                                      eina_strlcpy(sensor->child_name, d, 
sizeof(sensor->child_name));
+                                      free(d);
+                                   }
                               }
+                            else
+                              snprintf(sensor->child_name, 
sizeof(sensor->child_name), "fan%i", id);
+
                             sensors = eina_list_append(sensors, sensor);
                          }
                     }
@@ -220,19 +222,28 @@ sensors_find(void)
                        sensor = calloc(1, sizeof(Sensor));
                        if (sensor)
                          {
+                            char *d;
                             sensor->type = THERMAL;
-                            sensor->path = strdup(buf);
+                            eina_strlcpy(sensor->path, buf, 
sizeof(sensor->path));
                             snprintf(buf, sizeof(buf), "%s/name", link);
-                            sensor->name = file_contents(buf);
-
+                            d = file_contents(buf);
+                            if (d)
+                              {
+                                 eina_strlcpy(sensor->name, d, 
sizeof(sensor->name));
+                                 free(d);
+                              }
                             snprintf(buf, sizeof(buf), "%s/temp%i_label", 
link, id);
                             if (ecore_file_exists(buf))
-                              sensor->child_name = file_contents(buf);
-                            else
                               {
-                                 snprintf(buf, sizeof(buf), "%i", id);
-                                 sensor->child_name = strdup(buf);
+                                 d = file_contents(buf);
+                                 if (d)
+                                   {
+                                      eina_strlcpy(sensor->child_name, d, 
sizeof(sensor->child_name));
+                                      free(d);
+                                   }
                               }
+                             else
+                               snprintf(sensor->child_name, 
sizeof(sensor->child_name), "temp%i", id);
 
                              sensors = eina_list_append(sensors, sensor);
                           }
@@ -253,6 +264,16 @@ sensors_find(void)
    return sensors;
 }
 
+void
+sensors_update(Eina_List *sensors)
+{
+   Eina_List *l;
+   Sensor *sensor;
+
+   EINA_LIST_FOREACH(sensors, l, sensor)
+     sensor_update(sensor);
+}
+
 Eina_List *
 batteries_find(void)
 {
@@ -276,9 +297,9 @@ batteries_find(void)
              Battery *bat = calloc(1, sizeof(Battery));
              if (bat)
                {
-                  bat->name = strdup(snsrdev.xname);
-                  bat->model = strdup("Unknown");
-                  bat->vendor = strdup("Unknown");
+                  strlcpy(bat->name, snsrdev.xname, sizeof(bat->name));
+                  strlcpy(bat->model, "Unknown", sizeof(bat->model));
+                  strlcpy(bat->vendor, "Unknown", sizeof(bat->vendor));
                   bat->mibs[0] = mibs[0];
                   bat->mibs[1] = mibs[1];
                   bat->mibs[2] = mibs[2];
@@ -305,12 +326,13 @@ batteries_find(void)
              Battery *bat = calloc(1, sizeof(Battery));
              if (bat)
                {
+                  snprintf(bat->name, sizeof(bat->name), "bat%i", i);
                   if (battio.bst.state == ACPI_BATT_STAT_NOT_PRESENT)
                     bat->present = 0;
                   else
                     bat->present = 1;
-                  bat->vendor = strdup(battio.bix.oeminfo);
-                  bat->model = strdup(battio.bix.model);
+                  strlcpy(bat->vendor, battio.bix.oeminfo, 
sizeof(bat->vendor));
+                  strlcpy(bat->model, battio.bix.model, sizeof(bat->model));
                   bat->unit = i;
                   list = eina_list_append(list, bat);
                }
@@ -320,7 +342,6 @@ batteries_find(void)
 #elif defined(__linux__)
    char *type;
    struct dirent **names;
-   char *buf;
    char path[PATH_MAX];
    int i, n;
 
@@ -337,18 +358,29 @@ batteries_find(void)
                   Battery *bat = calloc(1, sizeof(Battery));
                   if (bat)
                     {
-                       bat->name = strdup(names[i]->d_name);
+                       char *d;
+                       eina_strlcpy(bat->name, names[i]->d_name, 
sizeof(bat->name));
                        snprintf(path, sizeof(path), 
"/sys/class/power_supply/%s/manufacturer", names[i]->d_name);
-                       bat->vendor = file_contents(path);
+                       d = file_contents(path);
+                       if (d)
+                         {
+                            eina_strlcpy(bat->vendor, d, sizeof(bat->vendor));
+                            free(d);
+                         }
                        snprintf(path, sizeof(path), 
"/sys/class/power_supply/%s/model_name", names[i]->d_name);
-                       bat->model = file_contents(path);
+                       d = file_contents(path);
+                       if (d)
+                         {
+                            eina_strlcpy(bat->model, d, sizeof(bat->model));
+                            free(d);
+                         }
                        snprintf(path, sizeof(path), 
"/sys/class/power_supply/%s/present", names[i]->d_name);
                        bat->present = 1;
-                       buf = file_contents(path);
-                       if (buf)
+                       d = file_contents(path);
+                       if (d)
                          {
-                            bat->present = atoi(buf);
-                            free(buf);
+                            bat->present = atoi(d);
+                            free(d);
                          }
                        list = eina_list_append(list, bat);
                     }
@@ -363,18 +395,6 @@ batteries_find(void)
    return list;
 }
 
-void
-battery_free(Battery *bat)
-{
-   if (bat->name)
-     free(bat->name);
-   if (bat->model)
-     free(bat->model);
-   if (bat->vendor)
-     free(bat->vendor);
-   free(bat);
-}
-
 void
 battery_update(Battery *bat)
 {
@@ -560,14 +580,43 @@ power_ac_present(void)
         close(fd);
      }
 #elif defined(__linux__)
-   char *buf = file_contents("/sys/class/power_supply/AC/online");
-   if (buf)
+   static const char *found = NULL;
+   static const char *known[] = {
+      "/sys/class/power_supply/AC/online",
+      "/sys/class/power_supply/ACAD/online",
+      "/sys/class/power_supply/ADP0/online",
+   };
+
+   for (int i = 0; (!found) && (i < sizeof(known) / sizeof(char *)); i++)
      {
-        have_ac = atoi(buf);
-        free(buf);
+        if (ecore_file_exists(known[i]))
+          {
+             found = known[i];
+             break;
+          }
+     }
+
+   if (found)
+     {
+        char *buf = file_contents(found);
+        if (buf)
+          {
+             have_ac = atoi(buf);
+             free(buf);
+          }
      }
 #endif
 
    return have_ac;
 }
 
+void
+batteries_update(Eina_List *batteries)
+{
+   Eina_List *l;
+   Battery *bat;
+
+   EINA_LIST_FOREACH(batteries, l, bat)
+      battery_update(bat);
+}
+
diff --git a/src/bin/next/meson.build b/src/bin/next/meson.build
index c0db5f0..72f58e2 100644
--- a/src/bin/next/meson.build
+++ b/src/bin/next/meson.build
@@ -1,8 +1,9 @@
-src_watch += files([
+src_next = files([
    'machine.c',
    'machine.h',
+   'file_systems.c',
+   'file_systems.h',
    'process.c',
    'process.h',
-   'filesystems.c',
-   'filesystems.h',
 ])
+
diff --git a/src/bin/next/process.c b/src/bin/next/process.c
index 4d0ec14..69ed426 100644
--- a/src/bin/next/process.c
+++ b/src/bin/next/process.c
@@ -2,7 +2,7 @@
 # define __MacOS__
 #endif
 
-#include "ui/gettext.h"
+#include "intl/gettext.h"
 #define _(STR) gettext(STR)
 
 #if defined(__MacOS__) || defined(__FreeBSD__) || defined(__DragonFly__) || 
defined(__OpenBSD__)
@@ -53,7 +53,7 @@
 
 #include "macros.h"
 
-static Eina_Bool _show_kthreads = 1;
+static Eina_Bool _show_kthreads = 0;
 
 void
 proc_info_kthreads_show_set(Eina_Bool enabled)
@@ -98,8 +98,10 @@ _states_init(void)
 #endif
 #endif
 }
-
-static const char *
+#ifndef __OpenBSD__
+static
+#endif
+const char *
 _process_state_name(char state)
 {
    static int init = 0;
@@ -159,37 +161,47 @@ _mem_size(Proc_Info *proc)
 static void
 _cmd_args(Proc_Info *p, char *name, size_t len)
 {
-   char buf[8192];
+   char path[PATH_MAX];
+   char line[4096];
    int pid = p->pid;
 
-   snprintf(buf, sizeof(buf), "/proc/%d/exe", pid);
-   char *link = ecore_file_readlink(buf);
+   snprintf(path, sizeof(path), "/proc/%d/exe", pid);
+   char *link = ecore_file_readlink(path);
    if (link)
      {
         snprintf(name, len, "%s", ecore_file_file_get(link));
         free(link);
      }
 
-   snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
-   FILE *f = fopen(buf, "r");
+   snprintf(path, sizeof(path), "/proc/%d/cmdline", pid);
+   FILE *f = fopen(path, "r");
    if (f)
      {
-        if (fgets(buf, sizeof(buf), f))
+        if (fgets(line, sizeof(line), f))
           {
-             Eina_Strbuf *b = eina_strbuf_new();
-             const char *n;
+             int sz = ftell(f);
+             Eina_Strbuf *buf = eina_strbuf_new();
 
-             if (ecore_file_exists(buf))
-               snprintf(name, len, "%s", ecore_file_file_get(buf));
+             if (ecore_file_exists(line))
+               snprintf(name, len, "%s", ecore_file_file_get(line));
 
-             n = buf;
-             while (n && *n && (*n + 1))
+             const char *cp = line;
+             for (int i = 0; i < sz; i++)
                {
-                  eina_strbuf_append(b, n);
-                  n = strchr(n, '\0') + 1;
-                  if (n && *n && (*n + 1)) eina_strbuf_append(b, " ");
+                  if (line[i] == '\0')
+                    {
+                       if (*cp)
+                         eina_strbuf_append(buf, cp);
+                       if ((i + 1) < sz)
+                         {
+                            i++;
+                            cp = &line[i];
+                            if (*cp)
+                              eina_strbuf_append(buf, " ");
+                         }
+                    }
                }
-             p->arguments = eina_strbuf_release(b);
+             p->arguments = eina_strbuf_release(buf);
           }
         fclose(f);
      }
@@ -360,7 +372,7 @@ _process_list_linux_get(void)
         p->ppid = st.ppid;
         p->uid = _uid(pid);
         p->cpu_id = st.psr;
-        p->start = st.start_time;
+        p->start_time = st.start_time;
         p->run_time = st.run_time;
         state = _process_state_name(st.state);
         snprintf(p->state, sizeof(p->state), "%s", state);
@@ -436,7 +448,7 @@ proc_info_by_pid(int pid)
    p->ppid = st.ppid;
    p->uid = _uid(pid);
    p->cpu_id = st.psr;
-   p->start = st.start_time;
+   p->start_time = st.start_time;
    p->run_time = st.run_time;
    state = _process_state_name(st.state);
    snprintf(p->state, sizeof(p->state), "%s", state);
@@ -470,7 +482,7 @@ _proc_get(Proc_Info *p, struct kinfo_proc *kp)
    p->ppid = kp->p_ppid;
    p->uid = kp->p_uid;
    p->cpu_id = kp->p_cpuid;
-   p->start = kp->p_ustart_sec;
+   p->start_time = kp->p_ustart_sec;
    p->run_time = kp->p_uutime_sec + kp->p_ustime_sec +
                  (kp->p_uutime_usec / 1000000) + (kp->p_ustime_usec / 1000000);
 
@@ -751,7 +763,7 @@ _proc_pidinfo(size_t pid)
    p->cpu_time = taskinfo.ptinfo.pti_total_user +
       taskinfo.ptinfo.pti_total_system;
    p->cpu_time /= 10000000;
-   p->start = taskinfo.pbsd.pbi_start_tvsec;
+   p->start_time = taskinfo.pbsd.pbi_start_tvsec;
    state = _process_state_name(taskinfo.pbsd.pbi_status);
    snprintf(p->state, sizeof(p->state), "%s", state);
    p->mem_size = p->mem_virt = taskinfo.ptinfo.pti_virtual_size;
@@ -840,7 +852,7 @@ proc_info_by_pid(int pid)
    p->cpu_time = taskinfo.ptinfo.pti_total_user +
       taskinfo.ptinfo.pti_total_system;
    p->cpu_time /= 10000000;
-   p->start = taskinfo.pbsd.pbi_start_tvsec;
+   p->start_time = taskinfo.pbsd.pbi_start_tvsec;
    state = _process_state_name(taskinfo.pbsd.pbi_status);
    snprintf(p->state, sizeof(p->state), "%s", state);
    p->mem_size = p->mem_virt = taskinfo.ptinfo.pti_virtual_size;
@@ -985,7 +997,7 @@ _proc_thread_info(struct kinfo_proc *kp, Eina_Bool 
is_thread)
    snprintf(p->wchan, sizeof(p->wchan), "%s", kp->ki_wmesg);
    p->mem_virt = kp->ki_size;
    p->mem_rss = MEMSIZE(kp->ki_rssize) * MEMSIZE(pagesize);
-   p->start = kp->ki_start.tv_sec;
+   p->start_time = kp->ki_start.tv_sec;
    p->mem_size = p->mem_virt;
    p->nice = kp->ki_nice - NZERO;
    p->priority = kp->ki_pri.pri_level - PZERO;
@@ -1494,6 +1506,6 @@ proc_sort_by_age(const void *p1, const void *p2)
 {
    const Proc_Info *c1 = p1, *c2 = p2;
 
-   return c1->start - c2->start;
+   return c1->start_time - c2->start_time;
 }
 
diff --git a/src/bin/next/process.h b/src/bin/next/process.h
index 9f3f795..ccc8d37 100644
--- a/src/bin/next/process.h
+++ b/src/bin/next/process.h
@@ -21,7 +21,7 @@ typedef struct _Proc_Info
    int64_t     cpu_time;
    double      cpu_usage;
    int64_t     run_time;
-   int64_t     start;
+   int64_t     start_time;
 
    uint64_t    mem_size;
    uint64_t    mem_virt;
@@ -36,7 +36,9 @@ typedef struct _Proc_Info
    Eina_List   *fds;
    int         numfiles;
 
-   short       is_kernel;
+   Eina_Bool   was_zero;
+   Eina_Bool   is_kernel;
+   Eina_Bool   is_new;
    int         tid;
    char       *thread_name;
 

-- 


Reply via email to