virnetlibsshsession: Reflect API change in libssh

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>
This commit is contained in:
Michal Privoznik 2024-08-12 12:41:13 +02:00
parent c195be19ab
commit 1b797e6421
2 changed files with 36 additions and 6 deletions

View 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)

View 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;