diff options
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2002-11-13 11:50:54 +0000 |
---|---|---|
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2002-11-13 11:50:54 +0000 |
commit | 9e009c4b1128352c6039d25b39213fd480e9b055 (patch) | |
tree | e1495ef4ada6f8e092e20bc474195719f1b2b4aa /plugins/check_disk.c | |
parent | 9728dcad931d1c442a6d8e3e6765e2d9870600d1 (diff) | |
download | monitoring-plugins-9e009c4b1128352c6039d25b39213fd480e9b055.tar.gz |
remove call_getopt and asprintf
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@190 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_disk.c')
-rw-r--r-- | plugins/check_disk.c | 82 |
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 | ||
41 | int process_arguments (int, char **); | 43 | int process_arguments (int, char **); |
42 | int call_getopt (int, char **); | ||
43 | int validate_arguments (void); | 44 | int validate_arguments (void); |
44 | int check_disk (int usp, int free_disk); | 45 | int check_disk (int usp, int free_disk); |
45 | void print_help (void); | 46 | void print_help (void); |
@@ -49,7 +50,7 @@ int w_df = -1; | |||
49 | int c_df = -1; | 50 | int c_df = -1; |
50 | float w_dfp = -1.0; | 51 | float w_dfp = -1.0; |
51 | float c_dfp = -1.0; | 52 | float c_dfp = -1.0; |
52 | char *path = NULL; | 53 | char *path = ""; |
53 | int verbose = FALSE; | 54 | int verbose = FALSE; |
54 | int display_mntp = FALSE; | 55 | int 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 | |||
208 | int | ||
209 | call_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 | ||
314 | int | 288 | int |
@@ -358,7 +332,7 @@ check_disk (usp, free_disk) | |||
358 | void | 332 | void |
359 | print_help (void) | 333 | print_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" |