From 938d0d68daecf2a4d45b9e39d191259b63304bd2 Mon Sep 17 00:00:00 2001 From: Karl DeBisschop Date: Sat, 9 Nov 2002 11:37:14 +0000 Subject: remove call_getopt git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@182 f882894a-f735-0410-b71e-b25c423dba1c diff --git a/plugins/check_ups.c b/plugins/check_ups.c index 1e1aa39..c711de2 100644 --- a/plugins/check_ups.c +++ b/plugins/check_ups.c @@ -57,6 +57,10 @@ #include "utils.h" #define PROGNAME "check_ups" +#define REVISION "$Revision$" +#define COPYRIGHT "1999-2002" +#define AUTHOR "Ethan Galstad" +#define EMAIL "nagios@nagios.org" #define CHECK_NONE 0 @@ -433,50 +437,6 @@ process_arguments (int argc, char **argv) { int c; - if (argc < 2) - return ERROR; - - for (c = 1; c < argc; c++) { - if (strcmp ("-to", argv[c]) == 0) - strcpy (argv[c], "-t"); - else if (strcmp ("-wt", argv[c]) == 0) - strcpy (argv[c], "-w"); - else if (strcmp ("-ct", argv[c]) == 0) - strcpy (argv[c], "-c"); - } - - c = 0; - while ((c += (call_getopt (argc - c, &argv[c]))) < argc) { - - if (is_option (argv[c])) - continue; - - if (server_address == NULL) { - if (is_host (argv[c])) { - server_address = argv[c]; - } - else { - usage ("Invalid host name"); - } - } - } - - if (server_address == NULL) - server_address = strscpy (NULL, "127.0.0.1"); - - return validate_arguments (); -} - - - - - - -int -call_getopt (int argc, char **argv) -{ - int c, i = 0; - #ifdef HAVE_GETOPT_H int option_index = 0; static struct option long_options[] = { @@ -493,40 +453,39 @@ call_getopt (int argc, char **argv) }; #endif + if (argc < 2) + return ERROR; + + for (c = 1; c < argc; c++) { + if (strcmp ("-to", argv[c]) == 0) + strcpy (argv[c], "-t"); + else if (strcmp ("-wt", argv[c]) == 0) + strcpy (argv[c], "-w"); + else if (strcmp ("-ct", argv[c]) == 0) + strcpy (argv[c], "-c"); + } + while (1) { #ifdef HAVE_GETOPT_H c = - getopt_long (argc, argv, "+hVH:u:p:v:c:w:t:", long_options, + getopt_long (argc, argv, "hVH:u:p:v:c:w:t:", long_options, &option_index); #else - c = getopt (argc, argv, "+?hVH:u:p:v:c:w:t:"); + c = getopt (argc, argv, "hVH:u:p:v:c:w:t:"); #endif - i++; - - if (c == -1 || c == EOF || c == 1) + if (c == -1 || c == EOF) break; switch (c) { - case 'H': - case 'u': - case 'p': - case 'v': - case 'c': - case 'w': - case 't': - i++; - } - - switch (c) { case '?': /* help */ - usage ("Invalid argument\n"); + usage3 ("Unknown option", optopt); case 'H': /* hostname */ if (is_host (optarg)) { server_address = optarg; } else { - usage ("Invalid host name\n"); + usage2 ("Invalid host name", optarg); } break; case 'u': /* ups name */ @@ -537,7 +496,7 @@ call_getopt (int argc, char **argv) server_port = atoi (optarg); } else { - usage ("Server port must be a positive integer\n"); + usage2 ("Server port must be a positive integer", optarg); } break; case 'c': /* critical time threshold */ @@ -546,7 +505,7 @@ call_getopt (int argc, char **argv) check_critical_value = TRUE; } else { - usage ("Critical time must be a nonnegative integer\n"); + usage2 ("Critical time must be a nonnegative integer", optarg); } break; case 'w': /* warning time threshold */ @@ -555,7 +514,7 @@ call_getopt (int argc, char **argv) check_warning_value = TRUE; } else { - usage ("Warning time must be a nonnegative integer\n"); + usage2 ("Warning time must be a nonnegative integer", optarg); } break; case 'v': /* variable */ @@ -568,7 +527,7 @@ call_getopt (int argc, char **argv) else if (!strcmp (optarg, "LOADPCT")) check_variable = UPS_LOADPCT; else - usage ("Unrecognized UPS variable\n"); + usage2 ("Unrecognized UPS variable", optarg); break; case 't': /* timeout */ if (is_intnonneg (optarg)) { @@ -586,7 +545,20 @@ call_getopt (int argc, char **argv) exit (STATE_OK); } } - return i; + + + if (server_address == NULL) { + if (optind >= argc) { + server_address = strscpy (NULL, "127.0.0.1"); + } + else if (is_host (argv[optind])) { + server_address = argv[optind++]; + } + else { + usage ("Invalid host name"); + } + } + return validate_arguments(); } diff --git a/plugins/check_users.c b/plugins/check_users.c index 2b8fa15..e39e0d2 100644 --- a/plugins/check_users.c +++ b/plugins/check_users.c @@ -49,11 +49,14 @@ #include "utils.h" #define PROGNAME "check_users" +#define REVISION "$Revision$" +#define COPYRIGHT "1999-2002" +#define AUTHOR "Ethan Galstad" +#define EMAIL "nagios@nagios.org" #define possibly_set(a,b) ((a) == 0 ? (b) : 0) int process_arguments (int, char **); -int call_getopt (int, char **); void print_usage (void); void print_help (void); @@ -133,40 +136,6 @@ process_arguments (int argc, char **argv) { int c; - if (argc < 2) - usage ("\n"); - - c = 0; - while ((c += call_getopt (argc - c, &argv[c])) < argc) { - - if (is_option (argv[c])) - continue; - - if (wusers == -1 && argc > c) { - if (is_intnonneg (argv[c]) == FALSE) - usage ("Warning threshold must be a nonnegative integer\n"); - wusers = atoi (argv[c]); - - } - else if (cusers == -1 && argc > c) { - if (is_intnonneg (argv[c]) == FALSE) - usage ("Warning threshold must be a nonnegative integer\n"); - cusers = atoi (argv[c]); - } - } - - return OK; -} - - - - - -int -call_getopt (int argc, char **argv) -{ - int c, i = 0; - #ifdef HAVE_GETOPT_H int option_index = 0; static struct option long_options[] = { @@ -178,6 +147,9 @@ call_getopt (int argc, char **argv) }; #endif + if (argc < 2) + usage ("\n"); + while (1) { #ifdef HAVE_GETOPT_H c = getopt_long (argc, argv, "+hVvc:w:", long_options, &option_index); @@ -185,27 +157,19 @@ call_getopt (int argc, char **argv) c = getopt (argc, argv, "+hVvc:w:"); #endif - i++; - if (c == -1 || c == EOF || c == 1) break; switch (c) { - case 'c': - case 'w': - i++; - } - - switch (c) { case '?': /* print short usage statement if args not parsable */ - printf ("%s: Unknown argument: %s\n\n", my_basename (argv[0]), optarg); + printf ("%s: Unknown argument: %s\n\n", PROGNAME, optarg); print_usage (); exit (STATE_UNKNOWN); case 'h': /* help */ print_help (); exit (STATE_OK); case 'V': /* version */ - print_revision (my_basename (argv[0]), "$Revision$"); + print_revision (PROGNAME, REVISION); exit (STATE_OK); case 'c': /* critical */ if (!is_intnonneg (optarg)) @@ -219,7 +183,21 @@ call_getopt (int argc, char **argv) break; } } - return i; + + c = optind; + if (wusers == -1 && argc > c) { + if (is_intnonneg (argv[c]) == FALSE) + usage ("Warning threshold must be a nonnegative integer\n"); + wusers = atoi (argv[c++]); + } + + if (cusers == -1 && argc > c) { + if (is_intnonneg (argv[c]) == FALSE) + usage ("Warning threshold must be a nonnegative integer\n"); + cusers = atoi (argv[c]); + } + + return OK; } @@ -239,9 +217,9 @@ print_usage (void) void print_help (void) { - print_revision (PROGNAME, "$Revision$"); + print_revision (PROGNAME, REVISION); printf - ("Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)\n\n" + ("Copyright (c) " COPYRIGHT " " AUTHOR "(" EMAIL ")\n\n" "This plugin checks the number of users currently logged in on the local\n" "system and generates an error if the number exceeds the thresholds specified.\n"); print_usage (); -- cgit v0.10-9-g596f