提交 d5f0c1b6 编写于 作者: D Daniel P. Berrangé

remote: stop trying to print help as giant blocks of text

The remote daemon tries to print out its help text in a couple of giant
blocks of text. This has already lead to duplication of the text for the
privileged vs unprivileged execution mode. With the introduction of more
daemons, this text is going to be duplicated many more times with small
variations. This is very unfriendly to translators as they have to
translate approximately the same text many times with small tweaks.

Splitting the text up into individual strings to print means that each
piece will only need translating once. It also gets rid of all the
layout information from the translated strings, so avoids the problem of
translators breaking formatting by mistake.
Reviewed-by: NChristophe de Dinechin <dinechin@redhat.com>
Reviewed-by: NAndrea Bolognani <abologna@redhat.com>
Signed-off-by: NDaniel P. Berrangé <berrange@redhat.com>
上级 73663a28
...@@ -146,6 +146,7 @@ libvirtd_CFLAGS = \ ...@@ -146,6 +146,7 @@ libvirtd_CFLAGS = \
-I$(srcdir)/access \ -I$(srcdir)/access \
-I$(srcdir)/conf \ -I$(srcdir)/conf \
-I$(srcdir)/rpc \ -I$(srcdir)/rpc \
-DSOCK_PREFIX="\"libvirt\"" \
$(NULL) $(NULL)
libvirtd_LDFLAGS = \ libvirtd_LDFLAGS = \
......
...@@ -221,19 +221,25 @@ daemonUnixSocketPaths(struct daemonConfig *config, ...@@ -221,19 +221,25 @@ daemonUnixSocketPaths(struct daemonConfig *config,
char *rundir = NULL; char *rundir = NULL;
if (config->unix_sock_dir) { if (config->unix_sock_dir) {
if (virAsprintf(sockfile, "%s/libvirt-sock", config->unix_sock_dir) < 0) if (virAsprintf(sockfile, "%s/%s-sock",
SOCK_PREFIX, config->unix_sock_dir) < 0)
goto cleanup; goto cleanup;
if (privileged) { if (privileged) {
if (virAsprintf(rosockfile, "%s/libvirt-sock-ro", config->unix_sock_dir) < 0 || if (virAsprintf(rosockfile, "%s/%s-sock-ro",
virAsprintf(admsockfile, "%s/libvirt-admin-sock", config->unix_sock_dir) < 0) SOCK_PREFIX, config->unix_sock_dir) < 0 ||
virAsprintf(admsockfile, "%s/%s-admin-sock",
SOCK_PREFIX, config->unix_sock_dir) < 0)
goto cleanup; goto cleanup;
} }
} else { } else {
if (privileged) { if (privileged) {
if (VIR_STRDUP(*sockfile, LOCALSTATEDIR "/run/libvirt/libvirt-sock") < 0 || if (virAsprintf(sockfile, "%s/run/libvirt/%s-sock",
VIR_STRDUP(*rosockfile, LOCALSTATEDIR "/run/libvirt/libvirt-sock-ro") < 0 || LOCALSTATEDIR, SOCK_PREFIX) < 0 ||
VIR_STRDUP(*admsockfile, LOCALSTATEDIR "/run/libvirt/libvirt-admin-sock") < 0) virAsprintf(rosockfile, "%s/run/libvirt/%s-sock-ro",
LOCALSTATEDIR, SOCK_PREFIX) < 0 ||
virAsprintf(admsockfile, "%s/run/libvirt/%s-admin-sock",
LOCALSTATEDIR, SOCK_PREFIX) < 0)
goto cleanup; goto cleanup;
} else { } else {
mode_t old_umask; mode_t old_umask;
...@@ -248,8 +254,10 @@ daemonUnixSocketPaths(struct daemonConfig *config, ...@@ -248,8 +254,10 @@ daemonUnixSocketPaths(struct daemonConfig *config,
} }
umask(old_umask); umask(old_umask);
if (virAsprintf(sockfile, "%s/libvirt-sock", rundir) < 0 || if (virAsprintf(sockfile, "%s/%s-sock",
virAsprintf(admsockfile, "%s/libvirt-admin-sock", rundir) < 0) rundir, SOCK_PREFIX) < 0 ||
virAsprintf(admsockfile, "%s/%s-admin-sock",
rundir, SOCK_PREFIX) < 0)
goto cleanup; goto cleanup;
} }
} }
...@@ -859,75 +867,76 @@ daemonSetupHostUUID(const struct daemonConfig *config) ...@@ -859,75 +867,76 @@ daemonSetupHostUUID(const struct daemonConfig *config)
return 0; return 0;
} }
typedef struct {
const char *opts;
const char *help;
} virOptionHelp;
/* Print command-line usage. */ /* Print command-line usage. */
static void static void
daemonUsage(const char *argv0, bool privileged) daemonUsage(const char *argv0, bool privileged)
{ {
fprintf(stderr, size_t i;
_("\n" virOptionHelp opthelp[] = {
"Usage:\n" { "-h | --help", N_("Display program help") },
" %s [options]\n" { "-v | --verbose", N_("Verbose messages") },
"\n" { "-d | --daemon", N_("Run as a daemon & write PID file") },
"Options:\n" { "-l | --listen", N_("Listen for TCP/IP connections") },
" -h | --help Display program help:\n" { "-t | --timeout <secs>", N_("Exit after timeout period") },
" -v | --verbose Verbose messages.\n" { "-f | --config <file>", N_("Configuration file") },
" -d | --daemon Run as a daemon & write PID file.\n" { "-V | --version", N_("Display version information") },
" -l | --listen Listen for TCP/IP connections.\n" { "-p | --pid-file <file>", N_("Change name of PID file") },
" -t | --timeout <secs> Exit after timeout period.\n" };
" -f | --config <file> Configuration file.\n"
" -V | --version Display version information.\n"
" -p | --pid-file <file> Change name of PID file.\n"
"\n"
"libvirt management daemon:\n"),
argv0);
if (privileged) { fprintf(stderr, "\n");
fprintf(stderr, fprintf(stderr, "%s\n", _("Usage:"));
_("\n" fprintf(stderr, " %s [%s]\n", argv0, _("options"));
" Default paths:\n" fprintf(stderr, "\n");
"\n"
" Configuration file (unless overridden by -f):\n" fprintf(stderr, "%s\n", _("Options:"));
" %s\n" for (i = 0; i < ARRAY_CARDINALITY(opthelp); i++)
"\n" fprintf(stderr, " %-22s %s\n", opthelp[i].opts,
" Sockets:\n" _(opthelp[i].help));
" %s\n" fprintf(stderr, "\n");
" %s\n"
"\n" fprintf(stderr, "%s\n", _("libvirt management daemon:"));
" TLS:\n"
" CA certificate: %s\n" fprintf(stderr, "\n");
" Server certificate: %s\n" fprintf(stderr, " %s\n", _("Default paths:"));
" Server private key: %s\n" fprintf(stderr, "\n");
"\n"
" PID file (unless overridden by -p):\n" fprintf(stderr, " %s\n", _("Configuration file (unless overridden by -f):"));
" %s/run/libvirtd.pid\n" fprintf(stderr, " %s/libvirt/libvirtd.conf\n",
"\n"), privileged ? SYSCONFDIR : "$XDG_CONFIG_HOME");
LIBVIRTD_CONFIGURATION_FILE, fprintf(stderr, "\n");
LIBVIRTD_PRIV_UNIX_SOCKET,
LIBVIRTD_PRIV_UNIX_SOCKET_RO, fprintf(stderr, " %s\n", _("Sockets:"));
LIBVIRT_CACERT, fprintf(stderr, " %s/libvirt/%s-sock\n",
LIBVIRT_SERVERCERT, privileged ? LOCALSTATEDIR "/run" : "$XDG_RUNTIME_DIR",
LIBVIRT_SERVERKEY, SOCK_PREFIX);
LOCALSTATEDIR); if (privileged)
} else { fprintf(stderr, " %s/run/libvirt/%s-sock-ro\n",
fprintf(stderr, "%s", LOCALSTATEDIR, SOCK_PREFIX);
_("\n" fprintf(stderr, "\n");
" Default paths:\n"
"\n" fprintf(stderr, " %s\n", _("TLS:"));
" Configuration file (unless overridden by -f):\n" fprintf(stderr, " %s %s\n",
" $XDG_CONFIG_HOME/libvirt/libvirtd.conf\n" _("CA certificate:"),
"\n" privileged ? LIBVIRT_CACERT : "$HOME/.pki/libvirt/cacert.pem");
" Sockets:\n" fprintf(stderr, " %s %s\n",
" $XDG_RUNTIME_DIR/libvirt/libvirt-sock\n" _("Server certificate:"),
"\n" privileged ? LIBVIRT_SERVERCERT : "$HOME/.pki/libvirt/servercert.pem");
" TLS:\n" fprintf(stderr, " %s %s\n",
" CA certificate: $HOME/.pki/libvirt/cacert.pem\n" _("Server private key:"),
" Server certificate: $HOME/.pki/libvirt/servercert.pem\n" privileged ? LIBVIRT_SERVERKEY : "$HOME/.pki/libvirt/serverkey.pem");
" Server private key: $HOME/.pki/libvirt/serverkey.pem\n" fprintf(stderr, "\n");
"\n"
" PID file:\n" fprintf(stderr, " %s\n",
" $XDG_RUNTIME_DIR/libvirt/libvirtd.pid\n" _("PID file (unless overridden by -p):"));
"\n")); fprintf(stderr, " %s\n",
} privileged ? LOCALSTATEDIR "/run/libvirtd.pid":
"$XDG_RUNTIME_DIR/libvirt/libvirtd.pid");
fprintf(stderr, "\n");
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
......
...@@ -34,7 +34,6 @@ unsigned long remoteVersion(void); ...@@ -34,7 +34,6 @@ unsigned long remoteVersion(void);
#define LIBVIRTD_PRIV_UNIX_SOCKET LOCALSTATEDIR "/run/libvirt/libvirt-sock" #define LIBVIRTD_PRIV_UNIX_SOCKET LOCALSTATEDIR "/run/libvirt/libvirt-sock"
#define LIBVIRTD_PRIV_UNIX_SOCKET_RO LOCALSTATEDIR "/run/libvirt/libvirt-sock-ro" #define LIBVIRTD_PRIV_UNIX_SOCKET_RO LOCALSTATEDIR "/run/libvirt/libvirt-sock-ro"
#define LIBVIRTD_USER_UNIX_SOCKET "libvirt-sock" #define LIBVIRTD_USER_UNIX_SOCKET "libvirt-sock"
#define LIBVIRTD_CONFIGURATION_FILE SYSCONFDIR "/libvirt/libvirtd.conf"
/* Defaults for PKI directory. */ /* Defaults for PKI directory. */
#define LIBVIRT_PKI_DIR SYSCONFDIR "/pki" #define LIBVIRT_PKI_DIR SYSCONFDIR "/pki"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册