diff options
Diffstat (limited to 'qarsh/qarsh.c')
-rw-r--r-- | qarsh/qarsh.c | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/qarsh/qarsh.c b/qarsh/qarsh.c index fcfda10..0c90568 100644 --- a/qarsh/qarsh.c +++ b/qarsh/qarsh.c @@ -28,6 +28,11 @@ /* Globals */ int qarsh_fd = -1; /* The control connection to qarshd */ +void +usage() +{ + printf("Usage: qarsh hostname cmdline ...\n"); +} char * copyargs(char **argv) @@ -39,6 +44,7 @@ copyargs(char **argv) cc = 0; for (ap = argv; *ap; ++ap) cc += strlen(*ap) + 1; + if (cc == 0) return NULL; args = malloc(cc); if (!args) { perror("qarsh: malloc failed in copyargs"); @@ -49,7 +55,7 @@ copyargs(char **argv) if (ap[1]) *p++ = ' '; } - return(args); + return args; } @@ -232,19 +238,31 @@ main(int argc, char *argv[]) break; case '?': default: - printf("Unknown option %c\n", (char)c); + printf("Unknown option %c\n", (char)optopt); + usage(); + exit(1); } } - host = argv[optind++]; + if ((host = argv[optind++]) == NULL) { + usage(); + exit(1); + } argc -= optind; argv += optind; - args = copyargs(argv); - + if ((args = copyargs(argv)) == NULL) { + usage(); + exit(1); + } qarsh_fd = connect_to_host(host, port); if (qarsh_fd == -1) { - fprintf(stderr, "Could not connect to %s:%d, %d: %s\n", + if (errno == 0) { + fprintf(stderr, "Could not connect to %s:%d, %d: %s\n", + host, port, h_errno, hstrerror(h_errno)); + } else { + fprintf(stderr, "Could not connect to %s:%d, %d: %s\n", host, port, errno, strerror(errno)); + } return 127; } |