[PATCH 1/3] smpp_smsc: Print errno and close socket if read returns -1

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/OpenBSC@lists.osmocom.org/.

Daniel Willmann dwillmann at sysmocom.de
Fri Jan 17 16:26:26 UTC 2014


Read returning -1 is an error here so make sure and print the actual
reason and close the socket. Otherwise we just loop over the fd with
read returning -1 every time.

EINTR is handled to not cause an error and because the socket is not
opened with O_NONBLOCK we don't need to check EAGAIN/EWOULDBLOCK.
---
 openbsc/src/libmsc/smpp_smsc.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/openbsc/src/libmsc/smpp_smsc.c b/openbsc/src/libmsc/smpp_smsc.c
index 64ed200..943464f 100644
--- a/openbsc/src/libmsc/smpp_smsc.c
+++ b/openbsc/src/libmsc/smpp_smsc.c
@@ -778,8 +778,12 @@ static int esme_link_read_cb(struct osmo_fd *ofd)
 		rdlen = sizeof(uint32_t) - esme->read_idx;
 		rc = read(ofd->fd, lenptr + esme->read_idx, rdlen);
 		if (rc < 0) {
-			LOGP(DSMPP, LOGL_ERROR, "[%s] read returned %d\n",
-			     esme->system_id, rc);
+			/* EINTR is a non-fatal error, just try again */
+			if (errno == EINTR)
+				return 0;
+			LOGP(DSMPP, LOGL_ERROR, "[%s] read returned %d (%s)\n",
+			     esme->system_id, rc, strerror(errno));
+			goto dead_socket;
 		} else if (rc == 0) {
 			goto dead_socket;
 		} else
@@ -801,8 +805,9 @@ static int esme_link_read_cb(struct osmo_fd *ofd)
 		rdlen = esme->read_len - esme->read_idx;
 		rc = read(ofd->fd, msg->tail, OSMO_MIN(rdlen, msgb_tailroom(msg)));
 		if (rc < 0) {
-			LOGP(DSMPP, LOGL_ERROR, "[%s] read returned %d\n",
-				esme->system_id, rc);
+			LOGP(DSMPP, LOGL_ERROR, "[%s] read returned %d (%s)\n",
+				esme->system_id, rc, strerror(errno));
+			goto dead_socket;
 		} else if (rc == 0) {
 			goto dead_socket;
 		} else {
-- 
1.8.4.2





More information about the OpenBSC mailing list