We have helper methods that return boolans for ro/user/autostart
properties. We then pack them into a flags parameter, and later
unpack them again. This makes te code consistently use flags
throughout.
Signed-off-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
src/remote/remote_driver.c | 16 ++++-----------
src/remote/remote_sockets.c | 37 ++++++++++++++++------------------
src/remote/remote_sockets.h | 6 ++----
src/remote/remote_ssh_helper.c | 13 ++++++------
4 files changed, 30 insertions(+), 42 deletions(-)
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 6b615b9286..d03369b168 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -917,9 +917,7 @@ doRemoteOpen(virConnectPtr conn,
case REMOTE_DRIVER_TRANSPORT_LIBSSH2:
if (!sockname &&
!(sockname = remoteGetUNIXSocket(transport, mode, driver_str,
- flags & REMOTE_DRIVER_OPEN_RO,
- flags & REMOTE_DRIVER_OPEN_USER,
- &daemon_name)))
+ flags, &daemon_name)))
goto failed;
break;
@@ -1232,9 +1230,7 @@ remoteConnectOpen(virConnectPtr conn,
{
struct private_data *priv;
int ret = VIR_DRV_OPEN_ERROR;
- int rflags = 0;
- bool user;
- bool autostart;
+ unsigned int rflags = 0;
char *driver = NULL;
remoteDriverTransport transport;
@@ -1270,15 +1266,11 @@ remoteConnectOpen(virConnectPtr conn,
if (!(priv = remoteAllocPrivateData()))
goto cleanup;
+
+ remoteGetURIDaemonInfo(conn->uri, transport, &rflags);
if (flags & VIR_CONNECT_RO)
rflags |= REMOTE_DRIVER_OPEN_RO;
- remoteGetURIDaemonInfo(conn->uri, transport, &user, &autostart);
- if (user)
- rflags |= REMOTE_DRIVER_OPEN_USER;
- if (autostart)
- rflags |= REMOTE_DRIVER_OPEN_AUTOSTART;
-
ret = doRemoteOpen(conn, priv, driver, transport, auth, conf, rflags);
if (ret != VIR_DRV_OPEN_SUCCESS) {
conn->privateData = NULL;
diff --git a/src/remote/remote_sockets.c b/src/remote/remote_sockets.c
index e9d865213f..06315fe9c0 100644
--- a/src/remote/remote_sockets.c
+++ b/src/remote/remote_sockets.c
@@ -101,13 +101,12 @@ remoteSplitURIScheme(virURI *uri,
static char *
remoteGetUNIXSocketHelper(remoteDriverTransport transport,
const char *sock_prefix,
- bool ro,
- bool session)
+ unsigned int flags)
{
char *sockname = NULL;
g_autofree char *userdir = NULL;
- if (session) {
+ if (flags & REMOTE_DRIVER_OPEN_USER) {
userdir = virGetUserRuntimeDirectory();
sockname = g_strdup_printf("%s/%s-sock", userdir, sock_prefix);
@@ -120,13 +119,14 @@ remoteGetUNIXSocketHelper(remoteDriverTransport transport,
*/
sockname = g_strdup_printf("%s/run/libvirt/%s-%s", LOCALSTATEDIR,
sock_prefix,
- ro ? "sock-ro" : "sock");
+ flags & REMOTE_DRIVER_OPEN_RO ?
+ "sock-ro" : "sock");
}
VIR_DEBUG("Built UNIX sockname=%s for transport=%s "
- "prefix=%s ro=%d session=%d",
+ "prefix=%s flags=0x%x",
sockname, remoteDriverTransportTypeToString(transport),
- sock_prefix, ro, session);
+ sock_prefix, flags);
return sockname;
}
@@ -135,8 +135,7 @@ char *
remoteGetUNIXSocket(remoteDriverTransport transport,
remoteDriverMode mode,
const char *driver,
- bool ro,
- bool session,
+ unsigned int flags,
char **daemon)
{
char *sock_name = NULL;
@@ -145,10 +144,10 @@ remoteGetUNIXSocket(remoteDriverTransport transport,
g_autofree char *direct_sock_name = NULL;
g_autofree char *legacy_sock_name = NULL;
- VIR_DEBUG("Choosing remote socket for transport=%s mode=%s driver=%s ro=%d
session=%d",
+ VIR_DEBUG("Choosing remote socket for transport=%s mode=%s driver=%s
flags=0x%x",
remoteDriverTransportTypeToString(transport),
remoteDriverModeTypeToString(mode),
- driver, ro, session);
+ driver, flags);
if (driver)
direct_daemon = g_strdup_printf("virt%sd", driver);
@@ -156,9 +155,9 @@ remoteGetUNIXSocket(remoteDriverTransport transport,
legacy_daemon = g_strdup("libvirtd");
if (driver)
- direct_sock_name = remoteGetUNIXSocketHelper(transport, direct_daemon, ro,
session);
+ direct_sock_name = remoteGetUNIXSocketHelper(transport, direct_daemon, flags);
- legacy_sock_name = remoteGetUNIXSocketHelper(transport, "libvirt", ro,
session);
+ legacy_sock_name = remoteGetUNIXSocketHelper(transport, "libvirt", flags);
if (mode == REMOTE_DRIVER_MODE_AUTO) {
if (transport == REMOTE_DRIVER_TRANSPORT_UNIX) {
@@ -221,13 +220,11 @@ remoteGetUNIXSocket(remoteDriverTransport transport,
void
remoteGetURIDaemonInfo(virURI *uri,
remoteDriverTransport transport,
- bool *session,
- bool *autostart)
+ unsigned int *flags)
{
const char *autostart_str = getenv("LIBVIRT_AUTOSTART");
- *session = false;
- *autostart = false;
+ *flags = 0;
/*
* User session daemon is used for
@@ -244,7 +241,7 @@ remoteGetURIDaemonInfo(virURI *uri,
STRPREFIX(uri->scheme, "test+")) &&
geteuid() > 0) {
VIR_DEBUG("User session daemon required");
- *session = true;
+ *flags |= REMOTE_DRIVER_OPEN_USER;
/*
* Furthermore if no servername is given,
@@ -256,7 +253,7 @@ remoteGetURIDaemonInfo(virURI *uri,
(!autostart_str ||
STRNEQ(autostart_str, "0"))) {
VIR_DEBUG("Try daemon autostart");
- *autostart = true;
+ *flags |= REMOTE_DRIVER_OPEN_AUTOSTART;
}
}
@@ -268,10 +265,10 @@ remoteGetURIDaemonInfo(virURI *uri,
VIR_DEBUG("Auto-probe remote URI");
if (geteuid() > 0) {
VIR_DEBUG("Auto-spawn user daemon instance");
- *session = true;
+ *flags |= REMOTE_DRIVER_OPEN_USER;
if (!autostart_str ||
STRNEQ(autostart_str, "0"))
- *autostart = true;
+ *flags |= REMOTE_DRIVER_OPEN_AUTOSTART;
}
}
}
diff --git a/src/remote/remote_sockets.h b/src/remote/remote_sockets.h
index 749389700e..2331f81425 100644
--- a/src/remote/remote_sockets.h
+++ b/src/remote/remote_sockets.h
@@ -66,12 +66,10 @@ char *
remoteGetUNIXSocket(remoteDriverTransport transport,
remoteDriverMode mode,
const char *driver,
- bool ro,
- bool session,
+ unsigned int flags, /* remoteDriverOpenFlags */
char **daemon);
void
remoteGetURIDaemonInfo(virURI *uri,
remoteDriverTransport transport,
- bool *session,
- bool *autostart);
+ unsigned int *flags); /* remoteDriverOpenFlags */
diff --git a/src/remote/remote_ssh_helper.c b/src/remote/remote_ssh_helper.c
index 7934e14509..7123fc6d00 100644
--- a/src/remote/remote_ssh_helper.c
+++ b/src/remote/remote_ssh_helper.c
@@ -355,8 +355,6 @@ int main(int argc, char **argv)
g_autoptr(virURI) uri = NULL;
g_autofree char *driver = NULL;
remoteDriverTransport transport;
- bool user = false;
- bool autostart = false;
gboolean version = false;
gboolean readonly = false;
g_autofree char *sock_path = NULL;
@@ -369,6 +367,7 @@ int main(int argc, char **argv)
{ "version", 'V', 0, G_OPTION_ARG_NONE, &version,
"Display version information", NULL },
{ NULL, '\0', 0, 0, NULL, NULL, NULL }
};
+ unsigned int flags;
context = g_option_context_new("- libvirt socket proxy");
g_option_context_add_main_entries(context, entries, PACKAGE);
@@ -422,16 +421,18 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}
- remoteGetURIDaemonInfo(uri, transport, &user, &autostart);
+ remoteGetURIDaemonInfo(uri, transport, &flags);
+ if (readonly)
+ flags |= REMOTE_DRIVER_OPEN_RO;
sock_path = remoteGetUNIXSocket(transport,
REMOTE_DRIVER_MODE_AUTO,
driver,
- !!readonly,
- user,
+ flags,
&daemon_name);
- if (virNetSocketNewConnectUNIX(sock_path, autostart, daemon_name, &sock) < 0)
{
+ if (virNetSocketNewConnectUNIX(sock_path, flags & REMOTE_DRIVER_OPEN_AUTOSTART,
+ daemon_name, &sock) < 0) {
g_printerr(_("%s: cannot connect to '%s': %s\n"),
argv[0], sock_path, virGetLastErrorMessage());
exit(EXIT_FAILURE);
--
2.31.1