]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
rpc: remove "spawnDaemon" parameter
authorDaniel P. Berrangé <berrange@redhat.com>
Mon, 24 May 2021 14:07:19 +0000 (15:07 +0100)
committerDaniel P. Berrangé <berrange@redhat.com>
Fri, 4 Jun 2021 10:42:59 +0000 (11:42 +0100)
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.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
12 files changed:
src/admin/admin_remote.c
src/locking/lock_driver_lockd.c
src/logging/log_manager.c
src/lxc/lxc_monitor.c
src/qemu/qemu_migration.c
src/remote/remote_driver.c
src/remote/remote_ssh_helper.c
src/rpc/virnetclient.c
src/rpc/virnetclient.h
src/rpc/virnetsocket.c
src/rpc/virnetsocket.h
tests/virnetsockettest.c

index 55ac81c5def7bdffc92767956c48179018503ac5..83a6be2b97605c1a4558cfbf661617f637a2d671 100644 (file)
@@ -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,
index 823b918db33b0c9d33cba5fa12427089888d8cd2..3a7386af304c9ee3f14c1bc46b066f6d5f144c9d 100644 (file)
@@ -208,7 +208,6 @@ static virNetClient *virLockManagerLockDaemonConnectionNew(bool privileged,
         goto error;
 
     if (!(client = virNetClientNewUNIX(lockdpath,
-                                       daemonPath != NULL,
                                        daemonPath)))
         goto error;
 
index f66ebda4954b780c6e44d502f93db1be3a909529..e605ed9930297e963ffa61859f8e96de899fe2a1 100644 (file)
@@ -79,7 +79,6 @@ virLogManagerConnect(bool privileged,
         goto error;
 
     if (!(client = virNetClientNewUNIX(logdpath,
-                                       daemonPath != NULL,
                                        daemonPath)))
         goto error;
 
index 445bea281d2a0bad6688fa072fe3894512c6ee9c..d8ef489a0175278094d10acbe38c24365ddfcfc5 100644 (file)
@@ -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)
index 3b0026a28ebdcae3246ecaba1ce9a2d0b28dd8bb..a199758febd4827704fb94b6c5553a0123741383 100644 (file)
@@ -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);
         }
index 1ba66c1f81b58c8682f250e3a33c139d1987bbc4..da672b0d00097a292855c5cf96871ff8158e07bc 100644 (file)
@@ -1022,7 +1022,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;
 
index 2a24f2df96a5848757010379dbef4842c73440e9..0945b90331920c56c253bbacbb1200532e37b56b 100644 (file)
@@ -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);
index 3797a6097b3eb9b04a96ffdb88156052c79e3f16..ffe2f343f9168366b8500193b317baae68420a43 100644 (file)
@@ -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);
index c6ad59cf0d8b196409bb05c06baf5d8f2344c517..504803332577ccd77a50179a30efe046f550fd3b 100644 (file)
@@ -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,
index c762b605a5ed496dfc7550bc69533036fbb4e52e..c3fae8b6266002e05887ad3827f1f2b86f0b339c 100644 (file)
@@ -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",
index 2dc4d06f429162cfaeb88c6b6970b321f27efad0..6fef8d30b3812729cc8699f04dd02742a40c723a 100644 (file)
@@ -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,
index 6afdcbdbc78292222268f85b1aaef6d369dd1bb4..8059c6cbb06e05cca0534ad28209b9aad8361361 100644 (file)
@@ -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")) {