[PATCH 2/2] Wayland logging, replace printf by WL_PRINTF

Martin Minarik minarik11 at student.fiit.stuba.sk
Wed May 23 08:13:14 PDT 2012


WL_PRINTF(..) is macro to wl_log(..), takes the same
parameters as regular printf()
---
 src/connection.c     |   58 ++++++++++++++++++++++++-------------------------
 src/event-loop.c     |    8 +++---
 src/wayland-client.c |   20 +++++++---------
 src/wayland-server.c |   26 +++++++++++++---------
 4 files changed, 56 insertions(+), 56 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 5b7965e..fad59c0 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -278,8 +278,7 @@ wl_connection_data(struct wl_connection *connection, uint32_t mask)
 		if (len == -1 && errno == EPIPE) {
 			return -1;
 		} else if (len < 0) {
-			fprintf(stderr,
-				"write error for connection %p, fd %d: %m\n",
+			WL_PRINTF("write error for connection %p, fd %d: %m\n",
 				connection, connection->fd);
 			return -1;
 		}
@@ -312,8 +311,7 @@ wl_connection_data(struct wl_connection *connection, uint32_t mask)
 		} while (len < 0 && errno == EINTR);
 
 		if (len < 0) {
-			fprintf(stderr,
-				"read error from connection %p: %m (%d)\n",
+			WL_PRINTF("read error from connection %p: %m (%d)\n",
 				connection, errno);
 			return -1;
 		} else if (len == 0) {
@@ -529,13 +527,13 @@ wl_closure_vmarshal(struct wl_closure *closure,
 			fd = va_arg(ap, int);
 			dup_fd = wl_os_dupfd_cloexec(fd, 0);
 			if (dup_fd < 0) {
-				fprintf(stderr, "dup failed: %m");
+				WL_PRINTF("dup failed: %m");
 				abort();
 			}
 			*fd_ptr = dup_fd;
 			break;
 		default:
-			fprintf(stderr, "unhandled format code: '%c'\n",
+			WL_PRINTF("unhandled format code: '%c'\n",
 				message->signature[i - 2]);
 			assert(0);
 			break;
@@ -556,7 +554,7 @@ wl_closure_vmarshal(struct wl_closure *closure,
 	return 0;
 
 err:
-	printf("request too big to marshal, maximum size is %zu\n",
+	WL_PRINTF("request too big to marshal, maximum size is %zu\n",
 	       sizeof closure->buffer);
 	errno = ENOMEM;
 	return -1;
@@ -578,7 +576,7 @@ wl_connection_demarshal(struct wl_connection *connection,
 
 	count = strlen(message->signature) + 2;
 	if (count > ARRAY_LENGTH(closure->types)) {
-		printf("too many args (%d)\n", count);
+		WL_PRINTF("too many args (%d)\n", count);
 		errno = EINVAL;
 		wl_connection_consume(connection, size);
 		return -1;
@@ -586,7 +584,7 @@ wl_connection_demarshal(struct wl_connection *connection,
 
 	extra_space = wl_message_size_extra(message);
 	if (sizeof closure->buffer < size + extra_space) {
-		printf("request too big to demarshal, maximum %zu actual %d\n",
+		WL_PRINTF("request too big to demarshal, maximum %zu actual %d\n",
 		       sizeof closure->buffer, size + extra_space);
 		errno = ENOMEM;
 		wl_connection_consume(connection, size);
@@ -603,7 +601,7 @@ wl_connection_demarshal(struct wl_connection *connection,
 	extra = (char *) end;
 	for (i = 2; i < count; i++) {
 		if (p + 1 > end) {
-			printf("message too short, "
+			WL_PRINTF("message too short, "
 			       "object (%d), message %s(%s)\n",
 			       *p, message->name, message->signature);
 			errno = EINVAL;
@@ -629,7 +627,7 @@ wl_connection_demarshal(struct wl_connection *connection,
 
 			next = p + DIV_ROUNDUP(length, sizeof *p);
 			if (next > end) {
-				printf("message too short, "
+				WL_PRINTF("message too short, "
 				       "object (%d), message %s(%s)\n",
 				       *p, message->name, message->signature);
 				errno = EINVAL;
@@ -647,7 +645,7 @@ wl_connection_demarshal(struct wl_connection *connection,
 			}
 
 			if (length > 0 && (*s)[length - 1] != '\0') {
-				printf("string not nul-terminated, "
+				WL_PRINTF("string not nul-terminated, "
 				       "message %s(%s)\n",
 				       message->name, message->signature);
 				errno = EINVAL;
@@ -667,7 +665,7 @@ wl_connection_demarshal(struct wl_connection *connection,
 				 * destroyed client side */
 				*object = NULL;
 			} else if (*object == NULL && *p != 0) {
-				printf("unknown object (%d), message %s(%s)\n",
+				WL_PRINTF("unknown object (%d), message %s(%s)\n",
 				       *p, message->name, message->signature);
 				*object = NULL;
 				errno = EINVAL;
@@ -676,7 +674,7 @@ wl_connection_demarshal(struct wl_connection *connection,
 
 			if (*object != NULL && message->types[i-2] != NULL &&
 			    (*object)->interface != message->types[i-2]) {
-				printf("invalid object (%d), type (%s), "
+				WL_PRINTF("invalid object (%d), type (%s), "
 					"message %s(%s)\n",
 				       *p, (*object)->interface->name,
 				       message->name, message->signature);
@@ -691,7 +689,7 @@ wl_connection_demarshal(struct wl_connection *connection,
 			closure->args[i] = p;
 			object = wl_map_lookup(objects, *p);
 			if (object != NULL) {
-				printf("not a new object (%d), "
+				WL_PRINTF("not a new object (%d), "
 				       "message %s(%s)\n",
 				       *p, message->name, message->signature);
 				errno = EINVAL;
@@ -705,7 +703,7 @@ wl_connection_demarshal(struct wl_connection *connection,
 
 			next = p + DIV_ROUNDUP(length, sizeof *p);
 			if (next > end) {
-				printf("message too short, "
+				WL_PRINTF("message too short, "
 				       "object (%d), message %s(%s)\n",
 				       *p, message->name, message->signature);
 				errno = EINVAL;
@@ -735,7 +733,7 @@ wl_connection_demarshal(struct wl_connection *connection,
 			connection->fds_in.tail += sizeof *fd;
 			break;
 		default:
-			printf("unknown type\n");
+			WL_PRINTF("unknown type\n");
 			assert(0);
 			break;
 		}
@@ -785,7 +783,7 @@ copy_fds_to_connection(struct wl_closure *closure,
 
 		fd = closure->args[i];
 		if (wl_connection_put_fd(connection, *fd)) {
-			fprintf(stderr, "request could not be marshaled: "
+			WL_PRINTF("request could not be marshaled: "
 				"can't send file descriptor");
 			return -1;
 		}
@@ -832,7 +830,7 @@ wl_closure_print(struct wl_closure *closure, struct wl_object *target, int send)
 	clock_gettime(CLOCK_REALTIME, &tp);
 	time = (tp.tv_sec * 1000000L) + (tp.tv_nsec / 1000);
 
-	fprintf(stderr, "[%10.3f] %s%s@%u.%s(",
+	WL_PRINTF("[%10.3f] %s%s@%u.%s(",
 		time / 1000.0,
 		send ? " -> " : "",
 		target->interface->name, target->id,
@@ -840,45 +838,45 @@ wl_closure_print(struct wl_closure *closure, struct wl_object *target, int send)
 
 	for (i = 2; i < closure->count; i++) {
 		if (i > 2)
-			fprintf(stderr, ", ");
+			WL_PRINTF(", ");
 
 		value = closure->args[i];
 		switch (closure->message->signature[i - 2]) {
 		case 'u':
-			fprintf(stderr, "%u", value->uint32);
+			WL_PRINTF("%u", value->uint32);
 			break;
 		case 'i':
 			si = (int32_t) value->uint32;
-			fprintf(stderr, "%d", si);
+			WL_PRINTF("%d", si);
 			break;
 		case 'f':
 			si = (int32_t) value->uint32;
-			fprintf(stderr, "%f", wl_fixed_to_double(si));
+			WL_PRINTF("%f", wl_fixed_to_double(si));
 			break;
 		case 's':
-			fprintf(stderr, "\"%s\"", value->string);
+			WL_PRINTF("\"%s\"", value->string);
 			break;
 		case 'o':
 			if (value->object)
-				fprintf(stderr, "%s@%u",
+				WL_PRINTF("%s@%u",
 					value->object->interface->name,
 					value->object->id);
 			else
-				fprintf(stderr, "nil");
+				WL_PRINTF("nil");
 			break;
 		case 'n':
-			fprintf(stderr, "new id %u", value->uint32);
+			WL_PRINTF("new id %u", value->uint32);
 			break;
 		case 'a':
-			fprintf(stderr, "array");
+			WL_PRINTF("array");
 			break;
 		case 'h':
-			fprintf(stderr, "fd %d", value->uint32);
+			WL_PRINTF("fd %d", value->uint32);
 			break;
 		}
 	}
 
-	fprintf(stderr, ")\n");
+	WL_PRINTF(")\n");
 }
 
 void
diff --git a/src/event-loop.c b/src/event-loop.c
index a839daf..dc0e1f5 100644
--- a/src/event-loop.c
+++ b/src/event-loop.c
@@ -90,7 +90,7 @@ add_source(struct wl_event_loop *loop,
 	struct epoll_event ep;
 
 	if (source->fd < 0) {
-		fprintf(stderr, "could not add source\n: %m");
+		WL_PRINTF("could not add source\n: %m");
 		free(source);
 		return NULL;
 	}
@@ -168,7 +168,7 @@ wl_event_source_timer_dispatch(struct wl_event_source *source,
 	len = read(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_PRINTF("timerfd read error: %m\n");
 
 	return timer_source->func(timer_source->base.data);
 }
@@ -205,7 +205,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(source->fd, 0, &its, NULL) < 0) {
-		fprintf(stderr, "could not set timerfd\n: %m");
+		WL_PRINTF("could not set timerfd\n: %m");
 		return -1;
 	}
 
@@ -230,7 +230,7 @@ wl_event_source_signal_dispatch(struct wl_event_source *source,
 	len = read(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_PRINTF("signalfd read error: %m\n");
 
 	return signal_source->func(signal_source->signal_number,
 				   signal_source->base.data);
diff --git a/src/wayland-client.c b/src/wayland-client.c
index ecedd99..92e627f 100644
--- a/src/wayland-client.c
+++ b/src/wayland-client.c
@@ -177,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_PRINTF("proxy already has listener\n");
 		return -1;
 	}
 
@@ -200,12 +200,12 @@ wl_proxy_marshal(struct wl_proxy *proxy, uint32_t opcode, ...)
 	va_end(ap);
 
 	if (ret) {
-		fprintf(stderr, "Error marshalling request\n");
+		WL_PRINTF("Error marshalling request\n");
 		abort();
 	}
 
 	if (wl_closure_send(&closure, proxy->display->connection)) {
-		fprintf(stderr, "Error sending request: %m\n");
+		WL_PRINTF("Error sending request: %m\n");
 		abort();
 	}
 
@@ -236,7 +236,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_PRINTF("%s@%d: error %d: %s\n",
 		object->interface->name, object->id, code, message);
 	abort();
 }
@@ -288,7 +288,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_PRINTF("server sent delete_id for live object\n");
 	else
 		wl_map_remove(&display->objects, id);
 }
@@ -315,8 +315,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,
-			"XDG_RUNTIME_DIR not set, falling back to %s\n",
+		WL_PRINTF("XDG_RUNTIME_DIR not set, falling back to %s\n",
 			runtime_dir);
 	}
 
@@ -484,7 +483,7 @@ handle_event(struct wl_display *display,
 				      size, &display->objects, message);
 
 	if (ret) {
-		fprintf(stderr, "Error demarshalling event\n");
+		WL_PRINTF("Error demarshalling event\n");
 		abort();
 	}
 
@@ -506,8 +505,7 @@ wl_display_iterate(struct wl_display *display, uint32_t mask)
 
 	mask &= display->mask;
 	if (mask == 0) {
-		fprintf(stderr,
-			"wl_display_iterate called with unsolicited flags");
+		WL_PRINTF("wl_display_iterate called with unsolicited flags");
 		return;
 	}
 
@@ -529,7 +527,7 @@ wl_display_iterate(struct wl_display *display, uint32_t mask)
 	}
 
 	if (len < 0) {
-		fprintf(stderr, "read error: %m\n");
+		WL_PRINTF("read error: %m\n");
 		exit(EXIT_FAILURE);
 	}
 }
diff --git a/src/wayland-server.c b/src/wayland-server.c
index 9f07b88..a9d964d 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -437,7 +437,7 @@ wl_client_destroy(struct wl_client *client)
 {
 	uint32_t serial = 0;
 	
-	printf("disconnect from client %p\n", client);
+	WL_PRINTF("disconnect from client %p\n", client);
 
 	wl_signal_emit(&client->destroy_signal, client);
 
@@ -881,11 +881,14 @@ wl_display_create(void)
 		wl_debug = 1;
 
 	display = malloc(sizeof *display);
-	if (display == NULL)
+	if (display == NULL) {
+		WL_PRINTF("Malloc failed");
 		return NULL;
+	}
 
 	display->loop = wl_event_loop_create();
 	if (display->loop == NULL) {
+		WL_PRINTF("Event loop create failed");
 		free(display);
 		return NULL;
 	}
@@ -899,6 +902,7 @@ wl_display_create(void)
 
 	if (!wl_display_add_global(display, &wl_display_interface, 
 				   display, bind_display)) {
+		WL_PRINTF("Display add global failed");
 		wl_event_loop_destroy(display->loop);
 		free(display);
 		return NULL;
@@ -938,8 +942,10 @@ wl_display_add_global(struct wl_display *display,
 	struct wl_client *client;
 
 	global = malloc(sizeof *global);
-	if (global == NULL)
+	if (global == NULL) {
+		WL_PRINTF("Malloc failed");
 		return NULL;
+	}
 
 	global->name = display->id++;
 	global->interface = interface;
@@ -1016,7 +1022,7 @@ socket_data(int fd, uint32_t mask, void *data)
 	client_fd = wl_os_accept_cloexec(fd, (struct sockaddr *) &name,
 					 &length);
 	if (client_fd < 0)
-		fprintf(stderr, "failed to accept, errno: %d\n", errno);
+		WL_PRINTF("failed to accept, errno: %d\n", errno);
 	else
 		wl_client_create(display, client_fd);
 
@@ -1036,14 +1042,13 @@ 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,
-			"unable to open lockfile %s check permissions\n",
+		WL_PRINTF("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_PRINTF(
 			"unable to lock lockfile %s, maybe another compositor is running\n",
 			socket->lock_addr);
 		close(socket->fd_lock);
@@ -1052,7 +1057,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_PRINTF("did not manage to stat file %s\n",
 				socket->addr.sun_path);
 			close(socket->fd_lock);
 			return -1;
@@ -1085,8 +1090,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,
-			"XDG_RUNTIME_DIR not set, falling back to %s\n",
+		WL_PRINTF("XDG_RUNTIME_DIR not set, falling back to %s\n",
 			runtime_dir);
 	}
 
@@ -1099,7 +1103,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_PRINTF("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