diff options
author | Helmut Grohne <helmut@subdivi.de> | 2009-01-23 12:56:20 +0000 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2009-01-23 12:56:20 +0000 |
commit | cea149b541f802d28b3a5b0cfa00441d3ac1f0e3 (patch) | |
tree | 1f5a91d5242e29f9c766c39fa7d2d0ed2f0a1fef | |
parent | 84194373370b46a346231c1762c038cc683abc45 (diff) | |
download | munin-plugins-busybox-cea149b541f802d28b3a5b0cfa00441d3ac1f0e3.tar.gz |
made more paths be macros
-rw-r--r-- | entropy.c | 8 | ||||
-rw-r--r-- | fw_packets.c | 12 | ||||
-rw-r--r-- | load.c | 8 | ||||
-rw-r--r-- | open_files.c | 26 | ||||
-rw-r--r-- | open_inodes.c | 12 |
5 files changed, 40 insertions, 26 deletions
@@ -2,6 +2,8 @@ #include <stdio.h> #include "common.h" +#define ENTROPY_AVAIL "/proc/sys/kernel/random/entropy_avail" + int entropy(int argc, char **argv) { FILE *f; int entropy; @@ -20,12 +22,12 @@ int entropy(int argc, char **argv) { if(!strcmp(argv[1], "autoconf")) return writeyes(); } - if(!(f=fopen("/proc/sys/kernel/random/entropy_avail", "r"))) { - fputs("cannot open /proc/sys/kernel/random/entropy_avail\n", stderr); + if(!(f=fopen(ENTROPY_AVAIL, "r"))) { + fputs("cannot open " ENTROPY_AVAIL "\n", stderr); return 1; } if(1 != fscanf(f, "%d", &entropy)) { - fputs("cannot read from /proc/sys/kernel/random/entropy_avail\n", stderr); + fputs("cannot read from " ENTROPY_AVAIL "\n", stderr); fclose(f); return 1; } diff --git a/fw_packets.c b/fw_packets.c index 06367dd..8e94fde 100644 --- a/fw_packets.c +++ b/fw_packets.c @@ -4,6 +4,8 @@ #include <ctype.h> #include "common.h" +#define PROC_NET_SNMP "/proc/net/snmp" + int fw_packets(int argc, char **argv) { FILE *f; char buff[1024], *s; @@ -24,14 +26,14 @@ int fw_packets(int argc, char **argv) { return 0; } if(!strcmp(argv[1], "autoconf")) { - if(0 == access("/proc/net/snmp", R_OK)) + if(0 == access(PROC_NET_SNMP, R_OK)) return writeyes(); else - return writeno("/proc/net/snmp not readable"); + return writeno(PROC_NET_SNMP " not readable"); } } - if(!(f=fopen("/proc/net/snmp", "r"))) { - fputs("cannot open /proc/net/snmp\n", stderr); + if(!(f=fopen(PROC_NET_SNMP, "r"))) { + fputs("cannot open " PROC_NET_SNMP "\n", stderr); return 1; } while(fgets(buff, 1024, f)) { @@ -55,6 +57,6 @@ int fw_packets(int argc, char **argv) { } } fclose(f); - fputs("no ip line found in /proc/net/snmp\n", stderr); + fputs("no ip line found in " PROC_NET_SNMP "\n", stderr); return 1; } @@ -3,6 +3,8 @@ #include <stdlib.h> #include "common.h" +#define PROC_LOADAVG "/proc/loadavg" + int load(int argc, char **argv) { FILE *f; int warn, crit; @@ -32,12 +34,12 @@ int load(int argc, char **argv) { if(!strcmp(argv[1], "autoconf")) return writeyes(); } - if(!(f=fopen("/proc/loadavg", "r"))) { - fputs("cannot open /proc/loadavg\n", stderr); + if(!(f=fopen(PROC_LOADAVG, "r"))) { + fputs("cannot open " PROC_LOADAVG "\n", stderr); return 1; } if(1 != fscanf(f, "%*f %f", &val)) { - fputs("cannot read from /proc/loadavg\n", stderr); + fputs("cannot read from " PROC_LOADAVG "\n", stderr); fclose(f); return 1; } diff --git a/open_files.c b/open_files.c index 3f82c8b..9eb5c3d 100644 --- a/open_files.c +++ b/open_files.c @@ -3,18 +3,21 @@ #include <unistd.h> #include "common.h" +#define FS_FILE_NR "/proc/sys/fs/file-nr" + int open_files(int argc, char **argv) { FILE *f; int alloc, freeh, avail; if(argc > 1) { if(!strcmp(argv[1], "config")) { - if(!(f=fopen("/proc/sys/fs/file-nr", "r"))) { - fprintf(stderr, "cannot open /proc/sys/fs/file-nr\n"); + if(!(f=fopen(FS_FILE_NR, "r"))) { + fprintf(stderr, "cannot open " FS_FILE_NR "\n"); return 1; } if(1 != fscanf(f, "%*d %*d %d", &avail)) { fclose(f); - fprintf(stderr, "cannot read from /proc/sys/fs/file-nr\n"); + fprintf(stderr, "cannot read from " FS_FILE_NR + "\n"); return 1; } fclose(f); @@ -26,24 +29,27 @@ int open_files(int argc, char **argv) { "used.label open files\n" "used.info The number of currently open files.\n" "max.label max open files\n" - "max.info The maximum supported number of open files. Tune by modifying /proc/sys/fs/file-max."); - printf("used.warning %d\nused.critical %d\n", (int)(avail*0.92), (int)(avail*0.98)); + "max.info The maximum supported number of open " + "files. Tune by modifying " FS_FILE_NR + "."); + printf("used.warning %d\nused.critical %d\n", + (int)(avail*0.92), (int)(avail*0.98)); return 0; } if(!strcmp(argv[1], "autoconf")) { - if(0 == access("/proc/sys/fs/file-nr", R_OK)) + if(0 == access(FS_FILE_NR, R_OK)) return writeyes(); else - return writeno("/proc/sys/fs/file-nr not readable"); + return writeno(FS_FILE_NR " not readable"); } } - if(!(f=fopen("/proc/sys/fs/file-nr", "r"))) { - fputs("cannot open /proc/sys/fs/file-nr\n", stderr); + if(!(f=fopen(FS_FILE_NR, "r"))) { + fputs("cannot open " FS_FILE_NR "\n", stderr); return 1; } if(3 != fscanf(f, "%d %d %d", &alloc, &freeh, &avail)) { fclose(f); - fputs("cannot read from /proc/sys/fs/file-nr\n", stderr); + fputs("cannot read from " FS_FILE_NR "\n", stderr); return 1; } fclose(f); diff --git a/open_inodes.c b/open_inodes.c index bc20cc6..d9e8657 100644 --- a/open_inodes.c +++ b/open_inodes.c @@ -3,6 +3,8 @@ #include <unistd.h> #include "common.h" +#define FS_INODE_NR "/proc/sys/fs/inode-nr" + int open_inodes(int argc, char **argv) { FILE *f; int nr, freen; @@ -21,19 +23,19 @@ int open_inodes(int argc, char **argv) { return 0; } if(!strcmp(argv[1], "autoconf")) { - if(0 == access("/proc/sys/fs/inode-nr", R_OK)) + if(0 == access(FS_INODE_NR, R_OK)) return writeyes(); else - return writeno("/proc/sys/fs/inode-nr not readable"); + return writeno(FS_INODE_NR " not readable"); } } - if(!(f=fopen("/proc/sys/fs/inode-nr", "r"))) { - fputs("cannot open /proc/sys/fs/inode-nr\n", stderr); + if(!(f=fopen(FS_INODE_NR, "r"))) { + fputs("cannot open " FS_INODE_NR "\n", stderr); return 1; } if(2 != fscanf(f, "%d %d", &nr, &freen)) { fclose(f); - fputs("cannot read from /proc/sys/fs/inode-nr\n", stderr); + fputs("cannot read from " FS_INODE_NR "\n", stderr); return 1; } fclose(f); |