summaryrefslogtreecommitdiffstats
path: root/plugins/check_disk.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_disk.c')
-rw-r--r--plugins/check_disk.c82
1 files changed, 28 insertions, 54 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 9ce4a324..bde95631 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -37,9 +37,10 @@
37#include <stdarg.h> 37#include <stdarg.h>
38 38
39#define PROGNAME "check_disk" 39#define PROGNAME "check_disk"
40#define REVISION "$Revision$"
41#define COPYRIGHT "2000-2002"
40 42
41int process_arguments (int, char **); 43int process_arguments (int, char **);
42int call_getopt (int, char **);
43int validate_arguments (void); 44int validate_arguments (void);
44int check_disk (int usp, int free_disk); 45int check_disk (int usp, int free_disk);
45void print_help (void); 46void print_help (void);
@@ -49,7 +50,7 @@ int w_df = -1;
49int c_df = -1; 50int c_df = -1;
50float w_dfp = -1.0; 51float w_dfp = -1.0;
51float c_dfp = -1.0; 52float c_dfp = -1.0;
52char *path = NULL; 53char *path = "";
53int verbose = FALSE; 54int verbose = FALSE;
54int display_mntp = FALSE; 55int display_mntp = FALSE;
55 56
@@ -73,7 +74,7 @@ main (int argc, char **argv)
73 if (process_arguments (argc, argv) != OK) 74 if (process_arguments (argc, argv) != OK)
74 usage ("Could not parse arguments\n"); 75 usage ("Could not parse arguments\n");
75 76
76 command_line = ssprintf (command_line, "%s %s", DF_COMMAND, path); 77 asprintf (&command_line, "%s %s", DF_COMMAND, path);
77 78
78 if (verbose) 79 if (verbose)
79 printf ("%s ==> ", command_line); 80 printf ("%s ==> ", command_line);
@@ -175,41 +176,6 @@ process_arguments (int argc, char **argv)
175{ 176{
176 int c; 177 int c;
177 178
178 if (argc < 2)
179 return ERROR;
180
181 for (c = 1; c < argc; c++) {
182 if (strcmp ("-to", argv[c]) == 0) {
183 strcpy (argv[c], "-t");
184 }
185 }
186
187 c = 0;
188 while ((c += (call_getopt (argc - c, &argv[c]))) < argc) {
189
190 if (w_dfp == -1 && is_intnonneg (argv[c]))
191 w_dfp = (100.0 - atof (argv[c]));
192 else if (c_dfp == -1 && is_intnonneg (argv[c]))
193 c_dfp = (100.0 - atof (argv[c]));
194 else if (path == NULL || path[0] == 0)
195 path = strscpy (path, argv[c]);
196 }
197
198 if (path == NULL) {
199 path = malloc (1);
200 if (path == NULL)
201 terminate (STATE_UNKNOWN, "Could not malloc empty path\n");
202 path[0] = 0;
203 }
204
205 return validate_arguments ();
206}
207
208int
209call_getopt (int argc, char **argv)
210{
211 int c, i = 0;
212
213#ifdef HAVE_GETOPT_H 179#ifdef HAVE_GETOPT_H
214 int option_index = 0; 180 int option_index = 0;
215 static struct option long_options[] = { 181 static struct option long_options[] = {
@@ -226,28 +192,25 @@ call_getopt (int argc, char **argv)
226 }; 192 };
227#endif 193#endif
228 194
195 if (argc < 2)
196 return ERROR;
197
198 for (c = 1; c < argc; c++)
199 if (strcmp ("-to", argv[c]) == 0)
200 strcpy (argv[c], "-t");
201
229 while (1) { 202 while (1) {
230#ifdef HAVE_GETOPT_H 203#ifdef HAVE_GETOPT_H
231 c = 204 c =
232 getopt_long (argc, argv, "+?Vhvt:c:w:p:m", long_options, &option_index); 205 getopt_long (argc, argv, "Vhvt:c:w:p:m", long_options, &option_index);
233#else 206#else
234 c = getopt (argc, argv, "+?Vhvt:c:w:p:m"); 207 c = getopt (argc, argv, "Vhvt:c:w:p:m");
235#endif 208#endif
236 209
237 i++; 210 if (c == -1 || c == EOF)
238
239 if (c == -1 || c == EOF || c == 1)
240 break; 211 break;
241 212
242 switch (c) { 213 switch (c) {
243 case 't':
244 case 'c':
245 case 'w':
246 case 'p':
247 i++;
248 }
249
250 switch (c) {
251 case 'w': /* warning time threshold */ 214 case 'w': /* warning time threshold */
252 if (is_intnonneg (optarg)) { 215 if (is_intnonneg (optarg)) {
253 w_df = atoi (optarg); 216 w_df = atoi (optarg);
@@ -298,7 +261,7 @@ call_getopt (int argc, char **argv)
298 display_mntp = TRUE; 261 display_mntp = TRUE;
299 break; 262 break;
300 case 'V': /* version */ 263 case 'V': /* version */
301 print_revision (my_basename (argv[0]), "$Revision$"); 264 print_revision (PROGNAME, REVISION);
302 exit (STATE_OK); 265 exit (STATE_OK);
303 case 'h': /* help */ 266 case 'h': /* help */
304 print_help (); 267 print_help ();
@@ -308,7 +271,18 @@ call_getopt (int argc, char **argv)
308 break; 271 break;
309 } 272 }
310 } 273 }
311 return i; 274
275 c = optind;
276 if (w_dfp == -1 && argc > c && is_intnonneg (argv[c]))
277 w_dfp = (100.0 - atof (argv[c++]));
278
279 if (c_dfp == -1 && argc > c && is_intnonneg (argv[c]))
280 c_dfp = (100.0 - atof (argv[c++]));
281
282 if (argc > c && strlen (path) == 0)
283 path = argv[c++];
284
285 return validate_arguments ();
312} 286}
313 287
314int 288int
@@ -358,7 +332,7 @@ check_disk (usp, free_disk)
358void 332void
359print_help (void) 333print_help (void)
360{ 334{
361 print_revision (PROGNAME, "$Revision$"); 335 print_revision (PROGNAME, REVISION);
362 printf 336 printf
363 ("Copyright (c) 2000 Ethan Galstad/Karl DeBisschop\n\n" 337 ("Copyright (c) 2000 Ethan Galstad/Karl DeBisschop\n\n"
364 "This plugin will check the percent of used disk space on a mounted\n" 338 "This plugin will check the percent of used disk space on a mounted\n"