summaryrefslogtreecommitdiffstats
path: root/plugins/popen.c
diff options
context:
space:
mode:
authorSven Nierlein <sven@nierlein.org>2019-02-19 20:42:02 (GMT)
committerGitHub <noreply@github.com>2019-02-19 20:42:02 (GMT)
commit931ed78b5dc062fff33652d87406f1547da5ddbe (patch)
tree9caf8031a15d7f046e77693c4002bf750bfef3d3 /plugins/popen.c
parent2813d08b92d08ba56ec22da00a23fff3a22ed74b (diff)
parent7cafb0e84550035fe671662c293122be975065ca (diff)
downloadmonitoring-plugins-931ed78b5dc062fff33652d87406f1547da5ddbe.tar.gz
Merge pull request #1583 from sni/fix_check_by_ssh_timeout_child_leak
check_by_ssh: fix child process leak on timeouts
Diffstat (limited to 'plugins/popen.c')
-rw-r--r--plugins/popen.c29
1 files changed, 0 insertions, 29 deletions
diff --git a/plugins/popen.c b/plugins/popen.c
index 592263f..116d168 100644
--- a/plugins/popen.c
+++ b/plugins/popen.c
@@ -78,7 +78,6 @@ RETSIGTYPE popen_timeout_alarm_handler (int);
78 78
79#define min(a,b) ((a) < (b) ? (a) : (b)) 79#define min(a,b) ((a) < (b) ? (a) : (b))
80#define max(a,b) ((a) > (b) ? (a) : (b)) 80#define max(a,b) ((a) > (b) ? (a) : (b))
81int open_max (void); /* {Prog openmax} */
82static void err_sys (const char *, ...) __attribute__((noreturn,format(printf, 1, 2))); 81static void err_sys (const char *, ...) __attribute__((noreturn,format(printf, 1, 2)));
83char *rtrim (char *, const char *); 82char *rtrim (char *, const char *);
84 83
@@ -86,7 +85,6 @@ char *pname = NULL; /* caller can set this from argv[0] */
86 85
87/*int *childerr = NULL;*//* ptr to array allocated at run-time */ 86/*int *childerr = NULL;*//* ptr to array allocated at run-time */
88/*extern pid_t *childpid = NULL; *//* ptr to array allocated at run-time */ 87/*extern pid_t *childpid = NULL; *//* ptr to array allocated at run-time */
89static int maxfd; /* from our open_max(), {Prog openmax} */
90 88
91#ifdef REDHAT_SPOPEN_ERROR 89#ifdef REDHAT_SPOPEN_ERROR
92static volatile int childtermd = 0; 90static volatile int childtermd = 0;
@@ -187,13 +185,11 @@ spopen (const char *cmdstring)
187 argv[i] = NULL; 185 argv[i] = NULL;
188 186
189 if (childpid == NULL) { /* first time through */ 187 if (childpid == NULL) { /* first time through */
190 maxfd = open_max (); /* allocate zeroed out array for child pids */
191 if ((childpid = calloc ((size_t)maxfd, sizeof (pid_t))) == NULL) 188 if ((childpid = calloc ((size_t)maxfd, sizeof (pid_t))) == NULL)
192 return (NULL); 189 return (NULL);
193 } 190 }
194 191
195 if (child_stderr_array == NULL) { /* first time through */ 192 if (child_stderr_array == NULL) { /* first time through */
196 maxfd = open_max (); /* allocate zeroed out array for child pids */
197 if ((child_stderr_array = calloc ((size_t)maxfd, sizeof (int))) == NULL) 193 if ((child_stderr_array = calloc ((size_t)maxfd, sizeof (int))) == NULL)
198 return (NULL); 194 return (NULL);
199 } 195 }
@@ -273,15 +269,6 @@ spclose (FILE * fp)
273 return (1); 269 return (1);
274} 270}
275 271
276#ifdef OPEN_MAX
277static int openmax = OPEN_MAX;
278#else
279static int openmax = 0;
280#endif
281
282#define OPEN_MAX_GUESS 256 /* if OPEN_MAX is indeterminate */
283 /* no guarantee this is adequate */
284
285#ifdef REDHAT_SPOPEN_ERROR 272#ifdef REDHAT_SPOPEN_ERROR
286RETSIGTYPE 273RETSIGTYPE
287popen_sigchld_handler (int signo) 274popen_sigchld_handler (int signo)
@@ -311,22 +298,6 @@ popen_timeout_alarm_handler (int signo)
311} 298}
312 299
313 300
314int
315open_max (void)
316{
317 if (openmax == 0) { /* first time through */
318 errno = 0;
319 if ((openmax = sysconf (_SC_OPEN_MAX)) < 0) {
320 if (errno == 0)
321 openmax = OPEN_MAX_GUESS; /* it's indeterminate */
322 else
323 err_sys (_("sysconf error for _SC_OPEN_MAX"));
324 }
325 }
326 return (openmax);
327}
328
329
330/* Fatal error related to a system call. 301/* Fatal error related to a system call.
331 * Print a message and die. */ 302 * Print a message and die. */
332 303