summaryrefslogtreecommitdiff
path: root/serverloop.c
diff options
context:
space:
mode:
authorBen Lindstrom <mouring@eviladmin.org>2001-07-18 16:01:46 +0000
committerBen Lindstrom <mouring@eviladmin.org>2001-07-18 16:01:46 +0000
commit16d29d57e85fd84c9dc06fd803d1abeceadff14c (patch)
tree4ab48758471d33120e01e3877e2083ac0213b0c5 /serverloop.c
parenta3d5a4c2dbc4fa92333b76882b00e3811177eff6 (diff)
- markus@cvs.openbsd.org 2001/07/17 21:04:58
[channels.c channels.h clientloop.c nchan.c serverloop.c] keep track of both maxfd and the size of the malloc'ed fdsets. update maxfd if maxfd gets closed.
Diffstat (limited to 'serverloop.c')
-rw-r--r--serverloop.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/serverloop.c b/serverloop.c
index f826c6cb2..d9791274c 100644
--- a/serverloop.c
+++ b/serverloop.c
@@ -35,7 +35,7 @@
35 */ 35 */
36 36
37#include "includes.h" 37#include "includes.h"
38RCSID("$OpenBSD: serverloop.c,v 1.75 2001/07/15 16:17:08 markus Exp $"); 38RCSID("$OpenBSD: serverloop.c,v 1.76 2001/07/17 21:04:58 markus Exp $");
39 39
40#include "xmalloc.h" 40#include "xmalloc.h"
41#include "packet.h" 41#include "packet.h"
@@ -169,7 +169,7 @@ make_packets_from_stdout_data(void)
169 */ 169 */
170static void 170static void
171wait_until_can_do_something(fd_set **readsetp, fd_set **writesetp, int *maxfdp, 171wait_until_can_do_something(fd_set **readsetp, fd_set **writesetp, int *maxfdp,
172 u_int max_time_milliseconds) 172 int *nallocp, u_int max_time_milliseconds)
173{ 173{
174 struct timeval tv, *tvp; 174 struct timeval tv, *tvp;
175 int ret; 175 int ret;
@@ -193,7 +193,7 @@ wait_until_can_do_something(fd_set **readsetp, fd_set **writesetp, int *maxfdp,
193retry_select: 193retry_select:
194 194
195 /* Allocate and update select() masks for channel descriptors. */ 195 /* Allocate and update select() masks for channel descriptors. */
196 channel_prepare_select(readsetp, writesetp, maxfdp, 0); 196 channel_prepare_select(readsetp, writesetp, maxfdp, nallocp, 0);
197 197
198 if (compat20) { 198 if (compat20) {
199 /* wrong: bad condition XXX */ 199 /* wrong: bad condition XXX */
@@ -435,7 +435,7 @@ void
435server_loop(pid_t pid, int fdin_arg, int fdout_arg, int fderr_arg) 435server_loop(pid_t pid, int fdin_arg, int fdout_arg, int fderr_arg)
436{ 436{
437 fd_set *readset = NULL, *writeset = NULL; 437 fd_set *readset = NULL, *writeset = NULL;
438 int max_fd; 438 int max_fd = 0, nalloc = 0;
439 int wait_status; /* Status returned by wait(). */ 439 int wait_status; /* Status returned by wait(). */
440 pid_t wait_pid; /* pid returned by wait(). */ 440 pid_t wait_pid; /* pid returned by wait(). */
441 int waiting_termination = 0; /* Have displayed waiting close message. */ 441 int waiting_termination = 0; /* Have displayed waiting close message. */
@@ -476,12 +476,14 @@ server_loop(pid_t pid, int fdin_arg, int fdout_arg, int fderr_arg)
476 else 476 else
477 buffer_high = 64 * 1024; 477 buffer_high = 64 * 1024;
478 478
479#if 0
479 /* Initialize max_fd to the maximum of the known file descriptors. */ 480 /* Initialize max_fd to the maximum of the known file descriptors. */
480 max_fd = MAX(fdin, fdout); 481 max_fd = MAX(connection_in, connection_out);
482 max_fd = MAX(max_fd, fdin);
483 max_fd = MAX(max_fd, fdout);
481 if (fderr != -1) 484 if (fderr != -1)
482 max_fd = MAX(max_fd, fderr); 485 max_fd = MAX(max_fd, fderr);
483 max_fd = MAX(max_fd, connection_in); 486#endif
484 max_fd = MAX(max_fd, connection_out);
485 487
486 /* Initialize Initialize buffers. */ 488 /* Initialize Initialize buffers. */
487 buffer_init(&stdin_buffer); 489 buffer_init(&stdin_buffer);
@@ -567,9 +569,14 @@ server_loop(pid_t pid, int fdin_arg, int fdout_arg, int fderr_arg)
567 xfree(cp); 569 xfree(cp);
568 } 570 }
569 } 571 }
572 max_fd = MAX(connection_in, connection_out);
573 max_fd = MAX(max_fd, fdin);
574 max_fd = MAX(max_fd, fdout);
575 max_fd = MAX(max_fd, fderr);
576
570 /* Sleep in select() until we can do something. */ 577 /* Sleep in select() until we can do something. */
571 wait_until_can_do_something(&readset, &writeset, &max_fd, 578 wait_until_can_do_something(&readset, &writeset, &max_fd,
572 max_time_milliseconds); 579 &nalloc, max_time_milliseconds);
573 580
574 /* Process any channel events. */ 581 /* Process any channel events. */
575 channel_after_select(readset, writeset); 582 channel_after_select(readset, writeset);
@@ -662,7 +669,7 @@ void
662server_loop2(Authctxt *authctxt) 669server_loop2(Authctxt *authctxt)
663{ 670{
664 fd_set *readset = NULL, *writeset = NULL; 671 fd_set *readset = NULL, *writeset = NULL;
665 int rekeying = 0, max_fd, status; 672 int rekeying = 0, max_fd, status, nalloc = 0;
666 pid_t pid; 673 pid_t pid;
667 674
668 debug("Entering interactive session for SSH2."); 675 debug("Entering interactive session for SSH2.");
@@ -685,7 +692,7 @@ server_loop2(Authctxt *authctxt)
685 if (!rekeying && packet_not_very_much_data_to_write()) 692 if (!rekeying && packet_not_very_much_data_to_write())
686 channel_output_poll(); 693 channel_output_poll();
687 wait_until_can_do_something(&readset, &writeset, &max_fd, 694 wait_until_can_do_something(&readset, &writeset, &max_fd,
688 rekeying); 695 &nalloc, 0);
689 if (child_terminated) { 696 if (child_terminated) {
690 while ((pid = waitpid(-1, &status, WNOHANG)) > 0) 697 while ((pid = waitpid(-1, &status, WNOHANG)) > 0)
691 session_close_by_pid(pid, status); 698 session_close_by_pid(pid, status);