summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2014-05-23 22:55:53 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2014-05-23 22:55:53 -0700
commitf25c51fba6c7a08748892050c9db78e911e80ede (patch)
tree5ce52f13ae8ab58861187c3d374770fb75b12800
parent9298ede3e9b9a4707d91a460f2f9e91aef23d6c1 (diff)
Print which option was in error along with usage message
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--os/utils.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/os/utils.c b/os/utils.c
index ff382c7..9e209f5 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -188,8 +188,10 @@ GetTimeInMillis(void)
}
static void _X_NORETURN
-usage(void)
+usage(const char *errmsg)
{
+ if (errmsg != NULL)
+ fprintf (stderr, "%s: %s\n", progname, errmsg);
fprintf(stderr, "usage: %s [-config config_file] [-port tcp_port] [-droppriv] [-daemon] [-nodaemon] [-user user_name] [-ls listen_socket]\n",
progname);
exit(1);
@@ -243,7 +245,7 @@ ProcessLSoption (char *str)
{
slash = (char *) strchr (ptr, '/');
if (slash == NULL) {
- usage();
+ usage("invalid argument for -ls");
}
len = slash - ptr;
strncpy (number, ptr, len);
@@ -254,7 +256,7 @@ ProcessLSoption (char *str)
slash = (char *) strchr (ptr, '/');
if (slash == NULL) {
- usage();
+ usage("invalid argument for -ls");
}
len = slash - ptr;
strncpy (number, ptr, len);
@@ -269,7 +271,7 @@ ProcessLSoption (char *str)
{
char *comma = (char *) strchr (ptr, ',');
if (comma == NULL) {
- usage();
+ usage("invalid argument for -ls");
}
len = comma - ptr;
strncpy (number, ptr, len);
@@ -296,12 +298,12 @@ ProcessCmdLine(int argc, char **argv)
ListenPort = atoi(argv[++i]);
portFromCmdline = TRUE;
} else
- usage();
+ usage("-port requires an argument");
} else if (!strcmp(argv[i], "-ls")) {
if (argv[i + 1])
ProcessLSoption (argv[++i]);
else
- usage();
+ usage("-ls requires an argument");
} else if (!strcmp(argv[i], "-droppriv")) {
dropPriv = TRUE;
} else if (!strcmp(argv[i], "-daemon")) {
@@ -319,15 +321,17 @@ ProcessCmdLine(int argc, char **argv)
if (argv[i + 1])
userId = argv[++i];
else
- usage();
+ usage("-user requires an argument");
} else if (!strcmp(argv[i], "-cf") || !strcmp(argv[i], "-config")) {
if (argv[i + 1])
configfilename = argv[++i];
else
- usage();
+ usage("-config requires an argument");
+ }
+ else {
+ fprintf (stderr, "%s: unrecognized option %s\n", progname, argv[i]);
+ usage(NULL);
}
- else
- usage();
}
}