diff options
author | Aris Adamantiadis <aris@0xbadc0de.be> | 2009-02-03 18:07:26 +0000 |
---|---|---|
committer | Aris Adamantiadis <aris@0xbadc0de.be> | 2009-02-03 18:07:26 +0000 |
commit | ac3d66ac69278906bb09c4c751c6b9827d7ca17a (patch) | |
tree | 3b9ffa2dfa1f34ec1ccffd32d419aa18dcbc4063 | |
parent | 903e22cd1154270f10d765a754cb077df7b87e46 (diff) | |
download | libssh-ac3d66ac69278906bb09c4c751c6b9827d7ca17a.tar.gz libssh-ac3d66ac69278906bb09c4c751c6b9827d7ca17a.tar.xz libssh-ac3d66ac69278906bb09c4c751c6b9827d7ca17a.zip |
channel_get_exit_status()
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@228 7dcaeef0-15fb-0310-b436-a5af3365683c
-rw-r--r-- | include/libssh/libssh.h | 1 | ||||
-rw-r--r-- | include/libssh/priv.h | 1 | ||||
-rw-r--r-- | libssh/channels.c | 12 | ||||
-rw-r--r-- | sample.c | 5 |
4 files changed, 18 insertions, 1 deletions
diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h index 6e242114..03265cb3 100644 --- a/include/libssh/libssh.h +++ b/include/libssh/libssh.h @@ -253,6 +253,7 @@ int channel_is_closed(CHANNEL *channel); int channel_select(CHANNEL **readchans, CHANNEL **writechans, CHANNEL **exceptchans, struct timeval * timeout); SSH_SESSION *channel_get_session(CHANNEL *channel); +int channel_get_exit_status(CHANNEL *channel); /* in options.c */ /** diff --git a/include/libssh/priv.h b/include/libssh/priv.h index 23981b74..67cd6bf1 100644 --- a/include/libssh/priv.h +++ b/include/libssh/priv.h @@ -284,6 +284,7 @@ struct channel_struct { void *userarg; int version; int blocking; + int exit_status; }; struct agent_struct { diff --git a/libssh/channels.c b/libssh/channels.c index 33c86407..26409b85 100644 --- a/libssh/channels.c +++ b/libssh/channels.c @@ -57,6 +57,7 @@ CHANNEL *channel_new(SSH_SESSION *session){ channel->prev=session->channels->prev; channel->next->prev=channel; channel->prev->next=channel; + channel->exit_status=-1; return channel; } @@ -299,6 +300,7 @@ static void channel_rcv_request(SSH_SESSION *session){ ssh_log(session,SSH_LOG_PACKET,"received exit-status"); buffer_get_u32(session->in_buffer,&status); status=ntohl(status); + channel->exit_status=status; /* TODO do something with status, we might need it */ free(request_s); free(request); @@ -955,6 +957,16 @@ SSH_SESSION *channel_get_session(CHANNEL *channel){ return channel->session; } +/** \brief get the exit status of the channel (error code from the executed instruction). + * \param channel channel + * \return -1 no exit status was returned. + * \return other values : exit status + */ + +int channel_get_exit_status(CHANNEL *channel){ + return channel->exit_status; +} + /* This function acts as a meta select. */ /* first, channels are analyzed to seek potential can-write or can-read ones. */ /* Then, if no channel has been elected, it goes in a loop with the posix select(2) */ @@ -180,7 +180,9 @@ void select_loop(SSH_SESSION *session,CHANNEL *channel){ return; } if(lus==0){ - ssh_say(1,"EOF received\n"); + ssh_log(session,SSH_LOG_RARE,"EOF received\n"); + ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",channel_get_exit_status(channel)); + channel_free(channel); channel=channels[0]=NULL; } else @@ -194,6 +196,7 @@ void select_loop(SSH_SESSION *session,CHANNEL *channel){ } if(lus==0){ ssh_log(session,SSH_LOG_RARE,"EOF received\n"); + ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",channel_get_exit_status(channel)); channel_free(channel); channel=channels[0]=NULL; } else |