[Pkg-wmaker-commits] [wmbubble] 02/207: Adds support for parsing memory on machines newer than 2.4 (from debian)
Doug Torrance
dtorrance-guest at moszumanska.debian.org
Mon Aug 24 04:17:46 UTC 2015
This is an automated email from the git hooks/post-receive script.
dtorrance-guest pushed a commit to branch master
in repository wmbubble.
commit 575eabbd6c37eb34b2ded930c3fafa79af72795f
Author: Robert Jacobs <rnjacobs at mit.edu>
Date: Mon Aug 29 19:09:02 2011 -0700
Adds support for parsing memory on machines newer than 2.4 (from debian)
---
Makefile | 1 -
bubblemon.c | 6 +--
sys_linux.c | 141 ++++++++++++++++++++++++++++++++++++------------------------
3 files changed, 88 insertions(+), 60 deletions(-)
diff --git a/Makefile b/Makefile
index 1396075..0672355 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,6 @@
EXTRA = -DENABLE_DUCK
EXTRA += -DENABLE_CPU
EXTRA += -DENABLE_MEMSCREEN
-EXTRA += -DKERNEL_26
# EXTRA += -DKDE_DOCKAPP
# EXTRA += -DUPSIDE_DOWN_DUCK
diff --git a/bubblemon.c b/bubblemon.c
index c0679c1..89cdee7 100644
--- a/bubblemon.c
+++ b/bubblemon.c
@@ -106,8 +106,8 @@ static int animate_correctly(void);
static void duck_set(int x, int y, int nr, int rev, int upsidedown);
static void duck_swimmer(int posy);
#endif
-#ifdef __FreeBSD__
-extern int init_stuff(); /* defined in sys_freebsd.c */
+#if defined(__FreeBSD__) || defined(__linux__)
+extern int init_stuff(); /* defined in sys_{freebsd,linux}.c */
#endif
/* local prototypes end *INDENT-ON* */
@@ -392,7 +392,7 @@ int main(int argc, char **argv)
/* zero data structure */
memset(&bm, 0, sizeof(bm));
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__linux__)
if (init_stuff())
exit(-1);
#endif
diff --git a/sys_linux.c b/sys_linux.c
index 0aaeb7a..f17f5f3 100644
--- a/sys_linux.c
+++ b/sys_linux.c
@@ -19,11 +19,43 @@
#include <stdio.h>
#include <string.h>
+#include <sys/utsname.h>
#include "include/bubblemon.h"
#include "include/sys_include.h"
extern BubbleMonData bm;
+#define LINUX_2_4 1
+#define LINUX_2_6 2
+
+static unsigned char ver;
+
+int init_stuff()
+{
+ struct utsname u;
+
+ ver = 0;
+
+ if (uname(&u) == -1) {
+ puts("Error getting kernel version: uname returned -1");
+ return 1;
+ }
+
+ if (strncmp(u.release, "2.4", 3) == 0) {
+ ver = LINUX_2_4;
+ } else if ((strncmp(u.release, "2.5", 3) == 0) ||
+ (strncmp(u.release, "2.6", 3) == 0)) {
+ ver = LINUX_2_6;
+ }
+
+ if (!ver) {
+ /* Default to Linux 2.4 format. */
+ ver = LINUX_2_4;
+ }
+
+ return 0;
+}
+
/* returns current CPU load in percent, 0 to 100 */
int system_cpu(void)
{
@@ -73,84 +105,81 @@ int system_memory(void)
{
u_int64_t my_mem_used, my_mem_max;
u_int64_t my_swap_used, my_swap_max;
-#ifdef KERNEL_26
char *p;
-#endif
static int mem_delay = 0;
FILE *mem;
static u_int64_t aa, ab, ac, ad;
-#ifndef KERNEL_26
static u_int64_t ae, af, ag, ah;
-#endif
+
/* put this in permanent storage instead of stack */
static char shit[2048];
/* we might as well get both swap and memory at the same time.
* sure beats opening the same file twice */
if (mem_delay-- <= 0) {
-#ifdef KERNEL_26
- mem = fopen("/proc/meminfo", "r");
- memset(shit, 0, sizeof(shit));
- fread(shit, 2048, 1, mem);
- p = strstr(shit, "MemTotal");
- if (p) {
- sscanf(p, "MemTotal:%Ld", &aa);
- my_mem_max = aa << 10;
-
- p = strstr(p, "Active");
+ if (ver == LINUX_2_6) {
+ mem = fopen("/proc/meminfo", "r");
+ memset(shit, 0, sizeof(shit));
+ fread(shit, 2048, 1, mem);
+ p = strstr(shit, "MemTotal");
if (p) {
- sscanf(p, "Active:%Ld", &ab);
- my_mem_used = ab << 10;
+ sscanf(p, "MemTotal:%Ld", &aa);
+ my_mem_max = aa << 10;
- p = strstr(p, "SwapTotal");
+ p = strstr(p, "Active");
if (p) {
- sscanf(p, "SwapTotal:%Ld", &ac);
- my_swap_max = ac << 10;
+ sscanf(p, "Active:%Ld", &ab);
+ my_mem_used = ab << 10;
- p = strstr(p, "SwapFree");
+ p = strstr(p, "SwapTotal");
if (p) {
- sscanf(p, "SwapFree:%Ld", &ad);
- my_swap_used = my_swap_max - (ad << 10);
-
- bm.mem_used = my_mem_used;
- bm.mem_max = my_mem_max;
- bm.swap_used = my_swap_used;
- bm.swap_max = my_swap_max;
+ sscanf(p, "SwapTotal:%Ld", &ac);
+ my_swap_max = ac << 10;
+
+ p = strstr(p, "SwapFree");
+ if (p) {
+ sscanf(p, "SwapFree:%Ld", &ad);
+ my_swap_used = my_swap_max - (ad << 10);
+
+ bm.mem_used = my_mem_used;
+ bm.mem_max = my_mem_max;
+ bm.swap_used = my_swap_used;
+ bm.swap_max = my_swap_max;
+ }
}
}
}
- }
- fclose(mem);
- mem_delay = 25;
-#else
- mem = fopen("/proc/meminfo", "r");
- fgets(shit, 2048, mem);
+ fclose(mem);
+ mem_delay = 25;
+ } else if (ver == LINUX_2_4) {
+ mem = fopen("/proc/meminfo", "r");
+ fgets(shit, 2048, mem);
- fscanf(mem, "%*s %Ld %Ld %Ld %Ld %Ld %Ld", &aa, &ab, &ac,
- &ad, &ae, &af);
- fscanf(mem, "%*s %Ld %Ld", &ag, &ah);
- fclose(mem);
- mem_delay = 25;
-
- /* calculate it */
- my_mem_max = aa; /* memory.total; */
- my_swap_max = ag; /* swap.total; */
-
- my_mem_used = ah + ab - af - ae; /* swap.used + memory.used - memory.cached - memory.buffer; */
-
- if (my_mem_used > my_mem_max) {
- my_swap_used = my_mem_used - my_mem_max;
- my_mem_used = my_mem_max;
- } else {
- my_swap_used = 0;
- }
+ fscanf(mem, "%*s %Ld %Ld %Ld %Ld %Ld %Ld", &aa, &ab, &ac,
+ &ad, &ae, &af);
+ fscanf(mem, "%*s %Ld %Ld", &ag, &ah);
+ fclose(mem);
+ mem_delay = 25;
+
+ /* calculate it */
+ my_mem_max = aa; /* memory.total; */
+ my_swap_max = ag; /* swap.total; */
+
+ my_mem_used = ah + ab - af - ae; /* swap.used + memory.used - memory.cached - memory.buffer; */
+
+ if (my_mem_used > my_mem_max) {
+ my_swap_used = my_mem_used - my_mem_max;
+ my_mem_used = my_mem_max;
+ } else {
+ my_swap_used = 0;
+ }
- bm.mem_used = my_mem_used;
- bm.mem_max = my_mem_max;
- bm.swap_used = my_swap_used;
- bm.swap_max = my_swap_max;
-#endif
+ bm.mem_used = my_mem_used;
+ bm.mem_max = my_mem_max;
+ bm.swap_used = my_swap_used;
+ bm.swap_max = my_swap_max;
+ }
/* memory info changed - update things */
return 1;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-wmaker/wmbubble.git
More information about the Pkg-wmaker-commits
mailing list