Disk i/o support on FreeBSD patch.
authorNikos Ntarmos <ntarmos@users.sourceforge.net>
Mon, 16 Mar 2009 01:11:49 +0000 (19:11 -0600)
committerBrenden Matthews <brenden@rty.ca>
Mon, 16 Mar 2009 01:11:49 +0000 (19:11 -0600)
Patch sf.net id #2657227 (thanks Nikos).

ChangeLog
src/conky.c
src/freebsd.c

index 7cf5c45..a55aa72 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
 2009-03-15
        * Added extra newline patch, sf.net id #2638601 (thanks Ali)
+       * Disk i/o support on FreeBSD patch, sf.net id #2657227 (thanks Nikos)
 
 2009-03-07
        * Added alias patch ( sf.net id #2663691 ) changed it to prevent it from
index 963c198..eb0a1d0 100644 (file)
@@ -1321,7 +1321,6 @@ static struct text_object *construct_text_object(const char *s,
                        obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
                        free(buf);
                }
-#if defined(__linux__)
        END OBJ(diskio, INFO_DISKIO)
                obj->data.diskio = prepare_diskio_stat(dev_name(arg));
        END OBJ(diskio_read, INFO_DISKIO)
@@ -1349,7 +1348,6 @@ static struct text_object *construct_text_object(const char *s,
                obj->data.diskio = prepare_diskio_stat(dev_name(buf));
                if (buf)
                        free(buf);
-#endif
        END OBJ(color, 0)
 #ifdef X11
                if (output_methods & TO_X) {
index bf3a59a..d5859d7 100644 (file)
@@ -64,6 +64,8 @@ inline void proc_find_top(struct process **cpu, struct process **mem);
 u_int64_t diskio_prev = 0;
 static short cpu_setup = 0;
 static short diskio_setup = 0;
+static struct diskio_stat diskio_stats_[MAX_DISKIO_STATS];
+struct diskio_stat *diskio_stats = diskio_stats_;
 
 static int getsysctl(char *name, void *ptr, size_t len)
 {
@@ -717,6 +719,66 @@ void update_diskio()
 
 void clear_diskio_stats()
 {
+       unsigned i;
+       for(i = 0; i < MAX_DISKIO_STATS; i++) {
+               if (diskio_stats[i].dev) {
+                       free(diskio_stats[i].dev);
+                       diskio_stats[i].dev = 0;
+               }
+       }
+}
+
+struct diskio_stat *prepare_diskio_stat(const char *s)
+{
+       struct diskio_stat *new = 0;
+       struct stat sb;
+       unsigned i;
+       FILE *fp;
+       int found = 0;
+       char device[text_buffer_size], fbuf[text_buffer_size];
+       static int rep = 0;
+       /* lookup existing or get new */
+       for (i = 0; i < MAX_DISKIO_STATS; i++) {
+               if (diskio_stats[i].dev) {
+                       if (strcmp(diskio_stats[i].dev, s) == 0) {
+                               return &diskio_stats[i];
+                       }
+               } else {
+                       new = &diskio_stats[i];
+                       break;
+               }
+       }
+       /* new dev */
+       if (!new) {
+               ERR("too many diskio stats");
+               return 0;
+       }
+       if (new->dev) {
+               free(new->dev);
+               new->dev = 0;
+       }
+       if (strncmp(s, "/dev/", 5) == 0) {
+               // supplied a /dev/device arg, so cut off the /dev part
+               new->dev = strndup(s + 5, text_buffer_size);
+       } else {
+               new->dev = strndup(s, text_buffer_size);
+       }
+       /*
+        * check that device actually exists
+        */
+       snprintf(device, text_buffer_size, "/dev/%s", new->dev);
+
+       if (stat(device, &sb)) {
+               ERR("diskio device '%s' does not exist", s);
+               return 0;
+       }
+       new->current = 0;
+       new->current_read = 0;
+       new ->current_write = 0;
+       new->last = UINT_MAX;
+       new->last_read = UINT_MAX;
+       new->last_write = UINT_MAX;
+       return new;
 }
 
 /* While topless is obviously better, top is also not bad. */