summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlastair Poole <mail@alastairpoole.com>2021-11-11 19:27:38 +0000
committerAlastair Poole <mail@alastairpoole.com>2021-11-11 19:27:38 +0000
commitd82aa24eb47d19b38febac4b7548f43ba2ea3905 (patch)
tree23b668841bdfc4998ae0d33e38fd1dfcab21d8a2
parent7a2d1f0e48574ebf5c96fa813504a7773db5c206 (diff)
next: up-to-date.
-rw-r--r--src/bin/next/file_systems.c (renamed from src/bin/next/filesystems.c)58
-rw-r--r--src/bin/next/file_systems.h (renamed from src/bin/next/filesystems.h)18
-rw-r--r--src/bin/next/machine.c3
-rw-r--r--src/bin/next/machine.h78
-rw-r--r--src/bin/next/machine/cpu.x91
-rw-r--r--src/bin/next/machine/sensors.x177
-rw-r--r--src/bin/next/meson.build7
-rw-r--r--src/bin/next/process.c66
-rw-r--r--src/bin/next/process.h6
9 files changed, 275 insertions, 229 deletions
diff --git a/src/bin/next/filesystems.c b/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 @@
1#include "filesystems.h" 1#include "file_systems.h"
2 2
3#include <stdio.h> 3#include <stdio.h>
4#include <limits.h> 4#include <limits.h>
@@ -29,7 +29,7 @@
29#endif 29#endif
30 30
31Eina_List * 31Eina_List *
32file_system_info_all_get(void) 32file_systems_find(void)
33{ 33{
34 Eina_List *list = NULL; 34 Eina_List *list = NULL;
35# if defined(__linux__) 35# if defined(__linux__)
@@ -45,7 +45,7 @@ file_system_info_all_get(void)
45 { 45 {
46 mount = strchr(buf, ' ') + 1; 46 mount = strchr(buf, ' ') + 1;
47 if (!mount) continue; 47 if (!mount) continue;
48 dev = strndup(buf, mount - buf); 48 dev = strndup(buf, mount - buf - 1);
49 cp = strchr(mount, ' '); 49 cp = strchr(mount, ' ');
50 if (!cp) continue; 50 if (!cp) continue;
51 end = cp; 51 end = cp;
@@ -55,7 +55,7 @@ file_system_info_all_get(void)
55 if (!end) continue; 55 if (!end) continue;
56 type_name = strndup(cp, end - cp); 56 type_name = strndup(cp, end - cp);
57 57
58 if ((strstr(cp, "nodev")) || (statfs(mount, &stats) < 0) || 58 if ((statfs(mount, &stats) < 0) ||
59 (stats.f_blocks == 0 && stats.f_bfree == 0)) 59 (stats.f_blocks == 0 && stats.f_bfree == 0))
60 { 60 {
61 free(dev); 61 free(dev);
@@ -64,12 +64,16 @@ file_system_info_all_get(void)
64 } 64 }
65 65
66 File_System *fs = calloc(1, sizeof(File_System)); 66 File_System *fs = calloc(1, sizeof(File_System));
67 fs->mount = strdup(mount); 67 if (fs)
68 fs->path = dev; 68 {
69 fs->type_name = type_name; 69 snprintf(fs->mount, sizeof(fs->mount), "%s", mount);
70 fs->usage.total = stats.f_bsize * stats.f_blocks; 70 snprintf(fs->path, sizeof(fs->path), "%s", dev);
71 fs->usage.used = fs->usage.total - (stats.f_bsize * stats.f_bfree); 71 snprintf(fs->type_name, sizeof(fs->type_name), "%s", type_name);
72 list = eina_list_append(list, fs); 72 fs->usage.total = stats.f_bsize * stats.f_blocks;
73 fs->usage.used = fs->usage.total - (stats.f_bsize * stats.f_bfree);
74 free(dev); free(type_name);
75 list = eina_list_append(list, fs);
76 }
73 } 77 }
74 fclose(f); 78 fclose(f);
75# else 79# else
@@ -80,32 +84,26 @@ file_system_info_all_get(void)
80 for (i = 0; i < count; i++) 84 for (i = 0; i < count; i++)
81 { 85 {
82 File_System *fs = calloc(1, sizeof(File_System)); 86 File_System *fs = calloc(1, sizeof(File_System));
83 fs->mount = strdup(mounts[i].f_mntonname); 87 if (fs)
84 fs->path = strdup(mounts[i].f_mntfromname); 88 {
89 snprintf(fs->mount, sizeof(fs->mount), "%s", mounts[i].f_mntonname);
90 snprintf(fs->path, sizeof(fs->path), "%s", mounts[i].f_mntfromname);
85#if defined(__OpenBSD__) 91#if defined(__OpenBSD__)
86#else 92#else
87 fs->type = mounts[i].f_type; 93 fs->type = mounts[i].f_type;
88#endif 94#endif
89 fs->type_name = strdup(mounts[i].f_fstypename); 95 snprintf(fs->type_name, sizeof(fs->type_name), "%s", mounts[i].f_fstypename);
90 fs->usage.total = mounts[i].f_bsize * mounts[i].f_blocks; 96
91 fs->usage.used = fs->usage.total - (mounts[i].f_bsize * mounts[i].f_bfree); 97 fs->usage.total = mounts[i].f_bsize * mounts[i].f_blocks;
98 fs->usage.used = fs->usage.total - (mounts[i].f_bsize * mounts[i].f_bfree);
92 99
93 list = eina_list_append(list, fs); 100 list = eina_list_append(list, fs);
101 }
94 } 102 }
95# endif 103# endif
96 return list; 104 return list;
97} 105}
98 106
99void
100file_system_info_free(File_System *fs)
101{
102 free(fs->mount);
103 free(fs->path);
104 if (fs->type_name)
105 free(fs->type_name);
106 free(fs);
107}
108
109Eina_Bool 107Eina_Bool
110file_system_in_use(const char *name) 108file_system_in_use(const char *name)
111{ 109{
@@ -115,13 +113,13 @@ file_system_in_use(const char *name)
115 113
116 if (!name) return 0; 114 if (!name) return 0;
117 115
118 list = file_system_info_all_get(); 116 list = file_systems_find();
119 EINA_LIST_FREE(list, fs) 117 EINA_LIST_FREE(list, fs)
120 { 118 {
121 if (fs->type_name && (!strcasecmp(fs->type_name, name))) 119 if ((fs->type_name[0]) && (!strcasecmp(fs->type_name, name)))
122 mounted = 1; 120 mounted = 1;
123 121
124 file_system_info_free(fs); 122 free(fs);
125 } 123 }
126 124
127 return mounted; 125 return mounted;
diff --git a/src/bin/next/filesystems.h b/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 @@
4#include <Eina.h> 4#include <Eina.h>
5 5
6typedef struct { 6typedef struct {
7 unsigned long long total; 7 uint64_t total;
8 unsigned long long used; 8 uint64_t used;
9} _Usage; 9} _Usage;
10 10
11typedef struct _File_System { 11typedef struct _File_System {
12 char *path; 12 char path[PATH_MAX];
13 char *mount; 13 char mount[PATH_MAX];
14 char *type_name; 14 char type_name[64];
15 unsigned int type; 15 unsigned int type;
16 _Usage usage; 16 _Usage usage;
17
18 int unique_id;
17} File_System; 19} File_System;
18 20
19Eina_List * 21Eina_List *
20file_system_info_all_get(void); 22file_systems_find(void);
21 23
22void 24void
23file_system_info_free(File_System *fs); 25file_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 @@
63# include <sys/resource.h> 63# include <sys/resource.h>
64#endif 64#endif
65 65
66#include <Ecore.h>
67#include <Ecore_File.h>
68
66#include "macros.h" 69#include "macros.h"
67#include "machine.h" 70#include "machine.h"
68#include "machine/machine.x" 71#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 @@
2#define MACHINE_H 2#define MACHINE_H
3 3
4#include <Eina.h> 4#include <Eina.h>
5#include <Ecore.h>
6#include <Ecore_File.h>
7#include <stdint.h> 5#include <stdint.h>
8#include <stdbool.h> 6#include <stdbool.h>
9 7
8#define CPUFREQ_INVALID -1
9
10typedef struct 10typedef struct
11{ 11{
12 char name[16];
12 unsigned long total; 13 unsigned long total;
13 unsigned long idle; 14 unsigned long idle;
14 float percent; 15 int8_t percent;
15 int id; 16 uint16_t id;
16 int top_id; 17 uint16_t top_id;
18 int freq;
19 int temp;
20 int unique_id;
17} Cpu_Core; 21} Cpu_Core;
18 22
19#define MEM_VIDEO_CARD_MAX 8 23#define MEM_VIDEO_CARD_MAX 8
@@ -40,6 +44,8 @@ typedef struct
40 Meminfo_Video video[MEM_VIDEO_CARD_MAX]; 44 Meminfo_Video video[MEM_VIDEO_CARD_MAX];
41} Meminfo; 45} Meminfo;
42 46
47#define THERMAL_INVALID -999
48
43typedef enum 49typedef enum
44{ 50{
45 THERMAL = 0, 51 THERMAL = 0,
@@ -48,10 +54,10 @@ typedef enum
48 54
49typedef struct 55typedef struct
50{ 56{
51 char *name; 57 char name[255];
52 char *child_name; 58 char child_name[255];
53#if defined(__linux__) 59#if defined(__linux__)
54 char *path; 60 char path[PATH_MAX];
55#elif defined(__OpenBSD__) 61#elif defined(__OpenBSD__)
56 int mibs[5]; 62 int mibs[5];
57#endif 63#endif
@@ -59,37 +65,43 @@ typedef struct
59 bool invalid; 65 bool invalid;
60 int id; 66 int id;
61 Sensor_Type type; 67 Sensor_Type type;
68 int unique_id;
62} Sensor; 69} Sensor;
63 70
64typedef struct 71typedef struct
65{ 72{
66 char *name; 73 char name[255];
67 char *vendor; 74 char vendor[64];
68 char *model; 75 char model[64];
69 double charge_full; 76 uint32_t charge_full;
70 double charge_current; 77 uint32_t charge_current;
71 double percent; 78 float percent;
72 bool present; 79 bool present;
73#if defined(__OpenBSD__) 80#if defined(__OpenBSD__)
74 int mibs[5]; 81 int mibs[5];
75#elif defined(__FreeBSD__) || defined(__DragonFly__) 82#elif defined(__FreeBSD__) || defined(__DragonFly__)
76 char unit; 83 char unit;
77#endif 84#endif
85 int unique_id;
78} Battery; 86} Battery;
79 87
80typedef struct 88typedef struct
81{ 89{
82 char name[255]; 90 char name[255];
83 uint64_t total_in; 91 uint64_t total_in;
84 uint64_t total_out; 92 uint64_t total_out;
85 93
86 uint64_t peak_in; 94 uint64_t peak_in;
87 uint64_t peak_out; 95 uint64_t peak_out;
88 96
89 uint64_t in; 97 uint64_t in;
90 uint64_t out; 98 uint64_t out;
99
100 int unique_id;
91} Network_Interface; 101} Network_Interface;
92 102
103// Power
104
93Eina_Bool 105Eina_Bool
94power_ac_present(void); 106power_ac_present(void);
95 107
@@ -97,26 +109,34 @@ Eina_List *
97batteries_find(void); 109batteries_find(void);
98 110
99void 111void
100battery_free(Battery *bat); 112batteries_update(Eina_List *batteries);
101 113
102void 114void
103battery_update(Battery *bat); 115battery_update(Battery *bat);
104 116
117// Sensors
118
105Eina_List * 119Eina_List *
106sensors_find(void); 120sensors_find(void);
107 121
108void 122void
109memory_info(Meminfo *memory); 123sensors_update(Eina_List *sensors);
110
111void
112sensor_free(Sensor *sensor);
113 124
114Eina_Bool 125Eina_Bool
115sensor_update(Sensor *sensor); 126sensor_update(Sensor *sensor);
116 127
128// Network
129
117Eina_List * 130Eina_List *
118network_interfaces_find(void); 131network_interfaces_find(void);
119 132
133// Memory
134
135void
136memory_info(Meminfo *memory);
137
138// CPU Cores
139
120Eina_List * 140Eina_List *
121cores_find(void); 141cores_find(void);
122 142
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
48cores_online_count(void) 48cores_online_count(void)
49{ 49{
50#if defined(__OpenBSD__) 50#if defined(__OpenBSD__)
51 static int cores = 0; 51 int cores = 0;
52
53 if (cores != 0) return cores;
54
55 size_t len; 52 size_t len;
56 int mib[2] = { CTL_HW, HW_NCPUONLINE }; 53 int mib[2] = { CTL_HW, HW_NCPUONLINE };
57 54
@@ -68,9 +65,7 @@ cores_online_count(void)
68void 65void
69cores_update(Eina_List *cores) 66cores_update(Eina_List *cores)
70{ 67{
71 int diff_total, diff_idle; 68 unsigned long total, idle;
72 double ratio, percent;
73 unsigned long total, idle, used;
74 Cpu_Core *core; 69 Cpu_Core *core;
75 int ncpu = eina_list_count(cores); 70 int ncpu = eina_list_count(cores);
76 if (!ncpu) return; 71 if (!ncpu) return;
@@ -96,21 +91,10 @@ cores_update(Eina_List *cores)
96 91
97 idle = cpu[CP_IDLE]; 92 idle = cpu[CP_IDLE];
98 93
99 diff_total = total - core->total;
100 diff_idle = idle - core->idle;
101 if (diff_total == 0) diff_total = 1;
102
103 ratio = diff_total / 100.0;
104 used = diff_total - diff_idle;
105 percent = used / ratio;
106
107 if (percent > 100) percent = 100;
108 else if (percent < 0)
109 percent = 0;
110
111 core->percent = percent;
112 core->total = total; 94 core->total = total;
113 core->idle = idle; 95 core->idle = idle;
96 core->freq = core_id_frequency(core->id);
97 core->temp = core_id_temperature(core->id);
114 } 98 }
115#elif defined(__OpenBSD__) 99#elif defined(__OpenBSD__)
116 static struct cpustats cpu_times[CPU_STATES]; 100 static struct cpustats cpu_times[CPU_STATES];
@@ -134,21 +118,10 @@ cores_update(Eina_List *cores)
134 118
135 idle = cpu_times[i].cs_time[CP_IDLE]; 119 idle = cpu_times[i].cs_time[CP_IDLE];
136 120
137 diff_total = total - core->total;
138 if (diff_total == 0) diff_total = 1;
139
140 diff_idle = idle - core->idle;
141 ratio = diff_total / 100.0;
142 used = diff_total - diff_idle;
143 percent = used / ratio;
144
145 if (percent > 100) percent = 100;
146 else if (percent < 0)
147 percent = 0;
148
149 core->percent = percent;
150 core->total = total; 121 core->total = total;
151 core->idle = idle; 122 core->idle = idle;
123 core->freq = core_id_frequency(core->id);
124 core->temp = core_id_temperature(core->id);
152 } 125 }
153#elif defined(__linux__) 126#elif defined(__linux__)
154 char *buf, name[128]; 127 char *buf, name[128];
@@ -173,21 +146,11 @@ cores_update(Eina_List *cores)
173 146
174 total = cpu_times[0] + cpu_times[1] + cpu_times[2] + cpu_times[3]; 147 total = cpu_times[0] + cpu_times[1] + cpu_times[2] + cpu_times[3];
175 idle = cpu_times[3]; 148 idle = cpu_times[3];
176 diff_total = total - core->total;
177 if (diff_total == 0) diff_total = 1;
178
179 diff_idle = idle - core->idle;
180 ratio = diff_total / 100.0;
181 used = diff_total - diff_idle;
182 percent = used / ratio;
183 149
184 if (percent > 100) percent = 100;
185 else if (percent < 0)
186 percent = 0;
187
188 core->percent = percent;
189 core->total = total; 150 core->total = total;
190 core->idle = idle; 151 core->idle = idle;
152 core->freq = core_id_frequency(core->id);
153 core->temp = core_id_temperature(core->id);
191 } 154 }
192 } 155 }
193 free(buf); 156 free(buf);
@@ -216,18 +179,6 @@ cores_update(Eina_List *cores)
216 load[i].cpu_ticks[CPU_STATE_NICE]; 179 load[i].cpu_ticks[CPU_STATE_NICE];
217 idle = load[i].cpu_ticks[CPU_STATE_IDLE]; 180 idle = load[i].cpu_ticks[CPU_STATE_IDLE];
218 181
219 diff_total = total - core->total;
220 if (diff_total == 0) diff_total = 1;
221 diff_idle = idle - core->idle;
222 ratio = diff_total / 100.0;
223 used = diff_total - diff_idle;
224 percent = used / ratio;
225
226 if (percent > 100) percent = 100;
227 else if (percent < 0)
228 percent = 0;
229
230 core->percent = percent;
231 core->total = total; 182 core->total = total;
232 core->idle = idle; 183 core->idle = idle;
233 } 184 }
@@ -246,6 +197,7 @@ cores_find(void)
246 { 197 {
247 core = calloc(1, sizeof(Cpu_Core)); 198 core = calloc(1, sizeof(Cpu_Core));
248 core->id = i; 199 core->id = i;
200 snprintf(core->name, sizeof(core->name), "cpu%i", i);
249 cores = eina_list_append(cores, core); 201 cores = eina_list_append(cores, core);
250 } 202 }
251 cores_topology(cores); 203 cores_topology(cores);
@@ -260,7 +212,7 @@ static char _hwmon_path[256];
260int 212int
261_core_n_temperature_read(int n) 213_core_n_temperature_read(int n)
262{ 214{
263 int temp = -1; 215 int temp = THERMAL_INVALID;
264#if defined(__linux__) 216#if defined(__linux__)
265 217
266 char *b = file_contents(_core_temps[n]); 218 char *b = file_contents(_core_temps[n]);
@@ -357,7 +309,7 @@ core_id_temperature(int id)
357 if (!dir) 309 if (!dir)
358 { 310 {
359 init = 1; 311 init = 1;
360 return -1; 312 return THERMAL_INVALID;
361 } 313 }
362 314
363 while ((dh = readdir(dir)) != NULL) 315 while ((dh = readdir(dir)) != NULL)
@@ -389,7 +341,7 @@ core_id_temperature(int id)
389 init = 1; 341 init = 1;
390 } 342 }
391 343
392 if (!_hwmon_path[0]) return -1; 344 if (!_hwmon_path[0]) return THERMAL_INVALID;
393 345
394 return _core_n_temperature_read(id); 346 return _core_n_temperature_read(id);
395#elif defined(__FreeBSD__) || defined(__DragonFly__) 347#elif defined(__FreeBSD__) || defined(__DragonFly__)
@@ -403,7 +355,7 @@ core_id_temperature(int id)
403 355
404 return _core_n_temperature_read(id); 356 return _core_n_temperature_read(id);
405#endif 357#endif
406 return -1; 358 return THERMAL_INVALID;
407} 359}
408 360
409int 361int
@@ -420,7 +372,7 @@ int
420core_id_frequency(int id) 372core_id_frequency(int id)
421{ 373{
422#if defined(__linux__) 374#if defined(__linux__)
423 int freq = -1; 375 int freq = CPUFREQ_INVALID;
424 FILE *f; 376 FILE *f;
425 char buf[4096]; 377 char buf[4096];
426 int tmp; 378 int tmp;
@@ -436,7 +388,7 @@ core_id_frequency(int id)
436 freq = tmp; 388 freq = tmp;
437 } 389 }
438 fclose(f); 390 fclose(f);
439 if (freq != -1) return freq; 391 if (freq != CPUFREQ_INVALID) return freq;
440 } 392 }
441 393
442 return freq; 394 return freq;
@@ -444,7 +396,7 @@ core_id_frequency(int id)
444 return cores_frequency(); 396 return cores_frequency();
445#endif 397#endif
446 398
447 return -1; 399 return CPUFREQ_INVALID;
448} 400}
449 401
450int 402int
@@ -534,7 +486,7 @@ cores_frequency_min_max(int *min, int *max)
534int 486int
535cores_frequency(void) 487cores_frequency(void)
536{ 488{
537 int freq = -1; 489 int freq = CPUFREQ_INVALID;
538 490
539#if defined(__FreeBSD__) || defined(__DragonFly__) 491#if defined(__FreeBSD__) || defined(__DragonFly__)
540 size_t len = sizeof(freq); 492 size_t len = sizeof(freq);
@@ -560,7 +512,7 @@ cores_frequency(void)
560 freq = tmp; 512 freq = tmp;
561 } 513 }
562 fclose(f); 514 fclose(f);
563 if (freq != -1) return freq; 515 if (freq != CPUFREQ_INVALID) return freq;
564 } 516 }
565 517
566 f = fopen("/proc/cpuinfo", "r"); 518 f = fopen("/proc/cpuinfo", "r");
@@ -635,5 +587,12 @@ cores_topology(Eina_List *cores)
635 core->top_id = cores_top[i].id; 587 core->top_id = cores_top[i].id;
636 } 588 }
637 free(cores_top); 589 free(cores_top);
590#else
591 Cpu_Core *core;
592 Eina_List *l;
593
594 EINA_LIST_FOREACH(cores, l, core)
595 core->top_id = core->id;
638#endif 596#endif
597
639} 598}
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 @@
1void
2sensor_free(Sensor *sensor)
3{
4 if (sensor->name)
5 free(sensor->name);
6 if (sensor->child_name)
7 free(sensor->child_name);
8#if defined(__linux__)
9 if (sensor->path)
10 free(sensor->path);
11#endif
12 free(sensor);
13}
14
15Eina_Bool 1Eina_Bool
16sensor_update(Sensor *sensor) 2sensor_update(Sensor *sensor)
17{ 3{
@@ -70,7 +56,6 @@ sensors_find(void)
70 struct sensordev snsrdev; 56 struct sensordev snsrdev;
71 size_t slen = sizeof(struct sensor); 57 size_t slen = sizeof(struct sensor);
72 size_t sdlen = sizeof(struct sensordev); 58 size_t sdlen = sizeof(struct sensordev);
73 char buf[32];
74 enum sensor_type type; 59 enum sensor_type type;
75 60
76 for (devn = 0;; devn++) 61 for (devn = 0;; devn++)
@@ -99,13 +84,17 @@ sensors_find(void)
99 sensor = calloc(1, sizeof(Sensor)); 84 sensor = calloc(1, sizeof(Sensor));
100 if (sensor) 85 if (sensor)
101 { 86 {
102 sensor->name = strdup(snsrdev.xname); 87 strlcpy(sensor->name, snsrdev.xname, sizeof(sensor->name));
103 snprintf(buf, sizeof(buf), "%i", n);
104 sensor->child_name = strdup(buf);
105 if (snsr.type == SENSOR_TEMP) 88 if (snsr.type == SENSOR_TEMP)
106 sensor->type = THERMAL; 89 {
90 snprintf(sensor->child_name, sizeof(sensor->child_name), "temp%i", n);
91 sensor->type = THERMAL;
92 }
107 else if (snsr.type == SENSOR_FANRPM) 93 else if (snsr.type == SENSOR_FANRPM)
108 sensor->type = FANRPM; 94 {
95 snprintf(sensor->child_name, sizeof(sensor->child_name), "fan%i", n);
96 sensor->type = FANRPM;
97 }
109 memcpy(sensor->mibs, &mibs, sizeof(mibs)); 98 memcpy(sensor->mibs, &mibs, sizeof(mibs));
110 99
111 sensors = eina_list_append(sensors, sensor); 100 sensors = eina_list_append(sensors, sensor);
@@ -124,7 +113,8 @@ sensors_find(void)
124 sensor = calloc(1, sizeof(Sensor)); 113 sensor = calloc(1, sizeof(Sensor));
125 if (sensor) 114 if (sensor)
126 { 115 {
127 sensor->name = strdup("hw.acpi.thermal.tz0.temperature"); 116 strlcpy(sensor->name, "hw.acpi.thermal.tz0.temperature", sizeof(sensor->name));
117 strlcpy(sensor->child_name, "0", sizeof(sensor->child_name));
128 sensor->value = (float) (value - 2732) / 10; 118 sensor->value = (float) (value - 2732) / 10;
129 sensors = eina_list_append(sensors, sensor); 119 sensors = eina_list_append(sensors, sensor);
130 } 120 }
@@ -141,7 +131,8 @@ sensors_find(void)
141 sensor = calloc(1, sizeof(Sensor)); 131 sensor = calloc(1, sizeof(Sensor));
142 if (sensor) 132 if (sensor)
143 { 133 {
144 sensor->name = strdup(buf); 134 strlcpy(sensor->name, buf, sizeof(sensor->name));
135 snprintf(sensor->child_name, sizeof(sensor->child_name), "%i", i);
145 sensor->value = (float) (value - 2732) / 10; 136 sensor->value = (float) (value - 2732) / 10;
146 sensors = eina_list_append(sensors, sensor); 137 sensors = eina_list_append(sensors, sensor);
147 } 138 }
@@ -198,18 +189,29 @@ sensors_find(void)
198 sensor = calloc(1, sizeof(Sensor)); 189 sensor = calloc(1, sizeof(Sensor));
199 if (sensor) 190 if (sensor)
200 { 191 {
192 char *d;
201 sensor->type = FANRPM; 193 sensor->type = FANRPM;
202 sensor->path = strdup(buf); 194 eina_strlcpy(sensor->path, buf, sizeof(sensor->path));
203 snprintf(buf, sizeof(buf), "%s/name", link); 195 snprintf(buf, sizeof(buf), "%s/name", link);
204 sensor->name = file_contents(buf); 196 d = file_contents(buf);
197 if (d)
198 {
199 eina_strlcpy(sensor->name, d, sizeof(sensor->name));
200 free(d);
201 }
205 snprintf(buf, sizeof(buf), "%s/fan%i_label", link, id); 202 snprintf(buf, sizeof(buf), "%s/fan%i_label", link, id);
206 if (ecore_file_exists(buf)) 203 if (ecore_file_exists(buf))
207 sensor->child_name = file_contents(buf);
208 else
209 { 204 {
210 snprintf(buf, sizeof(buf), "fan%i", id); 205 d = file_contents(buf);
211 sensor->child_name = strdup(buf); 206 if (d)
207 {
208 eina_strlcpy(sensor->child_name, d, sizeof(sensor->child_name));
209 free(d);
210 }
212 } 211 }
212 else
213 snprintf(sensor->child_name, sizeof(sensor->child_name), "fan%i", id);
214
213 sensors = eina_list_append(sensors, sensor); 215 sensors = eina_list_append(sensors, sensor);
214 } 216 }
215 } 217 }
@@ -220,19 +222,28 @@ sensors_find(void)
220 sensor = calloc(1, sizeof(Sensor)); 222 sensor = calloc(1, sizeof(Sensor));
221 if (sensor) 223 if (sensor)
222 { 224 {
225 char *d;
223 sensor->type = THERMAL; 226 sensor->type = THERMAL;
224 sensor->path = strdup(buf); 227 eina_strlcpy(sensor->path, buf, sizeof(sensor->path));
225 snprintf(buf, sizeof(buf), "%s/name", link); 228 snprintf(buf, sizeof(buf), "%s/name", link);
226 sensor->name = file_contents(buf); 229 d = file_contents(buf);
227 230 if (d)
231 {
232 eina_strlcpy(sensor->name, d, sizeof(sensor->name));
233 free(d);
234 }
228 snprintf(buf, sizeof(buf), "%s/temp%i_label", link, id); 235 snprintf(buf, sizeof(buf), "%s/temp%i_label", link, id);
229 if (ecore_file_exists(buf)) 236 if (ecore_file_exists(buf))
230 sensor->child_name = file_contents(buf);
231 else
232 { 237 {
233 snprintf(buf, sizeof(buf), "%i", id); 238 d = file_contents(buf);
234 sensor->child_name = strdup(buf); 239 if (d)
240 {
241 eina_strlcpy(sensor->child_name, d, sizeof(sensor->child_name));
242 free(d);
243 }
235 } 244 }
245 else
246 snprintf(sensor->child_name, sizeof(sensor->child_name), "temp%i", id);
236 247
237 sensors = eina_list_append(sensors, sensor); 248 sensors = eina_list_append(sensors, sensor);
238 } 249 }
@@ -253,6 +264,16 @@ sensors_find(void)
253 return sensors; 264 return sensors;
254} 265}
255 266
267void
268sensors_update(Eina_List *sensors)
269{
270 Eina_List *l;
271 Sensor *sensor;
272
273 EINA_LIST_FOREACH(sensors, l, sensor)
274 sensor_update(sensor);
275}
276
256Eina_List * 277Eina_List *
257batteries_find(void) 278batteries_find(void)
258{ 279{
@@ -276,9 +297,9 @@ batteries_find(void)
276 Battery *bat = calloc(1, sizeof(Battery)); 297 Battery *bat = calloc(1, sizeof(Battery));
277 if (bat) 298 if (bat)
278 { 299 {
279 bat->name = strdup(snsrdev.xname); 300 strlcpy(bat->name, snsrdev.xname, sizeof(bat->name));
280 bat->model = strdup("Unknown"); 301 strlcpy(bat->model, "Unknown", sizeof(bat->model));
281 bat->vendor = strdup("Unknown"); 302 strlcpy(bat->vendor, "Unknown", sizeof(bat->vendor));
282 bat->mibs[0] = mibs[0]; 303 bat->mibs[0] = mibs[0];
283 bat->mibs[1] = mibs[1]; 304 bat->mibs[1] = mibs[1];
284 bat->mibs[2] = mibs[2]; 305 bat->mibs[2] = mibs[2];
@@ -305,12 +326,13 @@ batteries_find(void)
305 Battery *bat = calloc(1, sizeof(Battery)); 326 Battery *bat = calloc(1, sizeof(Battery));
306 if (bat) 327 if (bat)
307 { 328 {
329 snprintf(bat->name, sizeof(bat->name), "bat%i", i);
308 if (battio.bst.state == ACPI_BATT_STAT_NOT_PRESENT) 330 if (battio.bst.state == ACPI_BATT_STAT_NOT_PRESENT)
309 bat->present = 0; 331 bat->present = 0;
310 else 332 else
311 bat->present = 1; 333 bat->present = 1;
312 bat->vendor = strdup(battio.bix.oeminfo); 334 strlcpy(bat->vendor, battio.bix.oeminfo, sizeof(bat->vendor));
313 bat->model = strdup(battio.bix.model); 335 strlcpy(bat->model, battio.bix.model, sizeof(bat->model));
314 bat->unit = i; 336 bat->unit = i;
315 list = eina_list_append(list, bat); 337 list = eina_list_append(list, bat);
316 } 338 }
@@ -320,7 +342,6 @@ batteries_find(void)
320#elif defined(__linux__) 342#elif defined(__linux__)
321 char *type; 343 char *type;
322 struct dirent **names; 344 struct dirent **names;
323 char *buf;
324 char path[PATH_MAX]; 345 char path[PATH_MAX];
325 int i, n; 346 int i, n;
326 347
@@ -337,18 +358,29 @@ batteries_find(void)
337 Battery *bat = calloc(1, sizeof(Battery)); 358 Battery *bat = calloc(1, sizeof(Battery));
338 if (bat) 359 if (bat)
339 { 360 {
340 bat->name = strdup(names[i]->d_name); 361 char *d;
362 eina_strlcpy(bat->name, names[i]->d_name, sizeof(bat->name));
341 snprintf(path, sizeof(path), "/sys/class/power_supply/%s/manufacturer", names[i]->d_name); 363 snprintf(path, sizeof(path), "/sys/class/power_supply/%s/manufacturer", names[i]->d_name);
342 bat->vendor = file_contents(path); 364 d = file_contents(path);
365 if (d)
366 {
367 eina_strlcpy(bat->vendor, d, sizeof(bat->vendor));
368 free(d);
369 }
343 snprintf(path, sizeof(path), "/sys/class/power_supply/%s/model_name", names[i]->d_name); 370 snprintf(path, sizeof(path), "/sys/class/power_supply/%s/model_name", names[i]->d_name);
344 bat->model = file_contents(path); 371 d = file_contents(path);
372 if (d)
373 {
374 eina_strlcpy(bat->model, d, sizeof(bat->model));
375 free(d);
376 }
345 snprintf(path, sizeof(path), "/sys/class/power_supply/%s/present", names[i]->d_name); 377 snprintf(path, sizeof(path), "/sys/class/power_supply/%s/present", names[i]->d_name);
346 bat->present = 1; 378 bat->present = 1;
347 buf = file_contents(path); 379 d = file_contents(path);
348 if (buf) 380 if (d)
349 { 381 {
350 bat->present = atoi(buf); 382 bat->present = atoi(d);
351 free(buf); 383 free(d);
352 } 384 }
353 list = eina_list_append(list, bat); 385 list = eina_list_append(list, bat);
354 } 386 }
@@ -364,18 +396,6 @@ batteries_find(void)
364} 396}
365 397
366void 398void
367battery_free(Battery *bat)
368{
369 if (bat->name)
370 free(bat->name);
371 if (bat->model)
372 free(bat->model);
373 if (bat->vendor)
374 free(bat->vendor);
375 free(bat);
376}
377
378void
379battery_update(Battery *bat) 399battery_update(Battery *bat)
380{ 400{
381 double charge_full = 0, charge_current = 0; 401 double charge_full = 0, charge_current = 0;
@@ -560,14 +580,43 @@ power_ac_present(void)
560 close(fd); 580 close(fd);
561 } 581 }
562#elif defined(__linux__) 582#elif defined(__linux__)
563 char *buf = file_contents("/sys/class/power_supply/AC/online"); 583 static const char *found = NULL;
564 if (buf) 584 static const char *known[] = {
585 "/sys/class/power_supply/AC/online",
586 "/sys/class/power_supply/ACAD/online",
587 "/sys/class/power_supply/ADP0/online",
588 };
589
590 for (int i = 0; (!found) && (i < sizeof(known) / sizeof(char *)); i++)
565 { 591 {
566 have_ac = atoi(buf); 592 if (ecore_file_exists(known[i]))
567 free(buf); 593 {
594 found = known[i];
595 break;
596 }
597 }
598
599 if (found)
600 {
601 char *buf = file_contents(found);
602 if (buf)
603 {
604 have_ac = atoi(buf);
605 free(buf);
606 }
568 } 607 }
569#endif 608#endif
570 609
571 return have_ac; 610 return have_ac;
572} 611}
573 612
613void
614batteries_update(Eina_List *batteries)
615{
616 Eina_List *l;
617 Battery *bat;
618
619 EINA_LIST_FOREACH(batteries, l, bat)
620 battery_update(bat);
621}
622
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 @@
1src_watch += files([ 1src_next = files([
2 'machine.c', 2 'machine.c',
3 'machine.h', 3 'machine.h',
4 'file_systems.c',
5 'file_systems.h',
4 'process.c', 6 'process.c',
5 'process.h', 7 'process.h',
6 'filesystems.c',
7 'filesystems.h',
8]) 8])
9
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 @@
2# define __MacOS__ 2# define __MacOS__
3#endif 3#endif
4 4
5#include "ui/gettext.h" 5#include "intl/gettext.h"
6#define _(STR) gettext(STR) 6#define _(STR) gettext(STR)
7 7
8#if defined(__MacOS__) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__) 8#if defined(__MacOS__) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__)
@@ -53,7 +53,7 @@
53 53
54#include "macros.h" 54#include "macros.h"
55 55
56static Eina_Bool _show_kthreads = 1; 56static Eina_Bool _show_kthreads = 0;
57 57
58void 58void
59proc_info_kthreads_show_set(Eina_Bool enabled) 59proc_info_kthreads_show_set(Eina_Bool enabled)
@@ -98,8 +98,10 @@ _states_init(void)
98#endif 98#endif
99#endif 99#endif
100} 100}
101 101#ifndef __OpenBSD__
102static const char * 102static
103#endif
104const char *
103_process_state_name(char state) 105_process_state_name(char state)
104{ 106{
105 static int init = 0; 107 static int init = 0;
@@ -159,37 +161,47 @@ _mem_size(Proc_Info *proc)
159static void 161static void
160_cmd_args(Proc_Info *p, char *name, size_t len) 162_cmd_args(Proc_Info *p, char *name, size_t len)
161{ 163{
162 char buf[8192]; 164 char path[PATH_MAX];
165 char line[4096];
163 int pid = p->pid; 166 int pid = p->pid;
164 167
165 snprintf(buf, sizeof(buf), "/proc/%d/exe", pid); 168 snprintf(path, sizeof(path), "/proc/%d/exe", pid);
166 char *link = ecore_file_readlink(buf); 169 char *link = ecore_file_readlink(path);
167 if (link) 170 if (link)
168 { 171 {
169 snprintf(name, len, "%s", ecore_file_file_get(link)); 172 snprintf(name, len, "%s", ecore_file_file_get(link));
170 free(link); 173 free(link);
171 } 174 }
172 175
173 snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid); 176 snprintf(path, sizeof(path), "/proc/%d/cmdline", pid);
174 FILE *f = fopen(buf, "r"); 177 FILE *f = fopen(path, "r");
175 if (f) 178 if (f)
176 { 179 {
177 if (fgets(buf, sizeof(buf), f)) 180 if (fgets(line, sizeof(line), f))
178 { 181 {
179 Eina_Strbuf *b = eina_strbuf_new(); 182 int sz = ftell(f);
180 const char *n; 183 Eina_Strbuf *buf = eina_strbuf_new();
181 184
182 if (ecore_file_exists(buf)) 185 if (ecore_file_exists(line))
183 snprintf(name, len, "%s", ecore_file_file_get(buf)); 186 snprintf(name, len, "%s", ecore_file_file_get(line));
184 187
185 n = buf; 188 const char *cp = line;
186 while (n && *n && (*n + 1)) 189 for (int i = 0; i < sz; i++)
187 { 190 {
188 eina_strbuf_append(b, n); 191 if (line[i] == '\0')
189 n = strchr(n, '\0') + 1; 192 {
190 if (n && *n && (*n + 1)) eina_strbuf_append(b, " "); 193 if (*cp)
194 eina_strbuf_append(buf, cp);
195 if ((i + 1) < sz)
196 {
197 i++;
198 cp = &line[i];
199 if (*cp)
200 eina_strbuf_append(buf, " ");
201 }
202 }
191 } 203 }
192 p->arguments = eina_strbuf_release(b); 204 p->arguments = eina_strbuf_release(buf);
193 } 205 }
194 fclose(f); 206 fclose(f);
195 } 207 }
@@ -360,7 +372,7 @@ _process_list_linux_get(void)
360 p->ppid = st.ppid; 372 p->ppid = st.ppid;
361 p->uid = _uid(pid); 373 p->uid = _uid(pid);
362 p->cpu_id = st.psr; 374 p->cpu_id = st.psr;
363 p->start = st.start_time; 375 p->start_time = st.start_time;
364 p->run_time = st.run_time; 376 p->run_time = st.run_time;
365 state = _process_state_name(st.state); 377 state = _process_state_name(st.state);
366 snprintf(p->state, sizeof(p->state), "%s", state); 378 snprintf(p->state, sizeof(p->state), "%s", state);
@@ -436,7 +448,7 @@ proc_info_by_pid(int pid)
436 p->ppid = st.ppid; 448 p->ppid = st.ppid;
437 p->uid = _uid(pid); 449 p->uid = _uid(pid);
438 p->cpu_id = st.psr; 450 p->cpu_id = st.psr;
439 p->start = st.start_time; 451 p->start_time = st.start_time;
440 p->run_time = st.run_time; 452 p->run_time = st.run_time;
441 state = _process_state_name(st.state); 453 state = _process_state_name(st.state);
442 snprintf(p->state, sizeof(p->state), "%s", state); 454 snprintf(p->state, sizeof(p->state), "%s", state);
@@ -470,7 +482,7 @@ _proc_get(Proc_Info *p, struct kinfo_proc *kp)
470 p->ppid = kp->p_ppid; 482 p->ppid = kp->p_ppid;
471 p->uid = kp->p_uid; 483 p->uid = kp->p_uid;
472 p->cpu_id = kp->p_cpuid; 484 p->cpu_id = kp->p_cpuid;
473 p->start = kp->p_ustart_sec; 485 p->start_time = kp->p_ustart_sec;
474 p->run_time = kp->p_uutime_sec + kp->p_ustime_sec + 486 p->run_time = kp->p_uutime_sec + kp->p_ustime_sec +
475 (kp->p_uutime_usec / 1000000) + (kp->p_ustime_usec / 1000000); 487 (kp->p_uutime_usec / 1000000) + (kp->p_ustime_usec / 1000000);
476 488
@@ -751,7 +763,7 @@ _proc_pidinfo(size_t pid)
751 p->cpu_time = taskinfo.ptinfo.pti_total_user + 763 p->cpu_time = taskinfo.ptinfo.pti_total_user +
752 taskinfo.ptinfo.pti_total_system; 764 taskinfo.ptinfo.pti_total_system;
753 p->cpu_time /= 10000000; 765 p->cpu_time /= 10000000;
754 p->start = taskinfo.pbsd.pbi_start_tvsec; 766 p->start_time = taskinfo.pbsd.pbi_start_tvsec;
755 state = _process_state_name(taskinfo.pbsd.pbi_status); 767 state = _process_state_name(taskinfo.pbsd.pbi_status);
756 snprintf(p->state, sizeof(p->state), "%s", state); 768 snprintf(p->state, sizeof(p->state), "%s", state);
757 p->mem_size = p->mem_virt = taskinfo.ptinfo.pti_virtual_size; 769 p->mem_size = p->mem_virt = taskinfo.ptinfo.pti_virtual_size;
@@ -840,7 +852,7 @@ proc_info_by_pid(int pid)
840 p->cpu_time = taskinfo.ptinfo.pti_total_user + 852 p->cpu_time = taskinfo.ptinfo.pti_total_user +
841 taskinfo.ptinfo.pti_total_system; 853 taskinfo.ptinfo.pti_total_system;
842 p->cpu_time /= 10000000; 854 p->cpu_time /= 10000000;
843 p->start = taskinfo.pbsd.pbi_start_tvsec; 855 p->start_time = taskinfo.pbsd.pbi_start_tvsec;
844 state = _process_state_name(taskinfo.pbsd.pbi_status); 856 state = _process_state_name(taskinfo.pbsd.pbi_status);
845 snprintf(p->state, sizeof(p->state), "%s", state); 857 snprintf(p->state, sizeof(p->state), "%s", state);
846 p->mem_size = p->mem_virt = taskinfo.ptinfo.pti_virtual_size; 858 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)
985 snprintf(p->wchan, sizeof(p->wchan), "%s", kp->ki_wmesg); 997 snprintf(p->wchan, sizeof(p->wchan), "%s", kp->ki_wmesg);
986 p->mem_virt = kp->ki_size; 998 p->mem_virt = kp->ki_size;
987 p->mem_rss = MEMSIZE(kp->ki_rssize) * MEMSIZE(pagesize); 999 p->mem_rss = MEMSIZE(kp->ki_rssize) * MEMSIZE(pagesize);
988 p->start = kp->ki_start.tv_sec; 1000 p->start_time = kp->ki_start.tv_sec;
989 p->mem_size = p->mem_virt; 1001 p->mem_size = p->mem_virt;
990 p->nice = kp->ki_nice - NZERO; 1002 p->nice = kp->ki_nice - NZERO;
991 p->priority = kp->ki_pri.pri_level - PZERO; 1003 p->priority = kp->ki_pri.pri_level - PZERO;
@@ -1494,6 +1506,6 @@ proc_sort_by_age(const void *p1, const void *p2)
1494{ 1506{
1495 const Proc_Info *c1 = p1, *c2 = p2; 1507 const Proc_Info *c1 = p1, *c2 = p2;
1496 1508
1497 return c1->start - c2->start; 1509 return c1->start_time - c2->start_time;
1498} 1510}
1499 1511
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
21 int64_t cpu_time; 21 int64_t cpu_time;
22 double cpu_usage; 22 double cpu_usage;
23 int64_t run_time; 23 int64_t run_time;
24 int64_t start; 24 int64_t start_time;
25 25
26 uint64_t mem_size; 26 uint64_t mem_size;
27 uint64_t mem_virt; 27 uint64_t mem_virt;
@@ -36,7 +36,9 @@ typedef struct _Proc_Info
36 Eina_List *fds; 36 Eina_List *fds;
37 int numfiles; 37 int numfiles;
38 38
39 short is_kernel; 39 Eina_Bool was_zero;
40 Eina_Bool is_kernel;
41 Eina_Bool is_new;
40 int tid; 42 int tid;
41 char *thread_name; 43 char *thread_name;
42 44