From: Pete Zaitcev <zaitcev@redhat.com>
To: Jeff Garzik <jeff@garzik.org>
Cc: Project Hail List <hail-devel@vger.kernel.org>
Subject: [Patch] cldcli: better error messages
Date: Tue, 4 Aug 2009 19:06:02 -0600 [thread overview]
Message-ID: <20090804190602.4d7918df@redhat.com> (raw)
Produce more specific error messages for those who think that host
does not necesserily imply port. Also, clean up a bit.
Signed-Off-By: Pete Zaitcev <zaitcev@redhat.com>
diff --git a/tools/cldcli.c b/tools/cldcli.c
index 758385d..1367b43 100644
--- a/tools/cldcli.c
+++ b/tools/cldcli.c
@@ -9,13 +9,10 @@
#include <argp.h>
#include <poll.h>
#include <locale.h>
-#include <syslog.h>
#include <stdarg.h>
#include <ctype.h>
#include <cldc.h>
-#define PROGRAM_NAME "cld"
-
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
const char *argp_program_version = PACKAGE_VERSION;
@@ -32,8 +29,8 @@ enum thread_codes {
static struct argp_option options[] = {
{ "debug", 'D', "LEVEL", 0,
"Set debug output to LEVEL (0 = off, 2 = max verbose)" },
- { "host", 'h', "HOST", 0,
- "Connect to remote host. Used once in normal case (DNS SRV records), or may be specified multiple times." },
+ { "host", 'h', "HOST:PORT", 0,
+ "Connect to remote CLD at specified HOST:PORT" },
{ "user", 'u', "USER", 0,
"Set username to USER" },
{ }
@@ -749,22 +746,32 @@ static bool push_host(const char *arg)
struct cldc_host *dr;
dr = malloc(sizeof(*dr));
- if (!dr)
- return false;
+ if (!dr) {
+ fprintf(stderr, "no core for %u", (int) sizeof(*dr));
+ goto err;
+ }
memset(dr, 0, sizeof(*dr));
dr->host = strdup(arg);
- if (!dr->host)
+ if (!dr->host) {
+ fprintf(stderr, "no core for host"); // don't print, too long
goto err_out;
+ }
colon = strrchr(dr->host, ':');
- if (!colon)
+ if (!colon) {
+ fprintf(stderr, "no port in host specifier `%s'\n", dr->host);
goto err_out_host;
+ }
- if (sscanf(colon, ":%u", &port) != 1)
+ if (sscanf(colon, ":%u", &port) != 1) {
+ fprintf(stderr, "port `%s' is invalid\n", colon+1);
goto err_out_host;
- if (port < 1 || port > 65535)
+ }
+ if (port < 1 || port > 65535) {
+ fprintf(stderr, "port `%s' is out of range\n", colon+1);
goto err_out_host;
+ }
dr->port = port;
@@ -778,6 +785,7 @@ err_out_host:
free(dr->host);
err_out:
free(dr);
+err:
return false;
}
@@ -793,10 +801,8 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state)
}
break;
case 'h':
- if (!push_host(arg)) {
- fprintf(stderr, "invalid host: '%s'\n", arg);
+ if (!push_host(arg))
argp_usage(state);
- }
break;
case 'u':
if (strlen(arg) >= CLD_MAX_USERNAME) {
next reply other threads:[~2009-08-05 1:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-05 1:06 Pete Zaitcev [this message]
2009-08-05 1:24 ` [Patch] cldcli: better error messages Jeff Garzik
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090804190602.4d7918df@redhat.com \
--to=zaitcev@redhat.com \
--cc=hail-devel@vger.kernel.org \
--cc=jeff@garzik.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.