summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_dbi.c1
-rw-r--r--plugins/check_pgsql.c1
-rw-r--r--plugins/common.h14
-rw-r--r--plugins/popen.c29
-rw-r--r--plugins/runcmd.c13
-rw-r--r--plugins/utils.c31
-rw-r--r--plugins/utils.h9
7 files changed, 16 insertions, 82 deletions
diff --git a/plugins/check_dbi.c b/plugins/check_dbi.c
index 826eb8d..ced13d0 100644
--- a/plugins/check_dbi.c
+++ b/plugins/check_dbi.c
@@ -35,6 +35,7 @@ const char *email = "devel@monitoring-plugins.org";
35 35
36#include "common.h" 36#include "common.h"
37#include "utils.h" 37#include "utils.h"
38#include "utils_cmd.h"
38 39
39#include "netutils.h" 40#include "netutils.h"
40 41
diff --git a/plugins/check_pgsql.c b/plugins/check_pgsql.c
index 5cd4709..11ce691 100644
--- a/plugins/check_pgsql.c
+++ b/plugins/check_pgsql.c
@@ -34,6 +34,7 @@ const char *email = "devel@monitoring-plugins.org";
34 34
35#include "common.h" 35#include "common.h"
36#include "utils.h" 36#include "utils.h"
37#include "utils_cmd.h"
37 38
38#include "netutils.h" 39#include "netutils.h"
39#include <libpq-fe.h> 40#include <libpq-fe.h>
diff --git a/plugins/common.h b/plugins/common.h
index 6bf4fca..0f08e2f 100644
--- a/plugins/common.h
+++ b/plugins/common.h
@@ -225,4 +225,18 @@ enum {
225# define __attribute__(x) /* do nothing */ 225# define __attribute__(x) /* do nothing */
226#endif 226#endif
227 227
228/* Try sysconf(_SC_OPEN_MAX) first, as it can be higher than OPEN_MAX.
229 * If that fails and the macro isn't defined, we fall back to an educated
230 * guess. There's no guarantee that our guess is adequate and the program
231 * will die with SIGSEGV if it isn't and the upper boundary is breached. */
232#define DEFAULT_MAXFD 256 /* fallback value if no max open files value is set */
233#define MAXFD_LIMIT 8192 /* upper limit of open files */
234#ifdef _SC_OPEN_MAX
235static long maxfd = 0;
236#elif defined(OPEN_MAX)
237# define maxfd OPEN_MAX
238#else /* sysconf macro unavailable, so guess (may be wildly inaccurate) */
239# define maxfd DEFAULT_MAXFD
240#endif
241
228#endif /* _COMMON_H_ */ 242#endif /* _COMMON_H_ */
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
diff --git a/plugins/runcmd.c b/plugins/runcmd.c
index 1a7c904..c382867 100644
--- a/plugins/runcmd.c
+++ b/plugins/runcmd.c
@@ -67,19 +67,6 @@
67 * occur in any number of threads simultaneously. */ 67 * occur in any number of threads simultaneously. */
68static pid_t *np_pids = NULL; 68static pid_t *np_pids = NULL;
69 69
70/* Try sysconf(_SC_OPEN_MAX) first, as it can be higher than OPEN_MAX.
71 * If that fails and the macro isn't defined, we fall back to an educated
72 * guess. There's no guarantee that our guess is adequate and the program
73 * will die with SIGSEGV if it isn't and the upper boundary is breached. */
74#ifdef _SC_OPEN_MAX
75static long maxfd = 0;
76#elif defined(OPEN_MAX)
77# define maxfd OPEN_MAX
78#else /* sysconf macro unavailable, so guess (may be wildly inaccurate) */
79# define maxfd 256
80#endif
81
82
83/** prototypes **/ 70/** prototypes **/
84static int np_runcmd_open(const char *, int *, int *) 71static int np_runcmd_open(const char *, int *, int *)
85 __attribute__((__nonnull__(1, 2, 3))); 72 __attribute__((__nonnull__(1, 2, 3)));
diff --git a/plugins/utils.c b/plugins/utils.c
index 231af92..ee62013 100644
--- a/plugins/utils.c
+++ b/plugins/utils.c
@@ -36,9 +36,6 @@ extern const char *progname;
36#define STRLEN 64 36#define STRLEN 64
37#define TXTBLK 128 37#define TXTBLK 128
38 38
39unsigned int timeout_state = STATE_CRITICAL;
40unsigned int timeout_interval = DEFAULT_SOCKET_TIMEOUT;
41
42time_t start_time, end_time; 39time_t start_time, end_time;
43 40
44/* ************************************************************************** 41/* **************************************************************************
@@ -148,33 +145,6 @@ print_revision (const char *command_name, const char *revision)
148 command_name, revision, PACKAGE, VERSION); 145 command_name, revision, PACKAGE, VERSION);
149} 146}
150 147
151const char *
152state_text (int result)
153{
154 switch (result) {
155 case STATE_OK:
156 return "OK";
157 case STATE_WARNING:
158 return "WARNING";
159 case STATE_CRITICAL:
160 return "CRITICAL";
161 case STATE_DEPENDENT:
162 return "DEPENDENT";
163 default:
164 return "UNKNOWN";
165 }
166}
167
168void
169timeout_alarm_handler (int signo)
170{
171 if (signo == SIGALRM) {
172 printf (_("%s - Plugin timed out after %d seconds\n"),
173 state_text(timeout_state), timeout_interval);
174 exit (timeout_state);
175 }
176}
177
178int 148int
179is_numeric (char *number) 149is_numeric (char *number)
180{ 150{
@@ -708,4 +678,3 @@ char *sperfdata_int (const char *label,
708 678
709 return data; 679 return data;
710} 680}
711
diff --git a/plugins/utils.h b/plugins/utils.h
index a436e1c..6aa316f 100644
--- a/plugins/utils.h
+++ b/plugins/utils.h
@@ -29,13 +29,6 @@ suite of plugins. */
29void support (void); 29void support (void);
30void print_revision (const char *, const char *); 30void print_revision (const char *, const char *);
31 31
32/* Handle timeouts */
33
34extern unsigned int timeout_state;
35extern unsigned int timeout_interval;
36
37RETSIGTYPE timeout_alarm_handler (int);
38
39extern time_t start_time, end_time; 32extern time_t start_time, end_time;
40 33
41/* Test input types */ 34/* Test input types */
@@ -89,8 +82,6 @@ void usage4(const char *) __attribute__((noreturn));
89void usage5(void) __attribute__((noreturn)); 82void usage5(void) __attribute__((noreturn));
90void usage_va(const char *fmt, ...) __attribute__((noreturn)); 83void usage_va(const char *fmt, ...) __attribute__((noreturn));
91 84
92const char *state_text (int);
93
94#define max(a,b) (((a)>(b))?(a):(b)) 85#define max(a,b) (((a)>(b))?(a):(b))
95#define min(a,b) (((a)<(b))?(a):(b)) 86#define min(a,b) (((a)<(b))?(a):(b))
96 87