summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRincewindsHat <12514511+RincewindsHat@users.noreply.github.com>2023-03-05 15:03:37 (GMT)
committerLorenz Kästle <lorenz.kaestle@netways.de>2023-09-22 13:24:26 (GMT)
commit0162cb2d4f7040e3b2d48095182f87ce565866a5 (patch)
tree2810709bcd208ec15a72ca942d47e565774a9408 /lib
parent7fd0e6f36d90a341e0d9b418f1cd64a3a5472a94 (diff)
downloadmonitoring-plugins-0162cb2d4f7040e3b2d48095182f87ce565866a5.tar.gz
fixup! Rework maxfd/open_max to avoid unused variables
Diffstat (limited to 'lib')
-rw-r--r--lib/maxfd.c26
-rw-r--r--lib/maxfd.h9
2 files changed, 35 insertions, 0 deletions
diff --git a/lib/maxfd.c b/lib/maxfd.c
new file mode 100644
index 0000000..dcd4d3d
--- /dev/null
+++ b/lib/maxfd.c
@@ -0,0 +1,26 @@
1#include "./maxfd.h"
2#include <errno.h>
3
4long open_max (void) {
5 long maxfd = 0L;
6 /* Try sysconf(_SC_OPEN_MAX) first, as it can be higher than OPEN_MAX.
7 * If that fails and the macro isn't defined, we fall back to an educated
8 * guess. There's no guarantee that our guess is adequate and the program
9 * will die with SIGSEGV if it isn't and the upper boundary is breached. */
10
11#ifdef _SC_OPEN_MAX
12 errno = 0;
13 if ((maxfd = sysconf (_SC_OPEN_MAX)) < 0) {
14 if (errno == 0)
15 maxfd = DEFAULT_MAXFD; /* it's indeterminate */
16 else
17 die (STATE_UNKNOWN, _("sysconf error for _SC_OPEN_MAX\n"));
18 }
19#elif defined(OPEN_MAX)
20 return OPEN_MAX
21#else /* sysconf macro unavailable, so guess (may be wildly inaccurate) */
22 return DEFAULT_MAXFD;
23#endif
24
25 return(maxfd);
26}
diff --git a/lib/maxfd.h b/lib/maxfd.h
new file mode 100644
index 0000000..0d734c5
--- /dev/null
+++ b/lib/maxfd.h
@@ -0,0 +1,9 @@
1#ifndef _MAXFD_
2#define _MAXFD_
3
4#define DEFAULT_MAXFD 256 /* fallback value if no max open files value is set */
5#define MAXFD_LIMIT 8192 /* upper limit of open files */
6
7long open_max (void);
8
9#endif // _MAXFD_