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 Weston 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 Weston code
by using directly the string returned by strerror(errno).
While there, fix some minor indentation issue.

Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
This commit is contained in:
Antonio Borneo
2019-04-26 23:57:31 +02:00
parent 45d38856c8
commit 3957863667
49 changed files with 265 additions and 149 deletions
+27 -17
View File
@@ -665,7 +665,8 @@ drm_output_pageflip_timer_create(struct drm_output *output)
output);
if (output->pageflip_timer == NULL) {
weston_log("creating drm pageflip timer failed: %m\n");
weston_log("creating drm pageflip timer failed: %s\n",
strerror(errno));
return -1;
}
@@ -1083,7 +1084,7 @@ drm_fb_create_dumb(struct drm_backend *b, int width, int height,
fb->fd = b->drm.fd;
if (drm_fb_addfb(b, fb) != 0) {
weston_log("failed to create kms fb: %m\n");
weston_log("failed to create kms fb: %s\n", strerror(errno));
goto err_bo;
}
@@ -1333,7 +1334,8 @@ drm_fb_get_from_bo(struct gbm_bo *bo, struct drm_backend *backend,
if (drm_fb_addfb(backend, fb) != 0) {
if (type == BUFFER_GBM_SURFACE)
weston_log("failed to create kms fb: %m\n");
weston_log("failed to create kms fb: %s\n",
strerror(errno));
goto err_free;
}
@@ -2104,7 +2106,8 @@ drm_output_render_gl(struct drm_output_state *state, pixman_region32_t *damage)
bo = gbm_surface_lock_front_buffer(output->gbm_surface);
if (!bo) {
weston_log("failed to lock front buffer: %m\n");
weston_log("failed to lock front buffer: %s\n",
strerror(errno));
return NULL;
}
@@ -2228,7 +2231,7 @@ drm_output_set_gamma(struct weston_output *output_base,
output->crtc_id,
size, r, g, b);
if (rc)
weston_log("set gamma failed: %m\n");
weston_log("set gamma failed: %s\n", strerror(errno));
}
/* Determine the type of vblank synchronization to use for the output.
@@ -2302,20 +2305,23 @@ drm_output_apply_state_legacy(struct drm_output_state *state)
ret = drmModeSetPlane(backend->drm.fd, p->plane_id,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
if (ret)
weston_log("drmModeSetPlane failed disable: %m\n");
weston_log("drmModeSetPlane failed disable: %s\n",
strerror(errno));
}
if (output->cursor_plane) {
ret = drmModeSetCursor(backend->drm.fd, output->crtc_id,
0, 0, 0);
if (ret)
weston_log("drmModeSetCursor failed disable: %m\n");
weston_log("drmModeSetCursor failed disable: %s\n",
strerror(errno));
}
ret = drmModeSetCrtc(backend->drm.fd, output->crtc_id, 0, 0, 0,
NULL, 0, NULL);
if (ret)
weston_log("drmModeSetCrtc failed disabling: %m\n");
weston_log("drmModeSetCrtc failed disabling: %s\n",
strerror(errno));
drm_output_assign_state(state, DRM_STATE_APPLY_SYNC);
weston_compositor_read_presentation_clock(output->base.compositor, &now);
@@ -2356,7 +2362,7 @@ drm_output_apply_state_legacy(struct drm_output_state *state)
connectors, n_conn,
&mode->mode_info);
if (ret) {
weston_log("set mode failed: %m\n");
weston_log("set mode failed: %s\n", strerror(errno));
goto err;
}
}
@@ -2369,7 +2375,7 @@ drm_output_apply_state_legacy(struct drm_output_state *state)
if (drmModePageFlip(backend->drm.fd, output->crtc_id,
scanout_state->fb->fb_id,
DRM_MODE_PAGE_FLIP_EVENT, output) < 0) {
weston_log("queueing pageflip failed: %m\n");
weston_log("queueing pageflip failed: %s\n", strerror(errno));
goto err;
}
@@ -2529,7 +2535,8 @@ drm_mode_ensure_blob(struct drm_backend *backend, struct drm_mode *mode)
sizeof(mode->mode_info),
&mode->blob_id);
if (ret != 0)
weston_log("failed to create mode property blob: %m\n");
weston_log("failed to create mode property blob: %s\n",
strerror(errno));
drm_debug(backend, "\t\t\t[atomic] created new mode blob %lu for %s\n",
(unsigned long) mode->blob_id, mode->mode_info.name);
@@ -2828,7 +2835,8 @@ drm_pending_state_apply_atomic(struct drm_pending_state *pending_state,
}
if (ret != 0) {
weston_log("atomic: couldn't commit new state: %m\n");
weston_log("atomic: couldn't commit new state: %s\n",
strerror(errno));
goto out;
}
@@ -3104,7 +3112,8 @@ drm_output_start_repaint_loop(struct weston_output *output_base)
ret = drm_pending_state_apply(pending_state);
if (ret != 0) {
weston_log("applying repaint-start state failed: %m\n");
weston_log("applying repaint-start state failed: %s\n",
strerror(errno));
goto finish_frame;
}
@@ -3462,7 +3471,7 @@ cursor_bo_update(struct drm_plane_state *plane_state, struct weston_view *ev)
wl_shm_buffer_end_access(buffer->shm_buffer);
if (gbm_bo_write(bo, buf, sizeof buf) < 0)
weston_log("failed update cursor: %m\n");
weston_log("failed update cursor: %s\n", strerror(errno));
}
static struct drm_plane_state *
@@ -3608,7 +3617,8 @@ drm_output_set_cursor(struct drm_output_state *output_state)
handle = gbm_bo_get_handle(bo).s32;
if (drmModeSetCursor(b->drm.fd, output->crtc_id, handle,
b->cursor_width, b->cursor_height)) {
weston_log("failed to set cursor: %m\n");
weston_log("failed to set cursor: %s\n",
strerror(errno));
goto err;
}
}
@@ -3618,7 +3628,7 @@ drm_output_set_cursor(struct drm_output_state *output_state)
if (drmModeMoveCursor(b->drm.fd, output->crtc_id,
state->dest_x, state->dest_y)) {
weston_log("failed to move cursor: %m\n");
weston_log("failed to move cursor: %s\n", strerror(errno));
goto err;
}
@@ -7057,7 +7067,7 @@ recorder_frame_notify(struct wl_listener *listener, void *data)
ret = vaapi_recorder_frame(output->recorder, fd,
output->scanout_plane->state_cur->fb->strides[0]);
if (ret < 0) {
weston_log("[libva recorder] aborted: %m\n");
weston_log("[libva recorder] aborted: %s\n", strerror(errno));
recorder_destroy(output);
}
}
+10 -5
View File
@@ -34,6 +34,7 @@
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <sys/mman.h>
#include <linux/input.h>
@@ -302,20 +303,23 @@ wayland_output_get_shm_buffer(struct wayland_output *output)
fd = os_create_anonymous_file(height * stride);
if (fd < 0) {
weston_log("could not create an anonymous file buffer: %m\n");
weston_log("could not create an anonymous file buffer: %s\n",
strerror(errno));
return NULL;
}
data = mmap(NULL, height * stride, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (data == MAP_FAILED) {
weston_log("could not mmap %d memory for data: %m\n", height * stride);
weston_log("could not mmap %d memory for data: %s\n", height * stride,
strerror(errno));
close(fd);
return NULL;
}
sb = zalloc(sizeof *sb);
if (sb == NULL) {
weston_log("could not zalloc %zu memory for sb: %m\n", sizeof *sb);
weston_log("could not zalloc %zu memory for sb: %s\n", sizeof *sb,
strerror(errno));
close(fd);
munmap(data, height * stride);
return NULL;
@@ -1917,7 +1921,7 @@ input_handle_keymap(void *data, struct wl_keyboard *keyboard, uint32_t format,
if (format == WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) {
map_str = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
if (map_str == MAP_FAILED) {
weston_log("mmap failed: %m\n");
weston_log("mmap failed: %s\n", strerror(errno));
goto error;
}
@@ -2729,7 +2733,8 @@ wayland_backend_create(struct weston_compositor *compositor,
b->parent.wl_display = wl_display_connect(new_config->display_name);
if (b->parent.wl_display == NULL) {
weston_log("Error: Failed to connect to parent Wayland compositor: %m\n");
weston_log("Error: Failed to connect to parent Wayland compositor: %s\n",
strerror(errno));
weston_log_continue(STAMP_SPACE "display option: %s, WAYLAND_DISPLAY=%s\n",
new_config->display_name ?: "(none)",
getenv("WAYLAND_DISPLAY") ?: "(not set)");
+3 -2
View File
@@ -7020,8 +7020,9 @@ weston_compositor_read_presentation_clock(
if (!warned)
weston_log("Error: failure to read "
"the presentation clock %#x: '%m' (%d)\n",
compositor->presentation_clock, errno);
"the presentation clock %#x: '%s' (%d)\n",
compositor->presentation_clock,
strerror(errno), errno);
warned = true;
}
}
+4 -2
View File
@@ -37,6 +37,7 @@
#include <values.h>
#include <fcntl.h>
#include <limits.h>
#include <errno.h>
#include "shared/helpers.h"
#include "shared/os-compatibility.h"
@@ -2089,8 +2090,9 @@ weston_keyboard_send_keymap(struct weston_keyboard *kbd, struct wl_resource *res
fd = os_create_anonymous_file(xkb_info->keymap_size);
if (fd < 0) {
weston_log("creating a keymap file for %lu bytes failed: %m\n",
(unsigned long) xkb_info->keymap_size);
weston_log("creating a keymap file for %lu bytes failed: %s\n",
(unsigned long) xkb_info->keymap_size,
strerror(errno));
return;
}
+16 -8
View File
@@ -32,6 +32,7 @@
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <linux/vt.h>
@@ -129,14 +130,16 @@ setup_tty(struct launcher_direct *launcher, int tty)
if (tty == 0) {
launcher->tty = dup(tty);
if (launcher->tty == -1) {
weston_log("couldn't dup stdin: %m\n");
weston_log("couldn't dup stdin: %s\n",
strerror(errno));
return -1;
}
} else {
snprintf(tty_device, sizeof tty_device, "/dev/tty%d", tty);
launcher->tty = open(tty_device, O_RDWR | O_CLOEXEC);
if (launcher->tty == -1) {
weston_log("couldn't open tty %s: %m\n", tty_device);
weston_log("couldn't open tty %s: %s\n", tty_device,
strerror(errno));
return -1;
}
}
@@ -151,7 +154,7 @@ setup_tty(struct launcher_direct *launcher, int tty)
ret = ioctl(launcher->tty, KDGETMODE, &kd_mode);
if (ret) {
weston_log("failed to get VT mode: %m\n");
weston_log("failed to get VT mode: %s\n", strerror(errno));
return -1;
}
if (kd_mode != KD_TEXT) {
@@ -164,19 +167,22 @@ setup_tty(struct launcher_direct *launcher, int tty)
ioctl(launcher->tty, VT_WAITACTIVE, minor(buf.st_rdev));
if (ioctl(launcher->tty, KDGKBMODE, &launcher->kb_mode)) {
weston_log("failed to read keyboard mode: %m\n");
weston_log("failed to read keyboard mode: %s\n",
strerror(errno));
goto err_close;
}
if (ioctl(launcher->tty, KDSKBMUTE, 1) &&
ioctl(launcher->tty, KDSKBMODE, K_OFF)) {
weston_log("failed to set K_OFF keyboard mode: %m\n");
weston_log("failed to set K_OFF keyboard mode: %s\n",
strerror(errno));
goto err_close;
}
ret = ioctl(launcher->tty, KDSETMODE, KD_GRAPHICS);
if (ret) {
weston_log("failed to set KD_GRAPHICS mode on tty: %m\n");
weston_log("failed to set KD_GRAPHICS mode on tty: %s\n",
strerror(errno));
goto err_close;
}
@@ -255,10 +261,12 @@ launcher_direct_restore(struct weston_launcher *launcher_base)
if (ioctl(launcher->tty, KDSKBMUTE, 0) &&
ioctl(launcher->tty, KDSKBMODE, launcher->kb_mode))
weston_log("failed to restore kb mode: %m\n");
weston_log("failed to restore kb mode: %s\n",
strerror(errno));
if (ioctl(launcher->tty, KDSETMODE, KD_TEXT))
weston_log("failed to set KD_TEXT mode on tty: %m\n");
weston_log("failed to set KD_TEXT mode on tty: %s\n",
strerror(errno));
/* We have to drop master before we switch the VT back in
* VT_AUTO, so we don't risk switching to a VT with another
+1 -1
View File
@@ -225,7 +225,7 @@ launcher_logind_close(struct weston_launcher *launcher, int fd)
r = fstat(fd, &st);
close(fd);
if (r < 0) {
weston_log("logind: cannot fstat fd: %m\n");
weston_log("logind: cannot fstat fd: %s\n", strerror(errno));
return;
}
+4 -2
View File
@@ -169,10 +169,12 @@ launcher_weston_launch_restore(struct weston_launcher *launcher_base)
if (ioctl(launcher->tty, KDSKBMUTE, 0) &&
ioctl(launcher->tty, KDSKBMODE, launcher->kb_mode))
weston_log("failed to restore kb mode: %m\n");
weston_log("failed to restore kb mode: %s\n",
strerror(errno));
if (ioctl(launcher->tty, KDSETMODE, KD_TEXT))
weston_log("failed to set KD_TEXT mode on tty: %m\n");
weston_log("failed to set KD_TEXT mode on tty: %s\n",
strerror(errno));
/* We have to drop master before we switch the VT back in
* VT_AUTO, so we don't risk switching to a VT with another
+3 -1
View File
@@ -32,6 +32,7 @@
#include <linux/input.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <sys/uio.h>
#include <libweston/libweston.h>
@@ -431,7 +432,8 @@ weston_recorder_create(struct weston_output *output, const char *filename)
O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
if (recorder->fd < 0) {
weston_log("problem opening output file %s: %m\n", filename);
weston_log("problem opening output file %s: %s\n", filename,
strerror(errno));
goto err_recorder;
}
+10 -6
View File
@@ -128,7 +128,8 @@ read_groups(int *ngroups)
n = getgroups(0, NULL);
if (n < 0) {
fprintf(stderr, "Unable to retrieve groups: %m\n");
fprintf(stderr, "Unable to retrieve groups: %s\n",
strerror(errno));
return NULL;
}
@@ -137,7 +138,8 @@ read_groups(int *ngroups)
return NULL;
if (getgroups(n, groups) < 0) {
fprintf(stderr, "Unable to retrieve groups: %m\n");
fprintf(stderr, "Unable to retrieve groups: %s\n",
strerror(errno));
free(groups);
return NULL;
}
@@ -325,8 +327,8 @@ handle_open(struct weston_launch *wl, struct msghdr *msg, ssize_t len)
fd = open(message->path, message->flags);
if (fd < 0) {
fprintf(stderr, "Error opening device %s: %m\n",
message->path);
fprintf(stderr, "Error opening device %s: %s\n",
message->path, strerror(errno));
goto err0;
}
@@ -439,10 +441,12 @@ quit(struct weston_launch *wl, int status)
if (ioctl(wl->tty, KDSKBMUTE, 0) &&
ioctl(wl->tty, KDSKBMODE, wl->kb_mode))
fprintf(stderr, "failed to restore keyboard mode: %m\n");
fprintf(stderr, "failed to restore keyboard mode: %s\n",
strerror(errno));
if (ioctl(wl->tty, KDSETMODE, KD_TEXT))
fprintf(stderr, "failed to set KD_TEXT mode on tty: %m\n");
fprintf(stderr, "failed to set KD_TEXT mode on tty: %s\n",
strerror(errno));
/* We have to drop master before we switch the VT back in
* VT_AUTO, so we don't risk switching to a VT with another