kwo pushed a commit to branch master.

http://git.enlightenment.org/e16/e16-epplets.git/commit/?id=c6c19d3411d4b496cf10a25502e64443b3de6148

commit c6c19d3411d4b496cf10a25502e64443b3de6148
Author: Kim Woelders <k...@woelders.dk>
Date:   Fri Aug 27 15:28:04 2021 +0200

    E-MemWatch: Drop ancient (<2.6) kernel support (fixing bad memory access)
---
 epplets/E-MemWatch.c | 104 +++++++++++++++------------------------------------
 1 file 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,
    title, cfg_button;
 static int          mem_val = 0, swap_val = 0;
 static int          show_title = 1;
-static int          kernel_2_6 = 0;
 
 static void
 timer_cb(void *data __UNUSED__)
@@ -70,32 +69,25 @@ timer_cb(void *data __UNUSED__)
        return;
      }
 
-   if (kernel_2_6)
-     {
-       fgets(buff, sizeof(buff), fp);
-       sscanf(buff, "%*s %lu", &total);
-       fgets(buff, sizeof(buff), fp);
-       sscanf(buff, "%*s %lu", &free);
-       fgets(buff, sizeof(buff), fp);
-       sscanf(buff, "%*s %lu", &buffers);
-       fgets(buff, sizeof(buff), fp);
-       sscanf(buff, "%*s %lu", &cached);
-
-       total *= 1024;
-       free *= 1024;
-       buffers *= 1024;
-       cached *= 1024;
-       used = total - free;
+   fgets(buff, sizeof(buff), fp);
+   sscanf(buff, "%*s %lu", &total);
+   fgets(buff, sizeof(buff), fp);
+   sscanf(buff, "%*s %lu", &free);
+   fgets(buff, sizeof(buff), fp);
+   sscanf(buff, "%*s %lu", &buffers);
+   fgets(buff, sizeof(buff), fp);
+   sscanf(buff, "%*s %lu", &cached);
 
-     }
-   else
-     {
+   total *= 1024;
+   free *= 1024;
+   buffers *= 1024;
+   cached *= 1024;
+   used = total - free;
 
-       fgets(buff, sizeof(buff), fp);  /* Ignore the first line */
-       fgets(buff, sizeof(buff), fp);
-       sscanf(buff, "%*s %lu %lu %*u %*u %lu %lu", &total, &used, &buffers,
-              &cached);
-     }
+   fgets(buff, sizeof(buff), fp);      /* Ignore the first line */
+   fgets(buff, sizeof(buff), fp);
+   sscanf(buff, "%*s %lu %lu %*u %*u %lu %lu", &total, &used, &buffers,
+         &cached);
 
 #endif /* HAVE_LIBGTOP */
 
@@ -134,31 +126,21 @@ timer_cb(void *data __UNUSED__)
    while (swap.total == 0 && swap.used == 0 && check++ < 15);
 #else
 
-   if (kernel_2_6)
-     {
-       fgets(buff, sizeof(buff), fp);
-       fgets(buff, sizeof(buff), fp);
-       fgets(buff, sizeof(buff), fp);
-       fgets(buff, sizeof(buff), fp);
-       fgets(buff, sizeof(buff), fp);
-       fgets(buff, sizeof(buff), fp);
-       fgets(buff, sizeof(buff), fp);
-       fgets(buff, sizeof(buff), fp);
-       sscanf(buff, "%*s %lu", &total);
-       fgets(buff, sizeof(buff), fp);
-       sscanf(buff, "%*s %lu", &free);;
-
-       total *= 1024;
-       free *= 1024;
-       used = total - free;
-
-     }
-   else
-     {
+   fgets(buff, sizeof(buff), fp);
+   fgets(buff, sizeof(buff), fp);
+   fgets(buff, sizeof(buff), fp);
+   fgets(buff, sizeof(buff), fp);
+   fgets(buff, sizeof(buff), fp);
+   fgets(buff, sizeof(buff), fp);
+   fgets(buff, sizeof(buff), fp);
+   fgets(buff, sizeof(buff), fp);
+   sscanf(buff, "%*s %lu", &total);
+   fgets(buff, sizeof(buff), fp);
+   sscanf(buff, "%*s %lu", &free);;
 
-       fgets(buff, sizeof(buff), fp);
-       sscanf(buff, "%*s %lu %lu", &total, &used);
-     }
+   total *= 1024;
+   free *= 1024;
+   used = total - free;
 
    fclose(fp);
 #endif /* HAVE_LIBGTOP */
@@ -245,30 +227,6 @@ main(int argc, char **argv)
 {
    Epplet_adjust_priority(10);
 
-   /* check for Kernel 2.6 */
-   FILE               *fp;
-   char                version[8], buff[1024];
-
-   if (!(fp = fopen("/proc/version", "r")))
-     {
-       D(("Failed to open /proc/version -- %s\nWill assume not 2.6 kernel",
-          strerror(errno)));
-       return 1;
-     }
-
-   fgets(buff, sizeof(buff), fp);
-   sscanf(buff, "%*s %*s %s", version);
-
-   if (version[2] == '6')
-     {
-       kernel_2_6 = 1;
-     }
-
-   fclose(fp);
-   /* end check for Kernel 2.6 */
-
-   atexit(Epplet_cleanup);
-
    Epplet_Init("E-MemWatch", "0.1", "Enlightenment RAM/Swap Monitor Epplet", 3,
               3, argc, argv, 0);
    Epplet_load_config();

-- 


Reply via email to