summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim Woelders <kim@woelders.dk>2021-08-27 15:28:04 +0200
committerKim Woelders <kim@woelders.dk>2021-09-02 19:58:04 +0200
commitc6c19d3411d4b496cf10a25502e64443b3de6148 (patch)
tree61c09050dbe9a0fa0e34b05d4ca668a933d9b057
parent9e2045a54b9ced077eaa6324f32154fe6a1fa685 (diff)
E-MemWatch: Drop ancient (<2.6) kernel support (fixing bad memory access)
-rw-r--r--epplets/E-MemWatch.c104
1 files changed, 31 insertions, 73 deletions
diff --git a/epplets/E-MemWatch.c b/epplets/E-MemWatch.c
index 9d0813e..fd69e3f 100644
--- a/epplets/E-MemWatch.c
+++ b/epplets/E-MemWatch.c
@@ -42,7 +42,6 @@ static Epplet_gadget close_button, mem_bar, swap_bar, mem_label, swap_label,
42 title, cfg_button; 42 title, cfg_button;
43static int mem_val = 0, swap_val = 0; 43static int mem_val = 0, swap_val = 0;
44static int show_title = 1; 44static int show_title = 1;
45static int kernel_2_6 = 0;
46 45
47static void 46static void
48timer_cb(void *data __UNUSED__) 47timer_cb(void *data __UNUSED__)
@@ -70,32 +69,25 @@ timer_cb(void *data __UNUSED__)
70 return; 69 return;
71 } 70 }
72 71
73 if (kernel_2_6) 72 fgets(buff, sizeof(buff), fp);
74 { 73 sscanf(buff, "%*s %lu", &total);
75 fgets(buff, sizeof(buff), fp); 74 fgets(buff, sizeof(buff), fp);
76 sscanf(buff, "%*s %lu", &total); 75 sscanf(buff, "%*s %lu", &free);
77 fgets(buff, sizeof(buff), fp); 76 fgets(buff, sizeof(buff), fp);
78 sscanf(buff, "%*s %lu", &free); 77 sscanf(buff, "%*s %lu", &buffers);
79 fgets(buff, sizeof(buff), fp); 78 fgets(buff, sizeof(buff), fp);
80 sscanf(buff, "%*s %lu", &buffers); 79 sscanf(buff, "%*s %lu", &cached);
81 fgets(buff, sizeof(buff), fp);
82 sscanf(buff, "%*s %lu", &cached);
83
84 total *= 1024;
85 free *= 1024;
86 buffers *= 1024;
87 cached *= 1024;
88 used = total - free;
89 80
90 } 81 total *= 1024;
91 else 82 free *= 1024;
92 { 83 buffers *= 1024;
84 cached *= 1024;
85 used = total - free;
93 86
94 fgets(buff, sizeof(buff), fp); /* Ignore the first line */ 87 fgets(buff, sizeof(buff), fp); /* Ignore the first line */
95 fgets(buff, sizeof(buff), fp); 88 fgets(buff, sizeof(buff), fp);
96 sscanf(buff, "%*s %lu %lu %*u %*u %lu %lu", &total, &used, &buffers, 89 sscanf(buff, "%*s %lu %lu %*u %*u %lu %lu", &total, &used, &buffers,
97 &cached); 90 &cached);
98 }
99 91
100#endif /* HAVE_LIBGTOP */ 92#endif /* HAVE_LIBGTOP */
101 93
@@ -134,31 +126,21 @@ timer_cb(void *data __UNUSED__)
134 while (swap.total == 0 && swap.used == 0 && check++ < 15); 126 while (swap.total == 0 && swap.used == 0 && check++ < 15);
135#else 127#else
136 128
137 if (kernel_2_6) 129 fgets(buff, sizeof(buff), fp);
138 { 130 fgets(buff, sizeof(buff), fp);
139 fgets(buff, sizeof(buff), fp); 131 fgets(buff, sizeof(buff), fp);
140 fgets(buff, sizeof(buff), fp); 132 fgets(buff, sizeof(buff), fp);
141 fgets(buff, sizeof(buff), fp); 133 fgets(buff, sizeof(buff), fp);
142 fgets(buff, sizeof(buff), fp); 134 fgets(buff, sizeof(buff), fp);
143 fgets(buff, sizeof(buff), fp); 135 fgets(buff, sizeof(buff), fp);
144 fgets(buff, sizeof(buff), fp); 136 fgets(buff, sizeof(buff), fp);
145 fgets(buff, sizeof(buff), fp); 137 sscanf(buff, "%*s %lu", &total);
146 fgets(buff, sizeof(buff), fp); 138 fgets(buff, sizeof(buff), fp);
147 sscanf(buff, "%*s %lu", &total); 139 sscanf(buff, "%*s %lu", &free);;
148 fgets(buff, sizeof(buff), fp);
149 sscanf(buff, "%*s %lu", &free);;
150
151 total *= 1024;
152 free *= 1024;
153 used = total - free;
154
155 }
156 else
157 {
158 140
159 fgets(buff, sizeof(buff), fp); 141 total *= 1024;
160 sscanf(buff, "%*s %lu %lu", &total, &used); 142 free *= 1024;
161 } 143 used = total - free;
162 144
163 fclose(fp); 145 fclose(fp);
164#endif /* HAVE_LIBGTOP */ 146#endif /* HAVE_LIBGTOP */
@@ -245,30 +227,6 @@ main(int argc, char **argv)
245{ 227{
246 Epplet_adjust_priority(10); 228 Epplet_adjust_priority(10);
247 229
248 /* check for Kernel 2.6 */
249 FILE *fp;
250 char version[8], buff[1024];
251
252 if (!(fp = fopen("/proc/version", "r")))
253 {
254 D(("Failed to open /proc/version -- %s\nWill assume not 2.6 kernel",
255 strerror(errno)));
256 return 1;
257 }
258
259 fgets(buff, sizeof(buff), fp);
260 sscanf(buff, "%*s %*s %s", version);
261
262 if (version[2] == '6')
263 {
264 kernel_2_6 = 1;
265 }
266
267 fclose(fp);
268 /* end check for Kernel 2.6 */
269
270 atexit(Epplet_cleanup);
271
272 Epplet_Init("E-MemWatch", "0.1", "Enlightenment RAM/Swap Monitor Epplet", 3, 230 Epplet_Init("E-MemWatch", "0.1", "Enlightenment RAM/Swap Monitor Epplet", 3,
273 3, argc, argv, 0); 231 3, argc, argv, 0);
274 Epplet_load_config(); 232 Epplet_load_config();