mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-09 06:25:19 +00:00
remote: change socket helper to return full daemon path
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. Reviewed-by: Ján Tomko <jtomko@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
faf8354674
commit
fcdcf8f70c
@ -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;
|
||||
@ -942,7 +925,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;
|
||||
|
||||
@ -1038,19 +1021,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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user