channels: Implement better ssh_channel_get_exit_state() variant

This way we will get errors as return code else we don't know if the
function failed (SSH_ERROR) or the exit_status is -1 which would
correspond to SSH_ERROR.

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
Andreas Schneider
2022-09-08 14:38:18 +02:00
parent d40a6448a4
commit 04d86aeeae
4 changed files with 111 additions and 17 deletions

View File

@@ -462,7 +462,11 @@ LIBSSH_API int ssh_channel_close(ssh_channel channel);
} \
} while (0)
LIBSSH_API void ssh_channel_free(ssh_channel channel);
LIBSSH_API int ssh_channel_get_exit_status(ssh_channel channel);
LIBSSH_API int ssh_channel_get_exit_state(ssh_channel channel,
uint32_t *pexit_code,
char **pexit_signal,
int *pcore_dumped);
SSH_DEPRECATED LIBSSH_API int ssh_channel_get_exit_status(ssh_channel channel);
LIBSSH_API ssh_session ssh_channel_get_session(ssh_channel channel);
LIBSSH_API int ssh_channel_is_closed(ssh_channel channel);
LIBSSH_API int ssh_channel_is_eof(ssh_channel channel);

View File

@@ -498,8 +498,22 @@ public:
return_throwable;
}
int getExitStatus(){
return ssh_channel_get_exit_status(channel);
/*
* @deprecated Please use getExitState()
*/
int getExitStatus() {
uint32_t exit_status = (uint32_t)-1;
ssh_channel_get_exit_state(channel, &exit_status, NULL, NULL);
return exit_status;
}
void_throwable getExitState(uint32_t & pexit_code,
char **pexit_signal,
int & pcore_dumped) {
ssh_throw(ssh_channel_get_exit_state(channel,
&pexit_code,
pexit_signal,
&pcore_dumped));
return_throwable;
}
Session &getSession(){
return *session;