diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile.am | 2 | ||||
-rw-r--r-- | lib/utils_cmd.c | 15 |
2 files changed, 8 insertions, 9 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am index 01d73a64..1a47395d 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am | |||
@@ -7,7 +7,7 @@ noinst_LIBRARIES = libmonitoringplug.a | |||
7 | AM_CPPFLAGS = -DNP_STATE_DIR_PREFIX=\"$(localstatedir)\" \ | 7 | AM_CPPFLAGS = -DNP_STATE_DIR_PREFIX=\"$(localstatedir)\" \ |
8 | -I$(srcdir) -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins | 8 | -I$(srcdir) -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins |
9 | 9 | ||
10 | libmonitoringplug_a_SOURCES = utils_base.c utils_disk.c utils_tcp.c utils_cmd.c | 10 | libmonitoringplug_a_SOURCES = utils_base.c utils_disk.c utils_tcp.c utils_cmd.c maxfd.c |
11 | EXTRA_DIST = utils_base.h utils_disk.h utils_tcp.h utils_cmd.h parse_ini.h extra_opts.h | 11 | EXTRA_DIST = utils_base.h utils_disk.h utils_tcp.h utils_cmd.h parse_ini.h extra_opts.h |
12 | 12 | ||
13 | if USE_PARSE_INI | 13 | if USE_PARSE_INI |
diff --git a/lib/utils_cmd.c b/lib/utils_cmd.c index 34fb3909..71da9d24 100644 --- a/lib/utils_cmd.c +++ b/lib/utils_cmd.c | |||
@@ -43,6 +43,9 @@ | |||
43 | #include "utils.h" | 43 | #include "utils.h" |
44 | #include "utils_cmd.h" | 44 | #include "utils_cmd.h" |
45 | #include "utils_base.h" | 45 | #include "utils_base.h" |
46 | |||
47 | #include "./maxfd.h" | ||
48 | |||
46 | #include <fcntl.h> | 49 | #include <fcntl.h> |
47 | 50 | ||
48 | #ifdef HAVE_SYS_WAIT_H | 51 | #ifdef HAVE_SYS_WAIT_H |
@@ -86,13 +89,7 @@ extern void die (int, const char *, ...) | |||
86 | void | 89 | void |
87 | cmd_init (void) | 90 | cmd_init (void) |
88 | { | 91 | { |
89 | #ifndef maxfd | 92 | long maxfd = open_max(); |
90 | if (!maxfd && (maxfd = sysconf (_SC_OPEN_MAX)) < 0) { | ||
91 | /* possibly log or emit a warning here, since there's no | ||
92 | * guarantee that our guess at maxfd will be adequate */ | ||
93 | maxfd = DEFAULT_MAXFD; | ||
94 | } | ||
95 | #endif | ||
96 | 93 | ||
97 | /* if maxfd is unnaturally high, we force it to a lower value | 94 | /* if maxfd is unnaturally high, we force it to a lower value |
98 | * ( e.g. on SunOS, when ulimit is set to unlimited: 2147483647 this would cause | 95 | * ( e.g. on SunOS, when ulimit is set to unlimited: 2147483647 this would cause |
@@ -148,6 +145,7 @@ _cmd_open (char *const *argv, int *pfd, int *pfderr) | |||
148 | /* close all descriptors in _cmd_pids[] | 145 | /* close all descriptors in _cmd_pids[] |
149 | * This is executed in a separate address space (pure child), | 146 | * This is executed in a separate address space (pure child), |
150 | * so we don't have to worry about async safety */ | 147 | * so we don't have to worry about async safety */ |
148 | long maxfd = open_max(); | ||
151 | for (i = 0; i < maxfd; i++) | 149 | for (i = 0; i < maxfd; i++) |
152 | if (_cmd_pids[i] > 0) | 150 | if (_cmd_pids[i] > 0) |
153 | close (i); | 151 | close (i); |
@@ -174,6 +172,7 @@ _cmd_close (int fd) | |||
174 | pid_t pid; | 172 | pid_t pid; |
175 | 173 | ||
176 | /* make sure the provided fd was opened */ | 174 | /* make sure the provided fd was opened */ |
175 | long maxfd = open_max(); | ||
177 | if (fd < 0 || fd > maxfd || !_cmd_pids || (pid = _cmd_pids[fd]) == 0) | 176 | if (fd < 0 || fd > maxfd || !_cmd_pids || (pid = _cmd_pids[fd]) == 0) |
178 | return -1; | 177 | return -1; |
179 | 178 | ||
@@ -265,7 +264,6 @@ _cmd_fetch_output (int fd, output * op, int flags) | |||
265 | int | 264 | int |
266 | cmd_run (const char *cmdstring, output * out, output * err, int flags) | 265 | cmd_run (const char *cmdstring, output * out, output * err, int flags) |
267 | { | 266 | { |
268 | int fd, pfd_out[2], pfd_err[2]; | ||
269 | int i = 0, argc; | 267 | int i = 0, argc; |
270 | size_t cmdlen; | 268 | size_t cmdlen; |
271 | char **argv = NULL; | 269 | char **argv = NULL; |
@@ -387,6 +385,7 @@ timeout_alarm_handler (int signo) | |||
387 | printf (_("%s - Plugin timed out after %d seconds\n"), | 385 | printf (_("%s - Plugin timed out after %d seconds\n"), |
388 | state_text(timeout_state), timeout_interval); | 386 | state_text(timeout_state), timeout_interval); |
389 | 387 | ||
388 | long maxfd = open_max(); | ||
390 | if(_cmd_pids) for(i = 0; i < maxfd; i++) { | 389 | if(_cmd_pids) for(i = 0; i < maxfd; i++) { |
391 | if(_cmd_pids[i] != 0) kill(_cmd_pids[i], SIGKILL); | 390 | if(_cmd_pids[i] != 0) kill(_cmd_pids[i], SIGKILL); |
392 | } | 391 | } |