Code

Remove unnecessary \ - complaints from Tru64's cc compiler
[nagiosplug.git] / plugins / check_by_ssh.c
index 59e417861fcac568f13e3c36cf79b5e04dc2f9e9..0cffaeb2ef251c81e77bd4e5c6aa8efb6fc343f7 100644 (file)
@@ -22,7 +22,7 @@
  *
  *****************************************************************************/
  
-#define PROGRAM check_by_ssh
+const char *progname = "check_by_ssh";
 #define DESCRIPTION "Run checks on a remote system using ssh, wrapping the proper timeout around the ssh invocation."
 #define AUTHOR "Karl DeBisschop"
 #define EMAIL "karl@debisschop.net"
 #include "utils.h"
 #include <time.h>
 
-#define PROGNAME "check_by_ssh"
-
 int process_arguments (int, char **);
 int validate_arguments (void);
-void print_help (char *command_name);
+void print_help (const char *command_name);
 void print_usage (void);
 
 
@@ -223,10 +221,10 @@ process_arguments (int argc, char **argv)
                        print_usage ();
                        exit (STATE_UNKNOWN);
                case 'V':                                                                       /* version */
-                       print_revision (PROGNAME, "$Revision$");
+                       print_revision (progname, "$Revision$");
                        exit (STATE_OK);
                case 'h':                                                                       /* help */
-                       print_help (PROGNAME);
+                       print_help (progname);
                        exit (STATE_OK);
                case 'v':                                                                       /* help */
                        verbose = TRUE;
@@ -251,12 +249,12 @@ process_arguments (int argc, char **argv)
                        passive = TRUE;
                        break;
                case 's':                                                                       /* description of service to check */
-                       service = realloc (service, ++services);
+                       service = realloc (service, (++services) * sizeof(char *));
                        p1 = optarg;
                        while (p2 = index (p1, ':')) {
                                *p2 = '\0';
                                asprintf (&service[services-1], "%s", p1);
-                               service = realloc (service, ++services);
+                               service = realloc (service, (++services) * sizeof(char *));
                                p1 = p2 + 1;
                        }
                        asprintf (&service[services-1], "%s", p1);
@@ -285,14 +283,19 @@ process_arguments (int argc, char **argv)
 
        c = optind;
        if (hostname == NULL) {
-               if (!is_host (argv[c]))
-                       terminate (STATE_UNKNOWN, "%s: Invalid host name %s\n", PROGNAME, argv[c]);
+               if (c <= argc) {
+                       terminate (STATE_UNKNOWN, "%s: You must provide a host name\n", progname);
+               } else if (!is_host (argv[c]))
+                       terminate (STATE_UNKNOWN, "%s: Invalid host name %s\n", progname, argv[c]);
                hostname = argv[c++];
        }
 
        if (strlen(remotecmd) == 0) {
                for (; c < argc; c++)
-                       asprintf (&remotecmd, "%s %s", remotecmd, argv[c]);
+                       if (strlen(remotecmd) > 0)
+                               asprintf (&remotecmd, "%s %s", remotecmd, argv[c]);
+                       else
+                               asprintf (&remotecmd, "%s", argv[c]);
        }
 
        if (commands > 1)
@@ -317,10 +320,10 @@ validate_arguments (void)
                return ERROR;
 
        if (passive && commands != services)
-               terminate (STATE_UNKNOWN, "%s: In passive mode, you must provide a service name for each command.\n", PROGNAME);
+               terminate (STATE_UNKNOWN, "%s: In passive mode, you must provide a service name for each command.\n", progname);
 
        if (passive && host_shortname == NULL)
-               terminate (STATE_UNKNOWN, "%s: In passive mode, you must provide the host short name from the nagios configs.\n", PROGNAME);
+               terminate (STATE_UNKNOWN, "%s: In passive mode, you must provide the host short name from the nagios configs.\n", progname);
 
        return OK;
 }
@@ -330,7 +333,7 @@ validate_arguments (void)
 
 
 void
-print_help (char *cmd)
+print_help (const char *cmd)
 {
        print_revision (cmd, "$Revision$");