summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilipp Maier <pmaier@sysmocom.de>2017-02-09 14:09:06 +0100
committerPhilipp Maier <pmaier@sysmocom.de>2017-02-09 16:21:01 +0100
commit6f0f560eab7bd28110b1bd1d3bcf97e2690e3d50 (patch)
treeeebb98a447c694871725ed5abb6a20f4636d2ebd
parent2c717948d91540016067f87bb3e0913067d42647 (diff)
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
-rw-r--r--src/socket.c20
-rw-r--r--tests/socket/socket_test.c17
2 files changed, 28 insertions, 9 deletions
diff --git a/src/socket.c b/src/socket.c
index 3c5548ff..2c1b547b 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -73,7 +73,7 @@ int osmo_sock_init(uint16_t family, uint16_t type, uint8_t proto,
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 @@ int osmo_sock_init(uint16_t family, uint16_t type, uint8_t proto,
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 @@ int osmo_sock_init(uint16_t family, uint16_t type, uint8_t proto,
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 @@ int osmo_sock_init(uint16_t family, uint16_t type, uint8_t proto,
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 @@ int osmo_sock_init(uint16_t family, uint16_t type, uint8_t proto,
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 @@ int osmo_sock_init_sa(struct sockaddr *ss, uint16_t type,
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 @@ int osmo_sockaddr_is_local(struct sockaddr *addr, unsigned int addrlen)
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 @@ int osmo_sock_unix_init(uint16_t type, uint8_t proto,
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 75088e5f..5b6abc42 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 @@ static int test_sockinit(void)
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;
}