summaryrefslogtreecommitdiffstats
path: root/plugins/check_procs.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_procs.c')
-rw-r--r--plugins/check_procs.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/plugins/check_procs.c b/plugins/check_procs.c
index 05318b6..755ed86 100644
--- a/plugins/check_procs.c
+++ b/plugins/check_procs.c
@@ -77,6 +77,7 @@ char *prog = "";
77char *args = ""; 77char *args = "";
78char *fmt = ""; 78char *fmt = "";
79char tmp[MAX_INPUT_BUFFER]; 79char tmp[MAX_INPUT_BUFFER];
80const char *zombie = "Z";
80 81
81int 82int
82main (int argc, char **argv) 83main (int argc, char **argv)
@@ -93,6 +94,7 @@ main (int argc, char **argv)
93 int found = 0; /* counter for number of lines returned in `ps` output */ 94 int found = 0; /* counter for number of lines returned in `ps` output */
94 int procs = 0; /* counter for number of processes meeting filter criteria */ 95 int procs = 0; /* counter for number of processes meeting filter criteria */
95 int pos; /* number of spaces before 'args' in `ps` output */ 96 int pos; /* number of spaces before 'args' in `ps` output */
97 int cols; /* number of columns in ps output */
96 98
97 int result = STATE_UNKNOWN; 99 int result = STATE_UNKNOWN;
98 100
@@ -115,14 +117,18 @@ main (int argc, char **argv)
115 fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process); 117 fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process);
116 118
117 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { 119 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
118 if (
119#ifdef USE_PS_VARS 120#ifdef USE_PS_VARS
120 sscanf (input_buffer, PS_FORMAT, PS_VARLIST) >= 4 121 cols = sscanf (input_buffer, PS_FORMAT, PS_VARLIST);
121#else 122#else
122 sscanf (input_buffer, PS_FORMAT, procstat, &procuid, &procppid, &pos, 123 cols = sscanf (input_buffer, PS_FORMAT, procstat, &procuid,
123 procprog) >= 4 124 &procppid, &pos, procprog);
124#endif 125#endif
125 ) { 126 /* Zombie processes do not give a procprog command */
127 if ( cols == 3 && strstr(procstat, zombie) ) {
128 strcpy(procprog, "");
129 cols = 4;
130 }
131 if ( cols >= 4 ) {
126 found++; 132 found++;
127 resultsum = 0; 133 resultsum = 0;
128 asprintf (&procargs, "%s", input_buffer + pos); 134 asprintf (&procargs, "%s", input_buffer + pos);
@@ -147,6 +153,10 @@ main (int argc, char **argv)
147#endif 153#endif
148 if (options == resultsum) 154 if (options == resultsum)
149 procs++; 155 procs++;
156 }
157 /* This should not happen */
158 else if (verbose) {
159 printf("Not parseable: %s", input_buffer);
150 } 160 }
151 } 161 }
152 162