summaryrefslogtreecommitdiff
path: root/recipes/matchbox-panel/matchbox-panel-0.9.2/system-monitor-crash-fix.patch
blob: 51c141db0370e4f13ad25ffadf04b6933a7b2a43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
--- matchbox-panel-0.9.2/applets/mb-applet-system-monitor.c.orig	2006-02-07 20:08:09.000000000 +0200
+++ matchbox-panel-0.9.2/applets/mb-applet-system-monitor.c	2006-02-07 20:53:20.000000000 +0200
@@ -37,6 +37,7 @@
 # define _(text) (text)
 #endif
 
+
 #ifdef MB_HAVE_PNG
 #define IMG_EXT "png"
 #else
@@ -66,8 +67,30 @@
 MBPixbufImage *ImgIcon = NULL, *ImgIconScaled = NULL, *ImgGraph = NULL;
 
 int GraphHeight = 0, GraphWidth = 0;
-
 char *ThemeName;
+static int kernelver = 0;
+
+/* returns 1 if the kernel version is 2.6, 0 otherwise */
+int kernel_version(void)
+{
+    float v_nr=0;
+    FILE *version;
+
+    if ((version = fopen("/proc/version", "r")) == NULL)
+      {
+        fprintf(stderr, "mb-applet-system-monitor: failed to open /proc/version. Exiting\n");
+        exit(1);
+      }
+    fscanf(version, "%*s %*s %f", &v_nr);
+    fclose(version);
+
+    if (v_nr > 2.5)
+	return 1;
+   else
+	return 0;	
+}
+
+
 
 /* returns current CPU load in percent, 0 to 100 */
 int system_cpu(void)
@@ -112,71 +135,86 @@
 
 int system_memory(void)
 {
-    u_int64_t my_mem_used, my_mem_max;
-    u_int64_t my_swap_max;
-
-    static int mem_delay = 0;
-    FILE *mem;
-    static u_int64_t total, used, mfree, shared, buffers, cached,
-      cache_total, cache_used;
-
-    /* put this in permanent storage instead of stack */
-    static char not_needed[2048];
-
-    if (mem_delay-- <= 0) {
-      if ((mem = fopen("/proc/meminfo", "r")) == NULL)
+  u_int64_t  total, mfree, buffers, cached, used, shared,
+    cache_total, cache_free, cache_used, uneeded = 0;
+  
+  u_int64_t my_mem_used, my_mem_max;
+  u_int64_t my_swap_max;
+  
+  static int mem_delay = 0;
+  FILE      *mem;
+  
+  /* put this in permanent storage instead of stack */
+  static char not_needed[2048];
+  
+  if (mem_delay-- <= 0) 
+    {
+      if ((mem = fopen("/proc/meminfo", "r")) == NULL) 
 	{
 	  fprintf(stderr, "mb-applet-system-monitor: failed to open /proc/meminfo. Exiting.\n");
 	  exit(1);
-      }
-
-
-
-	fgets(not_needed, 2048, mem);
-	
-	/* 
-	    total:    used:    free:  shared: buffers:  cached:
-	*/
-
-	fscanf(mem, "%*s %Ld %Ld %Ld %Ld %Ld %Ld", &total, &used, &mfree,
-	       &shared, &buffers, &cached);
-
-	fscanf(mem, "%*s %Ld %Ld", &cache_total, &cache_used);
-
-	fclose(mem);
-	mem_delay = 25;
-
-	/* calculate it */
-	my_mem_max = total;
-	my_swap_max = cache_total;
-
-	my_mem_used = cache_used + used - cached - buffers;
-
-	/* No swap on ipaq 
-	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;
 	}
-	*/
-	
-	msd.mem_used = my_mem_used;
-	msd.mem_max = my_mem_max;
-	//msd.swap_used = my_swap_used;
-	//msd.swap_max = my_swap_max;
+      
+      fgets(not_needed, 2048, mem);
 
-	msd.mem_percent = (100 * msd.mem_used) / msd.mem_max;
-	//msd.swap_percent = (100 * msd.swap_used) / msd.swap_max;
+/*if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)*/
 
-	/* memory info changed - update things */
-	return 1;
-	}
-    /* nothing new */
-    return 0;
+   if(kernelver)
+     {    
+      rewind (mem);
+      
+      fscanf (mem, "%*s %Ld %*s", &total);
+      fscanf (mem, "%*s %Ld %*s", &mfree);
+      fscanf (mem, "%*s %Ld %*s", &buffers);
+      fscanf (mem, "%*s %Ld %*s", &cached);
+      fscanf (mem, "%*s %Ld %*s", &shared);
+      fscanf (mem, "%*s %Ld %*s", &used);
+      fscanf (mem, "%*s %Ld %*s", &uneeded);
+      fscanf (mem, "%*s %Ld %*s", &uneeded);
+      fscanf (mem, "%*s %Ld %*s", &uneeded);
+      fscanf (mem, "%*s %Ld %*s", &uneeded);
+      fscanf (mem, "%*s %Ld %*s", &uneeded);
+      fscanf (mem, "%*s %Ld %*s", &cache_total);
+      fscanf (mem, "%*s %Ld %*s", &cache_free);
+      
+      total = total * 1024;
+      mfree = mfree * 1024;
+      buffers = buffers * 1024;
+      cached = cached * 1024;
+      used = used * 1024;
+      shared = shared * 1024;
+      cache_total = cache_total * 1024;
+      cache_used = cache_total - (cache_free * 1024);
+     }
+else
+     {
+      /*
+	total:    used:    free:  shared: buffers:  cached:
+      */
+      fscanf(mem, "%*s %Ld %Ld %Ld %Ld %Ld %Ld", &total, &used, &mfree,
+	     &shared, &buffers, &cached);
+      fscanf(mem, "%*s %Ld %Ld", &cache_total, &cache_used);
+     } 
+      
+      fclose(mem);
+      
+      mem_delay = 25;
+      
+      /* calculate it */
+      my_mem_max      = total;
+      my_swap_max     = cache_total;
+      my_mem_used     = cache_used + used - cached - buffers;
+      msd.mem_used    = my_mem_used;
+      msd.mem_max     = my_mem_max;
+      msd.mem_percent = (100 * msd.mem_used) / msd.mem_max;
+
+    /* memory info changed - update things */
+    return 1;
+  }
+  /* nothing new */
+  return 0;
 }
 
-
 void
 paint_callback (MBTrayApp *app, Drawable drw )
 {
@@ -340,6 +378,8 @@
 			  &argc,
 			  &argv );  
 
+   kernelver = kernel_version();
+
    msd.samples = 16;
    
    if (msd.load) {