summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSven Nierlein <sven@nierlein.de>2014-11-28 14:25:43 (GMT)
committerSven Nierlein <sven@nierlein.de>2014-11-28 14:25:43 (GMT)
commit7660540c31342eb7ea2f2ac24950094bf74f0a6f (patch)
treea70b7d276156d045a99e532b927cfff66806ba18 /lib
parent6bb5e1db525f44a7ab40e9391244dbe65daa08cc (diff)
downloadmonitoring-plugins-7660540c31342eb7ea2f2ac24950094bf74f0a6f.tar.gz
make constants from maxfd values (#1300)refs/pull/1304/head
its good practice to use constants instead of (random) values. Signed-off-by: Sven Nierlein <sven@nierlein.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/utils_cmd.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/utils_cmd.c b/lib/utils_cmd.c
index e41a982..7eb9a3a 100644
--- a/lib/utils_cmd.c
+++ b/lib/utils_cmd.c
@@ -79,12 +79,14 @@ static pid_t *_cmd_pids = NULL;
79 * If that fails and the macro isn't defined, we fall back to an educated 79 * If that fails and the macro isn't defined, we fall back to an educated
80 * guess. There's no guarantee that our guess is adequate and the program 80 * guess. There's no guarantee that our guess is adequate and the program
81 * will die with SIGSEGV if it isn't and the upper boundary is breached. */ 81 * will die with SIGSEGV if it isn't and the upper boundary is breached. */
82#define DEFAULT_MAXFD 256 /* fallback value if no max open files value is set */
83#define MAXFD_LIMIT 8192 /* upper limit of open files */
82#ifdef _SC_OPEN_MAX 84#ifdef _SC_OPEN_MAX
83static long maxfd = 0; 85static long maxfd = 0;
84#elif defined(OPEN_MAX) 86#elif defined(OPEN_MAX)
85# define maxfd OPEN_MAX 87# define maxfd OPEN_MAX
86#else /* sysconf macro unavailable, so guess (may be wildly inaccurate) */ 88#else /* sysconf macro unavailable, so guess (may be wildly inaccurate) */
87# define maxfd 256 89# define maxfd DEFAULT_MAXFD
88#endif 90#endif
89 91
90 92
@@ -112,7 +114,7 @@ cmd_init (void)
112 if (!maxfd && (maxfd = sysconf (_SC_OPEN_MAX)) < 0) { 114 if (!maxfd && (maxfd = sysconf (_SC_OPEN_MAX)) < 0) {
113 /* possibly log or emit a warning here, since there's no 115 /* possibly log or emit a warning here, since there's no
114 * guarantee that our guess at maxfd will be adequate */ 116 * guarantee that our guess at maxfd will be adequate */
115 maxfd = 256; 117 maxfd = DEFAULT_MAXFD;
116 } 118 }
117#endif 119#endif
118 120
@@ -120,8 +122,8 @@ cmd_init (void)
120 * ( e.g. on SunOS, when ulimit is set to unlimited: 2147483647 this would cause 122 * ( e.g. on SunOS, when ulimit is set to unlimited: 2147483647 this would cause
121 * a segfault when following calloc is called ... ) */ 123 * a segfault when following calloc is called ... ) */
122 124
123 if ( maxfd > 2048 ) { 125 if ( maxfd > MAXFD_LIMIT ) {
124 maxfd = 2048; 126 maxfd = MAXFD_LIMIT;
125 } 127 }
126 128
127 if (!_cmd_pids) 129 if (!_cmd_pids)