diff options
Diffstat (limited to '')
-rw-r--r-- | plugin_proc_stat.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/plugin_proc_stat.c b/plugin_proc_stat.c index f7276c4..d3b4815 100644 --- a/plugin_proc_stat.c +++ b/plugin_proc_stat.c @@ -1,4 +1,4 @@ -/* $Id: plugin_proc_stat.c,v 1.15 2004/02/04 19:10:51 reinelt Exp $ +/* $Id: plugin_proc_stat.c,v 1.16 2004/03/03 03:47:04 reinelt Exp $ * * plugin for /proc/stat parsing * @@ -23,6 +23,13 @@ * * * $Log: plugin_proc_stat.c,v $ + * Revision 1.16 2004/03/03 03:47:04 reinelt + * big patch from Martin Hejl: + * - use qprintf() where appropriate + * - save CPU cycles on gettimeofday() + * - add quit() functions to free allocated memory + * - fixed lots of memory leaks + * * Revision 1.15 2004/02/04 19:10:51 reinelt * Crystalfontz driver nearly finished * @@ -97,6 +104,7 @@ #include "debug.h" #include "plugin.h" #include "hash.h" +#include "qprintf.h" static HASH Stat = { 0, }; @@ -111,7 +119,7 @@ static void hash_set2 (char *key1, char *key2, char *val) { char key[32]; - snprintf (key, sizeof(key), "%s.%s", key1, key2); + qprintf(key, sizeof(key), "%s.%s", key1, key2); hash_set1 (key, val); } @@ -120,7 +128,7 @@ static void hash_set3 (char *key1, char *key2, char *key3, char *val) { char key[32]; - snprintf (key, sizeof(key), "%s.%s.%s", key1, key2, key3); + qprintf(key, sizeof(key), "%s.%s.%s", key1, key2, key3); hash_set1 (key, val); } @@ -201,9 +209,9 @@ static int parse_proc_stat (void) while (strchr(delim, *beg)) beg++; if ((end=strpbrk(beg, delim))) *end='\0'; if (i==0) - snprintf(num, sizeof(num), "sum"); + strncpy(num,"sum",sizeof(num)); else - snprintf(num, sizeof(num), "%d", i-1); + qprintf(num, sizeof(num), "%d", i-1); hash_set2 ("intr", num, beg); beg=end?end+1:NULL; } @@ -328,7 +336,7 @@ static void my_disk (RESULT *result, RESULT *arg1, RESULT *arg2, RESULT *arg3) key = R2S(arg2); delay = R2N(arg3); - snprintf (buffer, sizeof(buffer), "disk_io\\.%s\\.%s", dev, key); + qprintf(buffer, sizeof(buffer), "disk_io\\.%s\\.%s", dev, key); value = hash_get_regex(&Stat, buffer, delay); SetResult(&result, R_NUMBER, &value); @@ -342,3 +350,8 @@ int plugin_init_proc_stat (void) AddFunction ("disk", 3, my_disk); return 0; } + +void plugin_exit_proc_stat(void) +{ + hash_destroy(&Stat); +} |