diff options
author | Neels Hofmeyr <neels@hofmeyr.de> | 2018-12-12 03:05:33 +0100 |
---|---|---|
committer | Neels Hofmeyr <nhofmeyr@sysmocom.de> | 2018-12-17 13:37:18 +0000 |
commit | 32d15cc8bae0c88f62a7269327685f6c1820c1d9 (patch) | |
tree | 69a22b8128002d7294b676c4089df1a8273d2ad8 | |
parent | 1fd50e53069ac4361ef72b2ca632c7f31a66ff54 (diff) |
drop/replace very weird logging in mgcp_client.c
mgcp_do_write() is the final stage of writing data towards the MGCP server
(MGW). In that function, drop an unconditional iteration and copy of the MGCP
message to a static string buffer for no apparent reason besides debug logging.
Instead, use osmo_escape_str() with a limited length, which can just be an
inline format argument in the LOGP() statement. This way, the string mangling
is simpler and only gets run when DMGCP is actually on debug log level.
Change-Id: Id6877ed7fd7dbe009b2ece8792d5160d040c1aaa
-rw-r--r-- | src/libosmo-mgcp-client/mgcp_client.c | 21 |
1 files changed, 5 insertions, 16 deletions
diff --git a/src/libosmo-mgcp-client/mgcp_client.c b/src/libosmo-mgcp-client/mgcp_client.c index 2a8cc1568..fc9c5d3dc 100644 --- a/src/libosmo-mgcp-client/mgcp_client.c +++ b/src/libosmo-mgcp-client/mgcp_client.c @@ -735,26 +735,15 @@ static int mgcp_do_read(struct osmo_fd *fd) static int mgcp_do_write(struct osmo_fd *fd, struct msgb *msg) { int ret; - static char strbuf[4096]; - unsigned int l = msg->len < sizeof(strbuf) ? msg->len : sizeof(strbuf); - unsigned int i; - - osmo_strlcpy(strbuf, (const char*)msg->data, l); - for (i = 0; i < sizeof(strbuf); i++) { - if (strbuf[i] == '\n' || strbuf[i] == '\r') { - strbuf[i] = '\0'; - break; - } - } - DEBUGP(DLMGCP, "Tx MGCP msg to MGCP GW: '%s'\n", strbuf); - LOGP(DLMGCP, LOGL_DEBUG, "Sending msg to MGCP GW size: %u\n", msg->len); + LOGP(DLMGCP, LOGL_DEBUG, "Sending msg to MGCP GW size: len=%u '%s'...\n", + msg->len, osmo_escape_str((const char*)msg->data, OSMO_MIN(42, msg->len))); ret = write(fd->fd, msg->data, msg->len); if (ret != msg->len) - LOGP(DLMGCP, LOGL_ERROR, "Failed to forward message to MGCP" - " GW: %s\n", strerror(errno)); - + LOGP(DLMGCP, LOGL_ERROR, "Failed to Tx MGCP: %d='%s'; msg: len=%u '%s'...\n", + errno, strerror(errno), + msg->len, osmo_escape_str((const char*)msg->data, OSMO_MIN(42, msg->len))); return ret; } |