mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-17 10:35:10 +00:00
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
This commit is contained in:
parent
c2c6a63f5a
commit
0ee3efdc0f
4
README
4
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
|
||||
|
@ -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>
|
||||
|
36
src/diskio.c
36
src/diskio.c
@ -29,6 +29,7 @@
|
||||
|
||||
#include "conky.h"
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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 =
|
||||
|
Loading…
Reference in New Issue
Block a user