diff --git a/src/remote/Makefile.inc.am b/src/remote/Makefile.inc.am index 0400dabad96c67e60fee96543ffedeecbc2af541..ced940d3c1cc9505accdca3f93f08eab22dd4273 100644 --- a/src/remote/Makefile.inc.am +++ b/src/remote/Makefile.inc.am @@ -146,6 +146,7 @@ libvirtd_CFLAGS = \ -I$(srcdir)/access \ -I$(srcdir)/conf \ -I$(srcdir)/rpc \ + -DSOCK_PREFIX="\"libvirt\"" \ $(NULL) libvirtd_LDFLAGS = \ diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c index d887b7abfbb2b653002e78fb258595f1909ba1c0..39c5d8642ff4cf61fd7366da6a87bea81bc05236 100644 --- a/src/remote/remote_daemon.c +++ b/src/remote/remote_daemon.c @@ -221,19 +221,25 @@ daemonUnixSocketPaths(struct daemonConfig *config, char *rundir = NULL; 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; if (privileged) { - if (virAsprintf(rosockfile, "%s/libvirt-sock-ro", config->unix_sock_dir) < 0 || - virAsprintf(admsockfile, "%s/libvirt-admin-sock", config->unix_sock_dir) < 0) + if (virAsprintf(rosockfile, "%s/%s-sock-ro", + SOCK_PREFIX, config->unix_sock_dir) < 0 || + virAsprintf(admsockfile, "%s/%s-admin-sock", + SOCK_PREFIX, config->unix_sock_dir) < 0) goto cleanup; } } else { if (privileged) { - if (VIR_STRDUP(*sockfile, LOCALSTATEDIR "/run/libvirt/libvirt-sock") < 0 || - VIR_STRDUP(*rosockfile, LOCALSTATEDIR "/run/libvirt/libvirt-sock-ro") < 0 || - VIR_STRDUP(*admsockfile, LOCALSTATEDIR "/run/libvirt/libvirt-admin-sock") < 0) + if (virAsprintf(sockfile, "%s/run/libvirt/%s-sock", + LOCALSTATEDIR, SOCK_PREFIX) < 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; } else { mode_t old_umask; @@ -248,8 +254,10 @@ daemonUnixSocketPaths(struct daemonConfig *config, } umask(old_umask); - if (virAsprintf(sockfile, "%s/libvirt-sock", rundir) < 0 || - virAsprintf(admsockfile, "%s/libvirt-admin-sock", rundir) < 0) + if (virAsprintf(sockfile, "%s/%s-sock", + rundir, SOCK_PREFIX) < 0 || + virAsprintf(admsockfile, "%s/%s-admin-sock", + rundir, SOCK_PREFIX) < 0) goto cleanup; } } @@ -859,75 +867,76 @@ daemonSetupHostUUID(const struct daemonConfig *config) return 0; } +typedef struct { + const char *opts; + const char *help; +} virOptionHelp; + /* Print command-line usage. */ static void daemonUsage(const char *argv0, bool privileged) { - fprintf(stderr, - _("\n" - "Usage:\n" - " %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 Exit after timeout period.\n" - " -f | --config Configuration file.\n" - " -V | --version Display version information.\n" - " -p | --pid-file Change name of PID file.\n" - "\n" - "libvirt management daemon:\n"), - argv0); + size_t i; + virOptionHelp opthelp[] = { + { "-h | --help", N_("Display program help") }, + { "-v | --verbose", N_("Verbose messages") }, + { "-d | --daemon", N_("Run as a daemon & write PID file") }, + { "-l | --listen", N_("Listen for TCP/IP connections") }, + { "-t | --timeout ", N_("Exit after timeout period") }, + { "-f | --config ", N_("Configuration file") }, + { "-V | --version", N_("Display version information") }, + { "-p | --pid-file ", N_("Change name of PID file") }, + }; - if (privileged) { - fprintf(stderr, - _("\n" - " Default paths:\n" - "\n" - " Configuration file (unless overridden by -f):\n" - " %s\n" - "\n" - " Sockets:\n" - " %s\n" - " %s\n" - "\n" - " TLS:\n" - " CA certificate: %s\n" - " Server certificate: %s\n" - " Server private key: %s\n" - "\n" - " PID file (unless overridden by -p):\n" - " %s/run/libvirtd.pid\n" - "\n"), - LIBVIRTD_CONFIGURATION_FILE, - LIBVIRTD_PRIV_UNIX_SOCKET, - LIBVIRTD_PRIV_UNIX_SOCKET_RO, - LIBVIRT_CACERT, - LIBVIRT_SERVERCERT, - LIBVIRT_SERVERKEY, - LOCALSTATEDIR); - } else { - fprintf(stderr, "%s", - _("\n" - " Default paths:\n" - "\n" - " Configuration file (unless overridden by -f):\n" - " $XDG_CONFIG_HOME/libvirt/libvirtd.conf\n" - "\n" - " Sockets:\n" - " $XDG_RUNTIME_DIR/libvirt/libvirt-sock\n" - "\n" - " TLS:\n" - " CA certificate: $HOME/.pki/libvirt/cacert.pem\n" - " Server certificate: $HOME/.pki/libvirt/servercert.pem\n" - " Server private key: $HOME/.pki/libvirt/serverkey.pem\n" - "\n" - " PID file:\n" - " $XDG_RUNTIME_DIR/libvirt/libvirtd.pid\n" - "\n")); - } + fprintf(stderr, "\n"); + fprintf(stderr, "%s\n", _("Usage:")); + fprintf(stderr, " %s [%s]\n", argv0, _("options")); + fprintf(stderr, "\n"); + + fprintf(stderr, "%s\n", _("Options:")); + for (i = 0; i < ARRAY_CARDINALITY(opthelp); i++) + fprintf(stderr, " %-22s %s\n", opthelp[i].opts, + _(opthelp[i].help)); + fprintf(stderr, "\n"); + + fprintf(stderr, "%s\n", _("libvirt management daemon:")); + + fprintf(stderr, "\n"); + fprintf(stderr, " %s\n", _("Default paths:")); + fprintf(stderr, "\n"); + + fprintf(stderr, " %s\n", _("Configuration file (unless overridden by -f):")); + fprintf(stderr, " %s/libvirt/libvirtd.conf\n", + privileged ? SYSCONFDIR : "$XDG_CONFIG_HOME"); + fprintf(stderr, "\n"); + + fprintf(stderr, " %s\n", _("Sockets:")); + fprintf(stderr, " %s/libvirt/%s-sock\n", + privileged ? LOCALSTATEDIR "/run" : "$XDG_RUNTIME_DIR", + SOCK_PREFIX); + if (privileged) + fprintf(stderr, " %s/run/libvirt/%s-sock-ro\n", + LOCALSTATEDIR, SOCK_PREFIX); + fprintf(stderr, "\n"); + + fprintf(stderr, " %s\n", _("TLS:")); + fprintf(stderr, " %s %s\n", + _("CA certificate:"), + privileged ? LIBVIRT_CACERT : "$HOME/.pki/libvirt/cacert.pem"); + fprintf(stderr, " %s %s\n", + _("Server certificate:"), + privileged ? LIBVIRT_SERVERCERT : "$HOME/.pki/libvirt/servercert.pem"); + fprintf(stderr, " %s %s\n", + _("Server private key:"), + privileged ? LIBVIRT_SERVERKEY : "$HOME/.pki/libvirt/serverkey.pem"); + fprintf(stderr, "\n"); + + fprintf(stderr, " %s\n", + _("PID file (unless overridden by -p):")); + fprintf(stderr, " %s\n", + privileged ? LOCALSTATEDIR "/run/libvirtd.pid": + "$XDG_RUNTIME_DIR/libvirt/libvirtd.pid"); + fprintf(stderr, "\n"); } int main(int argc, char **argv) { diff --git a/src/remote/remote_driver.h b/src/remote/remote_driver.h index 8c7da6b000c3209f8d8371e5e832d7327a97241e..132e478ef35eaf0a691f25c69bec5f8e609199d0 100644 --- a/src/remote/remote_driver.h +++ b/src/remote/remote_driver.h @@ -34,7 +34,6 @@ unsigned long remoteVersion(void); #define LIBVIRTD_PRIV_UNIX_SOCKET LOCALSTATEDIR "/run/libvirt/libvirt-sock" #define LIBVIRTD_PRIV_UNIX_SOCKET_RO LOCALSTATEDIR "/run/libvirt/libvirt-sock-ro" #define LIBVIRTD_USER_UNIX_SOCKET "libvirt-sock" -#define LIBVIRTD_CONFIGURATION_FILE SYSCONFDIR "/libvirt/libvirtd.conf" /* Defaults for PKI directory. */ #define LIBVIRT_PKI_DIR SYSCONFDIR "/pki"