From 611bfb05808041e6841b41cb5230515611c79d79 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Fri, 23 Jan 2009 12:56:20 +0000 Subject: [PATCH] made more paths be macros --- tools/munin-plugins-busybox/entropy.c | 8 ++++--- tools/munin-plugins-busybox/fw_packets.c | 12 ++++++----- tools/munin-plugins-busybox/load.c | 8 ++++--- tools/munin-plugins-busybox/open_files.c | 26 ++++++++++++++--------- tools/munin-plugins-busybox/open_inodes.c | 12 ++++++----- 5 files changed, 40 insertions(+), 26 deletions(-) diff --git a/tools/munin-plugins-busybox/entropy.c b/tools/munin-plugins-busybox/entropy.c index 4a5d8468..cc7791fd 100644 --- a/tools/munin-plugins-busybox/entropy.c +++ b/tools/munin-plugins-busybox/entropy.c @@ -2,6 +2,8 @@ #include #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/tools/munin-plugins-busybox/fw_packets.c b/tools/munin-plugins-busybox/fw_packets.c index 06367dde..8e94fdea 100644 --- a/tools/munin-plugins-busybox/fw_packets.c +++ b/tools/munin-plugins-busybox/fw_packets.c @@ -4,6 +4,8 @@ #include #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; } diff --git a/tools/munin-plugins-busybox/load.c b/tools/munin-plugins-busybox/load.c index c894f5e2..27e18437 100644 --- a/tools/munin-plugins-busybox/load.c +++ b/tools/munin-plugins-busybox/load.c @@ -3,6 +3,8 @@ #include #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/tools/munin-plugins-busybox/open_files.c b/tools/munin-plugins-busybox/open_files.c index 3f82c8b5..9eb5c3d7 100644 --- a/tools/munin-plugins-busybox/open_files.c +++ b/tools/munin-plugins-busybox/open_files.c @@ -3,18 +3,21 @@ #include #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/tools/munin-plugins-busybox/open_inodes.c b/tools/munin-plugins-busybox/open_inodes.c index bc20cc60..d9e86577 100644 --- a/tools/munin-plugins-busybox/open_inodes.c +++ b/tools/munin-plugins-busybox/open_inodes.c @@ -3,6 +3,8 @@ #include #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);