[PATCH] rpc: adapt for deprecation of ssh_channel_get_exit_status

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

 



This method is deprecated in libssh 0.11.0 in favour of the more
flexible ssh_channel_get_exit_state. Rewrite our code to call the
latter, and provide a compat shim that only fills out exit status.

Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 src/rpc/virnetlibsshsession.c | 50 +++++++++++++++++++++++++++++------
 1 file changed, 42 insertions(+), 8 deletions(-)

diff --git a/src/rpc/virnetlibsshsession.c b/src/rpc/virnetlibsshsession.c
index 6632e4a9ef..faf7307725 100644
--- a/src/rpc/virnetlibsshsession.c
+++ b/src/rpc/virnetlibsshsession.c
@@ -48,6 +48,22 @@ VIR_LOG_INIT("rpc.netlibsshsession");
  */
 #define TRACE_LIBSSH  0
 
+#if LIBSSH_VERSION_INT < SSH_VERSION_INT(0, 11, 0)
+static int ssh_channel_get_exit_state(ssh_channel channel,
+                                      uint32_t *pexit_code,
+                                      char **pexit_signal,
+                                      int *pcore_dumped)
+{
+    if (pexit_code)
+        *pexit_code = ssh_channel_get_exit_status(channel);
+    if (pexit_signal)
+        *pexit_signal = 0;
+    if (pcore_dumped)
+        *pcore_dumped = 0;
+    return 0;
+}
+#endif
+
 typedef enum {
     VIR_NET_LIBSSH_STATE_NEW,
     VIR_NET_LIBSSH_STATE_HANDSHAKE_COMPLETE,
@@ -1179,12 +1195,21 @@ virNetLibsshChannelRead(virNetLibsshSession *sess,
     }
 
     if (ssh_channel_is_eof(sess->channel)) {
+        uint32_t status;
  eof:
-        if (ssh_channel_get_exit_status(sess->channel)) {
+        if (ssh_channel_get_exit_state(sess->channel, &status, NULL, NULL) != 0) {
+            virReportError(VIR_ERR_LIBSSH, "%s",
+                           _("Unable to fetch remote command exit status"));
+            sess->channelCommandReturnValue = 0;
+            sess->state = VIR_NET_LIBSSH_STATE_ERROR_REMOTE;
+            virObjectUnlock(sess);
+            return -1;
+        }
+        if (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);
+                           status);
+            sess->channelCommandReturnValue = status;
             sess->state = VIR_NET_LIBSSH_STATE_ERROR_REMOTE;
             virObjectUnlock(sess);
             return -1;
@@ -1227,15 +1252,24 @@ virNetLibsshChannelWrite(virNetLibsshSession *sess,
     }
 
     if (ssh_channel_is_eof(sess->channel)) {
-        if (ssh_channel_get_exit_status(sess->channel)) {
+        uint32_t status;
+        if (ssh_channel_get_exit_state(sess->channel, &status, NULL, NULL) != 0) {
+            virReportError(VIR_ERR_LIBSSH, "%s",
+                           _("Unable to fetch remote command exit status"));
+            sess->channelCommandReturnValue = 0;
+            sess->state = VIR_NET_LIBSSH_STATE_ERROR_REMOTE;
+            ret = -1;
+            goto cleanup;
+        }
+        if (status != 0) {
             virReportError(VIR_ERR_LIBSSH,
-                           _("Remote program terminated with non-zero code: %1$d"),
-                           ssh_channel_get_exit_status(sess->channel));
+                           _("Remote command terminated with non-zero code: %1$d"),
+                           status);
+            sess->channelCommandReturnValue = status;
             sess->state = VIR_NET_LIBSSH_STATE_ERROR_REMOTE;
-            sess->channelCommandReturnValue = ssh_channel_get_exit_status(sess->channel);
-
             ret = -1;
             goto cleanup;
+
         }
 
         sess->state = VIR_NET_LIBSSH_STATE_CLOSED;
-- 
2.45.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