diff options
Diffstat (limited to 'plugins/check_procs.c')
| -rw-r--r-- | plugins/check_procs.c | 61 |
1 files changed, 15 insertions, 46 deletions
diff --git a/plugins/check_procs.c b/plugins/check_procs.c index bebde983..7f35370b 100644 --- a/plugins/check_procs.c +++ b/plugins/check_procs.c | |||
| @@ -41,8 +41,8 @@ const char *copyright = "2000-2008"; | |||
| 41 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; | 41 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; |
| 42 | 42 | ||
| 43 | #include "common.h" | 43 | #include "common.h" |
| 44 | #include "popen.h" | ||
| 45 | #include "utils.h" | 44 | #include "utils.h" |
| 45 | #include "utils_cmd.h" | ||
| 46 | #include "regex.h" | 46 | #include "regex.h" |
| 47 | #include "utils_base.h" | 47 | #include "utils_base.h" |
| 48 | 48 | ||
| @@ -144,7 +144,7 @@ main (int argc, char **argv) | |||
| 144 | int pos; /* number of spaces before 'args' in `ps` output */ | 144 | int pos; /* number of spaces before 'args' in `ps` output */ |
| 145 | int cols; /* number of columns in ps output */ | 145 | int cols; /* number of columns in ps output */ |
| 146 | int expected_cols = PS_COLS - 1; | 146 | int expected_cols = PS_COLS - 1; |
| 147 | int i = 0; /* Temporary values */ | 147 | int i = 0, j = 0; /* Temporary values */ |
| 148 | double rss_sum = 0; | 148 | double rss_sum = 0; |
| 149 | double vsz_sum = 0; | 149 | double vsz_sum = 0; |
| 150 | double cpu_sum = 0; | 150 | double cpu_sum = 0; |
| @@ -153,6 +153,7 @@ main (int argc, char **argv) | |||
| 153 | double cpu_max = 0; | 153 | double cpu_max = 0; |
| 154 | int multiple_process_output_flag = 0; | 154 | int multiple_process_output_flag = 0; |
| 155 | int number_threshold_failure_flag = 0; | 155 | int number_threshold_failure_flag = 0; |
| 156 | output chld_out, chld_err; | ||
| 156 | 157 | ||
| 157 | 158 | ||
| 158 | setlocale (LC_ALL, ""); | 159 | setlocale (LC_ALL, ""); |
| @@ -173,41 +174,27 @@ main (int argc, char **argv) | |||
| 173 | mypid = getpid(); | 174 | mypid = getpid(); |
| 174 | 175 | ||
| 175 | /* Set signal handling and alarm timeout */ | 176 | /* Set signal handling and alarm timeout */ |
| 176 | if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) { | 177 | if (signal (SIGALRM, timeout_alarm_handler) == SIG_ERR) { |
| 177 | usage4 (_("Cannot catch SIGALRM")); | 178 | die (STATE_UNKNOWN, _("Cannot catch SIGALRM")); |
| 178 | } | 179 | } |
| 179 | alarm (timeout_interval); | 180 | (void) alarm ((unsigned) timeout_interval); |
| 180 | 181 | ||
| 181 | if (verbose >= 3) | 182 | if (verbose >= 3) |
| 182 | printf (_("CMD: %s\n"), PS_COMMAND); | 183 | printf (_("CMD: %s\n"), PS_COMMAND); |
| 183 | 184 | ||
| 184 | if (input_filename == NULL) { | 185 | if (input_filename == NULL) { |
| 185 | ps_input = spopen (PS_COMMAND); | 186 | result = cmd_run( PS_COMMAND, &chld_out, &chld_err, 0); |
| 186 | if (ps_input == NULL) { | 187 | if (chld_err.lines > 0) { |
| 187 | printf (_("Could not open pipe: %s\n"), PS_COMMAND); | 188 | printf ("%s: %s", _("System call sent warnings to stderr"), chld_err.line[0]); |
| 188 | return STATE_UNKNOWN; | 189 | exit(STATE_WARNING); |
| 189 | } | 190 | } |
| 190 | child_stderr = fdopen (child_stderr_array[fileno (ps_input)], "r"); | ||
| 191 | if (child_stderr == NULL) | ||
| 192 | printf (_("Could not open stderr for %s\n"), PS_COMMAND); | ||
| 193 | } else { | 191 | } else { |
| 194 | ps_input = fopen(input_filename, "r"); | 192 | result = cmd_file_read( input_filename, &chld_out, 0); |
| 195 | if (ps_input == NULL) { | ||
| 196 | die( STATE_UNKNOWN, _("Error opening %s\n"), input_filename ); | ||
| 197 | } | ||
| 198 | } | 193 | } |
| 199 | 194 | ||
| 200 | /* flush first line */ | 195 | /* flush first line: j starts at 1 */ |
| 201 | fgets (input_buffer, MAX_INPUT_BUFFER - 1, ps_input); | 196 | for (j = 1; j < chld_out.lines; j++) { |
| 202 | while ( input_buffer[strlen(input_buffer)-1] != '\n' ) | 197 | input_line = chld_out.line[j]; |
| 203 | fgets (input_buffer, MAX_INPUT_BUFFER - 1, ps_input); | ||
| 204 | |||
| 205 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, ps_input)) { | ||
| 206 | asprintf (&input_line, "%s", input_buffer); | ||
| 207 | while ( input_buffer[strlen(input_buffer)-1] != '\n' ) { | ||
| 208 | fgets (input_buffer, MAX_INPUT_BUFFER - 1, ps_input); | ||
| 209 | asprintf (&input_line, "%s%s", input_line, input_buffer); | ||
| 210 | } | ||
| 211 | 198 | ||
| 212 | if (verbose >= 3) | 199 | if (verbose >= 3) |
| 213 | printf ("%s", input_line); | 200 | printf ("%s", input_line); |
| @@ -353,27 +340,9 @@ main (int argc, char **argv) | |||
| 353 | } | 340 | } |
| 354 | } | 341 | } |
| 355 | 342 | ||
| 356 | /* If we get anything on STDERR, at least set warning */ | ||
| 357 | if (input_filename == NULL) { | ||
| 358 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) { | ||
| 359 | if (verbose) | ||
| 360 | printf ("STDERR: %s", input_buffer); | ||
| 361 | result = max_state (result, STATE_WARNING); | ||
| 362 | printf (_("System call sent warnings to stderr\n")); | ||
| 363 | } | ||
| 364 | |||
| 365 | (void) fclose (child_stderr); | ||
| 366 | |||
| 367 | /* close the pipe */ | ||
| 368 | if (spclose (ps_input)) { | ||
| 369 | printf (_("System call returned nonzero status\n")); | ||
| 370 | result = max_state (result, STATE_WARNING); | ||
| 371 | } | ||
| 372 | } | ||
| 373 | |||
| 374 | if (found == 0) { /* no process lines parsed so return STATE_UNKNOWN */ | 343 | if (found == 0) { /* no process lines parsed so return STATE_UNKNOWN */ |
| 375 | printf (_("Unable to read output\n")); | 344 | printf (_("Unable to read output\n")); |
| 376 | return result; | 345 | return STATE_UNKNOWN; |
| 377 | } | 346 | } |
| 378 | 347 | ||
| 379 | if ( result == STATE_UNKNOWN ) | 348 | if ( result == STATE_UNKNOWN ) |
