[PATCH] libosmocore[master]: control_if: Close control connection socket/fd on read/write...

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Fri Dec 22 15:48:35 UTC 2017


Review at  https://gerrit.osmocom.org/5550

control_if: Close control connection socket/fd on read/write == 0

When read() or write() system calls return '0' on a stream socket,
it means that the connection has been closed ("EOF").  We must
accordingly close this socket and remove all related state.

Before this patch, every new CTRL connection would introduce a leak
of both some memory/state, as well as a file descriptor :(

Change-Id: I4fb70e5f123b37dece29f156c5f430c875e7cbaf
---
M src/ctrl/control_if.c
1 file changed, 9 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/50/5550/1

diff --git a/src/ctrl/control_if.c b/src/ctrl/control_if.c
index 17a012a..6293ff5 100644
--- a/src/ctrl/control_if.c
+++ b/src/ctrl/control_if.c
@@ -341,6 +341,7 @@
 		/* msg was already discarded. */
 		if (ret == 0) {
 			LOGP(DLCTRL, LOGL_INFO, "The control connection was closed\n");
+			control_close_conn(ccon);
 			ret = -EIO;
 		}
 		else
@@ -414,10 +415,17 @@
 
 static int control_write_cb(struct osmo_fd *bfd, struct msgb *msg)
 {
+	struct osmo_wqueue *queue;
+	struct ctrl_connection *ccon;
 	int rc;
 
+	queue = container_of(bfd, struct osmo_wqueue, bfd);
+	ccon = container_of(queue, struct ctrl_connection, write_queue);
+
 	rc = write(bfd->fd, msg->data, msg->len);
-	if (rc != msg->len)
+	if (rc == 0)
+		control_close_conn(ccon);
+	else if (rc != msg->len)
 		LOGP(DLCTRL, LOGL_ERROR, "Failed to write message to the control connection.\n");
 
 	return rc;

-- 
To view, visit https://gerrit.osmocom.org/5550
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4fb70e5f123b37dece29f156c5f430c875e7cbaf
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>



More information about the gerrit-log mailing list