diff --git a/client/maxadmin.c b/client/maxadmin.c index 9a3b6ea08..dfb4dcfb5 100644 --- a/client/maxadmin.c +++ b/client/maxadmin.c @@ -108,15 +108,10 @@ char *hostname = "localhost"; char *port = "6603"; char *user = "admin"; char *passwd = NULL; -int so, cmdlen; -char *cmd; +int so; int option_index = 0; char c; - cmd = malloc(1); - *cmd = 0; - cmdlen = 1; - while ((c = getopt_long(argc, argv, "h:p:P:u:v?", long_options, &option_index)) >= 0) @@ -180,14 +175,28 @@ char c; exit(1); } - if (cmdlen > 1) - { - cmd[cmdlen - 2] = '\0'; /* Remove trailing space */ - if (access(cmd, R_OK) == 0) - DoSource(so, cmd); - else - sendCommand(so, cmd); - exit(0); + if (optind < argc) { + int i, len = 0; + char *cmd; + + for (i = optind; i < argc; i++) { + len += strlen(argv[i]) + 1; + } + + cmd = malloc(len); + strcpy(cmd, argv[optind]); + for (i = optind +1; i < argc; i++) { + strcat(cmd, " "); + strcat(cmd, argv[i]); + } + + if (access(cmd, R_OK) == 0) + DoSource(so, cmd); + else + sendCommand(so, cmd); + + free(cmd); + exit(0); } (void) setlocale(LC_CTYPE, ""); @@ -391,7 +400,7 @@ char buf[20]; * Send a comamnd using the MaxScaled protocol, display the return data * on standard output. * - * Input terminates with a lien containing jsut the text OK + * Input terminates with a lien containing just the text OK * * @param so The socket connect to MaxScale * @param cmd The command to send @@ -401,7 +410,7 @@ static int sendCommand(int so, char *cmd) { char buf[80]; -int i, j, newline = 0; +int i, j, newline = 1; write(so, cmd, strlen(cmd)); while (1)