]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virnetlibsshsession: Reflect API change in libssh
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 12 Aug 2024 10:41:13 +0000 (12:41 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 12 Aug 2024 13:47:48 +0000 (15:47 +0200)
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@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
meson.build
src/rpc/virnetlibsshsession.c

index 06d88ad1f35b6fc15815c46b24514b4d2068c4cc..f31485c395cac1a6199b2476e8cebd2a7cedb131 100644 (file)
@@ -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)
index 6632e4a9ef3107e015fff1cf6d29ba7e3ef5dcc3..e496d3334ef5d500b3a9ac7ea80cd5ccfdc93b5f 100644 (file)
@@ -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;