summaryrefslogtreecommitdiffstats
path: root/lib/maxfd.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/maxfd.c')
-rw-r--r--lib/maxfd.c38
1 files changed, 29 insertions, 9 deletions
diff --git a/lib/maxfd.c b/lib/maxfd.c
index 529b3568..a0f79949 100644
--- a/lib/maxfd.c
+++ b/lib/maxfd.c
@@ -1,7 +1,26 @@
1/*****************************************************************************
2 *
3 * License: GPL
4 * Copyright (c) 2024 Monitoring Plugins Development Team
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 *****************************************************************************/
20
1#include "./maxfd.h" 21#include "./maxfd.h"
2#include <errno.h>
3 22
4long mp_open_max (void) { 23long mp_open_max(void) {
5 long maxfd = 0L; 24 long maxfd = 0L;
6 /* Try sysconf(_SC_OPEN_MAX) first, as it can be higher than OPEN_MAX. 25 /* 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 26 * If that fails and the macro isn't defined, we fall back to an educated
@@ -10,17 +29,18 @@ long mp_open_max (void) {
10 29
11#ifdef _SC_OPEN_MAX 30#ifdef _SC_OPEN_MAX
12 errno = 0; 31 errno = 0;
13 if ((maxfd = sysconf (_SC_OPEN_MAX)) < 0) { 32 if ((maxfd = sysconf(_SC_OPEN_MAX)) < 0) {
14 if (errno == 0) 33 if (errno == 0) {
15 maxfd = DEFAULT_MAXFD; /* it's indeterminate */ 34 maxfd = DEFAULT_MAXFD; /* it's indeterminate */
16 else 35 } else {
17 die (STATE_UNKNOWN, _("sysconf error for _SC_OPEN_MAX\n")); 36 die(STATE_UNKNOWN, _("sysconf error for _SC_OPEN_MAX\n"));
37 }
18 } 38 }
19#elif defined(OPEN_MAX) 39#elif defined(OPEN_MAX)
20 return OPEN_MAX 40 return OPEN_MAX
21#else /* sysconf macro unavailable, so guess (may be wildly inaccurate) */ 41#else /* sysconf macro unavailable, so guess (may be wildly inaccurate) */
22 return DEFAULT_MAXFD; 42 return DEFAULT_MAXFD;
23#endif 43#endif
24 44
25 return(maxfd); 45 return (maxfd);
26} 46}