diff options
Diffstat (limited to 'channels.c')
-rw-r--r-- | channels.c | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/channels.c b/channels.c index 8aaf8c6e6..6aafc3dc3 100644 --- a/channels.c +++ b/channels.c | |||
@@ -40,7 +40,7 @@ | |||
40 | */ | 40 | */ |
41 | 41 | ||
42 | #include "includes.h" | 42 | #include "includes.h" |
43 | RCSID("$OpenBSD: channels.c,v 1.83 2001/01/24 21:03:50 stevesk Exp $"); | 43 | RCSID("$OpenBSD: channels.c,v 1.84 2001/01/29 16:55:36 markus Exp $"); |
44 | 44 | ||
45 | #include <openssl/rsa.h> | 45 | #include <openssl/rsa.h> |
46 | #include <openssl/dsa.h> | 46 | #include <openssl/dsa.h> |
@@ -84,7 +84,7 @@ static int channels_alloc = 0; | |||
84 | * Maximum file descriptor value used in any of the channels. This is | 84 | * Maximum file descriptor value used in any of the channels. This is |
85 | * updated in channel_allocate. | 85 | * updated in channel_allocate. |
86 | */ | 86 | */ |
87 | static int channel_max_fd_value = 0; | 87 | static int channel_max_fd = 0; |
88 | 88 | ||
89 | /* Name and directory of socket for authentication agent forwarding. */ | 89 | /* Name and directory of socket for authentication agent forwarding. */ |
90 | static char *channel_forwarded_auth_socket_name = NULL; | 90 | static char *channel_forwarded_auth_socket_name = NULL; |
@@ -181,12 +181,10 @@ channel_register_fds(Channel *c, int rfd, int wfd, int efd, | |||
181 | int extusage, int nonblock) | 181 | int extusage, int nonblock) |
182 | { | 182 | { |
183 | /* Update the maximum file descriptor value. */ | 183 | /* Update the maximum file descriptor value. */ |
184 | if (rfd > channel_max_fd_value) | 184 | channel_max_fd = MAX(channel_max_fd, rfd); |
185 | channel_max_fd_value = rfd; | 185 | channel_max_fd = MAX(channel_max_fd, wfd); |
186 | if (wfd > channel_max_fd_value) | 186 | channel_max_fd = MAX(channel_max_fd, efd); |
187 | channel_max_fd_value = wfd; | 187 | |
188 | if (efd > channel_max_fd_value) | ||
189 | channel_max_fd_value = efd; | ||
190 | /* XXX set close-on-exec -markus */ | 188 | /* XXX set close-on-exec -markus */ |
191 | 189 | ||
192 | c->rfd = rfd; | 190 | c->rfd = rfd; |
@@ -965,9 +963,27 @@ channel_handler(chan_fn *ftab[], fd_set * readset, fd_set * writeset) | |||
965 | } | 963 | } |
966 | 964 | ||
967 | void | 965 | void |
968 | channel_prepare_select(fd_set * readset, fd_set * writeset) | 966 | channel_prepare_select(fd_set **readsetp, fd_set **writesetp, int *maxfdp) |
969 | { | 967 | { |
970 | channel_handler(channel_pre, readset, writeset); | 968 | int n; |
969 | u_int sz; | ||
970 | |||
971 | n = MAX(*maxfdp, channel_max_fd); | ||
972 | |||
973 | sz = howmany(n+1, NFDBITS) * sizeof(fd_mask); | ||
974 | if (*readsetp == NULL || n > *maxfdp) { | ||
975 | if (*readsetp) | ||
976 | xfree(*readsetp); | ||
977 | if (*writesetp) | ||
978 | xfree(*writesetp); | ||
979 | *readsetp = xmalloc(sz); | ||
980 | *writesetp = xmalloc(sz); | ||
981 | *maxfdp = n; | ||
982 | } | ||
983 | memset(*readsetp, 0, sz); | ||
984 | memset(*writesetp, 0, sz); | ||
985 | |||
986 | channel_handler(channel_pre, *readsetp, *writesetp); | ||
971 | } | 987 | } |
972 | 988 | ||
973 | void | 989 | void |
@@ -976,7 +992,7 @@ channel_after_select(fd_set * readset, fd_set * writeset) | |||
976 | channel_handler(channel_post, readset, writeset); | 992 | channel_handler(channel_post, readset, writeset); |
977 | } | 993 | } |
978 | 994 | ||
979 | /* If there is data to send to the connection, send some of it now. */ | 995 | /* If there is data to send to the connection, enqueue some of it now. */ |
980 | 996 | ||
981 | void | 997 | void |
982 | channel_output_poll() | 998 | channel_output_poll() |
@@ -1417,14 +1433,6 @@ channel_close_all() | |||
1417 | channel_close_fds(&channels[i]); | 1433 | channel_close_fds(&channels[i]); |
1418 | } | 1434 | } |
1419 | 1435 | ||
1420 | /* Returns the maximum file descriptor number used by the channels. */ | ||
1421 | |||
1422 | int | ||
1423 | channel_max_fd() | ||
1424 | { | ||
1425 | return channel_max_fd_value; | ||
1426 | } | ||
1427 | |||
1428 | /* Returns true if any channel is still open. */ | 1436 | /* Returns true if any channel is still open. */ |
1429 | 1437 | ||
1430 | int | 1438 | int |