提交 63ba687f 编写于 作者: D Daniel P. Berrange

Properly handle -h / -V for --help/--version aliases in virtlockd/libvirtd

The virtlockd/libvirtd daemons had listed '?' as the short option
for --help. getopt_long uses '?' for any unknown option. We want
to be able to distinguish unknown options (which use EXIT_FAILURE)
from correct usage of help (which should use EXIT_SUCCESS). Thus
we should use 'h' as a short option for --help. Also add this to
the man page docs

The virtlockd/libvirtd daemons did not list any short option
for the --version arg. Add -V as a valid short option, since
-v is already used for --verbose.
Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
上级 a3964734
......@@ -1038,12 +1038,13 @@ daemonUsage(const char *argv0, bool privileged)
" %s [options]\n"
"\n"
"Options:\n"
" -h | --help Display program help:\n"
" -v | --verbose Verbose messages.\n"
" -d | --daemon Run as a daemon & write PID file.\n"
" -l | --listen Listen for TCP/IP connections.\n"
" -t | --timeout <secs> Exit after timeout period.\n"
" -f | --config <file> Configuration file.\n"
" | --version Display version information.\n"
" -V | --version Display version information.\n"
" -p | --pid-file <file> Change name of PID file.\n"
"\n"
"libvirt management daemon:\n"),
......@@ -1098,10 +1099,6 @@ daemonUsage(const char *argv0, bool privileged)
}
}
enum {
OPT_VERSION = 129
};
#define MAX_LISTEN 5
int main(int argc, char **argv) {
virNetServerPtr srv = NULL;
......@@ -1123,14 +1120,14 @@ int main(int argc, char **argv) {
mode_t old_umask;
struct option opts[] = {
{ "verbose", no_argument, &verbose, 1},
{ "daemon", no_argument, &godaemon, 1},
{ "listen", no_argument, &ipsock, 1},
{ "verbose", no_argument, &verbose, 'v'},
{ "daemon", no_argument, &godaemon, 'd'},
{ "listen", no_argument, &ipsock, 'l'},
{ "config", required_argument, NULL, 'f'},
{ "timeout", required_argument, NULL, 't'},
{ "pid-file", required_argument, NULL, 'p'},
{ "version", no_argument, NULL, OPT_VERSION },
{ "help", no_argument, NULL, '?' },
{ "version", no_argument, NULL, 'V' },
{ "help", no_argument, NULL, 'h' },
{0, 0, 0, 0}
};
......@@ -1173,7 +1170,7 @@ int main(int argc, char **argv) {
int c;
char *tmp;
c = getopt_long(argc, argv, "ldf:p:t:v", opts, &optidx);
c = getopt_long(argc, argv, "ldf:p:t:vVh", opts, &optidx);
if (c == -1) {
break;
......@@ -1219,17 +1216,17 @@ int main(int argc, char **argv) {
}
break;
case OPT_VERSION:
case 'V':
daemonVersion(argv[0]);
return 0;
exit(EXIT_SUCCESS);
case '?':
case 'h':
daemonUsage(argv[0], privileged);
return 2;
exit(EXIT_SUCCESS);
case '?':
default:
VIR_ERROR(_("%s: internal error: unknown flag: %c"),
argv[0], c);
daemonUsage(argv[0], privileged);
exit(EXIT_FAILURE);
}
}
......
......@@ -36,6 +36,10 @@ from the configuration.
=over
=item B<-h, --help>
Display command line help usage then exit.
=item B<-d, --daemon>
Run as a daemon & write PID file.
......
......@@ -1096,10 +1096,11 @@ virLockDaemonUsage(const char *argv0, bool privileged)
" %s [options]\n"
"\n"
"Options:\n"
" -h | --help Display program help:\n"
" -v | --verbose Verbose messages.\n"
" -d | --daemon Run as a daemon & write PID file.\n"
" -f | --config <file> Configuration file.\n"
" | --version Display version information.\n"
" -V | --version Display version information.\n"
" -p | --pid-file <file> Change name of PID file.\n"
"\n"
"libvirt lock management daemon:\n"), argv0);
......@@ -1138,10 +1139,6 @@ virLockDaemonUsage(const char *argv0, bool privileged)
}
}
enum {
OPT_VERSION = 129
};
#define MAX_LISTEN 5
int main(int argc, char **argv) {
virNetServerProgramPtr lockProgram = NULL;
......@@ -1161,12 +1158,12 @@ int main(int argc, char **argv) {
int rv;
struct option opts[] = {
{ "verbose", no_argument, &verbose, 1},
{ "daemon", no_argument, &godaemon, 1},
{ "verbose", no_argument, &verbose, 'v'},
{ "daemon", no_argument, &godaemon, 'd'},
{ "config", required_argument, NULL, 'f'},
{ "pid-file", required_argument, NULL, 'p'},
{ "version", no_argument, NULL, OPT_VERSION },
{ "help", no_argument, NULL, '?' },
{ "version", no_argument, NULL, 'V' },
{ "help", no_argument, NULL, 'h' },
{0, 0, 0, 0}
};
......@@ -1185,7 +1182,7 @@ int main(int argc, char **argv) {
int optidx = 0;
int c;
c = getopt_long(argc, argv, "ldf:p:t:v", opts, &optidx);
c = getopt_long(argc, argv, "ldf:p:t:vVh", opts, &optidx);
if (c == -1) {
break;
......@@ -1218,17 +1215,17 @@ int main(int argc, char **argv) {
}
break;
case OPT_VERSION:
case 'V':
virLockDaemonVersion(argv[0]);
return 0;
exit(EXIT_SUCCESS);
case '?':
case 'h':
virLockDaemonUsage(argv[0], privileged);
return 2;
exit(EXIT_SUCCESS);
case '?':
default:
fprintf(stderr, _("%s: internal error: unknown flag: %c\n"),
argv[0], c);
virLockDaemonUsage(argv[0], privileged);
exit(EXIT_FAILURE);
}
}
......
......@@ -26,6 +26,10 @@ The virtlockd daemon listens for requests on a local Unix domain socket.
=over
=item B<-h, --help>
Display command line help usage then exit.
=item B<-d, --daemon>
Run as a daemon and write PID file.
......@@ -42,7 +46,7 @@ Use this name for the PID file, overriding the default value.
Enable output of verbose messages.
=item B< --version>
=item B<-V, --version>
Display version information then exit.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册