summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNate Straz <nstraz@redhat.com>2005-08-24 18:48:34 +0000
committerNate Straz <nstraz@redhat.com>2005-08-24 18:48:34 +0000
commitb357abf9c5c832b32e80d28b5c59e573f4271afe (patch)
tree21438a3edb4f4df43693e9a5b78db64de531bc1f
parentb009d709d2ba73968cef9a702978efd2f39b7560 (diff)
downloadqarsh-b357abf9c5c832b32e80d28b5c59e573f4271afe.tar.gz
qarsh-b357abf9c5c832b32e80d28b5c59e573f4271afe.tar.xz
qarsh-b357abf9c5c832b32e80d28b5c59e573f4271afe.zip
Make qarsh a little more "user friendly."
-rw-r--r--qarsh/qarsh.c30
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;
}