summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2009-01-23 12:48:30 +0000
committerHelmut Grohne <helmut@subdivi.de>2009-01-23 12:48:30 +0000
commit84194373370b46a346231c1762c038cc683abc45 (patch)
tree2ebf7f63b4acbde53c92b03e308206218896a453
parent1de74e3d850636058f7283af732bcd3475c2d721 (diff)
downloadmunin-plugins-busybox-84194373370b46a346231c1762c038cc683abc45.tar.gz
added #define PROC_STAT "/proc/stat"
-rw-r--r--common.h2
-rw-r--r--cpu.c16
-rw-r--r--forks.c10
-rw-r--r--interrupts.c8
-rw-r--r--swap.c13
5 files changed, 26 insertions, 23 deletions
diff --git a/common.h b/common.h
index 67a5beb..8db440a 100644
--- a/common.h
+++ b/common.h
@@ -1,6 +1,8 @@
#ifndef COMMON_H
#define COMMON_H
+#define PROC_STAT "/proc/stat"
+
int writeyes(void);
int writeno(const char *);
diff --git a/cpu.c b/cpu.c
index 120293d..627eb7c 100644
--- a/cpu.c
+++ b/cpu.c
@@ -19,8 +19,8 @@ int cpu(int argc, char **argv) {
if(s && !strcmp(s, "yes"))
scaleto100=1;
- if(!(f=fopen("/proc/stat", "r"))) {
- fputs("cannot open /proc/stat\n", stderr);
+ if(!(f=fopen(PROC_STAT, "r"))) {
+ fputs("cannot open " PROC_STAT "\n", stderr);
return 1;
}
while(fgets(buff, 256, f)) {
@@ -37,7 +37,7 @@ int cpu(int argc, char **argv) {
fclose(f);
if(ncpu < 1 || extinfo < 4) {
- fputs("cannot parse /proc/stat\n", stderr);
+ fputs("cannot parse " PROC_STAT "\n", stderr);
return 1;
}
@@ -114,14 +114,14 @@ int cpu(int argc, char **argv) {
return 0;
}
if(!strcmp(argv[1], "autoconf")) {
- if(0 == access("/proc/stat", R_OK))
+ if(0 == access(PROC_STAT, R_OK))
return writeyes();
else
- return writeno("/proc/stat not readable");
+ return writeno(PROC_STAT " not readable");
}
}
- if(!(f=fopen("/proc/stat", "r"))) {
- fputs("cannot open /proc/stat\n", stderr);
+ if(!(f=fopen(PROC_STAT, "r"))) {
+ fputs("cannot open " PROC_STAT "\n", stderr);
return 1;
}
while(fgets(buff, 256, f)) {
@@ -152,6 +152,6 @@ int cpu(int argc, char **argv) {
}
}
fclose(f);
- fputs("no cpu line found in /proc/stat\n", stderr);
+ fputs("no cpu line found in " PROC_STAT "\n", stderr);
return 1;
}
diff --git a/forks.c b/forks.c
index fa4dadb..3d4a198 100644
--- a/forks.c
+++ b/forks.c
@@ -21,14 +21,14 @@ int forks(int argc, char **argv) {
return 0;
}
if(!strcmp(argv[1], "autoconf")) {
- if(0 == access("/proc/stat", R_OK))
+ if(0 == access(PROC_STAT, R_OK))
return writeyes();
else
- return writeno("/proc/stat not readable");
+ return writeno(PROC_STAT " not readable");
}
}
- if(!(f=fopen("/proc/stat", "r"))) {
- fputs("cannot open /proc/stat\n", stderr);
+ if(!(f=fopen(PROC_STAT, "r"))) {
+ fputs("cannot open " PROC_STAT "\n", stderr);
return 1;
}
while(fgets(buff, 256, f)) {
@@ -39,6 +39,6 @@ int forks(int argc, char **argv) {
}
}
fclose(f);
- fputs("no processes line found in /proc/stat\n", stderr);
+ fputs("no processes line found in " PROC_STAT "\n", stderr);
return 1;
}
diff --git a/interrupts.c b/interrupts.c
index 2755ccf..8c800c6 100644
--- a/interrupts.c
+++ b/interrupts.c
@@ -26,14 +26,14 @@ int interrupts(int argc, char **argv) {
return 0;
}
if(!strcmp(argv[1], "autoconf")) {
- if(0 == access("/proc/stat", R_OK))
+ if(0 == access(PROC_STAT, R_OK))
return writeyes();
else
- return writeno("/proc/stat not readable");
+ return writeno(PROC_STAT " not readable");
}
}
- if(!(f=fopen("/proc/stat", "r"))) {
- fputs("cannot open /proc/stat\n", stderr);
+ if(!(f=fopen(PROC_STAT, "r"))) {
+ fputs("cannot open " PROC_STAT "\n", stderr);
return 1;
}
while(fgets(buff, 256, f)) {
diff --git a/swap.c b/swap.c
index 1a270fe..3decfbb 100644
--- a/swap.c
+++ b/swap.c
@@ -27,10 +27,10 @@ int swap(int argc, char **argv) {
return 0;
}
if(!strcmp(argv[1], "autoconf")) {
- if(0 == access("/proc/stat", R_OK))
+ if(0 == access(PROC_STAT, R_OK))
return writeyes();
else
- return writeno("/proc/stat not readable");
+ return writeno(PROC_STAT " not readable");
}
}
if(!access("/proc/vmstat", F_OK)) {
@@ -56,15 +56,16 @@ int swap(int argc, char **argv) {
}
return 0;
} else {
- if(!(f=fopen("/proc/stat", "r"))) {
- fputs("cannot open /proc/stat\n", stderr);
+ if(!(f=fopen(PROC_STAT, "r"))) {
+ fputs("cannot open " PROC_STAT "\n", stderr);
return 1;
}
while(fgets(buff, 256, f)) {
if(!strncmp(buff, "swap ", 5)) {
fclose(f);
if(2 != sscanf(buff+5, "%d %d", &in, &out)) {
- fputs("bad data on /proc/stat\n", stderr);
+ fputs("bad data on " PROC_STAT "\n",
+ stderr);
return 1;
}
printf("swap_in.value %d\nswap_out.value %d\n", in, out);
@@ -72,7 +73,7 @@ int swap(int argc, char **argv) {
}
}
fclose(f);
- fputs("no swap line found in /proc/stat\n", stderr);
+ fputs("no swap line found in " PROC_STAT "\n", stderr);
return 1;
}
}