Change in libosmo-netif[master]: Stream client: update logging

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
Tue Feb 5 16:21:26 UTC 2019


Harald Welte has submitted this change and it was merged. ( https://gerrit.osmocom.org/12836 )

Change subject: Stream client: update logging
......................................................................

Stream client: update logging

Introduce logging macro wrapper to properly log current client state and
function to aid in debugging.

Change-Id: Ie22a80dcec95998cce0b25053fdf74f23eab6e53
---
M src/stream.c
1 file changed, 25 insertions(+), 16 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  osmith: Looks good to me, but someone else must approve
  Jenkins Builder: Verified



diff --git a/src/stream.c b/src/stream.c
index dbbaa9c..f1d87d4 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -49,6 +49,9 @@
 #include <netinet/sctp.h>
 #endif
 
+#define LOGSCLI(cli, level, fmt, args...) \
+	LOGP(DLINP, level, "[%s] %s(): " fmt, get_value_string(stream_cli_state_names, (cli)->state), __func__, ## args)
+
 /*! \addtogroup stream Osmocom Stream Socket
  *  @{
  *
@@ -131,6 +134,13 @@
         STREAM_CLI_STATE_MAX
 };
 
+static const struct value_string stream_cli_state_names[] = {
+	{ STREAM_CLI_STATE_NONE,       "      NONE" },
+	{ STREAM_CLI_STATE_CONNECTING, "CONNECTING" },
+	{ STREAM_CLI_STATE_CONNECTED,  " CONNECTED" },
+	{ 0, NULL }
+};
+
 #define OSMO_STREAM_CLI_F_RECONF	(1 << 0)
 #define OSMO_STREAM_CLI_F_NODELAY	(1 << 1)
 
@@ -160,12 +170,12 @@
 void osmo_stream_cli_reconnect(struct osmo_stream_cli *cli)
 {
 	if (cli->reconnect_timeout < 0) {
-		LOGP(DLINP, LOGL_DEBUG, "not reconnecting, disabled.\n");
+		LOGSCLI(cli, LOGL_DEBUG, "not reconnecting, disabled.\n");
 		return;
 	}
-	LOGP(DLINP, LOGL_DEBUG, "connection closed\n");
+	LOGSCLI(cli, LOGL_DEBUG, "connection closed\n");
 	osmo_stream_cli_close(cli);
-	LOGP(DLINP, LOGL_DEBUG, "retrying in %d seconds...\n",
+	LOGSCLI(cli, LOGL_DEBUG, "retrying in %d seconds...\n",
 		cli->reconnect_timeout);
 	osmo_timer_schedule(&cli->timer, cli->reconnect_timeout, 0);
 	cli->state = STREAM_CLI_STATE_CONNECTING;
@@ -186,7 +196,7 @@
 
 static void osmo_stream_cli_read(struct osmo_stream_cli *cli)
 {
-	LOGP(DLINP, LOGL_DEBUG, "message received\n");
+	LOGSCLI(cli, LOGL_DEBUG, "message received\n");
 
 	if (cli->read_cb)
 		cli->read_cb(cli);
@@ -201,7 +211,7 @@
 	struct llist_head *lh;
 	int ret;
 
-	LOGP(DLINP, LOGL_DEBUG, "sending data\n");
+	LOGSCLI(cli, LOGL_DEBUG, "sending data\n");
 
 	if (llist_empty(&cli->tx_queue)) {
 		cli->ofd.when &= ~BSC_FD_WRITE;
@@ -212,7 +222,7 @@
 	msg = llist_entry(lh, struct msgb, list);
 
 	if (cli->state == STREAM_CLI_STATE_CONNECTING) {
-		LOGP(DLINP, LOGL_ERROR, "not connected, dropping data!\n");
+		LOGSCLI(cli, LOGL_ERROR, "not connected, dropping data!\n");
 		return 0;
 	}
 
@@ -235,7 +245,7 @@
 		if (errno == EPIPE || errno == ENOTCONN) {
 			osmo_stream_cli_reconnect(cli);
 		}
-		LOGP(DLINP, LOGL_ERROR, "error to send\n");
+		LOGSCLI(cli, LOGL_ERROR, "error to send\n");
 	}
 	msgb_free(msg);
 	return 0;
@@ -255,7 +265,7 @@
 			return 0;
 		}
 		ofd->when &= ~BSC_FD_WRITE;
-		LOGP(DLINP, LOGL_DEBUG, "connection done.\n");
+		LOGSCLI(cli, LOGL_DEBUG, "connection done.\n");
 		cli->state = STREAM_CLI_STATE_CONNECTED;
 		if (cli->proto == IPPROTO_SCTP) {
 #ifdef SO_NOSIGPIPE
@@ -263,7 +273,7 @@
 
 			ret = setsockopt(ofd->fd, SOL_SOCKET, SO_NOSIGPIPE, (void*)&val, sizeof(val));
 			if (ret < 0)
-				LOGP(DLINP, LOGL_DEBUG, "Failed setting SO_NOSIGPIPE: %s\n", strerror(errno));
+				LOGSCLI(cli, LOGL_DEBUG, "Failed setting SO_NOSIGPIPE: %s\n", strerror(errno));
 #endif
 			sctp_sock_activate_events(ofd->fd);
 		}
@@ -272,11 +282,11 @@
 		break;
 	case STREAM_CLI_STATE_CONNECTED:
 		if (what & BSC_FD_READ) {
-			LOGP(DLINP, LOGL_DEBUG, "connected read\n");
+			LOGSCLI(cli, LOGL_DEBUG, "connected read\n");
 			osmo_stream_cli_read(cli);
 		}
 		if (what & BSC_FD_WRITE) {
-			LOGP(DLINP, LOGL_DEBUG, "connected write\n");
+			LOGSCLI(cli, LOGL_DEBUG, "connected write\n");
 			osmo_stream_cli_write(cli);
 		}
 		break;
@@ -503,7 +513,7 @@
 {
 	struct osmo_stream_cli *cli = data;
 
-	LOGP(DLINP, LOGL_DEBUG, "reconnecting.\n");
+	LOGSCLI(cli, LOGL_DEBUG, "reconnecting.\n");
 
 	switch(cli->state) {
 	case STREAM_CLI_STATE_CONNECTING:
@@ -535,18 +545,17 @@
 	ret = recv(cli->ofd.fd, msg->data, msg->data_len, 0);
 	if (ret < 0) {
 		if (errno == EPIPE || errno == ECONNRESET) {
-			LOGP(DLINP, LOGL_ERROR,
-				"lost connection with srv\n");
+			LOGSCLI(cli, LOGL_ERROR, "lost connection with srv\n");
 		}
 		osmo_stream_cli_reconnect(cli);
 		return ret;
 	} else if (ret == 0) {
-		LOGP(DLINP, LOGL_ERROR, "connection closed with srv\n");
+		LOGSCLI(cli, LOGL_ERROR, "connection closed with srv\n");
 		osmo_stream_cli_reconnect(cli);
 		return ret;
 	}
 	msgb_put(msg, ret);
-	LOGP(DLINP, LOGL_DEBUG, "received %d bytes from srv\n", ret);
+	LOGSCLI(cli, LOGL_DEBUG, "received %d bytes from srv\n", ret);
 	return ret;
 }
 

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

Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie22a80dcec95998cce0b25053fdf74f23eab6e53
Gerrit-Change-Number: 12836
Gerrit-PatchSet: 4
Gerrit-Owner: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: daniel <dwillmann at sysmocom.de>
Gerrit-Reviewer: osmith <osmith at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190205/ea0266e3/attachment.htm>


More information about the gerrit-log mailing list