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