Code

test GNU_SOURCE and include features.h if present to clear warning about asprintf...
[nagiosplug.git] / plugins / check_fping.c
index 9a2dd5570ba2b3b73f41fc5ec6ac775c6b341c05..ac203f523d3a646cd8e2dd11f54f098857cd0426 100644 (file)
@@ -32,7 +32,7 @@
 #include "popen.h"
 #include "utils.h"
 
-#define PROGNAME "check_fping"
+const char *progname = "check_fping";
 #define PACKET_COUNT 1
 #define PACKET_SIZE 56
 #define UNKNOWN_PACKET_LOSS 200        /* 200% */
@@ -71,9 +71,8 @@ main (int argc, char **argv)
        server = strscpy (server, server_name);
 
        /* compose the command */
-       command_line = ssprintf
-               (command_line, "%s -b %d -c %d %s",
-                PATH_TO_FPING, packet_size, packet_count, server);
+       asprintf (&command_line, "%s -b %d -c %d %s", PATH_TO_FPING,
+                 packet_size, packet_count, server);
 
        if (verbose)
                printf ("%s\n", command_line);
@@ -203,7 +202,6 @@ process_arguments (int argc, char **argv)
        int c;
        char *rv[2];
 
-#ifdef HAVE_GETOPT_H
        int option_index = 0;
        static struct option long_options[] = {
                {"hostname", required_argument, 0, 'H'},
@@ -216,7 +214,6 @@ process_arguments (int argc, char **argv)
                {"help", no_argument, 0, 'h'},
                {0, 0, 0, 0}
        };
-#endif
 
        rv[PL] = NULL;
        rv[RTA] = NULL;
@@ -232,26 +229,21 @@ process_arguments (int argc, char **argv)
        }
 
        while (1) {
-#ifdef HAVE_GETOPT_H
-               c =
-                       getopt_long (argc, argv, "+hVvH:c:w:b:n:", long_options, &option_index);
-#else
-               c = getopt (argc, argv, "+hVvH:c:w:b:n:");
-#endif
+               c = getopt_long (argc, argv, "+hVvH:c:w:b:n:", long_options, &option_index);
 
                if (c == -1 || c == EOF || c == 1)
                        break;
 
                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 'v':                                                                       /* verbose mode */
                        verbose = TRUE;
@@ -326,12 +318,12 @@ get_threshold (char *arg, char *rv[2])
                arg1[strcspn (arg1, ",:")] = 0;
                if (strstr (arg1, "%") && strstr (arg2, "%"))
                        terminate (STATE_UNKNOWN,
-                                                                "%s: Only one threshold may be packet loss (%s)\n", PROGNAME,
+                                                                "%s: Only one threshold may be packet loss (%s)\n", progname,
                                                                 arg);
                if (!strstr (arg1, "%") && !strstr (arg2, "%"))
                        terminate (STATE_UNKNOWN,
                                                                 "%s: Only one threshold must be packet loss (%s)\n",
-                                                                PROGNAME, arg);
+                                                                progname, arg);
        }
 
        if (arg2 && strstr (arg2, "%")) {
@@ -359,7 +351,7 @@ get_threshold (char *arg, char *rv[2])
 void
 print_usage (void)
 {
-       printf ("Usage: %s <host_address>\n", PROGNAME);
+       printf ("Usage: %s <host_address>\n", progname);
 }
 
 
@@ -370,7 +362,7 @@ void
 print_help (void)
 {
 
-       print_revision (PROGNAME, "$Revision$");
+       print_revision (progname, "$Revision$");
 
        printf
                ("Copyright (c) 1999 Didi Rieder (adrieder@sbox.tu-graz.ac.at)\n\n"