diff options
Diffstat (limited to 'open_files.c')
-rw-r--r-- | open_files.c | 26 |
1 files changed, 16 insertions, 10 deletions
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); |