diff options
author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2023-09-23 10:47:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-23 10:47:01 +0200 |
commit | 719e27ddc2f0b48bcd7fe5584b23e3ce83ddf291 (patch) | |
tree | 1ca6c622275cf8d57e0b6b6d7fb0da4cce8e9205 /plugins/runcmd.c | |
parent | fe718dec117a7adb8a7107a4137a86c79b54d15f (diff) | |
parent | 4295decfbf06adfa1bf019d28e9044971607b2d6 (diff) | |
download | monitoring-plugins-719e27d.tar.gz |
Merge pull request #1924 from RincewindsHat/compiler_warnings_4_1
Centralise and refactor maxfd related functionality
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 102191e4..bc0a4974 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 = mp_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 = 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,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 = mp_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 = mp_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 | } |