[Nagiosplug-checkins] CVS: nagiosplug/plugins check_procs.c,1.25,1.26

Karl DeBisschop kdebisschop at users.sourceforge.net
Thu Feb 19 21:16:12 CET 2004


Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22629

Modified Files:
	check_procs.c 
Log Message:
handle case where line from ps output exceed MAX_INPUT_BUFFER


Index: check_procs.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_procs.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -r1.25 -r1.26
*** check_procs.c	20 Feb 2004 03:00:19 -0000	1.25
--- check_procs.c	20 Feb 2004 05:04:32 -0000	1.26
***************
*** 80,84 ****
  main (int argc, char **argv)
  {
! 	char input_buffer[MAX_INPUT_BUFFER];
  
  	int procuid = 0;
--- 80,86 ----
  main (int argc, char **argv)
  {
! 	char *input_buffer;
! 	char *input_line;
! 	char *procprog;
  
  	int procuid = 0;
***************
*** 88,92 ****
  	float procpcpu = 0;
  	char procstat[8];
- 	char procprog[MAX_INPUT_BUFFER];
  	char *procargs;
  	char *temp_string;
--- 90,93 ----
***************
*** 110,113 ****
--- 111,117 ----
  	textdomain (PACKAGE);
  
+ 	input_buffer = malloc (MAX_INPUT_BUFFER);
+ 	procprog = malloc (MAX_INPUT_BUFFER);
+ 
  	asprintf (&metric_name, "PROCS");
  	metric = METRIC_PROCS;
***************
*** 129,139 ****
  		printf (_("Could not open stderr for %s\n"), PS_COMMAND);
  
  	fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process);
  
  	while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
  		strcpy (procprog, "");
  		asprintf (&procargs, "%s", "");
  
! 		cols = sscanf (input_buffer, PS_FORMAT, PS_VARLIST);
  
  		/* Zombie processes do not give a procprog command */
--- 133,155 ----
  		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_line, PS_FORMAT, PS_VARLIST);
  
  		/* Zombie processes do not give a procprog command */
***************
*** 147,151 ****
  		if ( cols >= expected_cols ) {
  			resultsum = 0;
! 			asprintf (&procargs, "%s", input_buffer + pos);
  			strip (procargs);
  
--- 163,167 ----
  		if ( cols >= expected_cols ) {
  			resultsum = 0;
! 			asprintf (&procargs, "%s", input_line + pos);
  			strip (procargs);
  





More information about the Commits mailing list