Fix device name parsing for diskio variables.
[monky] / src / diskio.c
index 147f5f7..d9b2f3f 100644 (file)
@@ -10,7 +10,7 @@
  * Please see COPYING for details
  *
  * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
- * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
+ * Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al.
  * (see AUTHORS)
  * All rights reserved.
  *
@@ -76,12 +76,6 @@ struct diskio_stat *prepare_diskio_stat(const char *s)
        if (!s)
                return &stats;
 
-#if defined(__FreeBSD__)
-       if (strncmp(s, "/dev/", 5) == 0) {
-               // supplied a /dev/device arg, so cut off the /dev part
-               strncpy(device_name, s + 5, text_buffer_size);
-       } else
-#endif
        strncpy(device_name, s, text_buffer_size);
 
        snprintf(stat_name, text_buffer_size, "/dev/%s", device_name);
@@ -119,7 +113,7 @@ void parse_diskio_arg(struct text_object *obj, const char *arg)
  *  0: read + write
  *  1: write
  */
-void print_diskio(struct text_object *obj, int dir, char *p, int p_max_size)
+static void print_diskio_dir(struct text_object *obj, int dir, char *p, int p_max_size)
 {
        struct diskio_stat *diskio = obj->data.opaque;
        double val;
@@ -129,7 +123,7 @@ void print_diskio(struct text_object *obj, int dir, char *p, int p_max_size)
 
        if (dir < 0)
                val = diskio->current_read;
-       if (dir == 0)
+       else if (dir == 0)
                val = diskio->current;
        else
                val = diskio->current_write;
@@ -139,20 +133,33 @@ void print_diskio(struct text_object *obj, int dir, char *p, int p_max_size)
        human_readable((val / update_interval) * 1024LL, p, p_max_size);
 }
 
+void print_diskio(struct text_object *obj, char *p, int p_max_size)
+{
+       print_diskio_dir(obj, 0, p, p_max_size);
+}
+
+void print_diskio_read(struct text_object *obj, char *p, int p_max_size)
+{
+       print_diskio_dir(obj, -1, p, p_max_size);
+}
+
+void print_diskio_write(struct text_object *obj, char *p, int p_max_size)
+{
+       print_diskio_dir(obj, 1, p, p_max_size);
+}
+
 #ifdef X11
 void parse_diskiograph_arg(struct text_object *obj, const char *arg)
 {
        char *buf = 0;
-       SIZE_DEFAULTS(graph);
-       buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
-                       &obj->e, &obj->char_a, &obj->char_b);
+       buf = scan_graph(obj, arg, 0);
 
        obj->data.opaque = prepare_diskio_stat(dev_name(buf));
        if (buf)
                free(buf);
 }
 
-void print_diskiograph(struct text_object *obj, int dir, char *p)
+static void print_diskiograph_dir(struct text_object *obj, int dir, char *p, int p_max_size)
 {
        struct diskio_stat *diskio = obj->data.opaque;
        double val;
@@ -160,6 +167,9 @@ void print_diskiograph(struct text_object *obj, int dir, char *p)
        if (!diskio)
                return;
 
+       if (!p_max_size)
+               return;
+
        if (dir < 0)
                val = diskio->current_read;
        else if (dir == 0)
@@ -167,8 +177,22 @@ void print_diskiograph(struct text_object *obj, int dir, char *p)
        else
                val = diskio->current_write;
 
-       new_graph(p, obj->a, obj->b, obj->c, obj->d,
-                       val, obj->e, 1, obj->char_a, obj->char_b);
+       new_graph(obj, p, p_max_size, val);
+}
+
+void print_diskiograph(struct text_object *obj, char *p, int p_max_size)
+{
+       print_diskiograph_dir(obj, 0, p, p_max_size);
+}
+
+void print_diskiograph_read(struct text_object *obj, char *p, int p_max_size)
+{
+       print_diskiograph_dir(obj, -1, p, p_max_size);
+}
+
+void print_diskiograph_write(struct text_object *obj, char *p, int p_max_size)
+{
+       print_diskiograph_dir(obj, 1, p, p_max_size);
 }
 #endif /* X11 */
 
@@ -184,7 +208,7 @@ void update_diskio_values(struct diskio_stat *ds,
                ds->last_read = reads;
                ds->last_write = writes;
        }
-       /* since the values in /proc/diskstats are absolute, we have to substract
+       /* since the values in /proc/diskstats are absolute, we have to subtract
         * our last reading. The numbers stand for "sectors read", and we therefore
         * have to divide by two to get KB */
        ds->sample_read[0] = (reads - ds->last_read) / 2;