summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/check_vsz.c92
1 files changed, 41 insertions, 51 deletions
diff --git a/plugins/check_vsz.c b/plugins/check_vsz.c
index f53eeae3..2ec8775b 100644
--- a/plugins/check_vsz.c
+++ b/plugins/check_vsz.c
@@ -33,12 +33,18 @@
33 * 33 *
34 *****************************************************************************/ 34 *****************************************************************************/
35 35
36#define PROGNAME "check_vsz"
37#define REVISION "$Revision$"
38#define COPYRIGHT "1999-2002"
39#define AUTHOR "Karl DeBisschop"
40#define EMAIL "karl@debisschop.net"
41#define SUMMARY "Check the image size of a running program.\n"
42
36#include "common.h" 43#include "common.h"
37#include "popen.h" 44#include "popen.h"
38#include "utils.h" 45#include "utils.h"
39 46
40int process_arguments (int argc, char **argv); 47int process_arguments (int argc, char **argv);
41int call_getopt (int argc, char **argv);
42void print_help (char *cmd); 48void print_help (char *cmd);
43void print_usage (char *cmd); 49void print_usage (char *cmd);
44 50
@@ -146,47 +152,6 @@ process_arguments (int argc, char **argv)
146{ 152{
147 int c; 153 int c;
148 154
149 if (argc < 2)
150 return ERROR;
151
152 c = 0;
153 while (c += (call_getopt (argc - c, &argv[c]))) {
154 if (argc <= c)
155 break;
156 if (warn == -1) {
157 if (!is_intnonneg (argv[c])) {
158 printf ("%s: critical threshold must be an integer: %s\n",
159 my_basename (argv[0]), argv[c]);
160 print_usage (my_basename (argv[0]));
161 exit (STATE_UNKNOWN);
162 }
163 warn = atoi (argv[c]);
164 }
165 else if (crit == -1) {
166 if (!is_intnonneg (argv[c])) {
167 printf ("%s: critical threshold must be an integer: %s\n",
168 my_basename (argv[0]), argv[c]);
169 print_usage (my_basename (argv[0]));
170 exit (STATE_UNKNOWN);
171 }
172 crit = atoi (argv[c]);
173 }
174 else if (proc == NULL) {
175 proc = malloc (strlen (argv[c]) + 1);
176 if (proc == NULL)
177 terminate (STATE_UNKNOWN,
178 "check_vsz: failed malloc of proc in process_arguments");
179 strcpy (proc, argv[c]);
180 }
181 }
182 return c;
183}
184
185int
186call_getopt (int argc, char **argv)
187{
188 int c, i = 1;
189
190#ifdef HAVE_GETOPT_H 155#ifdef HAVE_GETOPT_H
191 int option_index = 0; 156 int option_index = 0;
192 static struct option long_options[] = { 157 static struct option long_options[] = {
@@ -199,6 +164,9 @@ call_getopt (int argc, char **argv)
199 }; 164 };
200#endif 165#endif
201 166
167 if (argc < 2)
168 return ERROR;
169
202 while (1) { 170 while (1) {
203#ifdef HAVE_GETOPT_H 171#ifdef HAVE_GETOPT_H
204 c = getopt_long (argc, argv, "+hVc:w:C:", long_options, &option_index); 172 c = getopt_long (argc, argv, "+hVc:w:C:", long_options, &option_index);
@@ -208,14 +176,6 @@ call_getopt (int argc, char **argv)
208 if (c == EOF) 176 if (c == EOF)
209 break; 177 break;
210 178
211 i++;
212 switch (c) {
213 case 'c':
214 case 'w':
215 case 'C':
216 i++;
217 }
218
219 switch (c) { 179 switch (c) {
220 case '?': /* help */ 180 case '?': /* help */
221 printf ("%s: Unknown argument: %s\n\n", my_basename (argv[0]), optarg); 181 printf ("%s: Unknown argument: %s\n\n", my_basename (argv[0]), optarg);
@@ -254,7 +214,37 @@ call_getopt (int argc, char **argv)
254 break; 214 break;
255 } 215 }
256 } 216 }
257 return i; 217
218 c = optind;
219 if (warn == -1) {
220 if (!is_intnonneg (argv[c])) {
221 printf ("%s: critical threshold must be an integer: %s\n",
222 PROGNAME, argv[c]);
223 print_usage (PROGNAME);
224 exit (STATE_UNKNOWN);
225 }
226 warn = atoi (argv[c++]);
227 }
228
229 if (crit == -1) {
230 if (!is_intnonneg (argv[c])) {
231 printf ("%s: critical threshold must be an integer: %s\n",
232 PROGNAME, argv[c]);
233 print_usage (PROGNAME);
234 exit (STATE_UNKNOWN);
235 }
236 crit = atoi (argv[c++]);
237 }
238
239 if (proc == NULL) {
240 proc = malloc (strlen (argv[c]) + 1);
241 if (proc == NULL)
242 terminate (STATE_UNKNOWN,
243 "check_vsz: failed malloc of proc in process_arguments");
244 strcpy (proc, argv[c]);
245 }
246
247 return c;
258} 248}
259 249
260void 250void