From 61bf15c0f6a584a1503752b89cb13c44508b6922 Mon Sep 17 00:00:00 2001 From: Karl DeBisschop Date: Fri, 22 Nov 2002 01:33:26 +0000 Subject: add a few comments, trap a few place where a NULL string might have been handled git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@222 f882894a-f735-0410-b71e-b25c423dba1c diff --git a/plugins/check_procs.c b/plugins/check_procs.c index 27cd2da..967b4de 100644 --- a/plugins/check_procs.c +++ b/plugins/check_procs.c @@ -61,7 +61,7 @@ int cmax = -1; int wmin = -1; int cmin = -1; -int options = 0; +int options = 0; /* bitmask of filter criteria to test against */ #define ALL 1 #define STAT 2 #define PPID 4 @@ -89,15 +89,13 @@ main (int argc, char **argv) char procprog[MAX_INPUT_BUFFER]; char *procargs; - int resultsum = 0; - int found = 0; - int procs = 0; - int pos; + int resultsum = 0; /* bitmask of the filter criteria met by a process */ + int found = 0; /* counter for number of lines returned in `ps` output */ + int procs = 0; /* counter for number of processes meeting filter criteria */ + int pos; /* number of spaces before 'args' in `ps` output */ int result = STATE_UNKNOWN; - procargs = malloc (MAX_INPUT_BUFFER); - if (process_arguments (argc, argv) == ERROR) usage ("Unable to parse command line\n"); @@ -127,13 +125,13 @@ main (int argc, char **argv) ) { found++; resultsum = 0; - procargs = strcpy (procargs, &input_buffer[pos]); - strip (procargs); + asprintf (&procargs, "%s", input_buffer + pos); + strip (procargs); if ((options & STAT) && (strstr (statopts, procstat))) resultsum |= STAT; - if ((options & ARGS) && (strstr (procargs, args) == procargs)) + if ((options & ARGS) && procargs && (strstr (procargs, args) == procargs)) resultsum |= ARGS; - if ((options & PROG) && (strcmp (prog, procprog) == 0)) + if ((options & PROG) && procprog && (strcmp (prog, procprog) == 0)) resultsum |= PROG; if ((options & PPID) && (procppid == ppid)) resultsum |= PPID; -- cgit v0.10-9-g596f