summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2019-07-28 00:28:36 +0700
committerVadim Yanitskiy <axilirator@gmail.com>2019-07-30 17:17:15 +0000
commit74b6ff074b421c52e11fad0733ca9490eddc42dd (patch)
tree1ee1beeed35072067629c3dc777ce6881ba68e87
parent2605ffc3d70a7cf0be5828cc565d4d270a317a81 (diff)
vty/telnet_interface.c: log connection accept() / close() events
Unfortunately, osmo_sock_get_name_buf() fails in telnet_close_client(): DLGLOBAL INFO telnet_interface.c:130 Closing telnet connection <error-in-getsockname> because getsockname(), getpeername(), and even close() fail with: "Bad file descriptor". This looks like a bug of the existing code. Change-Id: I77b31abfa159d2f269deaa5a08d94b7bbba7d23c
-rw-r--r--src/vty/telnet_interface.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/vty/telnet_interface.c b/src/vty/telnet_interface.c
index d44754cf..9aa36fe4 100644
--- a/src/vty/telnet_interface.c
+++ b/src/vty/telnet_interface.c
@@ -123,6 +123,13 @@ extern struct host host;
int telnet_close_client(struct osmo_fd *fd)
{
struct telnet_connection *conn = (struct telnet_connection*)fd->data;
+ char sock_name_buf[OSMO_SOCK_NAME_MAXLEN];
+ int rc;
+
+ /* FIXME: getsockname() always fails: "Bad file descriptor" */
+ rc = osmo_sock_get_name_buf(sock_name_buf, OSMO_SOCK_NAME_MAXLEN, fd->fd);
+ LOGP(DLGLOBAL, LOGL_INFO, "Closing telnet connection %s\n",
+ (rc <= 0) ? "r=NULL<->l=NULL" : sock_name_buf);
close(fd->fd);
osmo_fd_unregister(fd);
@@ -166,6 +173,7 @@ static int telnet_new_connection(struct osmo_fd *fd, unsigned int what)
struct sockaddr_in sockaddr;
socklen_t len = sizeof(sockaddr);
int new_connection = accept(fd->fd, (struct sockaddr*)&sockaddr, &len);
+ char sock_name_buf[OSMO_SOCK_NAME_MAXLEN];
int rc;
if (new_connection < 0) {
@@ -173,6 +181,10 @@ static int telnet_new_connection(struct osmo_fd *fd, unsigned int what)
return new_connection;
}
+ rc = osmo_sock_get_name_buf(sock_name_buf, OSMO_SOCK_NAME_MAXLEN, new_connection);
+ LOGP(DLGLOBAL, LOGL_INFO, "Accept()ed new telnet connection %s\n",
+ (rc <= 0) ? "r=NULL<->l=NULL" : sock_name_buf);
+
connection = talloc_zero(tall_telnet_ctx, struct telnet_connection);
connection->priv = fd->data;
connection->fd.data = connection;