Prepare for reusing libvirtd source to create other daemons by making
the daemon name conditionally defined by the make rules.
Reviewed-by: Andrea Bolognani <abologna(a)redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
src/remote/Makefile.inc.am | 1 +
src/remote/remote_daemon.c | 50 +++++++++++++++++--------------
src/remote/remote_daemon_config.c | 5 ++--
3 files changed, 31 insertions(+), 25 deletions(-)
diff --git a/src/remote/Makefile.inc.am b/src/remote/Makefile.inc.am
index ced940d3c1..b72186109a 100644
--- a/src/remote/Makefile.inc.am
+++ b/src/remote/Makefile.inc.am
@@ -147,6 +147,7 @@ libvirtd_CFLAGS = \
-I$(srcdir)/conf \
-I$(srcdir)/rpc \
-DSOCK_PREFIX="\"libvirt\"" \
+ -DDAEMON_NAME="\"libvirtd\"" \
$(NULL)
libvirtd_LDFLAGS = \
diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c
index f9d923b357..f1daaeb944 100644
--- a/src/remote/remote_daemon.c
+++ b/src/remote/remote_daemon.c
@@ -64,7 +64,11 @@
#include "virdbus.h"
-VIR_LOG_INIT("daemon.libvirtd");
+VIR_LOG_INIT("daemon." DAEMON_NAME);
+
+#ifndef SOCK_PREFIX
+# define SOCK_PREFIX DAEMON_NAME
+#endif
#if WITH_SASL
virNetSASLContextPtr saslCtxt = NULL;
@@ -383,11 +387,11 @@ daemonSetupNetworking(virNetServerPtr srv,
int ret = -1;
VIR_AUTOPTR(virSystemdActivation) act = NULL;
virSystemdActivationMap actmap[] = {
- { .name = "libvirtd.socket", .family = AF_UNIX, .path = sock_path },
- { .name = "libvirtd-ro.socket", .family = AF_UNIX, .path = sock_path_ro
},
- { .name = "libvirtd-admin.socket", .family = AF_UNIX, .path =
sock_path_adm },
- { .name = "libvirtd-tcp.socket", .family = AF_INET },
- { .name = "libvirtd-tls.socket", .family = AF_INET },
+ { .name = DAEMON_NAME ".socket", .family = AF_UNIX, .path = sock_path
},
+ { .name = DAEMON_NAME "-ro.socket", .family = AF_UNIX, .path =
sock_path_ro },
+ { .name = DAEMON_NAME "-admin.socket", .family = AF_UNIX, .path =
sock_path_adm },
+ { .name = DAEMON_NAME "-tcp.socket", .family = AF_INET },
+ { .name = DAEMON_NAME "-tls.socket", .family = AF_INET },
};
if ((actmap[3].port = virSocketAddrResolveService(config->tcp_port)) < 0)
@@ -421,7 +425,7 @@ daemonSetupNetworking(virNetServerPtr srv,
if (virNetServerAddServiceUNIX(srv,
act,
- "libvirtd.socket",
+ DAEMON_NAME ".socket",
sock_path,
unix_sock_rw_mask,
unix_sock_gid,
@@ -434,7 +438,7 @@ daemonSetupNetworking(virNetServerPtr srv,
if (sock_path_ro &&
virNetServerAddServiceUNIX(srv,
act,
- "libvirtd-ro.socket",
+ DAEMON_NAME "-ro.socket",
sock_path_ro,
unix_sock_ro_mask,
unix_sock_gid,
@@ -448,7 +452,7 @@ daemonSetupNetworking(virNetServerPtr srv,
if (sock_path_adm &&
virNetServerAddServiceUNIX(srvAdm,
act,
- "libvirtd-admin.socket",
+ DAEMON_NAME "-admin.socket",
sock_path_adm,
unix_sock_adm_mask,
unix_sock_gid,
@@ -462,7 +466,7 @@ daemonSetupNetworking(virNetServerPtr srv,
if (((ipsock && config->listen_tcp) || act) &&
virNetServerAddServiceTCP(srv,
act,
- "libvirtd-tcp.socket",
+ DAEMON_NAME "-tcp.socket",
config->listen_addr,
config->tcp_port,
AF_UNSPEC,
@@ -519,7 +523,7 @@ daemonSetupNetworking(virNetServerPtr srv,
config->listen_addr, config->tls_port);
if (virNetServerAddServiceTCP(srv,
act,
- "libvirtd-tls.socket",
+ DAEMON_NAME "-tls.socket",
config->listen_addr,
config->tls_port,
AF_UNSPEC,
@@ -564,7 +568,7 @@ daemonSetupNetDevOpenvswitch(struct daemonConfig *config)
/*
* Set up the logging environment
- * By default if daemonized all errors go to the logfile libvirtd.log,
+ * By default if daemonized all errors go to journald/a logfile
* but if verbose or error debugging is asked for then also output
* informational and debug messages. Default size if 64 kB.
*/
@@ -577,7 +581,7 @@ daemonSetupLogging(struct daemonConfig *config,
virLogReset();
/*
- * Libvirtd's order of precedence is:
+ * Logging setup order of precedence is:
* cmdline > environment > config
*
* Given the precedence, we must process the variables in the opposite
@@ -605,7 +609,7 @@ daemonSetupLogging(struct daemonConfig *config,
/* Define the default output. This is only applied if there was no setting
* from either the config or the environment.
*/
- if (virLogSetDefaultOutput("libvirtd", godaemon, privileged) < 0)
+ if (virLogSetDefaultOutput(DAEMON_NAME, godaemon, privileged) < 0)
return -1;
if (virLogGetNbOutputs() == 0)
@@ -717,7 +721,7 @@ static void daemonStopWorker(void *opaque)
VIR_DEBUG("Completed stop dmn=%p", dmn);
- /* Exit libvirtd cleanly */
+ /* Exit daemon cleanly */
virNetDaemonQuit(dmn);
}
@@ -796,7 +800,7 @@ static void daemonRunStateInit(void *opaque)
driversInitialized = true;
#ifdef WITH_DBUS
- /* Tie the non-privileged libvirtd to the session/shutdown lifecycle */
+ /* Tie the non-privileged daemons to the session/shutdown lifecycle */
if (!virNetDaemonIsPrivileged(dmn)) {
sessionBus = virDBusGetSessionBus();
@@ -905,8 +909,8 @@ daemonUsage(const char *argv0, bool privileged)
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, " %s/libvirt/%s.conf\n",
+ privileged ? SYSCONFDIR : "$XDG_CONFIG_HOME", DAEMON_NAME);
fprintf(stderr, "\n");
fprintf(stderr, " %s:\n", _("Sockets"));
@@ -932,9 +936,9 @@ daemonUsage(const char *argv0, bool privileged)
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, " %s/%s.pid\n",
+ privileged ? LOCALSTATEDIR "/run" :
"$XDG_RUNTIME_DIR/libvirt",
+ DAEMON_NAME);
fprintf(stderr, "\n");
}
@@ -1098,7 +1102,7 @@ int main(int argc, char **argv) {
if (!pid_file &&
virPidFileConstructPath(privileged,
LOCALSTATEDIR,
- "libvirtd",
+ DAEMON_NAME,
&pid_file) < 0) {
VIR_ERROR(_("Can't determine pid file path."));
exit(EXIT_FAILURE);
@@ -1178,7 +1182,7 @@ int main(int argc, char **argv) {
goto cleanup;
}
- if (!(srv = virNetServerNew("libvirtd", 1,
+ if (!(srv = virNetServerNew(DAEMON_NAME, 1,
config->min_workers,
config->max_workers,
config->prio_workers,
diff --git a/src/remote/remote_daemon_config.c b/src/remote/remote_daemon_config.c
index 537b90a855..3e62b4203f 100644
--- a/src/remote/remote_daemon_config.c
+++ b/src/remote/remote_daemon_config.c
@@ -77,7 +77,8 @@ int
daemonConfigFilePath(bool privileged, char **configfile)
{
if (privileged) {
- if (VIR_STRDUP(*configfile, SYSCONFDIR "/libvirt/libvirtd.conf") <
0)
+ if (VIR_STRDUP(*configfile,
+ SYSCONFDIR "/libvirt/" DAEMON_NAME ".conf")
< 0)
goto error;
} else {
char *configdir = NULL;
@@ -85,7 +86,7 @@ daemonConfigFilePath(bool privileged, char **configfile)
if (!(configdir = virGetUserConfigDirectory()))
goto error;
- if (virAsprintf(configfile, "%s/libvirtd.conf", configdir) < 0) {
+ if (virAsprintf(configfile, "%s/%s.conf", configdir, DAEMON_NAME) <
0) {
VIR_FREE(configdir);
goto error;
}
--
2.21.0