summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Lindstrom <mouring@eviladmin.org>2001-07-04 05:26:06 +0000
committerBen Lindstrom <mouring@eviladmin.org>2001-07-04 05:26:06 +0000
commit809744e9125bb96c7115922bf747dc88c60a199e (patch)
tree035d4463a602c130e058348e20552da1af469c09
parent0047764526a5abcadc5cad7fe00d244e0dc47f75 (diff)
- markus@cvs.openbsd.org 2001/07/02 22:52:57
[channels.c channels.h serverloop.c] improve cleanup/exit logic in ssh2: stop listening to channels, detach channel users (e.g. sessions). wait for children (i.e. dying sessions), send exit messages, cleanup all channels.
-rw-r--r--ChangeLog8
-rw-r--r--channels.c56
-rw-r--r--channels.h10
-rw-r--r--serverloop.c6
4 files changed, 66 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index 211ecb85a..aa734bcd0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -124,6 +124,12 @@
124 - markus@cvs.openbsd.org 2001/07/02 22:40:18 124 - markus@cvs.openbsd.org 2001/07/02 22:40:18
125 [ssh-keygen.c] 125 [ssh-keygen.c]
126 update for sectok.h interface changes. 126 update for sectok.h interface changes.
127 - markus@cvs.openbsd.org 2001/07/02 22:52:57
128 [channels.c channels.h serverloop.c]
129 improve cleanup/exit logic in ssh2:
130 stop listening to channels, detach channel users (e.g. sessions).
131 wait for children (i.e. dying sessions), send exit messages,
132 cleanup all channels.
127 133
12820010629 13420010629
129 - (bal) Removed net_aton() since we don't use it any more 135 - (bal) Removed net_aton() since we don't use it any more
@@ -5951,4 +5957,4 @@
5951 - Wrote replacements for strlcpy and mkdtemp 5957 - Wrote replacements for strlcpy and mkdtemp
5952 - Released 1.0pre1 5958 - Released 1.0pre1
5953 5959
5954$Id: ChangeLog,v 1.1375 2001/07/04 05:24:27 mouring Exp $ 5960$Id: ChangeLog,v 1.1376 2001/07/04 05:26:06 mouring Exp $
diff --git a/channels.c b/channels.c
index 18b6c468e..35edff6dc 100644
--- a/channels.c
+++ b/channels.c
@@ -39,7 +39,7 @@
39 */ 39 */
40 40
41#include "includes.h" 41#include "includes.h"
42RCSID("$OpenBSD: channels.c,v 1.130 2001/06/30 18:08:39 stevesk Exp $"); 42RCSID("$OpenBSD: channels.c,v 1.131 2001/07/02 22:52:56 markus Exp $");
43 43
44#include "ssh.h" 44#include "ssh.h"
45#include "ssh1.h" 45#include "ssh1.h"
@@ -260,7 +260,7 @@ channel_new(char *ctype, int type, int rfd, int wfd, int efd,
260 c->cb_fn = NULL; 260 c->cb_fn = NULL;
261 c->cb_arg = NULL; 261 c->cb_arg = NULL;
262 c->cb_event = 0; 262 c->cb_event = 0;
263 c->dettach_user = NULL; 263 c->detach_user = NULL;
264 c->input_filter = NULL; 264 c->input_filter = NULL;
265 debug("channel %d: new [%s]", found, remote_name); 265 debug("channel %d: new [%s]", found, remote_name);
266 return c; 266 return c;
@@ -310,9 +310,9 @@ channel_free(Channel *c)
310 debug3("channel_free: status: %s", s); 310 debug3("channel_free: status: %s", s);
311 xfree(s); 311 xfree(s);
312 312
313 if (c->dettach_user != NULL) { 313 if (c->detach_user != NULL) {
314 debug("channel_free: channel %d: dettaching channel user", c->self); 314 debug("channel_free: channel %d: detaching channel user", c->self);
315 c->dettach_user(c->self, NULL); 315 c->detach_user(c->self, NULL);
316 } 316 }
317 if (c->sock != -1) 317 if (c->sock != -1)
318 shutdown(c->sock, SHUT_RDWR); 318 shutdown(c->sock, SHUT_RDWR);
@@ -338,6 +338,22 @@ channel_free_all(void)
338 channel_free(channels[i]); 338 channel_free(channels[i]);
339} 339}
340 340
341void
342channel_detach_all(void)
343{
344 int i;
345 Channel *c;
346
347 for (i = 0; i < channels_alloc; i++) {
348 c = channels[i];
349 if (c != NULL && c->detach_user != NULL) {
350 debug("channel_detach_all: channel %d", c->self);
351 c->detach_user(c->self, NULL);
352 c->detach_user = NULL;
353 }
354 }
355}
356
341/* 357/*
342 * Closes the sockets/fds of all channels. This is used to close extra file 358 * Closes the sockets/fds of all channels. This is used to close extra file
343 * descriptors after a fork. 359 * descriptors after a fork.
@@ -354,6 +370,32 @@ channel_close_all()
354} 370}
355 371
356/* 372/*
373 * Stop listening to channels.
374 */
375
376void
377channel_stop_listening(void)
378{
379 int i;
380 Channel *c;
381
382 for (i = 0; i < channels_alloc; i++) {
383 c = channels[i];
384 if (c != NULL) {
385 switch (c->type) {
386 case SSH_CHANNEL_AUTH_SOCKET:
387 case SSH_CHANNEL_PORT_LISTENER:
388 case SSH_CHANNEL_RPORT_LISTENER:
389 case SSH_CHANNEL_X11_LISTENER:
390 close(c->sock);
391 channel_free(c);
392 break;
393 }
394 }
395 }
396}
397
398/*
357 * Returns true if no channel has too much buffered data, and false if one or 399 * Returns true if no channel has too much buffered data, and false if one or
358 * more channel is overfull. 400 * more channel is overfull.
359 */ 401 */
@@ -579,7 +621,7 @@ channel_register_cleanup(int id, channel_callback_fn *fn)
579 log("channel_register_cleanup: %d: bad id", id); 621 log("channel_register_cleanup: %d: bad id", id);
580 return; 622 return;
581 } 623 }
582 c->dettach_user = fn; 624 c->detach_user = fn;
583} 625}
584void 626void
585channel_cancel_cleanup(int id) 627channel_cancel_cleanup(int id)
@@ -589,7 +631,7 @@ channel_cancel_cleanup(int id)
589 log("channel_cancel_cleanup: %d: bad id", id); 631 log("channel_cancel_cleanup: %d: bad id", id);
590 return; 632 return;
591 } 633 }
592 c->dettach_user = NULL; 634 c->detach_user = NULL;
593} 635}
594void 636void
595channel_register_filter(int id, channel_filter_fn *fn) 637channel_register_filter(int id, channel_filter_fn *fn)
diff --git a/channels.h b/channels.h
index c36f66b68..e4146b593 100644
--- a/channels.h
+++ b/channels.h
@@ -32,7 +32,7 @@
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */ 34 */
35/* RCSID("$OpenBSD: channels.h,v 1.43 2001/06/30 18:08:40 stevesk Exp $"); */ 35/* RCSID("$OpenBSD: channels.h,v 1.44 2001/07/02 22:52:57 markus Exp $"); */
36 36
37#ifndef CHANNEL_H 37#ifndef CHANNEL_H
38#define CHANNEL_H 38#define CHANNEL_H
@@ -102,7 +102,7 @@ struct Channel {
102 channel_callback_fn *cb_fn; 102 channel_callback_fn *cb_fn;
103 void *cb_arg; 103 void *cb_arg;
104 int cb_event; 104 int cb_event;
105 channel_callback_fn *dettach_user; 105 channel_callback_fn *detach_user;
106 106
107 /* filter */ 107 /* filter */
108 channel_filter_fn *input_filter; 108 channel_filter_fn *input_filter;
@@ -140,8 +140,10 @@ struct Channel {
140Channel *channel_lookup(int); 140Channel *channel_lookup(int);
141Channel *channel_new(char *, int, int, int, int, int, int, int, char *, int); 141Channel *channel_new(char *, int, int, int, int, int, int, int, char *, int);
142void channel_set_fds(int, int, int, int, int, int); 142void channel_set_fds(int, int, int, int, int, int);
143void channel_free(Channel *); 143void channel_free(Channel *);
144void channel_free_all(void); 144void channel_free_all(void);
145void channel_detach_all(void);
146void channel_stop_listening(void);
145 147
146void channel_send_open(int); 148void channel_send_open(int);
147void channel_request(int, char *, int); 149void channel_request(int, char *, int);
diff --git a/serverloop.c b/serverloop.c
index 773292a94..1db1c725a 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.73 2001/07/02 13:59:14 markus Exp $"); 38RCSID("$OpenBSD: serverloop.c,v 1.74 2001/07/02 22:52:57 markus Exp $");
39 39
40#include "xmalloc.h" 40#include "xmalloc.h"
41#include "packet.h" 41#include "packet.h"
@@ -711,7 +711,8 @@ server_loop2(Authctxt *authctxt)
711 * there is a race between channel_free_all() killing children and 711 * there is a race between channel_free_all() killing children and
712 * children dying before kill() 712 * children dying before kill()
713 */ 713 */
714 channel_free_all(); 714 channel_detach_all();
715 channel_stop_listening();
715 716
716 while (session_have_children()) { 717 while (session_have_children()) {
717 pid = waitpid(-1, &status, 0); 718 pid = waitpid(-1, &status, 0);
@@ -722,6 +723,7 @@ server_loop2(Authctxt *authctxt)
722 break; 723 break;
723 } 724 }
724 } 725 }
726 channel_free_all();
725} 727}
726 728
727static void 729static void