diff --git a/plugins/check_procs.c b/plugins/check_procs.c
index 27cd2daee7f17b8be3330952b05896935672242b..755ed8609814b3aefcd5dc7787bf1ea26321bc7c 100644 (file)
--- a/plugins/check_procs.c
+++ b/plugins/check_procs.c
*
******************************************************************************/
*
******************************************************************************/
-#define PROGNAME "check_snmp"
+const char *progname = "check_procs";
#define REVISION "$Revision$"
#define COPYRIGHT "1999-2002"
#define AUTHOR "Ethan Galstad"
#define REVISION "$Revision$"
#define COPYRIGHT "1999-2002"
#define AUTHOR "Ethan Galstad"
int wmin = -1;
int cmin = -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
#define ALL 1
#define STAT 2
#define PPID 4
int verbose = FALSE;
int uid;
int ppid;
int verbose = FALSE;
int uid;
int ppid;
-char *statopts = NULL;
-char *prog = NULL;
-char *args = NULL;
-char *fmt = NULL;
+char *statopts = "";
+char *prog = "";
+char *args = "";
+char *fmt = "";
char tmp[MAX_INPUT_BUFFER];
char tmp[MAX_INPUT_BUFFER];
+const char *zombie = "Z";
int
main (int argc, char **argv)
int
main (int argc, char **argv)
char procprog[MAX_INPUT_BUFFER];
char *procargs;
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 cols; /* number of columns in ps output */
int result = STATE_UNKNOWN;
int result = STATE_UNKNOWN;
- procargs = malloc (MAX_INPUT_BUFFER);
-
if (process_arguments (argc, argv) == ERROR)
usage ("Unable to parse command line\n");
if (process_arguments (argc, argv) == ERROR)
usage ("Unable to parse command line\n");
fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process);
while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process);
while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
- if (
#ifdef USE_PS_VARS
#ifdef USE_PS_VARS
- sscanf (input_buffer, PS_FORMAT, PS_VARLIST) >= 4
+ cols = sscanf (input_buffer, PS_FORMAT, PS_VARLIST);
#else
#else
- sscanf (input_buffer, PS_FORMAT, procstat, &procuid, &procppid, &pos,
- procprog) >= 4
+ cols = sscanf (input_buffer, PS_FORMAT, procstat, &procuid,
+ &procppid, &pos, procprog);
#endif
#endif
- ) {
+ /* Zombie processes do not give a procprog command */
+ if ( cols == 3 && strstr(procstat, zombie) ) {
+ strcpy(procprog, "");
+ cols = 4;
+ }
+ if ( cols >= 4 ) {
found++;
resultsum = 0;
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 & STAT) && (strstr (statopts, procstat)))
resultsum |= STAT;
- if ((options & ARGS) && (strstr (procargs, args) == procargs))
+ if ((options & ARGS) && procargs && (strstr (procargs, args) == procargs))
resultsum |= ARGS;
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;
resultsum |= PROG;
if ((options & PPID) && (procppid == ppid))
resultsum |= PPID;
#endif
if (options == resultsum)
procs++;
#endif
if (options == resultsum)
procs++;
+ }
+ /* This should not happen */
+ else if (verbose) {
+ printf("Not parseable: %s", input_buffer);
}
}
}
}
};
#endif
};
#endif
- asprintf (&fmt, "");
-
for (c = 1; c < argc; c++)
if (strcmp ("-to", argv[c]) == 0)
strcpy (argv[c], "-t");
for (c = 1; c < argc; c++)
if (strcmp ("-to", argv[c]) == 0)
strcpy (argv[c], "-t");
print_help ();
exit (STATE_OK);
case 'V': /* version */
print_help ();
exit (STATE_OK);
case 'V': /* version */
- print_revision (PROGNAME, REVISION);
+ print_revision (progname, REVISION);
exit (STATE_OK);
case 't': /* timeout period */
if (!is_integer (optarg)) {
printf ("%s: Timeout Interval must be an integer!\n\n",
exit (STATE_OK);
case 't': /* timeout period */
if (!is_integer (optarg)) {
printf ("%s: Timeout Interval must be an integer!\n\n",
- my_basename (argv[0]));
+ progname);
print_usage ();
exit (STATE_UNKNOWN);
}
print_usage ();
exit (STATE_UNKNOWN);
}
}
else {
printf ("%s: Critical Process Count must be an integer!\n\n",
}
else {
printf ("%s: Critical Process Count must be an integer!\n\n",
- my_basename (argv[0]));
+ progname);
print_usage ();
exit (STATE_UNKNOWN);
}
print_usage ();
exit (STATE_UNKNOWN);
}
}
else {
printf ("%s: Warning Process Count must be an integer!\n\n",
}
else {
printf ("%s: Warning Process Count must be an integer!\n\n",
- my_basename (argv[0]));
+ progname);
print_usage ();
exit (STATE_UNKNOWN);
}
case 'p': /* process id */
if (sscanf (optarg, "%d%[^0-9]", &ppid, tmp) == 1) {
print_usage ();
exit (STATE_UNKNOWN);
}
case 'p': /* process id */
if (sscanf (optarg, "%d%[^0-9]", &ppid, tmp) == 1) {
- asprintf (&fmt, "%s%sPPID = %d", (options ? ", " : ""), ppid);
+ asprintf (&fmt, "%s%sPPID = %d", fmt, (options ? ", " : ""), ppid);
options |= PPID;
break;
}
printf ("%s: Parent Process ID must be an integer!\n\n",
options |= PPID;
break;
}
printf ("%s: Parent Process ID must be an integer!\n\n",
- my_basename (argv[0]));
+ progname);
print_usage ();
exit (STATE_UNKNOWN);
case 's': /* status */
print_usage ();
exit (STATE_UNKNOWN);
case 's': /* status */
uid = pw->pw_uid;
}
user = pw->pw_name;
uid = pw->pw_uid;
}
user = pw->pw_name;
- asprintf (&fmt, "%s%sUID = %d (%s)", (options ? ", " : ""), fmt,
+ asprintf (&fmt, "%s%sUID = %d (%s)", fmt, (options ? ", " : ""),
uid, user);
options |= USER;
break;
uid, user);
options |= USER;
break;
void
print_help (void)
{
void
print_help (void)
{
- print_revision (PROGNAME, REVISION);
+ print_revision (progname, REVISION);
printf
("Copyright (c) %s %s <%s>\n\n%s\n",
COPYRIGHT, AUTHOR, EMAIL, SUMMARY);
printf
("Copyright (c) %s %s <%s>\n\n%s\n",
COPYRIGHT, AUTHOR, EMAIL, SUMMARY);