The remoteGetUNIXSocket method currently just returns the daemon name
and the caller then converts this to a path. Except the SSH helper
didn't do this, so it was relying on later code expanding $PATH, and
this doesn't allow for build root overrides.
Signed-off-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
src/remote/remote_driver.c | 33 +++-------------------------
src/remote/remote_sockets.c | 39 +++++++++++++++++++++++++++++-----
src/remote/remote_sockets.h | 2 +-
src/remote/remote_ssh_helper.c | 6 +++---
4 files changed, 41 insertions(+), 39 deletions(-)
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index d03369b168..e4e412dd01 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -700,23 +700,6 @@ remoteConnectSupportsFeatureUnlocked(virConnectPtr conn,
}
-#ifndef WIN32
-static const char *
-remoteGetDaemonPathEnv(void)
-{
- /* We prefer a VIRTD_PATH env var to use for all daemons,
- * but if it is not set we will fallback to LIBVIRTD_PATH
- * for previous behaviour
- */
- if (getenv("VIRTD_PATH") != NULL) {
- return "VIRTD_PATH";
- } else {
- return "LIBVIRTD_PATH";
- }
-}
-#endif /* WIN32 */
-
-
/*
* URIs that this driver needs to handle:
*
@@ -763,7 +746,7 @@ doRemoteOpen(virConnectPtr conn,
g_autofree char *knownHostsVerify = NULL;
g_autofree char *knownHosts = NULL;
g_autofree char *mode_str = NULL;
- g_autofree char *daemon_name = NULL;
+ g_autofree char *daemon_path = NULL;
g_autofree char *proxy_str = NULL;
bool sanity = true;
bool verify = true;
@@ -917,7 +900,7 @@ doRemoteOpen(virConnectPtr conn,
case REMOTE_DRIVER_TRANSPORT_LIBSSH2:
if (!sockname &&
!(sockname = remoteGetUNIXSocket(transport, mode, driver_str,
- flags, &daemon_name)))
+ flags, &daemon_path)))
goto failed;
break;
@@ -1013,19 +996,9 @@ doRemoteOpen(virConnectPtr conn,
#ifndef WIN32
case REMOTE_DRIVER_TRANSPORT_UNIX:
- if (flags & REMOTE_DRIVER_OPEN_AUTOSTART) {
- const char *env_name = remoteGetDaemonPathEnv();
- if (!(daemonPath = virFileFindResourceFull(daemon_name,
- NULL, NULL,
- abs_top_builddir
"/src",
- SBINDIR,
- env_name)))
- goto failed;
- }
-
if (!(priv->client = virNetClientNewUNIX(sockname,
flags &
REMOTE_DRIVER_OPEN_AUTOSTART,
- daemonPath)))
+ daemon_path)))
goto failed;
priv->is_secure = 1;
diff --git a/src/remote/remote_sockets.c b/src/remote/remote_sockets.c
index 06315fe9c0..6d33b69467 100644
--- a/src/remote/remote_sockets.c
+++ b/src/remote/remote_sockets.c
@@ -47,6 +47,22 @@ VIR_ENUM_IMPL(remoteDriverMode,
"legacy",
"direct");
+#ifndef WIN32
+static const char *
+remoteGetDaemonPathEnv(void)
+{
+ /* We prefer a VIRTD_PATH env var to use for all daemons,
+ * but if it is not set we will fallback to LIBVIRTD_PATH
+ * for previous behaviour
+ */
+ if (getenv("VIRTD_PATH") != NULL) {
+ return "VIRTD_PATH";
+ } else {
+ return "LIBVIRTD_PATH";
+ }
+}
+#endif /* WIN32 */
+
int
remoteSplitURIScheme(virURI *uri,
@@ -136,13 +152,19 @@ remoteGetUNIXSocket(remoteDriverTransport transport,
remoteDriverMode mode,
const char *driver,
unsigned int flags,
- char **daemon)
+ char **daemon_path)
{
char *sock_name = NULL;
g_autofree char *direct_daemon = NULL;
g_autofree char *legacy_daemon = NULL;
+ g_autofree char *daemon_name = NULL;
g_autofree char *direct_sock_name = NULL;
g_autofree char *legacy_sock_name = NULL;
+#ifndef WIN32
+ const char *env_name = remoteGetDaemonPathEnv();
+#else
+ const char *env_path = NULL;
+#endif
VIR_DEBUG("Choosing remote socket for transport=%s mode=%s driver=%s
flags=0x%x",
remoteDriverTransportTypeToString(transport),
@@ -182,7 +204,7 @@ remoteGetUNIXSocket(remoteDriverTransport transport,
switch ((remoteDriverMode)mode) {
case REMOTE_DRIVER_MODE_LEGACY:
sock_name = g_steal_pointer(&legacy_sock_name);
- *daemon = g_steal_pointer(&legacy_daemon);
+ daemon_name = g_steal_pointer(&legacy_daemon);
break;
case REMOTE_DRIVER_MODE_DIRECT:
@@ -200,7 +222,7 @@ remoteGetUNIXSocket(remoteDriverTransport transport,
}
sock_name = g_steal_pointer(&direct_sock_name);
- *daemon = g_steal_pointer(&direct_daemon);
+ daemon_name = g_steal_pointer(&direct_daemon);
break;
case REMOTE_DRIVER_MODE_AUTO:
@@ -210,8 +232,15 @@ remoteGetUNIXSocket(remoteDriverTransport transport,
return NULL;
}
- VIR_DEBUG("Chosen UNIX sockname=%s daemon=%s with mode=%s",
- sock_name, NULLSTR(*daemon),
+ if (!(*daemon_path = virFileFindResourceFull(daemon_name,
+ NULL, NULL,
+ abs_top_builddir "/src",
+ SBINDIR,
+ env_name)))
+ return NULL;
+
+ VIR_DEBUG("Chosen UNIX sockname=%s daemon_path=%s with mode=%s",
+ sock_name, NULLSTR(*daemon_path),
remoteDriverModeTypeToString(mode));
return sock_name;
}
diff --git a/src/remote/remote_sockets.h b/src/remote/remote_sockets.h
index 2331f81425..11934dbf70 100644
--- a/src/remote/remote_sockets.h
+++ b/src/remote/remote_sockets.h
@@ -67,7 +67,7 @@ remoteGetUNIXSocket(remoteDriverTransport transport,
remoteDriverMode mode,
const char *driver,
unsigned int flags, /* remoteDriverOpenFlags */
- char **daemon);
+ char **daemon_path);
void
remoteGetURIDaemonInfo(virURI *uri,
diff --git a/src/remote/remote_ssh_helper.c b/src/remote/remote_ssh_helper.c
index 7123fc6d00..2a24f2df96 100644
--- a/src/remote/remote_ssh_helper.c
+++ b/src/remote/remote_ssh_helper.c
@@ -358,7 +358,7 @@ int main(int argc, char **argv)
gboolean version = false;
gboolean readonly = false;
g_autofree char *sock_path = NULL;
- g_autofree char *daemon_name = NULL;
+ g_autofree char *daemon_path = NULL;
g_autoptr(virNetSocket) sock = NULL;
GError *error = NULL;
g_autoptr(GOptionContext) context = NULL;
@@ -429,10 +429,10 @@ int main(int argc, char **argv)
REMOTE_DRIVER_MODE_AUTO,
driver,
flags,
- &daemon_name);
+ &daemon_path);
if (virNetSocketNewConnectUNIX(sock_path, flags & REMOTE_DRIVER_OPEN_AUTOSTART,
- daemon_name, &sock) < 0) {
+ daemon_path, &sock) < 0) {
g_printerr(_("%s: cannot connect to '%s': %s\n"),
argv[0], sock_path, virGetLastErrorMessage());
exit(EXIT_FAILURE);
--
2.31.1