aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src/telnet_interface.c
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2009-08-07 00:31:23 +0200
committerHarald Welte <laforge@gnumonks.org>2009-08-07 00:31:23 +0200
commit3820254f7ae808aadf0b37229d7dc68845dc3750 (patch)
tree6f0de9fcca986cd975502a53121f6bc3f4029614 /openbsc/src/telnet_interface.c
parent31c3d34e61d04b98c372576bf42fe09da912f0c9 (diff)
telnet: deal gracefully with vty being closed by vty layer
also: ignore vty's that are not terminals (e.g. VTY_FILE)
Diffstat (limited to 'openbsc/src/telnet_interface.c')
-rw-r--r--openbsc/src/telnet_interface.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/openbsc/src/telnet_interface.c b/openbsc/src/telnet_interface.c
index 7a67fe1de..ba574704e 100644
--- a/openbsc/src/telnet_interface.c
+++ b/openbsc/src/telnet_interface.c
@@ -146,6 +146,10 @@ static int client_data(struct bsc_fd *fd, unsigned int what)
rc = vty_read(conn->vty);
}
+ /* vty might have been closed from vithin vty_read() */
+ if (!conn->vty)
+ return rc;
+
if (what & BSC_FD_WRITE) {
rc = buffer_flush_all(conn->vty->obuf, fd->fd);
if (rc == BUFFER_EMPTY)
@@ -192,6 +196,9 @@ void vty_event(enum event event, int sock, struct vty *vty)
struct telnet_connection *connection = vty->priv;
struct bsc_fd *bfd = &connection->fd;
+ if (vty->type != VTY_TERM)
+ return;
+
switch (event) {
case VTY_READ:
bfd->when |= BSC_FD_READ;
@@ -199,6 +206,11 @@ void vty_event(enum event event, int sock, struct vty *vty)
case VTY_WRITE:
bfd->when |= BSC_FD_WRITE;
break;
+ case VTY_CLOSED:
+ /* vty layer is about to free() vty */
+ connection->vty = NULL;
+ telnet_close_client(bfd);
+ break;
default:
break;
}