Code

test GNU_SOURCE and include features.h if present to clear warning about asprintf...
[nagiosplug.git] / plugins / check_procs.c
index 2cf550cc365ab35ab959b9c523abc141e84d1035..ccf0891d13322c61a6710c7621a6a46673851eba 100644 (file)
@@ -80,7 +80,7 @@ Optional Filters:\n\
  -u, --user=USER\n\
    Only scan for processes with user name or ID indicated.\n\
  -a, --argument-array=STRING\n\
-   Only scan for ARGS that match up to the length of the given STRING.\n\
+   Only scan for processes with args that contain STRING.\n\
  -C, --command=COMMAND\n\
    Only scan for exact matches to the named COMMAND.\n\
 \n\
@@ -202,19 +202,21 @@ main (int argc, char **argv)
                cols = sscanf (input_buffer, PS_FORMAT, PS_VARLIST);
 
                /* Zombie processes do not give a procprog command */
-               /* - would they give other columns? */
-               if ( cols == 3 && strstr(procstat, zombie) ) {
-                       cols = 4;
+               if ( cols == 6 && strstr(procstat, zombie) ) {
+                       cols = 7;
+                       /* Set some value for procargs for the strip command further below 
+                       Seen to be a problem on some Solaris 7 and 8 systems */
+                       input_buffer[pos] = '\n';
+                       input_buffer[pos+1] = 0x0;
                }
                if ( cols >= 7 ) {
-                       found++;
                        resultsum = 0;
                        asprintf (&procargs, "%s", input_buffer + pos);
-                       strip (procargs);
+                       strip (procargs);
 
                        if ((options & STAT) && (strstr (statopts, procstat)))
                                resultsum |= STAT;
-                       if ((options & ARGS) && procargs && (strstr (procargs, args) == procargs))
+                       if ((options & ARGS) && procargs && (strstr (procargs, args) != NULL))
                                resultsum |= ARGS;
                        if ((options & PROG) && procprog && (strcmp (prog, procprog) == 0))
                                resultsum |= PROG;
@@ -234,6 +236,12 @@ main (int argc, char **argv)
                                        procs, procuid, procvsz, procrss,
                                        procppid, procpcpu, procstat, procprog, procargs);
 
+                       /* Ignore self */
+                       if (strcmp (procprog, progname) == 0)
+                               continue;
+
+                       found++;
+
                        /* Next line if filters not matched */
                        if (!(options == resultsum || options == ALL))
                                continue;