|
|
43fe83 |
From 3ff9f885135bd131b2e014a4caf3f5092fd6c21f Mon Sep 17 00:00:00 2001
|
|
|
43fe83 |
Message-Id: <3ff9f885135bd131b2e014a4caf3f5092fd6c21f.1377873638.git.jdenemar@redhat.com>
|
|
|
43fe83 |
From: "Daniel P. Berrange" <berrange@redhat.com>
|
|
|
43fe83 |
Date: Tue, 13 Aug 2013 13:56:52 +0100
|
|
|
43fe83 |
Subject: [PATCH] Properly handle -h / -V for --help/--version aliases in
|
|
|
43fe83 |
virtlockd/libvirtd
|
|
|
43fe83 |
|
|
|
43fe83 |
https://bugzilla.redhat.com/show_bug.cgi?id=991494
|
|
|
43fe83 |
|
|
|
43fe83 |
The virtlockd/libvirtd daemons had listed '?' as the short option
|
|
|
43fe83 |
for --help. getopt_long uses '?' for any unknown option. We want
|
|
|
43fe83 |
to be able to distinguish unknown options (which use EXIT_FAILURE)
|
|
|
43fe83 |
from correct usage of help (which should use EXIT_SUCCESS). Thus
|
|
|
43fe83 |
we should use 'h' as a short option for --help. Also add this to
|
|
|
43fe83 |
the man page docs
|
|
|
43fe83 |
|
|
|
43fe83 |
The virtlockd/libvirtd daemons did not list any short option
|
|
|
43fe83 |
for the --version arg. Add -V as a valid short option, since
|
|
|
43fe83 |
-v is already used for --verbose.
|
|
|
43fe83 |
|
|
|
43fe83 |
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
|
|
|
43fe83 |
(cherry picked from commit 63ba687f2bb78bfe4df96eb3d68bf88f675f562c)
|
|
|
43fe83 |
---
|
|
|
43fe83 |
daemon/libvirtd.c | 31 ++++++++++++++-----------------
|
|
|
43fe83 |
daemon/libvirtd.pod.in | 4 ++++
|
|
|
43fe83 |
src/locking/lock_daemon.c | 29 +++++++++++++----------------
|
|
|
43fe83 |
src/locking/virtlockd.pod.in | 6 +++++-
|
|
|
43fe83 |
4 files changed, 36 insertions(+), 34 deletions(-)
|
|
|
43fe83 |
|
|
|
43fe83 |
diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
|
|
|
43fe83 |
index 402b494..c9cd1a1 100644
|
|
|
43fe83 |
--- a/daemon/libvirtd.c
|
|
|
43fe83 |
+++ b/daemon/libvirtd.c
|
|
|
43fe83 |
@@ -1038,12 +1038,13 @@ daemonUsage(const char *argv0, bool privileged)
|
|
|
43fe83 |
" %s [options]\n"
|
|
|
43fe83 |
"\n"
|
|
|
43fe83 |
"Options:\n"
|
|
|
43fe83 |
+ " -h | --help Display program help:\n"
|
|
|
43fe83 |
" -v | --verbose Verbose messages.\n"
|
|
|
43fe83 |
" -d | --daemon Run as a daemon & write PID file.\n"
|
|
|
43fe83 |
" -l | --listen Listen for TCP/IP connections.\n"
|
|
|
43fe83 |
" -t | --timeout <secs> Exit after timeout period.\n"
|
|
|
43fe83 |
" -f | --config <file> Configuration file.\n"
|
|
|
43fe83 |
- " | --version Display version information.\n"
|
|
|
43fe83 |
+ " -V | --version Display version information.\n"
|
|
|
43fe83 |
" -p | --pid-file <file> Change name of PID file.\n"
|
|
|
43fe83 |
"\n"
|
|
|
43fe83 |
"libvirt management daemon:\n"),
|
|
|
43fe83 |
@@ -1098,10 +1099,6 @@ daemonUsage(const char *argv0, bool privileged)
|
|
|
43fe83 |
}
|
|
|
43fe83 |
}
|
|
|
43fe83 |
|
|
|
43fe83 |
-enum {
|
|
|
43fe83 |
- OPT_VERSION = 129
|
|
|
43fe83 |
-};
|
|
|
43fe83 |
-
|
|
|
43fe83 |
#define MAX_LISTEN 5
|
|
|
43fe83 |
int main(int argc, char **argv) {
|
|
|
43fe83 |
virNetServerPtr srv = NULL;
|
|
|
43fe83 |
@@ -1123,14 +1120,14 @@ int main(int argc, char **argv) {
|
|
|
43fe83 |
mode_t old_umask;
|
|
|
43fe83 |
|
|
|
43fe83 |
struct option opts[] = {
|
|
|
43fe83 |
- { "verbose", no_argument, &verbose, 1},
|
|
|
43fe83 |
- { "daemon", no_argument, &godaemon, 1},
|
|
|
43fe83 |
- { "listen", no_argument, &ipsock, 1},
|
|
|
43fe83 |
+ { "verbose", no_argument, &verbose, 'v'},
|
|
|
43fe83 |
+ { "daemon", no_argument, &godaemon, 'd'},
|
|
|
43fe83 |
+ { "listen", no_argument, &ipsock, 'l'},
|
|
|
43fe83 |
{ "config", required_argument, NULL, 'f'},
|
|
|
43fe83 |
{ "timeout", required_argument, NULL, 't'},
|
|
|
43fe83 |
{ "pid-file", required_argument, NULL, 'p'},
|
|
|
43fe83 |
- { "version", no_argument, NULL, OPT_VERSION },
|
|
|
43fe83 |
- { "help", no_argument, NULL, '?' },
|
|
|
43fe83 |
+ { "version", no_argument, NULL, 'V' },
|
|
|
43fe83 |
+ { "help", no_argument, NULL, 'h' },
|
|
|
43fe83 |
{0, 0, 0, 0}
|
|
|
43fe83 |
};
|
|
|
43fe83 |
|
|
|
43fe83 |
@@ -1173,7 +1170,7 @@ int main(int argc, char **argv) {
|
|
|
43fe83 |
int c;
|
|
|
43fe83 |
char *tmp;
|
|
|
43fe83 |
|
|
|
43fe83 |
- c = getopt_long(argc, argv, "ldf:p:t:v", opts, &optidx);
|
|
|
43fe83 |
+ c = getopt_long(argc, argv, "ldf:p:t:vVh", opts, &optidx);
|
|
|
43fe83 |
|
|
|
43fe83 |
if (c == -1) {
|
|
|
43fe83 |
break;
|
|
|
43fe83 |
@@ -1219,17 +1216,17 @@ int main(int argc, char **argv) {
|
|
|
43fe83 |
}
|
|
|
43fe83 |
break;
|
|
|
43fe83 |
|
|
|
43fe83 |
- case OPT_VERSION:
|
|
|
43fe83 |
+ case 'V':
|
|
|
43fe83 |
daemonVersion(argv[0]);
|
|
|
43fe83 |
- return 0;
|
|
|
43fe83 |
+ exit(EXIT_SUCCESS);
|
|
|
43fe83 |
|
|
|
43fe83 |
- case '?':
|
|
|
43fe83 |
+ case 'h':
|
|
|
43fe83 |
daemonUsage(argv[0], privileged);
|
|
|
43fe83 |
- return 2;
|
|
|
43fe83 |
+ exit(EXIT_SUCCESS);
|
|
|
43fe83 |
|
|
|
43fe83 |
+ case '?':
|
|
|
43fe83 |
default:
|
|
|
43fe83 |
- VIR_ERROR(_("%s: internal error: unknown flag: %c"),
|
|
|
43fe83 |
- argv[0], c);
|
|
|
43fe83 |
+ daemonUsage(argv[0], privileged);
|
|
|
43fe83 |
exit(EXIT_FAILURE);
|
|
|
43fe83 |
}
|
|
|
43fe83 |
}
|
|
|
43fe83 |
diff --git a/daemon/libvirtd.pod.in b/daemon/libvirtd.pod.in
|
|
|
43fe83 |
index 930b752..9901ecf 100644
|
|
|
43fe83 |
--- a/daemon/libvirtd.pod.in
|
|
|
43fe83 |
+++ b/daemon/libvirtd.pod.in
|
|
|
43fe83 |
@@ -36,6 +36,10 @@ from the configuration.
|
|
|
43fe83 |
|
|
|
43fe83 |
=over
|
|
|
43fe83 |
|
|
|
43fe83 |
+=item B<-h, --help>
|
|
|
43fe83 |
+
|
|
|
43fe83 |
+Display command line help usage then exit.
|
|
|
43fe83 |
+
|
|
|
43fe83 |
=item B<-d, --daemon>
|
|
|
43fe83 |
|
|
|
43fe83 |
Run as a daemon & write PID file.
|
|
|
43fe83 |
diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c
|
|
|
43fe83 |
index c45f45c..77d6e0d 100644
|
|
|
43fe83 |
--- a/src/locking/lock_daemon.c
|
|
|
43fe83 |
+++ b/src/locking/lock_daemon.c
|
|
|
43fe83 |
@@ -1096,10 +1096,11 @@ virLockDaemonUsage(const char *argv0, bool privileged)
|
|
|
43fe83 |
" %s [options]\n"
|
|
|
43fe83 |
"\n"
|
|
|
43fe83 |
"Options:\n"
|
|
|
43fe83 |
+ " -h | --help Display program help:\n"
|
|
|
43fe83 |
" -v | --verbose Verbose messages.\n"
|
|
|
43fe83 |
" -d | --daemon Run as a daemon & write PID file.\n"
|
|
|
43fe83 |
" -f | --config <file> Configuration file.\n"
|
|
|
43fe83 |
- " | --version Display version information.\n"
|
|
|
43fe83 |
+ " -V | --version Display version information.\n"
|
|
|
43fe83 |
" -p | --pid-file <file> Change name of PID file.\n"
|
|
|
43fe83 |
"\n"
|
|
|
43fe83 |
"libvirt lock management daemon:\n"), argv0);
|
|
|
43fe83 |
@@ -1138,10 +1139,6 @@ virLockDaemonUsage(const char *argv0, bool privileged)
|
|
|
43fe83 |
}
|
|
|
43fe83 |
}
|
|
|
43fe83 |
|
|
|
43fe83 |
-enum {
|
|
|
43fe83 |
- OPT_VERSION = 129
|
|
|
43fe83 |
-};
|
|
|
43fe83 |
-
|
|
|
43fe83 |
#define MAX_LISTEN 5
|
|
|
43fe83 |
int main(int argc, char **argv) {
|
|
|
43fe83 |
virNetServerProgramPtr lockProgram = NULL;
|
|
|
43fe83 |
@@ -1161,12 +1158,12 @@ int main(int argc, char **argv) {
|
|
|
43fe83 |
int rv;
|
|
|
43fe83 |
|
|
|
43fe83 |
struct option opts[] = {
|
|
|
43fe83 |
- { "verbose", no_argument, &verbose, 1},
|
|
|
43fe83 |
- { "daemon", no_argument, &godaemon, 1},
|
|
|
43fe83 |
+ { "verbose", no_argument, &verbose, 'v'},
|
|
|
43fe83 |
+ { "daemon", no_argument, &godaemon, 'd'},
|
|
|
43fe83 |
{ "config", required_argument, NULL, 'f'},
|
|
|
43fe83 |
{ "pid-file", required_argument, NULL, 'p'},
|
|
|
43fe83 |
- { "version", no_argument, NULL, OPT_VERSION },
|
|
|
43fe83 |
- { "help", no_argument, NULL, '?' },
|
|
|
43fe83 |
+ { "version", no_argument, NULL, 'V' },
|
|
|
43fe83 |
+ { "help", no_argument, NULL, 'h' },
|
|
|
43fe83 |
{0, 0, 0, 0}
|
|
|
43fe83 |
};
|
|
|
43fe83 |
|
|
|
43fe83 |
@@ -1185,7 +1182,7 @@ int main(int argc, char **argv) {
|
|
|
43fe83 |
int optidx = 0;
|
|
|
43fe83 |
int c;
|
|
|
43fe83 |
|
|
|
43fe83 |
- c = getopt_long(argc, argv, "ldf:p:t:v", opts, &optidx);
|
|
|
43fe83 |
+ c = getopt_long(argc, argv, "ldf:p:t:vVh", opts, &optidx);
|
|
|
43fe83 |
|
|
|
43fe83 |
if (c == -1) {
|
|
|
43fe83 |
break;
|
|
|
43fe83 |
@@ -1218,17 +1215,17 @@ int main(int argc, char **argv) {
|
|
|
43fe83 |
}
|
|
|
43fe83 |
break;
|
|
|
43fe83 |
|
|
|
43fe83 |
- case OPT_VERSION:
|
|
|
43fe83 |
+ case 'V':
|
|
|
43fe83 |
virLockDaemonVersion(argv[0]);
|
|
|
43fe83 |
- return 0;
|
|
|
43fe83 |
+ exit(EXIT_SUCCESS);
|
|
|
43fe83 |
|
|
|
43fe83 |
- case '?':
|
|
|
43fe83 |
+ case 'h':
|
|
|
43fe83 |
virLockDaemonUsage(argv[0], privileged);
|
|
|
43fe83 |
- return 2;
|
|
|
43fe83 |
+ exit(EXIT_SUCCESS);
|
|
|
43fe83 |
|
|
|
43fe83 |
+ case '?':
|
|
|
43fe83 |
default:
|
|
|
43fe83 |
- fprintf(stderr, _("%s: internal error: unknown flag: %c\n"),
|
|
|
43fe83 |
- argv[0], c);
|
|
|
43fe83 |
+ virLockDaemonUsage(argv[0], privileged);
|
|
|
43fe83 |
exit(EXIT_FAILURE);
|
|
|
43fe83 |
}
|
|
|
43fe83 |
}
|
|
|
43fe83 |
diff --git a/src/locking/virtlockd.pod.in b/src/locking/virtlockd.pod.in
|
|
|
43fe83 |
index f5748ca..99612aa 100644
|
|
|
43fe83 |
--- a/src/locking/virtlockd.pod.in
|
|
|
43fe83 |
+++ b/src/locking/virtlockd.pod.in
|
|
|
43fe83 |
@@ -26,6 +26,10 @@ The virtlockd daemon listens for requests on a local Unix domain socket.
|
|
|
43fe83 |
|
|
|
43fe83 |
=over
|
|
|
43fe83 |
|
|
|
43fe83 |
+=item B<-h, --help>
|
|
|
43fe83 |
+
|
|
|
43fe83 |
+Display command line help usage then exit.
|
|
|
43fe83 |
+
|
|
|
43fe83 |
=item B<-d, --daemon>
|
|
|
43fe83 |
|
|
|
43fe83 |
Run as a daemon and write PID file.
|
|
|
43fe83 |
@@ -42,7 +46,7 @@ Use this name for the PID file, overriding the default value.
|
|
|
43fe83 |
|
|
|
43fe83 |
Enable output of verbose messages.
|
|
|
43fe83 |
|
|
|
43fe83 |
-=item B< --version>
|
|
|
43fe83 |
+=item B<-V, --version>
|
|
|
43fe83 |
|
|
|
43fe83 |
Display version information then exit.
|
|
|
43fe83 |
|
|
|
43fe83 |
--
|
|
|
43fe83 |
1.8.3.2
|
|
|
43fe83 |
|