changeset 253:84925eceeb13

* rename infd/outfd to writefd/readfd, to avoid confusion
author Matt Johnston <matt@ucc.asn.au>
date Thu, 20 Oct 2005 16:53:12 +0000
parents b02e8eef3c3a
children 8b62b0ea8f3b
files channel.h cli-chansession.c cli-tcpfwd.c common-channel.c svr-chansession.c svr-tcpfwd.c
diffstat 6 files changed, 83 insertions(+), 87 deletions(-) [+]
line wrap: on
line diff
--- a/channel.h	Wed Sep 21 15:58:19 2005 +0000
+++ b/channel.h	Thu Oct 20 16:53:12 2005 +0000
@@ -65,9 +65,9 @@
 	unsigned int recvdonelen;
 	unsigned int recvmaxpacket, transmaxpacket;
 	void* typedata; /* a pointer to type specific data */
-	int infd; /* data to send over the wire */
-	int outfd; /* data for consumption, what was in writebuf */
-	int errfd; /* used like infd or errfd, depending if it's client or server.
+	int writefd; /* read from wire, written to insecure side */
+	int readfd; /* read from insecure size, written to wire */
+	int errfd; /* used like writefd or readfd, depending if it's client or server.
 				  Doesn't exactly belong here, but is cleaner here */
 	circbuffer *writebuf; /* data from the wire, for local consumption */
 	circbuffer *extrabuf; /* extended-data for the program - used like writebuf
--- a/cli-chansession.c	Wed Sep 21 15:58:19 2005 +0000
+++ b/cli-chansession.c	Thu Oct 20 16:53:12 2005 +0000
@@ -340,10 +340,10 @@
 static int cli_initchansess(struct Channel *channel) {
 
 
-	channel->infd = STDOUT_FILENO;
+	channel->writefd = STDOUT_FILENO;
 	setnonblocking(STDOUT_FILENO);
 
-	channel->outfd = STDIN_FILENO;
+	channel->readfd = STDIN_FILENO;
 	setnonblocking(STDIN_FILENO);
 
 	channel->errfd = STDERR_FILENO;
--- a/cli-tcpfwd.c	Wed Sep 21 15:58:19 2005 +0000
+++ b/cli-tcpfwd.c	Thu Oct 20 16:53:12 2005 +0000
@@ -186,11 +186,9 @@
 
 	ses.maxfd = MAX(ses.maxfd, sock);
 
-	/* Note that infd is actually the "outgoing" direction on the
-	 * tcp connection, vice versa for outfd.
-	 * We don't set outfd, that will get set after the connection's
+	/* We don't set readfd, that will get set after the connection's
 	 * progress succeeds */
-	channel->infd = sock;
+	channel->writefd = sock;
 	channel->initconn = 1;
 	
 	err = SSH_OPEN_IN_PROGRESS;
--- a/common-channel.c	Wed Sep 21 15:58:19 2005 +0000
+++ b/common-channel.c	Thu Oct 20 16:53:12 2005 +0000
@@ -52,8 +52,8 @@
 static void checkinitdone(struct Channel *channel);
 static void checkclose(struct Channel *channel);
 
-static void closeinfd(struct Channel * channel);
-static void closeoutfd(struct Channel * channel, int fd);
+static void closewritefd(struct Channel * channel);
+static void closereadfd(struct Channel * channel, int fd);
 static void closechanfd(struct Channel *channel, int fd, int how);
 
 #define FD_UNINIT (-2)
@@ -143,8 +143,8 @@
 	newchan->transmaxpacket = transmaxpacket;
 	
 	newchan->typedata = NULL;
-	newchan->infd = FD_UNINIT;
-	newchan->outfd = FD_UNINIT;
+	newchan->writefd = FD_UNINIT;
+	newchan->readfd = FD_UNINIT;
 	newchan->errfd = FD_CLOSED; /* this isn't always set to start with */
 	newchan->initconn = 0;
 	newchan->await_open = 0;
