[PATCH 2/2] Replaced fprintf calls with the new wl_log function.

ustun.ergenoglu at gmail.com ustun.ergenoglu at gmail.com
Thu Feb 2 14:16:01 PST 2012


From: Ustun Ergenoglu <ego at ustun.fi>

Signed-off-by: Ustun Ergenoglu <ego at ustun.fi>
---
 src/connection.c     |    9 +++++----
 src/event-loop.c     |   11 ++++++-----
 src/wayland-client.c |   19 ++++++++++---------
 src/wayland-server.c |   15 ++++++++-------
 4 files changed, 29 insertions(+), 25 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 4ac5bf8..45562f9 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -38,6 +38,7 @@
 
 #include "wayland-util.h"
 #include "wayland-private.h"
+#include "wayland-log.h"
 
 struct wl_buffer {
 	char data[4096];
@@ -275,7 +276,7 @@ wl_connection_data(struct wl_connection *connection, uint32_t mask)
 		if (len == -1 && errno == EPIPE) {
 			return -1;
 		} else if (len < 0) {
-			fprintf(stderr,
+			wl_log(WL_LOG_ERROR,
 				"write error for connection %p, fd %d: %m\n",
 				connection, connection->fd);
 			return -1;
@@ -309,7 +310,7 @@ wl_connection_data(struct wl_connection *connection, uint32_t mask)
 		} while (len < 0 && errno == EINTR);
 
 		if (len < 0) {
-			fprintf(stderr,
+			wl_log(WL_LOG_ERROR,
 				"read error from connection %p: %m (%d)\n",
 				connection, errno);
 			return -1;
@@ -499,7 +500,7 @@ wl_connection_vmarshal(struct wl_connection *connection,
 			fd = va_arg(ap, int);
 			dup_fd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
 			if (dup_fd < 0) {
-				fprintf(stderr, "dup failed: %m");
+				wl_log(WL_LOG_ERROR, "dup failed: %m");
 				abort();
 			}
 			*fd_ptr = dup_fd;
@@ -507,7 +508,7 @@ wl_connection_vmarshal(struct wl_connection *connection,
 				      &dup_fd, sizeof dup_fd);
 			break;
 		default:
-			fprintf(stderr, "unhandled format code: '%c'\n",
+			wl_log(WL_LOG_ERROR, "unhandled format code: '%c'\n",
 				message->signature[i - 2]);
 			assert(0);
 			break;
diff --git a/src/event-loop.c b/src/event-loop.c
index 2dfe0ae..0a996e7 100644
--- a/src/event-loop.c
+++ b/src/event-loop.c
@@ -34,6 +34,7 @@
 #include <unistd.h>
 #include <assert.h>
 #include "wayland-server.h"
+#include "wayland-log.h"
 
 struct wl_event_loop {
 	int epoll_fd;
@@ -167,7 +168,7 @@ wl_event_source_timer_dispatch(struct wl_event_source *source,
 	len = read(timer_source->fd, &expires, sizeof expires);
 	if (len != sizeof expires)
 		/* Is there anything we can do here?  Will this ever happen? */
-		fprintf(stderr, "timerfd read error: %m\n");
+		wl_log(WL_LOG_WARNING, "timerfd read error: %m\n");
 
 	return timer_source->func(timer_source->base.data);
 }
@@ -206,7 +207,7 @@ wl_event_loop_add_timer(struct wl_event_loop *loop,
 
 	source->fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC);
 	if (source->fd < 0) {
-		fprintf(stderr, "could not create timerfd\n: %m");
+		wl_log(WL_LOG_WARNING, "could not create timerfd\n: %m");
 		free(source);
 		return NULL;
 	}
@@ -239,7 +240,7 @@ wl_event_source_timer_update(struct wl_event_source *source, int ms_delay)
 	its.it_value.tv_sec = ms_delay / 1000;
 	its.it_value.tv_nsec = (ms_delay % 1000) * 1000 * 1000;
 	if (timerfd_settime(timer_source->fd, 0, &its, NULL) < 0) {
-		fprintf(stderr, "could not set timerfd\n: %m");
+		wl_log(WL_LOG_WARNING, "could not set timerfd\n: %m");
 		return -1;
 	}
 
@@ -265,7 +266,7 @@ wl_event_source_signal_dispatch(struct wl_event_source *source,
 	len = read(signal_source->fd, &signal_info, sizeof signal_info);
 	if (len != sizeof signal_info)
 		/* Is there anything we can do here?  Will this ever happen? */
-		fprintf(stderr, "signalfd read error: %m\n");
+		wl_log(WL_LOG_WARNING, "signalfd read error: %m\n");
 
 	return signal_source->func(signal_source->signal_number,
 				   signal_source->base.data);
@@ -310,7 +311,7 @@ wl_event_loop_add_signal(struct wl_event_loop *loop,
 	sigaddset(&mask, signal_number);
 	source->fd = signalfd(-1, &mask, SFD_CLOEXEC);
 	if (source->fd < 0) {
-		fprintf(stderr, "could not create fd to watch signal\n: %m");
+		wl_log(WL_LOG_WARNING, "could not create fd to watch signal\n: %m");
 		free(source);
 		return NULL;
 	}
diff --git a/src/wayland-client.c b/src/wayland-client.c
index bbfc035..2a386d3 100644
--- a/src/wayland-client.c
+++ b/src/wayland-client.c
@@ -38,6 +38,7 @@
 #include "wayland-util.h"
 #include "wayland-client.h"
 #include "wayland-private.h"
+#include "wayland-log.h"
 
 struct wl_global_listener {
 	wl_display_global_func_t handler;
@@ -176,7 +177,7 @@ wl_proxy_add_listener(struct wl_proxy *proxy,
 		      void (**implementation)(void), void *data)
 {
 	if (proxy->object.implementation) {
-		fprintf(stderr, "proxy already has listener\n");
+		wl_log(WL_LOG_WARNING, "proxy already has listener\n");
 		return -1;
 	}
 
@@ -199,7 +200,7 @@ wl_proxy_marshal(struct wl_proxy *proxy, uint32_t opcode, ...)
 	va_end(ap);
 
 	if (closure == NULL) {
-		fprintf(stderr, "Error marshalling request\n");
+		wl_log(WL_LOG_WARNING, "Error marshalling request\n");
 		abort();
 	}
 
@@ -232,7 +233,7 @@ display_handle_error(void *data,
 		     struct wl_display *display, struct wl_object *object,
 		     uint32_t code, const char *message)
 {
-	fprintf(stderr, "%s@%d: error %d: %s\n",
+	wl_log(WL_LOG_ERROR, "%s@%d: error %d: %s\n",
 		object->interface->name, object->id, code, message);
 	abort();
 }
@@ -284,7 +285,7 @@ display_handle_delete_id(void *data, struct wl_display *display, uint32_t id)
 
 	proxy = wl_map_lookup(&display->objects, id);
 	if (proxy != WL_ZOMBIE_OBJECT)
-		fprintf(stderr, "server sent delete_id for live object\n");
+		wl_log(WL_LOG_WARNING, "server sent delete_id for live object\n");
 	else
 		wl_map_remove(&display->objects, id);
 }
@@ -311,7 +312,7 @@ connect_to_socket(struct wl_display *display, const char *name)
 	runtime_dir = getenv("XDG_RUNTIME_DIR");
 	if (runtime_dir == NULL) {
 		runtime_dir = ".";
-		fprintf(stderr,
+		wl_log(WL_LOG_INFO,
 			"XDG_RUNTIME_DIR not set, falling back to %s\n",
 			runtime_dir);
 	}
@@ -465,7 +466,7 @@ handle_event(struct wl_display *display,
 	proxy = wl_map_lookup(&display->objects, id);
 
 	if (proxy == WL_ZOMBIE_OBJECT) {
-		fprintf(stderr, "Message to zombie object\n");
+		wl_log(WL_LOG_WARNING, "Message to zombie object\n");
 		wl_connection_consume(display->connection, size);
 		return;
 	} else if (proxy == NULL || proxy->object.implementation == NULL) {
@@ -478,7 +479,7 @@ handle_event(struct wl_display *display,
 					  size, &display->objects, message);
 
 	if (closure == NULL) {
-		fprintf(stderr, "Error demarshalling event\n");
+		wl_log(WL_LOG_ERROR, "Error demarshalling event\n");
 		abort();
 	}
 
@@ -500,7 +501,7 @@ wl_display_iterate(struct wl_display *display, uint32_t mask)
 
 	mask &= display->mask;
 	if (mask == 0) {
-		fprintf(stderr,
+		wl_log(WL_LOG_WARNING,
 			"wl_display_iterate called with unsolicited flags");
 		return;
 	}
@@ -523,7 +524,7 @@ wl_display_iterate(struct wl_display *display, uint32_t mask)
 	}
 
 	if (len < 0) {
-		fprintf(stderr, "read error: %m\n");
+		wl_log(WL_LOG_ERROR, "read error: %m\n");
 		exit(EXIT_FAILURE);
 	}
 }
diff --git a/src/wayland-server.c b/src/wayland-server.c
index 70adf28..4d0c774 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -44,6 +44,7 @@
 #include "wayland-private.h"
 #include "wayland-server.h"
 #include "wayland-server-protocol.h"
+#include "wayland-log.h"
 
 struct wl_socket {
 	int fd;
@@ -799,11 +800,11 @@ socket_data(int fd, uint32_t mask, void *data)
 	if (client_fd < 0 && errno == ENOSYS) {
 		client_fd = accept(fd, (struct sockaddr *) &name, &length);
 		if (client_fd >= 0 && fcntl(client_fd, F_SETFD, FD_CLOEXEC) == -1)
-			fprintf(stderr, "failed to set FD_CLOEXEC flag on client fd, errno: %d\n", errno);
+			wl_log(WL_LOG_ERROR, "failed to set FD_CLOEXEC flag on client fd, errno: %d\n", errno);
 	}
 
 	if (client_fd < 0)
-		fprintf(stderr, "failed to accept, errno: %d\n", errno);
+		wl_log(WL_LOG_ERROR, "failed to accept, errno: %d\n", errno);
 
 	wl_client_create(display, client_fd);
 
@@ -823,14 +824,14 @@ get_socket_lock(struct wl_socket *socket, socklen_t name_size)
 			       (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP));
 
 	if (socket->fd_lock < 0) {
-		fprintf(stderr,
+		wl_log(WL_LOG_ERROR,
 			"unable to open lockfile %s check permissions\n",
 			socket->lock_addr);
 		return -1;
 	}
 
 	if (flock(socket->fd_lock, LOCK_EX | LOCK_NB) < 0) {
-		fprintf(stderr,
+		wl_log(WL_LOG_ERROR,
 			"unable to lock lockfile %s, maybe another compositor is running\n",
 			socket->lock_addr);
 		close(socket->fd_lock);
@@ -839,7 +840,7 @@ get_socket_lock(struct wl_socket *socket, socklen_t name_size)
 
 	if (stat(socket->addr.sun_path, &socket_stat) < 0 ) {
 		if (errno != ENOENT) {
-			fprintf(stderr, "did not manage to stat file %s\n",
+			wl_log(WL_LOG_ERROR, "did not manage to stat file %s\n",
 				socket->addr.sun_path);
 			close(socket->fd_lock);
 			return -1;
@@ -872,7 +873,7 @@ wl_display_add_socket(struct wl_display *display, const char *name)
 	runtime_dir = getenv("XDG_RUNTIME_DIR");
 	if (runtime_dir == NULL) {
 		runtime_dir = ".";
-		fprintf(stderr,
+		wl_log(WL_LOG_INFO,
 			"XDG_RUNTIME_DIR not set, falling back to %s\n",
 			runtime_dir);
 	}
@@ -886,7 +887,7 @@ wl_display_add_socket(struct wl_display *display, const char *name)
 	s->addr.sun_family = AF_LOCAL;
 	name_size = snprintf(s->addr.sun_path, sizeof s->addr.sun_path,
 			     "%s/%s", runtime_dir, name) + 1;
-	fprintf(stderr, "using socket %s\n", s->addr.sun_path);
+	wl_log(WL_LOG_INFO, "using socket %s\n", s->addr.sun_path);
 
 	if (get_socket_lock(s,name_size) < 0) {
 		close(s->fd);
-- 
1.7.5.4



More information about the wayland-devel mailing list