diff options
Diffstat (limited to 'plugins/runcmd.c')
-rw-r--r-- | plugins/runcmd.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/plugins/runcmd.c b/plugins/runcmd.c index 102191e..9816142 100644 --- a/plugins/runcmd.c +++ b/plugins/runcmd.c | |||
@@ -88,8 +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 | if(maxfd == 0) | 91 | long maxfd = open_max(); |
92 | maxfd = open_max(); | ||
93 | if(!np_pids) np_pids = calloc(maxfd, sizeof(pid_t)); | 92 | if(!np_pids) np_pids = calloc(maxfd, sizeof(pid_t)); |
94 | } | 93 | } |
95 | 94 | ||
@@ -192,6 +191,7 @@ np_runcmd_open(const char *cmdstring, int *pfd, int *pfderr) | |||
192 | /* close all descriptors in np_pids[] | 191 | /* close all descriptors in np_pids[] |
193 | * This is executed in a separate address space (pure child), | 192 | * This is executed in a separate address space (pure child), |
194 | * 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(); | ||
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,6 +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 | 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) |
223 | return -1; | 224 | return -1; |
224 | 225 | ||
@@ -242,6 +243,7 @@ runcmd_timeout_alarm_handler (int signo) | |||
242 | if (signo == SIGALRM) | 243 | if (signo == SIGALRM) |
243 | puts(_("CRITICAL - Plugin timed out while executing system call")); | 244 | puts(_("CRITICAL - Plugin timed out while executing system call")); |
244 | 245 | ||
246 | long maxfd = open_max(); | ||
245 | if(np_pids) for(i = 0; i < maxfd; i++) { | 247 | if(np_pids) for(i = 0; i < maxfd; i++) { |
246 | if(np_pids[i] != 0) kill(np_pids[i], SIGKILL); | 248 | if(np_pids[i] != 0) kill(np_pids[i], SIGKILL); |
247 | } | 249 | } |