diff options
Diffstat (limited to 'lib/maxfd.c')
-rw-r--r-- | lib/maxfd.c | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/lib/maxfd.c b/lib/maxfd.c index 529b356..ca5b6e5 100644 --- a/lib/maxfd.c +++ b/lib/maxfd.c | |||
@@ -1,7 +1,27 @@ | |||
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> | 22 | #include <errno.h> |
3 | 23 | ||
4 | long mp_open_max (void) { | 24 | long mp_open_max(void) { |
5 | long maxfd = 0L; | 25 | long maxfd = 0L; |
6 | /* Try sysconf(_SC_OPEN_MAX) first, as it can be higher than OPEN_MAX. | 26 | /* 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 | 27 | * If that fails and the macro isn't defined, we fall back to an educated |
@@ -10,17 +30,17 @@ long mp_open_max (void) { | |||
10 | 30 | ||
11 | #ifdef _SC_OPEN_MAX | 31 | #ifdef _SC_OPEN_MAX |
12 | errno = 0; | 32 | errno = 0; |
13 | if ((maxfd = sysconf (_SC_OPEN_MAX)) < 0) { | 33 | if ((maxfd = sysconf(_SC_OPEN_MAX)) < 0) { |
14 | if (errno == 0) | 34 | if (errno == 0) |
15 | maxfd = DEFAULT_MAXFD; /* it's indeterminate */ | 35 | maxfd = DEFAULT_MAXFD; /* it's indeterminate */ |
16 | else | 36 | else |
17 | die (STATE_UNKNOWN, _("sysconf error for _SC_OPEN_MAX\n")); | 37 | die(STATE_UNKNOWN, _("sysconf error for _SC_OPEN_MAX\n")); |
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 | } |