Commit 294ed97e authored by Antonio Borneo's avatar Antonio Borneo

log: remove "%m" from format strings by using strerror(errno)

The printf() format specifier "%m" is a glibc extension to print
the string returned by strerror(errno). While supported by other
libraries (e.g. uClibc and musl), it is not widely portable.

In Wayland code the format string is often passed to a logging
function that calls other syscalls before the conversion of "%m"
takes place. If one of such syscall modifies the value in errno,
the conversion of "%m" will incorrectly report the error string
corresponding to the new value of errno.

Remove all the occurrences of the specifier "%m" in Wayland code
by using directly the string returned by strerror(errno).
Signed-off-by: Antonio Borneo's avatarAntonio Borneo <borneo.antonio@gmail.com>
parent 6db761d1
Pipeline #34693 passed with stage
in 1 minute and 36 seconds
......@@ -231,7 +231,7 @@ wl_event_source_timer_dispatch(struct wl_event_source *source,
len = read(source->fd, &expires, sizeof expires);
if (!(len == -1 && errno == EAGAIN) && len != sizeof expires)
/* Is there anything we can do here? Will this ever happen? */
wl_log("timerfd read error: %m\n");
wl_log("timerfd read error: %s\n", strerror(errno));
return timer_source->func(timer_source->base.data);
}
......@@ -325,7 +325,7 @@ wl_event_source_signal_dispatch(struct wl_event_source *source,
len = read(source->fd, &signal_info, sizeof signal_info);
if (!(len == -1 && errno == EAGAIN) && len != sizeof signal_info)
/* Is there anything we can do here? Will this ever happen? */
wl_log("signalfd read error: %m\n");
wl_log("signalfd read error: %s\n", strerror(errno));
return signal_source->func(signal_source->signal_number,
signal_source->base.data);
......
......@@ -2015,7 +2015,7 @@ int main(int argc, char *argv[])
buf = XML_GetBuffer(ctx.parser, XML_BUFFER_SIZE);
len = fread(buf, 1, XML_BUFFER_SIZE, input);
if (len < 0) {
fprintf(stderr, "fread: %m\n");
fprintf(stderr, "fread: %s\n", strerror(errno));
fclose(input);
exit(EXIT_FAILURE);
}
......
......@@ -1362,7 +1362,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)
wl_log("failed to accept: %m\n");
wl_log("failed to accept: %s\n", strerror(errno));
else
if (!wl_client_create(display, client_fd))
close(client_fd);
......@@ -1467,12 +1467,12 @@ _wl_display_add_socket(struct wl_display *display, struct wl_socket *s)
size = offsetof (struct sockaddr_un, sun_path) + strlen(s->addr.sun_path);
if (bind(s->fd, (struct sockaddr *) &s->addr, size) < 0) {
wl_log("bind() failed with error: %m\n");
wl_log("bind() failed with error: %s\n", strerror(errno));
return -1;
}
if (listen(s->fd, 128) < 0) {
wl_log("listen() failed with error: %m\n");
wl_log("listen() failed with error: %s\n", strerror(errno));
return -1;
}
......
......@@ -40,6 +40,7 @@
#include <assert.h>
#include <signal.h>
#include <pthread.h>
#include <errno.h>
#include "wayland-util.h"
#include "wayland-private.h"
......@@ -281,7 +282,8 @@ shm_create_pool(struct wl_client *client, struct wl_resource *resource,
if (pool->data == MAP_FAILED) {
wl_resource_post_error(resource,
WL_SHM_ERROR_INVALID_FD,
"failed mmap fd %d: %m", fd);
"failed mmap fd %d: %s", fd,
strerror(errno));
goto err_free;
}
close(fd);
......
......@@ -338,7 +338,8 @@ int main(int argc, char *argv[])
if (waitid(P_PID, pid, &info, WEXITED)) {
stderr_set_color(RED);
fprintf(stderr, "waitid failed: %m\n");
fprintf(stderr, "waitid failed: %s\n",
strerror(errno));
stderr_reset_color();
abort();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment