[PATCH] libosmocore[master]: cosmetic: replace fprintf with LOGP

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/.

dexter gerrit-no-reply at lists.osmocom.org
Thu Feb 9 14:53:01 UTC 2017


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

cosmetic: replace fprintf with LOGP

socket.c still uses fprintf to output error messages. This commit
replaces the fprintf with proper LOGP messages.

Change-Id: Ia2993415d5f5c33ccd719af239ff59252d11b764
---
M src/socket.c
M tests/socket/socket_test.c
M tests/socket/socket_test.err
3 files changed, 27 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/82/1782/1

diff --git a/src/socket.c b/src/socket.c
index 3c5548f..2c1b547 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -73,7 +73,7 @@
 
 	if ((flags & (OSMO_SOCK_F_BIND | OSMO_SOCK_F_CONNECT)) ==
 		     (OSMO_SOCK_F_BIND | OSMO_SOCK_F_CONNECT)) {
-		fprintf(stderr, "invalid: both bind and connect flags set:"
+		LOGP(DLGLOBAL, LOGL_ERROR, "invalid: both bind and connect flags set:"
 			" %s:%u\n", host, port);
 		return -EINVAL;
 	}
@@ -97,7 +97,7 @@
 
 	rc = getaddrinfo(host, portbuf, &hints, &result);
 	if (rc != 0) {
-		fprintf(stderr, "getaddrinfo returned NULL: %s:%u: %s\n",
+		LOGP(DLGLOBAL, LOGL_ERROR, "getaddrinfo returned NULL: %s:%u: %s\n",
 			host, port, strerror(errno));
 		return -EINVAL;
 	}
@@ -114,7 +114,7 @@
 			continue;
 		if (flags & OSMO_SOCK_F_NONBLOCK) {
 			if (ioctl(sfd, FIONBIO, (unsigned char *)&on) < 0) {
-				fprintf(stderr,
+				LOGP(DLGLOBAL, LOGL_ERROR,
 					"cannot set this socket unblocking:"
 					" %s:%u: %s\n",
 					host, port, strerror(errno));
@@ -131,7 +131,7 @@
 			rc = setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR,
 							&on, sizeof(on));
 			if (rc < 0) {
-				fprintf(stderr,
+				LOGP(DLGLOBAL, LOGL_ERROR,
 					"cannot setsockopt socket:"
 					" %s:%u: %s\n",
 					host, port, strerror(errno));
@@ -145,7 +145,7 @@
 	freeaddrinfo(result);
 
 	if (rp == NULL) {
-		fprintf(stderr, "unable to connect/bind socket: %s:%u: %s\n",
+		LOGP(DLGLOBAL, LOGL_ERROR, "unable to connect/bind socket: %s:%u: %s\n",
 			host, port, strerror(errno));
 		return -ENODEV;
 	}
@@ -247,7 +247,8 @@
 	s = getnameinfo(ss, sa_len, host, NI_MAXHOST,
 			NULL, 0, NI_NUMERICHOST);
 	if (s != 0) {
-		perror("getnameinfo failed");
+		LOGP(DLGLOBAL, LOGL_ERROR, "getnameinfo failed:"
+		     " %s\n", strerror(errno));
 		return s;
 	}
 
@@ -292,7 +293,8 @@
 	struct ifaddrs *ifaddr, *ifa;
 
 	if (getifaddrs(&ifaddr) == -1) {
-		perror("getifaddrs");
+		LOGP(DLGLOBAL, LOGL_ERROR, "getifaddrs:"
+		     " %s\n", strerror(errno));
 		return -EIO;
 	}
 
@@ -359,7 +361,9 @@
 
 	if (flags & OSMO_SOCK_F_NONBLOCK) {
 		if (ioctl(sfd, FIONBIO, (unsigned char *)&on) < 0) {
-			perror("cannot set this socket unblocking");
+			LOGP(DLGLOBAL, LOGL_ERROR,
+			     "cannot set this socket unblocking: %s\n",
+			     strerror(errno));
 			close(sfd);
 			return -EINVAL;
 		}
diff --git a/tests/socket/socket_test.c b/tests/socket/socket_test.c
index 75088e5..dabff7b 100644
--- a/tests/socket/socket_test.c
+++ b/tests/socket/socket_test.c
@@ -30,6 +30,7 @@
 
 #include <osmocom/core/utils.h>
 #include <osmocom/core/socket.h>
+#include <osmocom/core/logging.h>
 
 #include "../config.h"
 
@@ -71,8 +72,19 @@
 	return 0;
 }
 
+const struct log_info_cat default_categories[] = {
+};
+
+static struct log_info info = {
+	.cat = default_categories,
+	.num_cat = ARRAY_SIZE(default_categories),
+};
+
 int main(int argc, char *argv[])
 {
+	osmo_init_logging(&info);
+
 	test_sockinit();
-	return 0;
+
+	return EXIT_SUCCESS;
 }
diff --git a/tests/socket/socket_test.err b/tests/socket/socket_test.err
index 5367239..750233a 100644
--- a/tests/socket/socket_test.err
+++ b/tests/socket/socket_test.err
@@ -1 +1,2 @@
-invalid: both bind and connect flags set: 0.0.0.0:0
+<0000> socket.c:77 invalid: both bind and connect flags set: 0.0.0.0:0
+
\ No newline at end of file

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia2993415d5f5c33ccd719af239ff59252d11b764
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: dexter <pmaier at sysmocom.de>



More information about the gerrit-log mailing list