From 0ee3efdc0f71180e58573a8ce6b12b5de81ebe52 Mon Sep 17 00:00:00 2001 From: Brenden Matthews Date: Mon, 31 Mar 2008 03:51:29 +0000 Subject: [PATCH] make diskio accept devices starting with "/dev/" git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@1087 7f574dfc-610e-0410-a909-a81674777703 --- README | 4 ++-- doc/conky.1 | 2 +- src/diskio.c | 36 +++++++++++++++++++++++++++++++++++- src/libmpdclient.c | 8 ++++---- src/libmpdclient.h | 4 ++-- src/linux.c | 2 +- 6 files changed, 45 insertions(+), 11 deletions(-) diff --git a/README b/README index 15b1740..c953003 100644 --- a/README +++ b/README @@ -1348,8 +1348,8 @@ VARIABLES This takes arguments in the form:top (name) (number) Basically, processes are ranked from highest to lowest in terms of cpu us- age, which is what (num) represents. The types are: "name", - "pid", "cpu", "mem", and "time". There can be a max of 10 pro- - cesses listed. + "pid", "cpu", "mem", "mem_res", "mem_vsize", and "time". There + can be a max of 10 processes listed. top_mem type, num diff --git a/doc/conky.1 b/doc/conky.1 index c031a97..b657a72 100644 --- a/doc/conky.1 +++ b/doc/conky.1 @@ -1196,7 +1196,7 @@ Total download, overflows at 4 GB on Linux with 32-bit arch and there doesn't se .TP \fB\*(T<\fBtop\fR\*(T>\fR \*(T<\fBtype, num\fR\*(T> -This takes arguments in the form:top (name) (number) Basically, processes are ranked from highest to lowest in terms of cpu usage, which is what (num) represents. The types are: "name", "pid", "cpu", "mem", and "time". There can be a max of 10 processes listed. +This takes arguments in the form:top (name) (number) Basically, processes are ranked from highest to lowest in terms of cpu usage, which is what (num) represents. The types are: "name", "pid", "cpu", "mem", "mem_res", "mem_vsize", and "time". There can be a max of 10 processes listed. .TP \fB\*(T<\fBtop_mem\fR\*(T>\fR \*(T<\fBtype, num\fR\*(T> diff --git a/src/diskio.c b/src/diskio.c index 15dd30b..0342818 100644 --- a/src/diskio.c +++ b/src/diskio.c @@ -29,6 +29,7 @@ #include "conky.h" #include +#include static struct diskio_stat diskio_stats_[MAX_DISKIO_STATS]; struct diskio_stat *diskio_stats = diskio_stats_; @@ -48,6 +49,10 @@ struct diskio_stat *prepare_diskio_stat(const char *s) { struct diskio_stat *new = 0; 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) { @@ -64,7 +69,36 @@ struct diskio_stat *prepare_diskio_stat(const char *s) ERR("too many diskio stats"); return 0; } - new->dev = strdup(s); + 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 + */ + + if (!(fp = open_file("/proc/diskstats", &rep))) { + ERR("cannot read from /proc/diskstats"); + return 0; + } + + while (!feof(fp)) { + fgets(fbuf, text_buffer_size, fp); + if (sscanf(fbuf, "%*u %*u %255s %*u %*u %*u %*u %*u %*u %*u", device)) { + // check for device match + if (strncmp(new->dev, device, 256) == 0) { + found = 1; + break; + } + } + } + fclose(fp); + fp = 0; + if (!found) { + ERR("diskio device '%s' does not exist", s); + } new->current = 0; new->current_read = 0; new ->current_write = 0; diff --git a/src/libmpdclient.c b/src/libmpdclient.c index 9eb0c05..ba2b822 100644 --- a/src/libmpdclient.c +++ b/src/libmpdclient.c @@ -1652,22 +1652,22 @@ void mpd_sendSwapIdCommand(mpd_Connection *connection, int id1, int id2) free(string); } -void mpd_sendSeekCommand(mpd_Connection *connection, int song, int time) +void mpd_sendSeekCommand(mpd_Connection *connection, int song, int seek_time) { int len = strlen("seek") + 2 + INTLEN + 3 + INTLEN + 3; char *string = malloc(len); - snprintf(string, len, "seek \"%i\" \"%i\"\n", song, time); + snprintf(string, len, "seek \"%i\" \"%i\"\n", song, seek_time); mpd_sendInfoCommand(connection, string); free(string); } -void mpd_sendSeekIdCommand(mpd_Connection *connection, int id, int time) +void mpd_sendSeekIdCommand(mpd_Connection *connection, int id, int seek_time) { int len = strlen("seekid") + 2 + INTLEN + 3 + INTLEN + 3; char *string = malloc(len); - snprintf(string, len, "seekid \"%i\" \"%i\"\n", id, time); + snprintf(string, len, "seekid \"%i\" \"%i\"\n", id, seek_time); mpd_sendInfoCommand(connection, string); free(string); } diff --git a/src/libmpdclient.h b/src/libmpdclient.h index 44b0282..9ae72d2 100644 --- a/src/libmpdclient.h +++ b/src/libmpdclient.h @@ -472,9 +472,9 @@ void mpd_sendSwapCommand(mpd_Connection *connection, int song1, int song2); void mpd_sendSwapIdCommand(mpd_Connection *connection, int song1, int song2); -void mpd_sendSeekCommand(mpd_Connection *connection, int song, int time); +void mpd_sendSeekCommand(mpd_Connection *connection, int song, int seek_time); -void mpd_sendSeekIdCommand(mpd_Connection *connection, int song, int time); +void mpd_sendSeekIdCommand(mpd_Connection *connection, int song, int seek_time); void mpd_sendRepeatCommand(mpd_Connection *connection, int repeatMode); diff --git a/src/linux.c b/src/linux.c index 97f7d2d..d8dd5d1 100644 --- a/src/linux.c +++ b/src/linux.c @@ -2134,7 +2134,7 @@ void update_diskio(void) } for (i = 0; i < MAX_DISKIO_STATS; i++) { if (diskio_stats[i].dev && - strcmp(devbuf, diskio_stats[i].dev) == 0) { + strncmp(devbuf, diskio_stats[i].dev, text_buffer_size) == 0) { diskio_stats[i].current = (reads + writes - diskio_stats[i].last) / 2; diskio_stats[i].current_read = -- 1.7.9.5