[PATCH 07/10] virt-ssh-helper: Accept ?socket= in connection URI

Michal Privoznik posted 10 patches 3 years ago
There is a newer version of this series
[PATCH 07/10] virt-ssh-helper: Accept ?socket= in connection URI
Posted by Michal Privoznik 3 years ago
Similarly to the previous commit, let's accept "socket" parameter
in the connection URI. This change will allow us to use
virt-ssh-helper instead of 'nc' in all cases (done in one of
future commits).

Please note, when the parameter is used it effectively disables
automatic daemon spawning and an error is reported. But this is
intentional - so that the helper behaves just like regular
virConnectOpen() with different transport than ssh, e.g. unix.

But this 'change' is acceptable - there's no way for users to
make our remote code pass the argument to virt-ssh-helper, yet.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/remote/remote_ssh_helper.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/remote/remote_ssh_helper.c b/src/remote/remote_ssh_helper.c
index 3b4de7f214..0eafc70d16 100644
--- a/src/remote/remote_ssh_helper.c
+++ b/src/remote/remote_ssh_helper.c
@@ -436,6 +436,7 @@ int main(int argc, char **argv)
         virURIParam *var = &uri->params[i];
 
         VIR_EXTRACT_URI_ARG_STR("mode", mode_str);
+        VIR_EXTRACT_URI_ARG_STR("socket", sock_path);
     }
 
     if (mode_str &&
@@ -444,11 +445,12 @@ int main(int argc, char **argv)
         exit(EXIT_FAILURE);
     }
 
-    sock_path = remoteGetUNIXSocket(transport,
-                                    mode,
-                                    driver,
-                                    flags,
-                                    &daemon_path);
+    if (!sock_path &&
+        !(sock_path = remoteGetUNIXSocket(transport, mode,
+                                          driver, flags, &daemon_path))) {
+        g_printerr(_("%s: failed to generate UNIX socket path"), argv[0]);
+        exit(EXIT_FAILURE);
+    }
 
     if (virNetSocketNewConnectUNIX(sock_path, daemon_path, &sock) < 0) {
         g_printerr(_("%s: cannot connect to '%s': %s\n"),
-- 
2.39.1
Re: [PATCH 07/10] virt-ssh-helper: Accept ?socket= in connection URI
Posted by Peter Krempa 3 years ago
On Mon, Feb 06, 2023 at 10:16:55 +0100, Michal Privoznik wrote:
> Similarly to the previous commit, let's accept "socket" parameter
> in the connection URI. This change will allow us to use
> virt-ssh-helper instead of 'nc' in all cases (done in one of
> future commits).
> 
> Please note, when the parameter is used it effectively disables
> automatic daemon spawning and an error is reported. But this is
> intentional - so that the helper behaves just like regular
> virConnectOpen() with different transport than ssh, e.g. unix.
> 
> But this 'change' is acceptable - there's no way for users to
> make our remote code pass the argument to virt-ssh-helper, yet.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/remote/remote_ssh_helper.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)

Reviewed-by: Peter Krempa <pkrempa@redhat.com>