diff options
Diffstat (limited to 'plugins/runcmd.c')
| -rw-r--r-- | plugins/runcmd.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/plugins/runcmd.c b/plugins/runcmd.c index c1d675d0..4f3e349b 100644 --- a/plugins/runcmd.c +++ b/plugins/runcmd.c | |||
| @@ -60,6 +60,8 @@ | |||
| 60 | # define SIG_ERR ((Sigfunc *)-1) | 60 | # define SIG_ERR ((Sigfunc *)-1) |
| 61 | #endif | 61 | #endif |
| 62 | 62 | ||
| 63 | #include "../lib/maxfd.h" | ||
| 64 | |||
| 63 | /* This variable must be global, since there's no way the caller | 65 | /* This variable must be global, since there's no way the caller |
| 64 | * can forcibly slay a dead or ungainly running program otherwise. | 66 | * can forcibly slay a dead or ungainly running program otherwise. |
| 65 | * Multithreading apps and plugins can initialize it (via NP_RUNCMD_INIT) | 67 | * Multithreading apps and plugins can initialize it (via NP_RUNCMD_INIT) |
| @@ -88,8 +90,7 @@ extern void die (int, const char *, ...) | |||
| 88 | * through this api and thus achieve async-safeness throughout the api */ | 90 | * through this api and thus achieve async-safeness throughout the api */ |
| 89 | void np_runcmd_init(void) | 91 | void np_runcmd_init(void) |
| 90 | { | 92 | { |
| 91 | if(maxfd == 0) | 93 | long maxfd = mp_open_max(); |
| 92 | maxfd = open_max(); | ||
| 93 | if(!np_pids) np_pids = calloc(maxfd, sizeof(pid_t)); | 94 | if(!np_pids) np_pids = calloc(maxfd, sizeof(pid_t)); |
| 94 | } | 95 | } |
| 95 | 96 | ||
| @@ -116,10 +117,6 @@ np_runcmd_open(const char *cmdstring, int *pfd, int *pfderr) | |||
| 116 | env[0] = strdup("LC_ALL=C"); | 117 | env[0] = strdup("LC_ALL=C"); |
| 117 | env[1] = '\0'; | 118 | env[1] = '\0'; |
| 118 | 119 | ||
| 119 | /* if no command was passed, return with no error */ | ||
| 120 | if (cmdstring == NULL) | ||
| 121 | return -1; | ||
| 122 | |||
| 123 | /* make copy of command string so strtok() doesn't silently modify it */ | 120 | /* make copy of command string so strtok() doesn't silently modify it */ |
| 124 | /* (the calling program may want to access it later) */ | 121 | /* (the calling program may want to access it later) */ |
| 125 | cmdlen = strlen(cmdstring); | 122 | cmdlen = strlen(cmdstring); |
| @@ -196,6 +193,7 @@ np_runcmd_open(const char *cmdstring, int *pfd, int *pfderr) | |||
| 196 | /* close all descriptors in np_pids[] | 193 | /* close all descriptors in np_pids[] |
| 197 | * This is executed in a separate address space (pure child), | 194 | * This is executed in a separate address space (pure child), |
| 198 | * so we don't have to worry about async safety */ | 195 | * so we don't have to worry about async safety */ |
| 196 | long maxfd = mp_open_max(); | ||
| 199 | for (i = 0; i < maxfd; i++) | 197 | for (i = 0; i < maxfd; i++) |
| 200 | if(np_pids[i] > 0) | 198 | if(np_pids[i] > 0) |
| 201 | close (i); | 199 | close (i); |
| @@ -223,6 +221,7 @@ np_runcmd_close(int fd) | |||
| 223 | pid_t pid; | 221 | pid_t pid; |
| 224 | 222 | ||
| 225 | /* make sure this fd was opened by popen() */ | 223 | /* make sure this fd was opened by popen() */ |
| 224 | long maxfd = mp_open_max(); | ||
| 226 | if(fd < 0 || fd > maxfd || !np_pids || (pid = np_pids[fd]) == 0) | 225 | if(fd < 0 || fd > maxfd || !np_pids || (pid = np_pids[fd]) == 0) |
| 227 | return -1; | 226 | return -1; |
| 228 | 227 | ||
| @@ -246,6 +245,7 @@ runcmd_timeout_alarm_handler (int signo) | |||
| 246 | if (signo == SIGALRM) | 245 | if (signo == SIGALRM) |
| 247 | puts(_("CRITICAL - Plugin timed out while executing system call")); | 246 | puts(_("CRITICAL - Plugin timed out while executing system call")); |
| 248 | 247 | ||
| 248 | long maxfd = mp_open_max(); | ||
| 249 | if(np_pids) for(i = 0; i < maxfd; i++) { | 249 | if(np_pids) for(i = 0; i < maxfd; i++) { |
| 250 | if(np_pids[i] != 0) kill(np_pids[i], SIGKILL); | 250 | if(np_pids[i] != 0) kill(np_pids[i], SIGKILL); |
| 251 | } | 251 | } |
