summaryrefslogtreecommitdiffstats
path: root/libssh/channels.c
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2005-10-26 16:59:16 +0000
committerAris Adamantiadis <aris@0xbadc0de.be>2005-10-26 16:59:16 +0000
commitc53b6b907ce7ccaf720777c18eed3eea46807bb7 (patch)
tree526f19bfe0a15e1711d42f8c9cdfc08c3aea3576 /libssh/channels.c
parentbef09f8848f60a2adfac7ef4a522c83fe184a854 (diff)
downloadlibssh-c53b6b907ce7ccaf720777c18eed3eea46807bb7.tar.gz
libssh-c53b6b907ce7ccaf720777c18eed3eea46807bb7.tar.xz
libssh-c53b6b907ce7ccaf720777c18eed3eea46807bb7.zip
resolved the infinite loop on exit (thanks giga for the hint).
I resolved a memory alloc problem into hmac_init (same kind that the one of md5_init). It's still saying there is a memory corruption. Since the memory corruption happens before it is found (in malloc()), I'll have to run valgrind to locate it. git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@46 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh/channels.c')
-rw-r--r--libssh/channels.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/libssh/channels.c b/libssh/channels.c
index a8f053c..83686af 100644
--- a/libssh/channels.c
+++ b/libssh/channels.c
@@ -25,6 +25,7 @@ MA 02111-1307, USA. */
#include <netdb.h>
#include <unistd.h>
#include <stdio.h>
+#include <errno.h>
#include "libssh/priv.h"
#include "libssh/ssh2.h"
@@ -665,20 +666,16 @@ int channel_read(CHANNEL *channel, BUFFER *buffer,int bytes,int is_stderr){
/* returns the number of bytes available, 0 if nothing is currently available, -1 if error */
int channel_poll(CHANNEL *channel, int is_stderr){
BUFFER *buffer;
- int r=0,w=0,err=0;
+ int r=0;
if(is_stderr)
buffer=channel->stderr_buffer;
else
buffer=channel->stdout_buffer;
while(buffer_get_rest_len(buffer)==0 && !channel->remote_eof){
- r=ssh_fd_poll(channel->session,&w,&err);
+ r=ssh_handle_packets(channel->session);
if(r<=0)
- return r; // error or no data available
- /* if an exception happened, it will be trapped by packet_read() */
- if(packet_read(channel->session)||packet_translate(channel->session))
- return -1;
- packet_parse(channel->session);
+ return r;
}
if(channel->remote_eof)
return 1;
@@ -722,7 +719,7 @@ static int channel_protocol_select(CHANNEL **rchans, CHANNEL **wchans, CHANNEL *
for(i=0;rchans[i];++i){
chan=rchans[i];
while(chan->open && chan->session->data_to_read){
- channel_poll(chan,0);
+ ssh_handle_packets(chan->session);
}
if( (chan->stdout_buffer && buffer_get_len(chan->stdout_buffer)>0) ||
(chan->stderr_buffer && buffer_get_len(chan->stderr_buffer)>0)){
@@ -770,6 +767,7 @@ int channel_select(CHANNEL **readchans, CHANNEL **writechans, CHANNEL **exceptch
CHANNEL **rchans, **wchans, **echans;
int fdmax=-1;
int i,fd;
+ int r;
/* don't allow NULL pointers */
if(!readchans)
readchans=&dummy;
@@ -832,7 +830,14 @@ int channel_select(CHANNEL **readchans, CHANNEL **writechans, CHANNEL **exceptch
}
}
/* here we go */
- select(fdmax,&rset,&wset,&eset,timeout);
+ r=select(fdmax,&rset,&wset,&eset,timeout);
+ /* leave if select was interrupted */
+ if(r==EINTR){
+ free(rchans);
+ free(wchans);
+ free(echans);
+ return SSH_EINTR;
+ }
for(i=0;readchans[i];++i){
if(FD_ISSET(readchans[i]->session->fd,&rset))
readchans[i]->session->data_to_read=1;