The "spawnDaemon" and "binary" parameters are co-dependant, with the
latter non-NULL, if-and-only-if the former is true. Getting rid of the
"spawnDaemon" parameter simplifies life for the callers and eliminates
an error checking scenario.
Signed-off-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
src/admin/admin_remote.c | 2 +-
src/locking/lock_driver_lockd.c | 1 -
src/logging/log_manager.c | 1 -
src/lxc/lxc_monitor.c | 2 +-
src/qemu/qemu_migration.c | 3 +--
src/remote/remote_driver.c | 1 -
src/remote/remote_ssh_helper.c | 3 +--
src/rpc/virnetclient.c | 5 ++---
src/rpc/virnetclient.h | 3 +--
src/rpc/virnetsocket.c | 26 +++++++-------------------
src/rpc/virnetsocket.h | 3 +--
tests/virnetsockettest.c | 4 ++--
12 files changed, 17 insertions(+), 37 deletions(-)
diff --git a/src/admin/admin_remote.c b/src/admin/admin_remote.c
index 55ac81c5de..83a6be2b97 100644
--- a/src/admin/admin_remote.c
+++ b/src/admin/admin_remote.c
@@ -222,7 +222,7 @@ remoteAdminPrivNew(const char *sock_path)
if (!(priv = virObjectLockableNew(remoteAdminPrivClass)))
goto error;
- if (!(priv->client = virNetClientNewUNIX(sock_path, false, NULL)))
+ if (!(priv->client = virNetClientNewUNIX(sock_path, NULL)))
goto error;
if (!(priv->program = virNetClientProgramNew(ADMIN_PROGRAM,
diff --git a/src/locking/lock_driver_lockd.c b/src/locking/lock_driver_lockd.c
index 823b918db3..3a7386af30 100644
--- a/src/locking/lock_driver_lockd.c
+++ b/src/locking/lock_driver_lockd.c
@@ -208,7 +208,6 @@ static virNetClient *virLockManagerLockDaemonConnectionNew(bool
privileged,
goto error;
if (!(client = virNetClientNewUNIX(lockdpath,
- daemonPath != NULL,
daemonPath)))
goto error;
diff --git a/src/logging/log_manager.c b/src/logging/log_manager.c
index f66ebda495..e605ed9930 100644
--- a/src/logging/log_manager.c
+++ b/src/logging/log_manager.c
@@ -79,7 +79,6 @@ virLogManagerConnect(bool privileged,
goto error;
if (!(client = virNetClientNewUNIX(logdpath,
- daemonPath != NULL,
daemonPath)))
goto error;
diff --git a/src/lxc/lxc_monitor.c b/src/lxc/lxc_monitor.c
index 445bea281d..d8ef489a01 100644
--- a/src/lxc/lxc_monitor.c
+++ b/src/lxc/lxc_monitor.c
@@ -151,7 +151,7 @@ virLXCMonitor *virLXCMonitorNew(virDomainObj *vm,
sockpath = g_strdup_printf("%s/%s.sock", socketdir, vm->def->name);
- if (!(mon->client = virNetClientNewUNIX(sockpath, false, NULL)))
+ if (!(mon->client = virNetClientNewUNIX(sockpath, NULL)))
goto error;
if (virNetClientRegisterAsyncIO(mon->client) < 0)
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 3b0026a28e..a199758feb 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -3761,8 +3761,7 @@ qemuMigrationSrcConnect(virQEMUDriver *driver,
break;
case MIGRATION_DEST_CONNECT_SOCKET:
if (virNetSocketNewConnectUNIX(spec->dest.socket.path,
- false, NULL,
- &sock) == 0) {
+ NULL, &sock) == 0) {
fd_qemu = virNetSocketDupFD(sock, true);
virObjectUnref(sock);
}
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index e4e412dd01..9ca4348f6f 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -997,7 +997,6 @@ doRemoteOpen(virConnectPtr conn,
#ifndef WIN32
case REMOTE_DRIVER_TRANSPORT_UNIX:
if (!(priv->client = virNetClientNewUNIX(sockname,
- flags &
REMOTE_DRIVER_OPEN_AUTOSTART,
daemon_path)))
goto failed;
diff --git a/src/remote/remote_ssh_helper.c b/src/remote/remote_ssh_helper.c
index 2a24f2df96..0945b90331 100644
--- a/src/remote/remote_ssh_helper.c
+++ b/src/remote/remote_ssh_helper.c
@@ -431,8 +431,7 @@ int main(int argc, char **argv)
flags,
&daemon_path);
- if (virNetSocketNewConnectUNIX(sock_path, flags & REMOTE_DRIVER_OPEN_AUTOSTART,
- daemon_path, &sock) < 0) {
+ if (virNetSocketNewConnectUNIX(sock_path, daemon_path, &sock) < 0) {
g_printerr(_("%s: cannot connect to '%s': %s\n"),
argv[0], sock_path, virGetLastErrorMessage());
exit(EXIT_FAILURE);
diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c
index 3797a6097b..ffe2f343f9 100644
--- a/src/rpc/virnetclient.c
+++ b/src/rpc/virnetclient.c
@@ -366,12 +366,11 @@ virNetClientFindDefaultSshKey(const char *homedir, char **retPath)
virNetClient *virNetClientNewUNIX(const char *path,
- bool spawnDaemon,
- const char *binary)
+ const char *spawnDaemonPath)
{
virNetSocket *sock;
- if (virNetSocketNewConnectUNIX(path, spawnDaemon, binary, &sock) < 0)
+ if (virNetSocketNewConnectUNIX(path, spawnDaemonPath, &sock) < 0)
return NULL;
return virNetClientNew(sock, NULL);
diff --git a/src/rpc/virnetclient.h b/src/rpc/virnetclient.h
index c6ad59cf0d..5048033325 100644
--- a/src/rpc/virnetclient.h
+++ b/src/rpc/virnetclient.h
@@ -48,8 +48,7 @@ virNetClientSSHHelperCommand(virNetClientProxy proxy,
bool readonly);
virNetClient *virNetClientNewUNIX(const char *path,
- bool spawnDaemon,
- const char *binary);
+ const char *spawnDaemonPath);
virNetClient *virNetClientNewTCP(const char *nodename,
const char *service,
diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
index c762b605a5..c3fae8b626 100644
--- a/src/rpc/virnetsocket.c
+++ b/src/rpc/virnetsocket.c
@@ -664,8 +664,7 @@ int virNetSocketNewConnectTCP(const char *nodename,
#ifndef WIN32
int virNetSocketNewConnectUNIX(const char *path,
- bool spawnDaemon,
- const char *binary,
+ const char *spawnDaemonPath,
virNetSocket **retsock)
{
char *lockpath = NULL;
@@ -678,25 +677,15 @@ int virNetSocketNewConnectUNIX(const char *path,
int ret = -1;
bool daemonLaunched = false;
- VIR_DEBUG("path=%s spawnDaemon=%d binary=%s", path, spawnDaemon,
- NULLSTR(binary));
+ VIR_DEBUG("path=%s spawnDaemonPath=%s", path, NULLSTR(spawnDaemonPath));
memset(&localAddr, 0, sizeof(localAddr));
memset(&remoteAddr, 0, sizeof(remoteAddr));
remoteAddr.len = sizeof(remoteAddr.data.un);
- if (spawnDaemon) {
- g_autofree char *binname = NULL;
-
- if (!binary) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Auto-spawn of daemon requested, "
- "but no binary specified"));
- goto cleanup;
- }
-
- binname = g_path_get_basename(binary);
+ if (spawnDaemonPath) {
+ g_autofree char *binname = g_path_get_basename(spawnDaemonPath);
rundir = virGetUserRuntimeDirectory();
if (g_mkdir_with_parents(rundir, 0700) < 0) {
@@ -741,7 +730,7 @@ int virNetSocketNewConnectUNIX(const char *path,
VIR_DEBUG("connect() failed: retries=%d errno=%d", retries, errno);
retries--;
- if (!spawnDaemon ||
+ if (!spawnDaemonPath ||
retries == 0 ||
(errno != ENOENT && errno != ECONNREFUSED)) {
virReportSystemError(errno, _("Failed to connect socket to
'%s'"),
@@ -750,7 +739,7 @@ int virNetSocketNewConnectUNIX(const char *path,
}
if (!daemonLaunched) {
- if (virNetSocketForkDaemon(binary) < 0)
+ if (virNetSocketForkDaemon(spawnDaemonPath) < 0)
goto cleanup;
daemonLaunched = true;
@@ -785,8 +774,7 @@ int virNetSocketNewConnectUNIX(const char *path,
}
#else
int virNetSocketNewConnectUNIX(const char *path G_GNUC_UNUSED,
- bool spawnDaemon G_GNUC_UNUSED,
- const char *binary G_GNUC_UNUSED,
+ const char *spawnDaemonPath,
virNetSocket **retsock G_GNUC_UNUSED)
{
virReportSystemError(ENOSYS, "%s",
diff --git a/src/rpc/virnetsocket.h b/src/rpc/virnetsocket.h
index 2dc4d06f42..6fef8d30b3 100644
--- a/src/rpc/virnetsocket.h
+++ b/src/rpc/virnetsocket.h
@@ -65,8 +65,7 @@ int virNetSocketNewConnectTCP(const char *nodename,
virNetSocket **addr);
int virNetSocketNewConnectUNIX(const char *path,
- bool spawnDaemon,
- const char *binary,
+ const char *spawnDaemonPath,
virNetSocket **addr);
int virNetSocketNewConnectCommand(virCommand *cmd,
diff --git a/tests/virnetsockettest.c b/tests/virnetsockettest.c
index 6afdcbdbc7..8059c6cbb0 100644
--- a/tests/virnetsockettest.c
+++ b/tests/virnetsockettest.c
@@ -131,7 +131,7 @@ testSocketClient(void *opaque)
virNetSocket *csock = NULL;
if (data->path) {
- if (virNetSocketNewConnectUNIX(data->path, false,
+ if (virNetSocketNewConnectUNIX(data->path,
NULL, &csock) < 0)
return;
} else {
@@ -339,7 +339,7 @@ static int testSocketUNIXAddrs(const void *data G_GNUC_UNUSED)
if (virNetSocketListen(lsock, 0) < 0)
goto cleanup;
- if (virNetSocketNewConnectUNIX(path, false, NULL, &csock) < 0)
+ if (virNetSocketNewConnectUNIX(path, NULL, &csock) < 0)
goto cleanup;
if (STRNEQ(virNetSocketLocalAddrStringSASL(csock), "127.0.0.1;0")) {
--
2.31.1