diff options
| author | Jan Wagner <waja@cyconet.org> | 2023-10-17 13:39:37 +0200 |
|---|---|---|
| committer | Jan Wagner <waja@cyconet.org> | 2023-10-17 13:39:37 +0200 |
| commit | 2a047014385022c8dc06dad4da0428db14898689 (patch) | |
| tree | 00abea46325decf0c72870ee8f9ec1472e8e5344 /lib/maxfd.c | |
| parent | f39211c26408af582121f519d89c8abf70e6d437 (diff) | |
| parent | e23a75d954311b3be429a9020e4d317b89615ee7 (diff) | |
| download | monitoring-plugins-2a047014385022c8dc06dad4da0428db14898689.tar.gz | |
Merge branch 'master' of github.com:monitoring-plugins/monitoring-plugins
Diffstat (limited to 'lib/maxfd.c')
| -rw-r--r-- | lib/maxfd.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/maxfd.c b/lib/maxfd.c new file mode 100644 index 00000000..529b3568 --- /dev/null +++ b/lib/maxfd.c | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | #include "./maxfd.h" | ||
| 2 | #include <errno.h> | ||
| 3 | |||
| 4 | long mp_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 | } | ||
