diff options
-rw-r--r-- | lib/maxfd.c | 2 | ||||
-rw-r--r-- | lib/maxfd.h | 2 | ||||
-rw-r--r-- | lib/utils_cmd.c | 8 | ||||
-rw-r--r-- | plugins/popen.c | 2 | ||||
-rw-r--r-- | plugins/runcmd.c | 8 |
5 files changed, 11 insertions, 11 deletions
diff --git a/lib/maxfd.c b/lib/maxfd.c index dcd4d3db..529b3568 100644 --- a/lib/maxfd.c +++ b/lib/maxfd.c | |||
@@ -1,7 +1,7 @@ | |||
1 | #include "./maxfd.h" | 1 | #include "./maxfd.h" |
2 | #include <errno.h> | 2 | #include <errno.h> |
3 | 3 | ||
4 | long open_max (void) { | 4 | long mp_open_max (void) { |
5 | long maxfd = 0L; | 5 | long maxfd = 0L; |
6 | /* Try sysconf(_SC_OPEN_MAX) first, as it can be higher than OPEN_MAX. | 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 | 7 | * If that fails and the macro isn't defined, we fall back to an educated |
diff --git a/lib/maxfd.h b/lib/maxfd.h index 0d734c5c..45218d0f 100644 --- a/lib/maxfd.h +++ b/lib/maxfd.h | |||
@@ -4,6 +4,6 @@ | |||
4 | #define DEFAULT_MAXFD 256 /* fallback value if no max open files value is set */ | 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 */ | 5 | #define MAXFD_LIMIT 8192 /* upper limit of open files */ |
6 | 6 | ||
7 | long open_max (void); | 7 | long mp_open_max (void); |
8 | 8 | ||
9 | #endif // _MAXFD_ | 9 | #endif // _MAXFD_ |
diff --git a/lib/utils_cmd.c b/lib/utils_cmd.c index 71da9d24..ef7053a5 100644 --- a/lib/utils_cmd.c +++ b/lib/utils_cmd.c | |||
@@ -89,7 +89,7 @@ extern void die (int, const char *, ...) | |||
89 | void | 89 | void |
90 | cmd_init (void) | 90 | cmd_init (void) |
91 | { | 91 | { |
92 | long maxfd = open_max(); | 92 | long maxfd = mp_open_max(); |
93 | 93 | ||
94 | /* 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 |
95 | * ( 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 |
@@ -145,7 +145,7 @@ _cmd_open (char *const *argv, int *pfd, int *pfderr) | |||
145 | /* close all descriptors in _cmd_pids[] | 145 | /* close all descriptors in _cmd_pids[] |
146 | * This is executed in a separate address space (pure child), | 146 | * This is executed in a separate address space (pure child), |
147 | * 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(); | 148 | long maxfd = mp_open_max(); |
149 | for (i = 0; i < maxfd; i++) | 149 | for (i = 0; i < maxfd; i++) |
150 | if (_cmd_pids[i] > 0) | 150 | if (_cmd_pids[i] > 0) |
151 | close (i); | 151 | close (i); |
@@ -172,7 +172,7 @@ _cmd_close (int fd) | |||
172 | pid_t pid; | 172 | pid_t pid; |
173 | 173 | ||
174 | /* make sure the provided fd was opened */ | 174 | /* make sure the provided fd was opened */ |
175 | long maxfd = open_max(); | 175 | long maxfd = mp_open_max(); |
176 | 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) |
177 | return -1; | 177 | return -1; |
178 | 178 | ||
@@ -385,7 +385,7 @@ timeout_alarm_handler (int signo) | |||
385 | printf (_("%s - Plugin timed out after %d seconds\n"), | 385 | printf (_("%s - Plugin timed out after %d seconds\n"), |
386 | state_text(timeout_state), timeout_interval); | 386 | state_text(timeout_state), timeout_interval); |
387 | 387 | ||
388 | long maxfd = open_max(); | 388 | long maxfd = mp_open_max(); |
389 | if(_cmd_pids) for(i = 0; i < maxfd; i++) { | 389 | if(_cmd_pids) for(i = 0; i < maxfd; i++) { |
390 | if(_cmd_pids[i] != 0) kill(_cmd_pids[i], SIGKILL); | 390 | if(_cmd_pids[i] != 0) kill(_cmd_pids[i], SIGKILL); |
391 | } | 391 | } |
diff --git a/plugins/popen.c b/plugins/popen.c index 7703afc8..b395f14a 100644 --- a/plugins/popen.c +++ b/plugins/popen.c | |||
@@ -178,7 +178,7 @@ spopen (const char *cmdstring) | |||
178 | } | 178 | } |
179 | argv[i] = NULL; | 179 | argv[i] = NULL; |
180 | 180 | ||
181 | long maxfd = open_max(); | 181 | long maxfd = mp_open_max(); |
182 | 182 | ||
183 | if (childpid == NULL) { /* first time through */ | 183 | if (childpid == NULL) { /* first time through */ |
184 | if ((childpid = calloc ((size_t)maxfd, sizeof (pid_t))) == NULL) | 184 | if ((childpid = calloc ((size_t)maxfd, sizeof (pid_t))) == NULL) |
diff --git a/plugins/runcmd.c b/plugins/runcmd.c index 98161421..bc0a4974 100644 --- a/plugins/runcmd.c +++ b/plugins/runcmd.c | |||
@@ -88,7 +88,7 @@ extern void die (int, const char *, ...) | |||
88 | * through this api and thus achieve async-safeness throughout the api */ | 88 | * through this api and thus achieve async-safeness throughout the api */ |
89 | void np_runcmd_init(void) | 89 | void np_runcmd_init(void) |
90 | { | 90 | { |
91 | long maxfd = open_max(); | 91 | long maxfd = mp_open_max(); |
92 | if(!np_pids) np_pids = calloc(maxfd, sizeof(pid_t)); | 92 | if(!np_pids) np_pids = calloc(maxfd, sizeof(pid_t)); |
93 | } | 93 | } |
94 | 94 | ||
@@ -191,7 +191,7 @@ np_runcmd_open(const char *cmdstring, int *pfd, int *pfderr) | |||
191 | /* close all descriptors in np_pids[] | 191 | /* close all descriptors in np_pids[] |
192 | * This is executed in a separate address space (pure child), | 192 | * This is executed in a separate address space (pure child), |
193 | * so we don't have to worry about async safety */ | 193 | * so we don't have to worry about async safety */ |
194 | long maxfd = open_max(); | 194 | long maxfd = mp_open_max(); |
195 | for (i = 0; i < maxfd; i++) | 195 | for (i = 0; i < maxfd; i++) |
196 | if(np_pids[i] > 0) | 196 | if(np_pids[i] > 0) |
197 | close (i); | 197 | close (i); |
@@ -219,7 +219,7 @@ np_runcmd_close(int fd) | |||
219 | pid_t pid; | 219 | pid_t pid; |
220 | 220 | ||
221 | /* make sure this fd was opened by popen() */ | 221 | /* make sure this fd was opened by popen() */ |
222 | long maxfd = open_max(); | 222 | long maxfd = mp_open_max(); |
223 | if(fd < 0 || fd > maxfd || !np_pids || (pid = np_pids[fd]) == 0) | 223 | if(fd < 0 || fd > maxfd || !np_pids || (pid = np_pids[fd]) == 0) |
224 | return -1; | 224 | return -1; |
225 | 225 | ||
@@ -243,7 +243,7 @@ runcmd_timeout_alarm_handler (int signo) | |||
243 | if (signo == SIGALRM) | 243 | if (signo == SIGALRM) |
244 | puts(_("CRITICAL - Plugin timed out while executing system call")); | 244 | puts(_("CRITICAL - Plugin timed out while executing system call")); |
245 | 245 | ||
246 | long maxfd = open_max(); | 246 | long maxfd = mp_open_max(); |
247 | if(np_pids) for(i = 0; i < maxfd; i++) { | 247 | if(np_pids) for(i = 0; i < maxfd; i++) { |
248 | if(np_pids[i] != 0) kill(np_pids[i], SIGKILL); | 248 | if(np_pids[i] != 0) kill(np_pids[i], SIGKILL); |
249 | } | 249 | } |