aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Karl DeBisschop <kdebisschop@users.sourceforge.net> 2004-02-20 05:04:32 +0000
committerGravatar Karl DeBisschop <kdebisschop@users.sourceforge.net> 2004-02-20 05:04:32 +0000
commitba7ac4ddde695230b1039205ffa3d5838251a974 (patch)
tree9ad700ff6f34b80d9ede11507bfb8a639d1ee5f4
parentf0b61a736e701e62805d4962563159c4bb901b68 (diff)
downloadmonitoring-plugins-ba7ac4ddde695230b1039205ffa3d5838251a974.tar.gz
handle case where line from ps output exceed MAX_INPUT_BUFFER
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@815 f882894a-f735-0410-b71e-b25c423dba1c
-rw-r--r--plugins/check_procs.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/plugins/check_procs.c b/plugins/check_procs.c
index 782a9a11..edb33aca 100644
--- a/plugins/check_procs.c
+++ b/plugins/check_procs.c
@@ -79,7 +79,9 @@ char tmp[MAX_INPUT_BUFFER];
int
main (int argc, char **argv)
{
- char input_buffer[MAX_INPUT_BUFFER];
+ char *input_buffer;
+ char *input_line;
+ char *procprog;
int procuid = 0;
int procppid = 0;
@@ -87,7 +89,6 @@ main (int argc, char **argv)
int procrss = 0;
float procpcpu = 0;
char procstat[8];
- char procprog[MAX_INPUT_BUFFER];
char *procargs;
char *temp_string;
@@ -109,6 +110,9 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ input_buffer = malloc (MAX_INPUT_BUFFER);
+ procprog = malloc (MAX_INPUT_BUFFER);
+
asprintf (&metric_name, "PROCS");
metric = METRIC_PROCS;
@@ -128,13 +132,25 @@ main (int argc, char **argv)
if (child_stderr == NULL)
printf (_("Could not open stderr for %s\n"), PS_COMMAND);
+ /* flush first line */
fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process);
+ while ( input_buffer[strlen(input_buffer)-1] != '\n' )
+ fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process);
while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
+ asprintf (&input_line, "%s", input_buffer);
+ while ( input_buffer[strlen(input_buffer)-1] != '\n' ) {
+ fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process);
+ asprintf (&input_line, "%s%s", input_line, input_buffer);
+ }
+
+ if (verbose >= 3)
+ printf ("%s", input_line);
+
strcpy (procprog, "");
asprintf (&procargs, "%s", "");
- cols = sscanf (input_buffer, PS_FORMAT, PS_VARLIST);
+ cols = sscanf (input_line, PS_FORMAT, PS_VARLIST);
/* Zombie processes do not give a procprog command */
if ( cols == (expected_cols - 1) && strstr(procstat, zombie) ) {
@@ -146,7 +162,7 @@ main (int argc, char **argv)
}
if ( cols >= expected_cols ) {
resultsum = 0;
- asprintf (&procargs, "%s", input_buffer + pos);
+ asprintf (&procargs, "%s", input_line + pos);
strip (procargs);
/* Some ps return full pathname for command. This removes path */