[PATCH] virnetlibsshsession: Reflect API change in libssh

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



As of libssh commit of libssh-0.11.0~70 [1] the
ssh_channel_get_exit_status() function is deprecated and a new
one is introduced instead: ssh_channel_get_exit_state().
It's not a drop-in replacement, but it's simple enough.
Adapt our libssh handling code to this change.

1: https://git.libssh.org/projects/libssh.git/commit/?id=04d86aeeae73c78af8b3dcdabb2e588cd31a8923

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 meson.build                   |  3 +++
 src/rpc/virnetlibsshsession.c | 39 +++++++++++++++++++++++++++++------
 2 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/meson.build b/meson.build
index 06d88ad1f3..f31485c395 100644
--- a/meson.build
+++ b/meson.build
@@ -1096,6 +1096,9 @@ if conf.has('WITH_REMOTE')
   libssh_dep = dependency('libssh', version: '>=' + libssh_version, required: get_option('libssh'))
   if libssh_dep.found()
     conf.set('WITH_LIBSSH', 1)
+    if cc.has_function('ssh_channel_get_exit_state', dependencies: libssh_dep)
+      conf.set('WITH_SSH_CHANNEL_GET_EXIT_STATE', 1)
+    endif
   endif
 else
   libssh_dep = dependency('', required: false)
diff --git a/src/rpc/virnetlibsshsession.c b/src/rpc/virnetlibsshsession.c
index 6632e4a9ef..e496d3334e 100644
--- a/src/rpc/virnetlibsshsession.c
+++ b/src/rpc/virnetlibsshsession.c
@@ -170,6 +170,25 @@ virNetLibsshSessionOnceInit(void)
 }
 VIR_ONCE_GLOBAL_INIT(virNetLibsshSession);
 
+
+static int virNetLibsshChannelGetExitStatus(ssh_channel channel,
+                                            uint32_t *exit_status)
+{
+#ifdef WITH_SSH_CHANNEL_GET_EXIT_STATE
+    return ssh_channel_get_exit_state(channel, exit_status, NULL, NULL);
+#else
+    int rc;
+
+    rc = *exit_status = ssh_channel_get_exit_status(channel);
+
+    if (rc != SSH_OK)
+        return SSH_ERROR;
+
+    return *exit_status;
+#endif
+}
+
+
 static virNetLibsshAuthMethod *
 virNetLibsshSessionAuthMethodNew(virNetLibsshSession *sess)
 {
@@ -1179,12 +1198,16 @@ virNetLibsshChannelRead(virNetLibsshSession *sess,
     }
 
     if (ssh_channel_is_eof(sess->channel)) {
+        uint32_t exit_status;
+        int rc;
  eof:
-        if (ssh_channel_get_exit_status(sess->channel)) {
+
+        rc = virNetLibsshChannelGetExitStatus(sess->channel, &exit_status);
+        if (rc != SSH_OK || exit_status != 0) {
             virReportError(VIR_ERR_LIBSSH,
                            _("Remote command terminated with non-zero code: %1$d"),
-                           ssh_channel_get_exit_status(sess->channel));
-            sess->channelCommandReturnValue = ssh_channel_get_exit_status(sess->channel);
+                           exit_status);
+            sess->channelCommandReturnValue = exit_status;
             sess->state = VIR_NET_LIBSSH_STATE_ERROR_REMOTE;
             virObjectUnlock(sess);
             return -1;
@@ -1227,12 +1250,16 @@ virNetLibsshChannelWrite(virNetLibsshSession *sess,
     }
 
     if (ssh_channel_is_eof(sess->channel)) {
-        if (ssh_channel_get_exit_status(sess->channel)) {
+        uint32_t exit_status;
+        int rc;
+
+        rc = virNetLibsshChannelGetExitStatus(sess->channel, &exit_status);
+        if (rc != SSH_OK || exit_status != 0) {
             virReportError(VIR_ERR_LIBSSH,
                            _("Remote program terminated with non-zero code: %1$d"),
-                           ssh_channel_get_exit_status(sess->channel));
+                           exit_status);
             sess->state = VIR_NET_LIBSSH_STATE_ERROR_REMOTE;
-            sess->channelCommandReturnValue = ssh_channel_get_exit_status(sess->channel);
+            sess->channelCommandReturnValue = exit_status;
 
             ret = -1;
             goto cleanup;
-- 
2.44.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux