[PATCH] connection: Use wl_log to report errors

Kristian Høgsberg hoegsberg at gmail.com
Tue Feb 18 14:48:46 PST 2014


On Mon, Feb 17, 2014 at 07:04:28PM -0500, Jasper St. Pierre wrote:
> In some cases, like Xwayland, stdout and stderr are redirected to
> /dev/null, losing us valuable information, while wl_log can be
> overridden, allowing us to send it to a log file instead. This
> can help debugging immensely.
> ---

Yeah, I think that's fine, patch applied.

Kristian

>  src/connection.c | 36 ++++++++++++++++++------------------
>  1 file changed, 18 insertions(+), 18 deletions(-)
> 
> diff --git a/src/connection.c b/src/connection.c
> index d05341a..40a2182 100644
> --- a/src/connection.c
> +++ b/src/connection.c
> @@ -512,7 +512,7 @@ wl_closure_marshal(struct wl_object *sender, uint32_t opcode,
>  
>  	count = arg_count_for_signature(message->signature);
>  	if (count > WL_CLOSURE_MAX_ARGS) {
> -		printf("too many args (%d)\n", count);
> +		wl_log("too many args (%d)\n", count);
>  		errno = EINVAL;
>  		return NULL;
>  	}
> @@ -557,13 +557,13 @@ wl_closure_marshal(struct wl_object *sender, uint32_t opcode,
>  			fd = args[i].h;
>  			dup_fd = wl_os_dupfd_cloexec(fd, 0);
>  			if (dup_fd < 0) {
> -				fprintf(stderr, "dup failed: %m");
> +				wl_log("dup failed: %m");
>  				abort();
>  			}
>  			closure->args[i].h = dup_fd;
>  			break;
>  		default:
> -			fprintf(stderr, "unhandled format code: '%c'\n",
> +			wl_log("unhandled format code: '%c'\n",
>  				arg.type);
>  			assert(0);
>  			break;
> @@ -615,7 +615,7 @@ wl_connection_demarshal(struct wl_connection *connection,
>  
>  	count = arg_count_for_signature(message->signature);
>  	if (count > WL_CLOSURE_MAX_ARGS) {
> -		printf("too many args (%d)\n", count);
> +		wl_log("too many args (%d)\n", count);
>  		errno = EINVAL;
>  		wl_connection_consume(connection, size);
>  		return NULL;
> @@ -642,7 +642,7 @@ wl_connection_demarshal(struct wl_connection *connection,
>  		signature = get_next_argument(signature, &arg);
>  
>  		if (arg.type != 'h' && p + 1 > end) {
> -			printf("message too short, "
> +			wl_log("message too short, "
>  			       "object (%d), message %s(%s)\n",
>  			       *p, message->name, message->signature);
>  			errno = EINVAL;
> @@ -669,7 +669,7 @@ wl_connection_demarshal(struct wl_connection *connection,
>  
>  			next = p + DIV_ROUNDUP(length, sizeof *p);
>  			if (next > end) {
> -				printf("message too short, "
> +				wl_log("message too short, "
>  				       "object (%d), message %s(%s)\n",
>  				       closure->sender_id, message->name,
>  				       message->signature);
> @@ -680,7 +680,7 @@ wl_connection_demarshal(struct wl_connection *connection,
>  			s = (char *) p;
>  
>  			if (length > 0 && s[length - 1] != '\0') {
> -				printf("string not nul-terminated, "
> +				wl_log("string not nul-terminated, "
>  				       "message %s(%s)\n",
>  				       message->name, message->signature);
>  				errno = EINVAL;
> @@ -695,7 +695,7 @@ wl_connection_demarshal(struct wl_connection *connection,
>  			closure->args[i].n = id;
>  
>  			if (id == 0 && !arg.nullable) {
> -				printf("NULL object received on non-nullable "
> +				wl_log("NULL object received on non-nullable "
>  				       "type, message %s(%s)\n", message->name,
>  				       message->signature);
>  				errno = EINVAL;
> @@ -707,7 +707,7 @@ wl_connection_demarshal(struct wl_connection *connection,
>  			closure->args[i].n = id;
>  
>  			if (id == 0 && !arg.nullable) {
> -				printf("NULL new ID received on non-nullable "
> +				wl_log("NULL new ID received on non-nullable "
>  				       "type, message %s(%s)\n", message->name,
>  				       message->signature);
>  				errno = EINVAL;
> @@ -715,7 +715,7 @@ wl_connection_demarshal(struct wl_connection *connection,
>  			}
>  
>  			if (wl_map_reserve_new(objects, id) < 0) {
> -				printf("not a valid new object id (%d), "
> +				wl_log("not a valid new object id (%d), "
>  				       "message %s(%s)\n",
>  				       id, message->name, message->signature);
>  				errno = EINVAL;
> @@ -728,7 +728,7 @@ wl_connection_demarshal(struct wl_connection *connection,
>  
>  			next = p + DIV_ROUNDUP(length, sizeof *p);
>  			if (next > end) {
> -				printf("message too short, "
> +				wl_log("message too short, "
>  				       "object (%d), message %s(%s)\n",
>  				       closure->sender_id, message->name,
>  				       message->signature);
> @@ -745,7 +745,7 @@ wl_connection_demarshal(struct wl_connection *connection,
>  			break;
>  		case 'h':
>  			if (connection->fds_in.tail == connection->fds_in.head) {
> -				printf("file descriptor expected, "
> +				wl_log("file descriptor expected, "
>  				       "object (%d), message %s(%s)\n",
>  				       closure->sender_id, message->name,
>  				       message->signature);
> @@ -758,7 +758,7 @@ wl_connection_demarshal(struct wl_connection *connection,
>  			closure->args[i].h = fd;
>  			break;
>  		default:
> -			printf("unknown type\n");
> +			wl_log("unknown type\n");
>  			assert(0);
>  			break;
>  		}
> @@ -817,7 +817,7 @@ wl_closure_lookup_objects(struct wl_closure *closure, struct wl_map *objects)
>  				 * destroyed client side */
>  				object = NULL;
>  			} else if (object == NULL && id != 0) {
> -				printf("unknown object (%u), message %s(%s)\n",
> +				wl_log("unknown object (%u), message %s(%s)\n",
>  				       id, message->name, message->signature);
>  				object = NULL;
>  				errno = EINVAL;
> @@ -827,7 +827,7 @@ wl_closure_lookup_objects(struct wl_closure *closure, struct wl_map *objects)
>  			if (object != NULL && message->types[i] != NULL &&
>  			    !wl_interface_equal((object)->interface,
>  						message->types[i])) {
> -				printf("invalid object (%u), type (%s), "
> +				wl_log("invalid object (%u), type (%s), "
>  				       "message %s(%s)\n",
>  				       id, (object)->interface->name,
>  				       message->name, message->signature);
> @@ -893,7 +893,7 @@ convert_arguments_to_ffi(const char *signature, uint32_t flags,
>  			ffi_args[i] = &args[i].h;
>  			break;
>  		default:
> -			printf("unknown type\n");
> +			wl_log("unknown type\n");
>  			assert(0);
>  			break;
>  		}
> @@ -953,8 +953,8 @@ copy_fds_to_connection(struct wl_closure *closure,
>  
>  		fd = closure->args[i].h;
>  		if (wl_connection_put_fd(connection, fd)) {
> -			fprintf(stderr, "request could not be marshaled: "
> -				"can't send file descriptor");
> +			wl_log("request could not be marshaled: "
> +			       "can't send file descriptor");
>  			return -1;
>  		}
>  	}
> -- 
> 1.8.5.3
> 
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel


More information about the wayland-devel mailing list