View | Details | Raw Unified | Return to bug 1086 | Differences between
and this patch

Collapse All | Expand All

(-)channels.c (-2 / +5 lines)
Lines 268-273 channel_new(char *ctype, int type, int r Link Here
268
	c->force_drain = 0;
268
	c->force_drain = 0;
269
	c->single_connection = 0;
269
	c->single_connection = 0;
270
	c->detach_user = NULL;
270
	c->detach_user = NULL;
271
	c->detach_close = 0;
271
	c->confirm = NULL;
272
	c->confirm = NULL;
272
	c->confirm_ctx = NULL;
273
	c->confirm_ctx = NULL;
273
	c->input_filter = NULL;
274
	c->input_filter = NULL;
Lines 627-633 channel_register_confirm(int id, channel Link Here
627
	c->confirm_ctx = ctx;
628
	c->confirm_ctx = ctx;
628
}
629
}
629
void
630
void
630
channel_register_cleanup(int id, channel_callback_fn *fn)
631
channel_register_cleanup(int id, channel_callback_fn *fn, int do_close)
631
{
632
{
632
	Channel *c = channel_lookup(id);
633
	Channel *c = channel_lookup(id);
633
634
Lines 636-641 channel_register_cleanup(int id, channel Link Here
636
		return;
637
		return;
637
	}
638
	}
638
	c->detach_user = fn;
639
	c->detach_user = fn;
640
	c->detach_close = do_close;
639
}
641
}
640
void
642
void
641
channel_cancel_cleanup(int id)
643
channel_cancel_cleanup(int id)
Lines 647-652 channel_cancel_cleanup(int id) Link Here
647
		return;
649
		return;
648
	}
650
	}
649
	c->detach_user = NULL;
651
	c->detach_user = NULL;
652
	c->detach_close = 0;
650
}
653
}
651
void
654
void
652
channel_register_filter(int id, channel_filter_fn *fn)
655
channel_register_filter(int id, channel_filter_fn *fn)
Lines 1660-1666 channel_garbage_collect(Channel *c) Link Here
1660
	if (c == NULL)
1676
	if (c == NULL)
1661
		return;
1677
		return;
1662
	if (c->detach_user != NULL) {
1678
	if (c->detach_user != NULL) {
1663
		if (!chan_is_dead(c, 0))
1679
		if (!chan_is_dead(c, c->detach_close))
1664
			return;
1680
			return;
1665
		debug2("channel %d: gc: notify user", c->self);
1681
		debug2("channel %d: gc: notify user", c->self);
1666
		c->detach_user(c->self, NULL);
1682
		c->detach_user(c->self, NULL);
(-)channels.h (-2 / +3 lines)
Lines 105-112 struct Channel { Link Here
105
105
106
	/* callback */
106
	/* callback */
107
	channel_callback_fn	*confirm;
107
	channel_callback_fn	*confirm;
108
	channel_callback_fn	*detach_user;
109
	void			*confirm_ctx;
108
	void			*confirm_ctx;
109
	channel_callback_fn	*detach_user;
110
	int			detach_close;
110
111
111
	/* filter */
112
	/* filter */
112
	channel_filter_fn	*input_filter;
113
	channel_filter_fn	*input_filter;
Lines 162-168 void channel_stop_listening(void); Link Here
162
163
163
void	 channel_send_open(int);
164
void	 channel_send_open(int);
164
void	 channel_request_start(int, char *, int);
165
void	 channel_request_start(int, char *, int);
165
void	 channel_register_cleanup(int, channel_callback_fn *);
166
void	 channel_register_cleanup(int, channel_callback_fn *, int);
166
void	 channel_register_confirm(int, channel_callback_fn *, void *);
167
void	 channel_register_confirm(int, channel_callback_fn *, void *);
167
void	 channel_register_filter(int, channel_filter_fn *);
168
void	 channel_register_filter(int, channel_filter_fn *);
168
void	 channel_cancel_cleanup(int);
169
void	 channel_cancel_cleanup(int);
(-)clientloop.c (-1 / +1 lines)
Lines 1379-1385 client_loop(int have_pty, int escape_cha Link Here
1379
			    simple_escape_filter);
1379
			    simple_escape_filter);
1380
		if (session_ident != -1)
1380
		if (session_ident != -1)
1381
			channel_register_cleanup(session_ident,
1381
			channel_register_cleanup(session_ident,
1382
			    client_channel_closed);
1382
			    client_channel_closed, 0);
1383
	} else {
1383
	} else {
1384
		/* Check if we should immediately send eof on stdin. */
1384
		/* Check if we should immediately send eof on stdin. */
1385
		client_check_initial_eof_on_stdin();
1385
		client_check_initial_eof_on_stdin();
(-)serverloop.c (-1 / +1 lines)
Lines 898-904 server_request_session(void) Link Here
898
		channel_free(c);
898
		channel_free(c);
899
		return NULL;
899
		return NULL;
900
	}
900
	}
