1 --- wmmon-1.0b2.orig/wmgeneral/wmgeneral.c
2 +++ wmmon-1.0b2/wmgeneral/wmgeneral.c
7 + 10/10/2003 (Simon Law, sfllaw@debian.org)
8 + * changed the parse_rcfile function to use getline instead of fgets.
9 02/05/1998 (Martijn Pieterse, pieterse@xs4all.nl)
10 * changed the read_rc_file to parse_rcfile, as suggester by Marcelo E. Magallon
11 * debugged the parse_rc file.
21 void parse_rcfile(const char *filename, rckeys *keys) {
26 + size_t line_size = 0;
27 char *tokens = " :\t\n";
31 fp = fopen(filename, "r");
33 - while (fgets(temp, 128, fp)) {
34 + while (getline(&line, &line_size, fp) >= 0) {
36 while (key >= 0 && keys[key].label) {
37 - if ((p = strstr(temp, keys[key].label))) {
38 + if ((p = strstr(line, keys[key].label))) {
39 p += strlen(keys[key].label);
40 p += strspn(p, tokens);
41 if ((i = strcspn(p, "#\n"))) p[i] = 0;
43 unsigned int borderwidth = 1;
45 char *display_name = NULL;
46 + char *geometry = NULL;
47 char *wname = argv[0];
52 for (i=1; argv[i]; i++) {
53 if (!strcmp(argv[i], "-display"))
54 - display_name = argv[i+1];
55 + display_name = argv[++i];
56 + else if (!strcmp(argv[i], "-geometry"))
57 + geometry = argv[++i];
60 if (!(display = XOpenDisplay(display_name))) {
62 fore_pix = GetColor("black");
64 XWMGeometry(display, screen, Geometry, NULL, borderwidth, &mysizehints,
65 - &mysizehints.x, &mysizehints.y,&mysizehints.width,&mysizehints.height, &dummy);
66 + &mysizehints.x, &mysizehints.y,
67 + &mysizehints.width, &mysizehints.height, &dummy);
69 + XParseGeometry(geometry, &mysizehints.x, &mysizehints.y,
70 + &mysizehints.width, &mysizehints.height);
72 mysizehints.width = 64;
73 mysizehints.height = 64;
75 XMapWindow(display, win);
79 +/* vim: sw=4 ts=4 columns=82
81 --- wmmon-1.0b2.orig/wmmon/wmmon.c
82 +++ wmmon-1.0b2/wmmon/wmmon.c
87 + 23/10/2003 (Simon Law, sfllaw@debian.org)
88 + * Eliminated exploitable static buffers
89 + * Added -geometry support.
90 + * /proc/meminfo support for Linux 2.6
91 18/05/1998 (Antoine Nulle, warp@xs4all.nl)
92 * MEM/SWAP/UPTIME only updated when visible
93 * Using global file descriptors to reduce file
95 * First Working Version
102 @@ -100,31 +105,27 @@
103 /* Global Variables */
104 /********************/
107 int stat_current = 0; /* now global */
115 void printversion(void);
116 void DrawStats(int *, int, int, int, int);
117 void DrawStats_io(int *, int, int, int, int);
119 void wmmon_routine(int, char **);
121 -void main(int argc, char *argv[]) {
122 +int main(int argc, char *argv[]) {
125 + char *name = argv[0];
128 /* Parse Command Line */
130 - ProgName = argv[0];
131 - if (strlen(ProgName) >= 5)
132 - ProgName += (strlen(ProgName) - 5);
134 for (i=1; i<argc; i++) {
137 @@ -132,29 +133,35 @@
140 if (strcmp(arg+1, "display")) {
152 + if (strcmp(arg+1, "geometry")) {
175 wmmon_routine(argc, argv);
181 /*******************************************************************************\
188 + char *conffile = NULL;
190 int xpm_X = 0, xpm_Y = 0;
192 @@ -246,16 +252,21 @@
193 if (RIGHT_ACTION) right_action = strdup(RIGHT_ACTION);
194 if (MIDDLE_ACTION) middle_action = strdup(MIDDLE_ACTION);
196 - strcpy(temp, "/etc/wmmonrc");
197 - parse_rcfile(temp, wmmon_keys);
198 + /* Scan through the .rc files */
199 + if (asprintf(&conffile, "/etc/wmmonrc") >= 0) {
200 + parse_rcfile(conffile, wmmon_keys);
204 - p = getenv("HOME");
206 - strcat(temp, "/.wmmonrc");
207 - parse_rcfile(temp, wmmon_keys);
209 - strcpy(temp, "/etc/wmmonrc.fixed");
210 - parse_rcfile(temp, wmmon_keys);
211 + if (asprintf(&conffile, "%s/.wmmonrc", getenv("HOME")) >= 0) {
212 + parse_rcfile(conffile, wmmon_keys);
216 + if (asprintf(&conffile, "/etc/wmmonrc.fixed") >= 0) {
217 + parse_rcfile(conffile, wmmon_keys);
221 stat_online = checksysdevs();
223 @@ -269,26 +280,36 @@
225 nexttime = starttime + 10;
227 + /* Collect information on each panel */
228 for (i=0; i<stat_online; i++) {
229 get_statistics(stat_device[i].name, &k, &istat, &idle);
230 stat_device[i].statlast = istat;
231 stat_device[i].idlelast = idle;
233 - if (stat_current == 0) DrawStats(stat_device[stat_current].his, 54, 40, 5, 58);
234 - if (stat_current == 1) {
235 - DrawStats_io(stat_device[stat_current].his, 54, 40, 5, 58);
237 - if (stat_current == 2) {
244 + /* Set the mask for the current window */
245 + switch (stat_current) {
258 + /* Draw statistics */
259 + if (stat_current == 0)
260 + DrawStats(stat_device[stat_current].his, 54, 40, 5, 58);
261 + if (stat_current == 1)
262 + DrawStats_io(stat_device[stat_current].his, 54, 40, 5, 58);
263 DrawActive(stat_device[stat_current].name);
267 + curtime = time(NULL);
269 waitpid(0, NULL, WNOHANG);
272 if (curtime >= nexttime) {
275 + if (curtime > nexttime) /* dont let APM suspends make this crazy */
276 + nexttime = curtime;
278 for (i=0; i<stat_online; i++) {
279 if (stat_device[i].his[54])
280 stat_device[i].his[54] /= stat_device[i].hisaddcnt;
285 - printf("current stat is :%d\n", stat_current);
286 if (stat_current == stat_online)
289 @@ -499,43 +522,80 @@
291 void update_stat_mem(stat_dev *st, stat_dev *st2) {
294 + static char *line = NULL;
295 + static size_t line_size = 0;
297 + unsigned long swapfree;
298 unsigned long free, shared, buffers, cached;
300 freopen("/proc/meminfo", "r", fp_meminfo);
301 - while (fgets(temp, 128, fp_meminfo)) {
302 - if (strstr(temp, "Mem:")) {
303 - sscanf(temp, "Mem: %ld %ld %ld %ld %ld %ld",
304 - &st->rt_idle, &st->rt_stat,
305 - &free, &shared, &buffers, &cached);
306 - st->rt_idle >>= 10;
307 - st->rt_stat -= buffers+cached;
308 - st->rt_stat >>= 10;
311 - if (strstr(temp, "Swap:")) {
312 - sscanf(temp, "Swap: %ld %ld", &st2->rt_idle, &st2->rt_stat);
313 - st2->rt_idle >>= 10;
314 - st2->rt_stat >>= 10;
316 + while ((getline(&line, &line_size, fp_meminfo)) > 0) {
317 + /* The original format for the first two lines of /proc/meminfo was
318 + * Mem: total used free shared buffers cached
319 + * Swap: total used free
321 + * As of at least 2.5.47 these two lines were removed, so that the
322 + * required information has to come from the rest of the lines.
323 + * On top of that, used is no longer recorded - you have to work
324 + * this out yourself, from total - free.
326 + * So, these changes below should work. They should also work with
327 + * older kernels, too, since the new format has been available for
330 + if (strstr(line, "MemTotal:")) {
331 + sscanf(line, "MemTotal: %ld", &st->rt_idle);
333 + else if (strstr(line, "MemFree:")) {
334 + sscanf(line, "MemFree: %ld", &free);
336 + else if (strstr(line, "MemShared:")) {
337 + sscanf(line, "MemShared: %ld", &shared);
339 + else if (strstr(line, "Buffers:")) {
340 + sscanf(line, "Buffers: %ld", &buffers);
342 + else if (strstr(line, "Cached:")) {
343 + sscanf(line, "Cached: %ld", &cached);
345 + else if (strstr(line, "SwapTotal:")) {
346 + sscanf(line, "SwapTotal: %ld", &st2->rt_idle);
348 + else if (strstr(line, "SwapFree:")) {
349 + sscanf(line, "SwapFree: %ld", &swapfree);
353 + /* memory use - rt_stat is the amount used, it seems, and this isn't
354 + * recorded in current version of /proc/meminfo (as of 2.5.47), so we
355 + * calculate it from MemTotal - MemFree
357 + st->rt_stat = st->rt_idle - free;
358 + st->rt_stat -= buffers+cached;
359 + /* As with the amount of memory used, it's not recorded any more, so
360 + * we have to calculate it ourselves.
362 + st2->rt_stat = st2->rt_idle - swapfree;
365 void update_stat_swp(stat_dev *st) {
368 + static char *line = NULL;
369 + static size_t line_size = 0;
370 + unsigned long swapfree;
372 fseek(fp_meminfo, 0, SEEK_SET);
373 - while (fgets(temp, 128, fp_meminfo)) {
374 - if (strstr(temp, "Swap:")) {
375 - sscanf(temp, "Swap: %ld %ld", &st->rt_idle, &st->rt_stat);
376 - st->rt_idle >>= 10;
377 - st->rt_stat >>= 10;
379 + while ((getline(&line, &line_size, fp_meminfo)) > 0) {
380 + /* As with update_stat_mem(), the format change to /proc/meminfo has
381 + * forced some changes here. */
382 + if (strstr(line, "SwapTotal:")) {
383 + sscanf(line, "SwapTotal: %ld", &st->rt_idle);
385 + else if (strstr(line, "SwapFree:")) {
386 + sscanf(line, "SwapFree: %ld", &swapfree);
390 + st->rt_stat = st->rt_idle - swapfree;
393 /*******************************************************************************\
394 @@ -545,11 +605,11 @@
395 void get_statistics(char *devname, long *is, long *ds, long *idle) {
399 + static char *line = NULL;
400 + static size_t line_size = 0;
402 char *tokens = " \t\n";
410 if (!strncmp(devname, "cpu", 3)) {
411 fseek(fp_stat, 0, SEEK_SET);
412 - while (fgets(temp, 128, fp_stat)) {
413 - if (strstr(temp, "cpu")) {
414 - p = strtok(temp, tokens);
415 + while ((getline(&line, &line_size, fp_stat)) > 0) {
416 + if (strstr(line, "cpu ")) {
417 + p = strtok(line, tokens);
418 /* 1..3, 4 == idle, we don't want idle! */
419 for (i=0; i<3; i++) {
420 p = strtok(NULL, tokens);
421 @@ -577,17 +637,35 @@
422 if (!strncmp(devname, "i/o", 3)) {
424 fseek(fp_stat, 0, SEEK_SET);
425 - while (fgets(temp, 128, fp_stat)) {
426 - if (strstr(temp, "disk_rio") || strstr(temp, "disk_wio")) {
427 - p = strtok(temp, tokens);
428 + while ((getline(&line, &line_size, fp_stat)) > 0) {
429 + if (strstr(line, "disk_rio") || strstr(line, "disk_wio")) {
430 + p = strtok(line, tokens);
432 for (i=0; i<4; i++) {
433 p = strtok(NULL, tokens);
437 + else if (strstr(line, "disk_io")) {
439 + unsigned int a, b, c, d, e, h, g;
441 + p = strtok(line, tokens);
443 + while ((p = strtok(NULL, tokens))) {
445 + "(%d,%d):(%d,%d,%d,%d,%d)",
446 + &a, &b, &c, &d, &e, &h,
457 - if (*ds > maxdiskio) maxdiskio = *ds;
461 @@ -715,16 +793,16 @@
463 \*******************************************************************************/
467 - fprintf(stderr, "\nwmmon - programming: tijno, (de)bugging & design warp, webhosting: bobby\n\n");
468 - fprintf(stderr, "usage:\n");
469 - fprintf(stderr, "\t-display <display name>\n");
470 - fprintf(stderr, "\t-h\tthis screen\n");
471 - fprintf(stderr, "\t-v\tprint the version number\n");
472 - fprintf(stderr, "\t-i\tstartup in DiskIO mode\n");
473 - fprintf(stderr, "\t-s\tstartup in SysInfo mode\n");
474 - fprintf(stderr, "\n");
475 +void usage(char *name) {
476 + printf("Usage: %s [OPTION]...\n", name);
477 + printf("WindowMaker dockapp that displays system information.\n");
479 + printf(" -display DISPLAY contact the DISPLAY X server\n");
480 + printf(" -geometry GEOMETRY position the clock at GEOMETRY\n");
481 + printf(" -i start in Disk I/O mode\n");
482 + printf(" -s start in System Info mode\n");
483 + printf(" -h display this help and exit\n");
484 + printf(" -v output version information and exit\n");
487 /*******************************************************************************\
490 void printversion(void) {
492 - if (!strcmp(ProgName, "wmmon")) {
493 - fprintf(stderr, "%s\n", WMMON_VERSION);
495 + printf("WMMon version %s\n", WMMON_VERSION);
497 +/* vim: sw=4 ts=4 columns=82
499 --- wmmon-1.0b2.orig/wmmon/wmmon.1
500 +++ wmmon-1.0b2/wmmon/wmmon.1
503 +.\" Man page for wmmon
504 +.\" Copyright (c) 2003 Software in the Public Interest, Inc.
506 +.\" This program is free software; you can redistribute it and/or modify
507 +.\" it under the terms of the GNU General Public License as published by
508 +.\" the Free Software Foundation; either version 2 of the License, or (at
509 +.\" your option) any later version.
511 +.\" This program is distributed in the hope that it will be useful, but
512 +.\" WITHOUT ANY WARRANTY; without even the implied warranty of
513 +.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
514 +.\" General Public License for more details.
516 +.\" You should have received a copy of the GNU General Public License
517 +.\" along with this program; if not, write to the Free Software
518 +.\" Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
520 +.TH wmmon 1 "May 1998" "WMMON 1.0b2"
523 +wmmon \- Window Maker dockapp for monitoring system information
535 +monitors the realtime CPU load as well as the average system load,
536 +and gives you some nice additional features too. It is intended for
537 +docking in Window Maker.
539 +It currently provides:
542 +a realtime CPU stress meter;
544 +an auto\-scaled average system load meter, like
549 +a realtime disk I/O stress meter;
551 +auto\-scaled disk I/O load meter;
553 +realtime memory and swap usage meters;
555 +a display for system uptime;
557 +three user\-defined commands to launch.
562 +.BI \-display \ display
563 +This option specifies the X server to contact; see
567 +.BI \-geometry \ geometry
568 +This option specifies the preferred position of clock; see
573 +start in disk I/O mode, which displays instantaneous disk usage and
578 +start in system information mode, which displays memory usage, swap usage,
583 +Show help information.
587 +Print the version number.
592 +display can be cycled between CPU, disk I/O, and system
593 +information displays by clicking on the upper\-left widget. This
594 +displays CPU information by default.
596 +WMMon can also be used to launch programs. You may click either left,
597 +middle, or right mouse buttons in the average\-load section of the
598 +window. The pre\-configured program will be launched according to the
599 +mouse button clicked. (see
600 +.B CONFIGURATION FILE
605 +drag on the outer edges. These are not sensitive to mouse clicks.
607 +.SH "DOCKING IN WINDOW MANAGERS"
612 +Window Maker users should drag and drop the
614 +window on the Dock. Then, right\-click on the border of the window and
615 +select \*(lqSettings...\*(rq. Check \*(lqStart when Window Maker
621 +AfterStep users should put the following in their
625 +Wharf wmmon \- MaxSwallow "wmmon" wmmon &
629 +Other window managers
632 +runs nicely as a 64x64 shaped icon on your desktop.
634 +.SH "CONFIGURATION FILE"
637 +can launch three user\-defined commands, triggered by left, middle and
638 +right mouse button clicks. You can define the commands to launch in
656 +file, it will launch the appropriate command when you click on the clock.
658 +The system administrator can define default commands in
660 +The administrator may also choose to \*(lqfix\*(rq particular commands,
661 +making it impossible for users to change. These commands can be defined in
662 +.IR /etc/wmmonrc.fixed ,
663 +although this isn't a nice thing to do.
671 +.I /etc/wmmonrc.fixed
676 +was written by Martijn Pieterse and Antoine Nulle.
678 +This manual page was written by Simon Law <sfllaw@debian.org> for the
680 +system (but may be used by others). It is based on the documentation provided
681 +by the original program.
683 +This manual is free software; you can redistribute it and/or modify
684 +it under the terms of the GNU General Public License as published by
685 +the Free Software Foundation; either version 2 of the License, or (at
686 +your option) any later version.