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

dexter gerrit-no-reply at lists.osmocom.org
Thu Feb 9 15:21:12 UTC 2017


Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/1782

to look at the new patch set (#3).

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
2 files changed, 28 insertions(+), 9 deletions(-)


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

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..5b6abc4 100644
--- a/tests/socket/socket_test.c
+++ b/tests/socket/socket_test.c
@@ -28,8 +28,10 @@
 #include <arpa/inet.h>
 #include <netinet/in.h>
 
+#include <osmocom/core/application.h>
 #include <osmocom/core/utils.h>
 #include <osmocom/core/socket.h>
+#include <osmocom/core/logging.h>
 
 #include "../config.h"
 
@@ -71,8 +73,21 @@
 	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);
+	log_set_use_color(osmo_stderr_target, 0);
+	log_set_print_filename(osmo_stderr_target, 0);
+
 	test_sockinit();
-	return 0;
+
+	return EXIT_SUCCESS;
 }

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

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Ia2993415d5f5c33ccd719af239ff59252d11b764
Gerrit-PatchSet: 3
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder


More information about the gerrit-log mailing list