Change in ...libosmocore[master]: vty/telnet_interface.c: log connection accept() / close() events

Vadim Yanitskiy gerrit-no-reply at lists.osmocom.org
Tue Jul 30 17:17:16 UTC 2019


Vadim Yanitskiy has submitted this change and it was merged. ( https://gerrit.osmocom.org/c/libosmocore/+/14972 )

Change subject: vty/telnet_interface.c: log connection accept() / close() events
......................................................................

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
---
M src/vty/telnet_interface.c
1 file changed, 12 insertions(+), 0 deletions(-)

Approvals:
  neels: Looks good to me, but someone else must approve
  pespin: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/vty/telnet_interface.c b/src/vty/telnet_interface.c
index d44754c..9aa36fe 100644
--- a/src/vty/telnet_interface.c
+++ b/src/vty/telnet_interface.c
@@ -123,6 +123,13 @@
 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 @@
 	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 @@
 		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;

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/14972
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I77b31abfa159d2f269deaa5a08d94b7bbba7d23c
Gerrit-Change-Number: 14972
Gerrit-PatchSet: 4
Gerrit-Owner: Vadim Yanitskiy <axilirator at gmail.com>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Vadim Yanitskiy <axilirator at gmail.com>
Gerrit-Reviewer: neels <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190730/84408314/attachment.html>


More information about the gerrit-log mailing list