901
	channel_register_cleanup(c->self, session_close_by_channel);
901
	channel_register_cleanup(c->self, session_close_by_channel, 0);
902
	return c;
902
	return c;
903
}
903
}
904
904
(-)session.c (-13 / +22 lines)
Lines 1792-1798 static void Link Here
1792
session_exit_message(Session *s, int status)
1792
session_exit_message(Session *s, int status)
1793
{
1793
{
1794
	Channel *c;
1794
	Channel *c;
1795
	u_int i;
1796
1795
1797
	if ((c = channel_lookup(s->chanid)) == NULL)
1796
	if ((c = channel_lookup(s->chanid)) == NULL)
1798
		fatal("session_exit_message: session %d: no channel %d",
1797
		fatal("session_exit_message: session %d: no channel %d",
Lines 1818-1824 session_exit_message(Session *s, int sta Link Here
1818
1817
1819
	/* disconnect channel */
1818
	/* disconnect channel */
1820
	debug("session_exit_message: release channel %d", s->chanid);
1819
	debug("session_exit_message: release channel %d", s->chanid);
1821
	channel_cancel_cleanup(s->chanid);
1820
	s->pid = 0;
1821
1822
	/*
1823
	 * Adjust cleanup callback attachment to send close messages when
1824
	 * the channel gets EOF. The session will be then be closed 
1825
	 * by session_close_by_channel when the childs close their fds.
1826
	 */
1827
	channel_register_cleanup(c->self, session_close_by_channel, 1);
1828
1822
	/*
1829
	/*
1823
	 * emulate a write failure with 'chan_write_failed', nobody will be
1830
	 * emulate a write failure with 'chan_write_failed', nobody will be
1824
	 * interested in data we write.
1831
	 * interested in data we write.
Lines 1827-1841 session_exit_message(Session *s, int sta Link Here
1827
	 */
1834
	 */
1828
	if (c->ostate != CHAN_OUTPUT_CLOSED)
1835
	if (c->ostate != CHAN_OUTPUT_CLOSED)
1829
		chan_write_failed(c);
1836
		chan_write_failed(c);
1830
	s->chanid = -1;
1831
1832
	/* Close any X11 listeners associated with this session */
1833
	if (s->x11_chanids != NULL) {
1834
		for (i = 0; s->x11_chanids[i] != -1; i++) {
1835
			session_close_x11(s->x11_chanids[i]);
1836
			s->x11_chanids[i] = -1;
1837
		}
1838
	}
1839
}
1837
}
1840
1838
1841
void
1839
void
Lines 1879-1885 session_close_by_pid(pid_t pid, int stat Link Here
1879
	}
1877
	}
1880
	if (s->chanid != -1)
1878
	if (s->chanid != -1)
1881
		session_exit_message(s, status);
1879
		session_exit_message(s, status);
1882
	session_close(s);
1880
	if (s->ttyfd != -1)
1881
		session_pty_cleanup(s);
1883
}
1882
}
1884
1883
1885
/*
1884
/*
Lines 1890-1895 void Link Here
1890
session_close_by_channel(int id, void *arg)
1889
session_close_by_channel(int id, void *arg)
1891
{
1890
{
1892
	Session *s = session_by_channel(id);
1891
	Session *s = session_by_channel(id);
1892
	u_int i;
1893
1893
1894
	if (s == NULL) {
1894
	if (s == NULL) {
1895
		debug("session_close_by_channel: no session for id %d", id);
1895
		debug("session_close_by_channel: no session for id %d", id);
Lines 1909-1914 session_close_by_channel(int id, void *a Link Here
1909
	}
1909
	}
1910
	/* detach by removing callback */
1910
	/* detach by removing callback */
1911
	channel_cancel_cleanup(s->chanid);
1911
	channel_cancel_cleanup(s->chanid);
1912
1913
	/* Close any X11 listeners associated with this session */
1914
	if (s->x11_chanids != NULL) {
1915
		for (i = 0; s->x11_chanids[i] != -1; i++) {
1916
			session_close_x11(s->x11_chanids[i]);
1917
			s->x11_chanids[i] = -1;
1918
		}
1919
	}
1920
1912
	s->chanid = -1;
1921
	s->chanid = -1;
1913
	session_close(s);
1922
	session_close(s);
1914
}
1923
}
Lines 1994-2000 session_setup_x11fwd(Session *s) Link Here
1994
	}
2003
	}
1995
	for (i = 0; s->x11_chanids[i] != -1; i++) {
2004
	for (i = 0; s->x11_chanids[i] != -1; i++) {
1996
		channel_register_cleanup(s->x11_chanids[i],
2005
		channel_register_cleanup(s->x11_chanids[i],
1997
		    session_close_single_x11);
2006
		    session_close_single_x11, 0);
1998
	}
2007
	}
1999
2008
2000
	/* Set up a suitable value for the DISPLAY variable. */
2009
	/* Set up a suitable value for the DISPLAY variable. */

Return to bug 1086