From 4e19425ce697ce17257b0db904a656e3c8557911 Mon Sep 17 00:00:00 2001 From: "M. Sean Finney" Date: Wed, 25 May 2005 00:43:20 +0000 Subject: fixes for check_procs: - added support for printing the pid in all the ps outputs - don't use the proc name to ignore self, use the pid vs getpid(). - initialize procetime to null string otherwise -vvv can have funny results git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1177 f882894a-f735-0410-b71e-b25c423dba1c --- plugins/check_nagios.c | 1 + plugins/check_procs.c | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) (limited to 'plugins') diff --git a/plugins/check_nagios.c b/plugins/check_nagios.c index 0176983c..089ff669 100644 --- a/plugins/check_nagios.c +++ b/plugins/check_nagios.c @@ -49,6 +49,7 @@ main (int argc, char **argv) char *temp_ptr; FILE *fp; int procuid = 0; + int procpid = 0; int procppid = 0; int procvsz = 0; int procrss = 0; diff --git a/plugins/check_procs.c b/plugins/check_procs.c index 15ec76f5..671190ca 100644 --- a/plugins/check_procs.c +++ b/plugins/check_procs.c @@ -85,7 +85,9 @@ main (int argc, char **argv) char *input_line; char *procprog; + pid_t mypid = 0; int procuid = 0; + int procpid = 0; int procppid = 0; int procvsz = 0; int procrss = 0; @@ -106,11 +108,12 @@ main (int argc, char **argv) int expected_cols = PS_COLS - 1; int warn = 0; /* number of processes in warn state */ int crit = 0; /* number of processes in crit state */ + procetime[0]='\0'; /* keep this clean because -vvv always prints it */ int i = 0; int result = STATE_UNKNOWN; - setlocale (LC_ALL, ""); + //setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); @@ -123,6 +126,9 @@ main (int argc, char **argv) if (process_arguments (argc, argv) == ERROR) usage4 (_("Could not parse arguments")); + /* get our pid */ + mypid = getpid(); + /* Set signal handling and alarm timeout */ if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) { usage4 (_("Cannot catch SIGALRM")); @@ -182,15 +188,13 @@ main (int argc, char **argv) procseconds = convert_to_seconds(procetime); if (verbose >= 3) - printf ("%d %d %d %d %d %.2f %s %s %s %s\n", + printf ("%d %d %d %d %d %d %.2f %s %s %s %s\n", procs, procuid, procvsz, procrss, - procppid, procpcpu, procstat, + procpid, procppid, procpcpu, procstat, procetime, procprog, procargs); /* Ignore self */ - if (strcmp (procprog, progname) == 0) { - continue; - } + if (mypid == procpid) continue; if ((options & STAT) && (strstr (statopts, procstat))) resultsum |= STAT; @@ -639,9 +643,6 @@ convert_to_seconds(char *etime) { (minutes * 60) + seconds; - if (verbose >= 3) { - printf("seconds: %d\n", total); - } return total; } -- cgit v1.2.3-74-g34f1