@@ -177,7 +177,7 @@
 }
 
 /* Iterate through the channels, performing IO if available */
-void channelio(fd_set *readfd, fd_set *writefd) {
+void channelio(fd_set *readfds, fd_set *writefds) {
 
 	struct Channel *channel;
 	unsigned int i;
@@ -192,21 +192,21 @@
 			continue;
 		}
 
-		/* read from program/pipe stdout */
-		if (channel->outfd >= 0 && FD_ISSET(channel->outfd, readfd)) {
+		/* read data and send it over the wire */
+		if (channel->readfd >= 0 && FD_ISSET(channel->readfd, readfds)) {
 			send_msg_channel_data(channel, 0, 0);
 		}
 
-		/* read from program/pipe stderr */
+		/* read stderr data and send it over the wire */
 		if (channel->extrabuf == NULL &&
-				channel->errfd >= 0 && FD_ISSET(channel->errfd, readfd)) {
+				channel->errfd >= 0 && FD_ISSET(channel->errfd, readfds)) {
 				send_msg_channel_data(channel, 1, SSH_EXTENDED_DATA_STDERR);
 		}
 
-		/* if we can read from the infd, it might be closed, so we try to
+		/* if we can read from the writefd, it might be closed, so we try to
 		 * see if it has errors */
-		if (channel->infd >= 0 && channel->infd != channel->outfd
-				&& FD_ISSET(channel->infd, readfd)) {
+		if (channel->writefd >= 0 && channel->writefd != channel->readfd
+				&& FD_ISSET(channel->writefd, readfds)) {
 			if (channel->initconn) {
 				/* Handling for "in progress" connection - this is needed
 				 * to avoid spinning 100% CPU when we connect to a server
@@ -215,25 +215,25 @@
 				continue; /* Important not to use the channel after 
 							 checkinitdone(), as it may be NULL */
 			}
-			ret = write(channel->infd, NULL, 0); /* Fake write */
+			ret = write(channel->writefd, NULL, 0); /* Fake write */
 			if (ret < 0 && errno != EINTR && errno != EAGAIN) {
-				closeinfd(channel);
+				closewritefd(channel);
 			}
 		}
 
 		/* write to program/pipe stdin */
-		if (channel->infd >= 0 && FD_ISSET(channel->infd, writefd)) {
+		if (channel->writefd >= 0 && FD_ISSET(channel->writefd, writefds)) {
 			if (channel->initconn) {
 				checkinitdone(channel);
 				continue; /* Important not to use the channel after
 							 checkinitdone(), as it may be NULL */
 			}
-			writechannel(channel, channel->infd, channel->writebuf);
+			writechannel(channel, channel->writefd, channel->writebuf);
 		}
 		
 		/* stderr for client mode */
 		if (channel->extrabuf != NULL 
-				&& channel->errfd >= 0 && FD_ISSET(channel->errfd, writefd)) {
+				&& channel->errfd >= 0 && FD_ISSET(channel->errfd, writefds)) {
 			writechannel(channel, channel->errfd, channel->extrabuf);
 		}
 	
@@ -244,7 +244,7 @@
 
 	/* Listeners such as TCP, X11, agent-auth */
 #ifdef USING_LISTENERS
-	handle_listeners(readfd);
+	handle_listeners(readfds);
 #endif
 }
 
@@ -252,8 +252,8 @@
 /* do all the EOF/close type stuff checking for a channel */
 static void checkclose(struct Channel *channel) {
 
-	TRACE(("checkclose: infd %d, outfd %d, errfd %d, sentclosed %d, recvclosed %d",
-				channel->infd, channel->outfd,
+	TRACE(("checkclose: writefd %d, readfd %d, errfd %d, sentclosed %d, recvclosed %d",
+				channel->writefd, channel->readfd,
 				channel->errfd, channel->sentclosed, channel->recvclosed))
 	TRACE(("writebuf %d extrabuf %s extrabuf %d",
 				cbuf_getused(channel->writebuf),
@@ -266,18 +266,18 @@
 		 * if the shell has exited etc */
 		if (channel->type->checkclose) {
 			if (channel->type->checkclose(channel)) {
-				closeinfd(channel);
+				closewritefd(channel);
 			}
 		}
 
 		if (!channel->senteof
-			&& channel->outfd == FD_CLOSED 
+			&& channel->readfd == FD_CLOSED 
 			&& (channel->extrabuf != NULL || channel->errfd == FD_CLOSED)) {
 			send_msg_channel_eof(channel);
 		}
 
-		if (channel->infd == FD_CLOSED
-			&& channel->outfd == FD_CLOSED
+		if (channel->writefd == FD_CLOSED
+			&& channel->readfd == FD_CLOSED
 			&& (channel->extrabuf != NULL || channel->errfd == FD_CLOSED)) {
 			send_msg_channel_close(channel);
 		}
@@ -314,17 +314,17 @@
 
 	TRACE(("enter checkinitdone"))
 
-	if (getsockopt(channel->infd, SOL_SOCKET, SO_ERROR, &val, &vallen)
+	if (getsockopt(channel->writefd, SOL_SOCKET, SO_ERROR, &val, &vallen)
 			|| val != 0) {
 		send_msg_channel_open_failure(channel->remotechan,
 				SSH_OPEN_CONNECT_FAILED, "", "");
-		close(channel->infd);
+		close(channel->writefd);
 		deletechannel(channel);
 		TRACE(("leave checkinitdone: fail"))
 	} else {
 		send_msg_channel_open_confirmation(channel, channel->recvwindow,
 				channel->recvmaxpacket);
-		channel->outfd = channel->infd;
+		channel->readfd = channel->writefd;
 		channel->initconn = 0;
 		TRACE(("leave checkinitdone: success"))
 	}
@@ -386,7 +386,7 @@
 		if (len < 0 && errno != EINTR) {
 			/* no more to write - we close it even if the fd was stderr, since
 			 * that's a nasty failure too */
-			closeinfd(channel);
+			closewritefd(channel);
 		}
 		TRACE(("leave writechannel: len <= 0"))
 		return;
@@ -395,9 +395,9 @@
 	cbuf_incrread(cbuf, len);
 	channel->recvdonelen += len;
 
-	if (fd == channel->infd && len == maxlen && channel->recveof) { 
+	if (fd == channel->writefd && len == maxlen && channel->recveof) { 
 		/* Check if we're closing up */
-		closeinfd(channel);
+		closewritefd(channel);
 		TRACE(("leave writechannel: recveof set"))
 		return;
 	}
@@ -421,7 +421,7 @@
 
 /* Set the file descriptors for the main select in session.c
  * This avoid channels which don't have any window available, are closed, etc*/
-void setchannelfds(fd_set *readfd, fd_set *writefd) {
+void setchannelfds(fd_set *readfds, fd_set *writefds) {
 	
 	unsigned int i;
 	struct Channel * channel;
@@ -436,41 +436,41 @@
 		/* Stuff to put over the wire */
 		if (channel->transwindow > 0) {
 
-			if (channel->outfd >= 0) {
-				FD_SET(channel->outfd, readfd);
+			if (channel->readfd >= 0) {
+				FD_SET(channel->readfd, readfds);
 			}
 			
 			if (channel->extrabuf == NULL && channel->errfd >= 0) {
-					FD_SET(channel->errfd, readfd);
+					FD_SET(channel->errfd, readfds);
 			}
 		}
 
 		/* For checking FD status (ie closure etc) - we don't actually
-		 * read data from infd */
-		TRACE(("infd = %d, outfd %d, errfd %d, bufused %d", 
-					channel->infd, channel->outfd,
+		 * read data from writefd */
+		TRACE(("writefd = %d, readfd %d, errfd %d, bufused %d", 
+					channel->writefd, channel->readfd,
 					channel->errfd,
 					cbuf_getused(channel->writebuf) ))
-		if (channel->infd >= 0 && channel->infd != channel->outfd) {
-			FD_SET(channel->infd, readfd);
+		if (channel->writefd >= 0 && channel->writefd != channel->readfd) {
+			FD_SET(channel->writefd, readfds);
 		}
 
 		/* Stuff from the wire, to local program/shell/user etc */
-		if ((channel->infd >= 0 && cbuf_getused(channel->writebuf) > 0 )
+		if ((channel->writefd >= 0 && cbuf_getused(channel->writebuf) > 0 )
 				|| channel->initconn) {
 
-				FD_SET(channel->infd, writefd);
+				FD_SET(channel->writefd, writefds);
 		}
 
 		if (channel->extrabuf != NULL && channel->errfd >= 0 
 				&& cbuf_getused(channel->extrabuf) > 0 ) {
-				FD_SET(channel->errfd, writefd);
+				FD_SET(channel->errfd, writefds);
 		}
 
 	} /* foreach channel */
 
 #ifdef USING_LISTENERS
-	set_listener_fds(readfd);
+	set_listener_fds(readfds);
 #endif
 
 }
@@ -493,7 +493,7 @@
 	if (cbuf_getused(channel->writebuf) == 0
 			&& (channel->extrabuf == NULL 
 					|| cbuf_getused(channel->extrabuf) == 0)) {
-		closeinfd(channel);
+		closewritefd(channel);
 	}
 
 	TRACE(("leave recv_msg_channel_eof"))
@@ -541,8 +541,8 @@
 
 	/* close the FDs in case they haven't been done
 	 * yet (ie they were shutdown etc */
-	close(channel->infd);
-	close(channel->outfd);
+	close(channel->writefd);
+	close(channel->readfd);
 	close(channel->errfd);
 
 	channel->typedata = NULL;
@@ -609,7 +609,7 @@
 	if (isextended) {
 		fd = channel->errfd;
 	} else {
-		fd = channel->outfd;
+		fd = channel->readfd;
 	}
 	dropbear_assert(fd >= 0);
 
@@ -631,7 +631,7 @@
 	if (len <= 0) {
 		/* on error/eof, send eof */
 		if (len == 0 || errno != EINTR) {
-			closeoutfd(channel, fd);
+			closereadfd(channel, fd);
 		}
 		buf_free(buf);
 		buf = NULL;
@@ -669,7 +669,7 @@
 		dropbear_exit("Unknown channel");
 	}
 
-	common_recv_msg_channel_data(channel, channel->infd, channel->writebuf);
+	common_recv_msg_channel_data(channel, channel->writefd, channel->writebuf);
 }
 
 /* Shared for data and stderr data - when we receive data, put it in a buffer
@@ -689,7 +689,7 @@
 	}
 
  	if (fd < 0) {
-		dropbear_exit("received data with bad infd");
+		dropbear_exit("received data with bad writefd");
 	}
 
 	datalen = buf_getint(ses.payload);
@@ -931,7 +931,7 @@
 	/* set fd non-blocking */
 	setnonblocking(fd);
 
-	chan->infd = chan->outfd = fd;
+	chan->writefd = chan->readfd = fd;
 	ses.maxfd = MAX(ses.maxfd, fd);
 
 	chan->await_open = 1;
@@ -1008,21 +1008,21 @@
 #endif /* USING_LISTENERS */
 
 /* close a stdout/stderr fd */
-static void closeoutfd(struct Channel * channel, int fd) {
+static void closereadfd(struct Channel * channel, int fd) {
 
-	/* don't close it if it is the same as infd,
-	 * unless infd is already set -1 */
-	TRACE(("enter closeoutfd"))
+	/* don't close it if it is the same as writefd,
+	 * unless writefd is already set -1 */
+	TRACE(("enter closereadfd"))
 	closechanfd(channel, fd, 0);
-	TRACE(("leave closeoutfd"))
+	TRACE(("leave closereadfd"))
 }
 
 /* close a stdin fd */
-static void closeinfd(struct Channel * channel) {
+static void closewritefd(struct Channel * channel) {
 
-	TRACE(("enter closeinfd"))
-	closechanfd(channel, channel->infd, 1);
-	TRACE(("leave closeinfd"))
+	TRACE(("enter closewritefd"))
+	closechanfd(channel, channel->writefd, 1);
+	TRACE(("leave closewritefd"))
 }
 
 /* close a fd, how is 0 for stdout/stderr, 1 for stdin */
@@ -1044,15 +1044,15 @@
 		closein = closeout = 1;
 	}
 
-	if (closeout && fd == channel->outfd) {
-		channel->outfd = FD_CLOSED;
+	if (closeout && fd == channel->readfd) {
+		channel->readfd = FD_CLOSED;
 	}
 	if (closeout && (channel->extrabuf == NULL) && (fd == channel->errfd)) {
 		channel->errfd = FD_CLOSED;
 	}
 
-	if (closein && fd == channel->infd) {
-		channel->infd = FD_CLOSED;
+	if (closein && fd == channel->writefd) {
+		channel->writefd = FD_CLOSED;
 	}
 	if (closein && (channel->extrabuf != NULL) && (fd == channel->errfd)) {
 		channel->errfd = FD_CLOSED;
@@ -1060,8 +1060,8 @@
 
 	/* if we called shutdown on it and all references are gone, then we 
 	 * need to close() it to stop it lingering */
-	if (channel->type->sepfds && channel->outfd == FD_CLOSED 
-		&& channel->infd == FD_CLOSED && channel->errfd == FD_CLOSED) {
+	if (channel->type->sepfds && channel->readfd == FD_CLOSED 
+		&& channel->writefd == FD_CLOSED && channel->errfd == FD_CLOSED) {
 		close(fd);
 	}
 }
--- a/svr-chansession.c	Wed Sep 21 15:58:19 2005 +0000
+++ b/svr-chansession.c	Thu Oct 20 16:53:12 2005 +0000
@@ -673,15 +673,15 @@
 		close(infds[FDIN]);
 		close(outfds[FDOUT]);
 		close(errfds[FDOUT]);
-		channel->infd = infds[FDOUT];
-		channel->outfd = outfds[FDIN];
+		channel->writefd = infds[FDOUT];
+		channel->readfd = outfds[FDIN];
 		channel->errfd = errfds[FDIN];
-		ses.maxfd = MAX(ses.maxfd, channel->infd);
-		ses.maxfd = MAX(ses.maxfd, channel->outfd);
+		ses.maxfd = MAX(ses.maxfd, channel->writefd);
+		ses.maxfd = MAX(ses.maxfd, channel->readfd);
 		ses.maxfd = MAX(ses.maxfd, channel->errfd);
 
-		setnonblocking(channel->outfd);
-		setnonblocking(channel->infd);
+		setnonblocking(channel->readfd);
+		setnonblocking(channel->writefd);
 		setnonblocking(channel->errfd);
 
 	}
@@ -784,8 +784,8 @@
 		addchildpid(chansess, pid);
 
 		close(chansess->slave);
-		channel->infd = chansess->master;
-		channel->outfd = chansess->master;
+		channel->writefd = chansess->master;
+		channel->readfd = chansess->master;
 		/* don't need to set stderr here */
 		ses.maxfd = MAX(ses.maxfd, chansess->master);
 
--- a/svr-tcpfwd.c	Wed Sep 21 15:58:19 2005 +0000
+++ b/svr-tcpfwd.c	Thu Oct 20 16:53:12 2005 +0000
@@ -272,11 +272,9 @@
 
 	ses.maxfd = MAX(ses.maxfd, sock);
 
-	/* Note that infd is actually the "outgoing" direction on the
-	 * tcp connection, vice versa for outfd.
-	 * We don't set outfd, that will get set after the connection's
+	 /* We don't set readfd, that will get set after the connection's
 	 * progress succeeds */
-	channel->infd = sock;
+	channel->writefd = sock;
 	channel->initconn = 1;
 	
 	err = SSH_OPEN_IN_PROGRESS;