summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetr Písař <ppisar@redhat.com>2013-04-09 14:20:41 +0200
committerMarco d'Itri <md@linux.it>2013-04-10 17:25:05 +0200
commit361164fea52c942279b47fd3406f82dfb0173b1b (patch)
tree6f43d080345b5fbfd6538c3f2c99d4b199fe0725
parent3f0c3d443652677e17cade066e4521b910a27c76 (diff)
downloadwhois-361164fea52c942279b47fd3406f82dfb0173b1b.tar.gz
Handle --help as success
whois --help output should go to standard output, and exit code should be zero.
-rw-r--r--whois.c18
-rw-r--r--whois.h2
2 files changed, 11 insertions, 9 deletions
diff --git a/whois.c b/whois.c
index 05bf055..66337fc 100644
--- a/whois.c
+++ b/whois.c
@@ -72,9 +72,9 @@ const char *client_tag = IDSTRING;
#ifdef HAVE_GETOPT_LONG
static const struct option longopts[] = {
- {"help", no_argument, NULL, 0 },
{"version", no_argument, NULL, 1 },
{"verbose", no_argument, NULL, 2 },
+ {"help", no_argument, NULL, 3 },
{"server", required_argument, NULL, 'h'},
{"host", required_argument, NULL, 'h'},
{"port", required_argument, NULL, 'p'},
@@ -139,22 +139,24 @@ int main(int argc, char *argv[])
case 'p':
port = strdup(optarg);
break;
+ case 3:
+ usage(EXIT_SUCCESS);
case 2:
verb = 1;
break;
case 1:
- fprintf(stderr, _("Version %s.\n\nReport bugs to %s.\n"),
+ fprintf(stdout, _("Version %s.\n\nReport bugs to %s.\n"),
VERSION, "<md+whois@linux.it>");
- exit(0);
+ exit(EXIT_SUCCESS);
default:
- usage();
+ usage(EXIT_FAILURE);
}
}
argc -= optind;
argv += optind;
if (argc == 0 && !nopar) /* there is no parameter */
- usage();
+ usage(EXIT_FAILURE);
/* On some systems realloc only works on non-NULL buffers */
/* I wish I could remember which ones they are... */
@@ -1181,9 +1183,9 @@ int isasciidigit(const char c) {
/* http://www.ripe.net/ripe/docs/databaseref-manual.html */
-void usage(void)
+void usage(int error)
{
- fprintf(stderr, _(
+ fprintf((EXIT_SUCCESS == error) ? stdout : stderr, _(
"Usage: whois [OPTION]... OBJECT...\n\n"
"-h HOST, --host HOST connect to server HOST\n"
"-p PORT, --port PORT connect to PORT\n"
@@ -1217,6 +1219,6 @@ void usage(void)
"-q [version|sources|types] query specified server info\n"
"-F fast raw output (implies -r)\n"
));
- exit(0);
+ exit(error);
}
diff --git a/whois.h b/whois.h
index 78ce21c..9afb2f8 100644
--- a/whois.h
+++ b/whois.h
@@ -21,7 +21,7 @@ const char *query_pir(const int, const char *);
const char *query_afilias(const int, const char *);
int openconn(const char *, const char *);
int connect_with_timeout(int, const struct sockaddr *, socklen_t, int);
-void usage(void);
+void usage(int error);
void alarm_handler(int);
void sighandler(int);
int japanese_locale(void);