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
+4 -2
View File
@@ -100,7 +100,8 @@ bind_to_abstract_socket(int display)
"%c/tmp/.X11-unix/X%d", 0, display);
size = offsetof(struct sockaddr_un, sun_path) + name_size;
if (bind(fd, (struct sockaddr *) &addr, size) < 0) {
weston_log("failed to bind to @%s: %m\n", addr.sun_path + 1);
weston_log("failed to bind to @%s: %s\n", addr.sun_path + 1,
strerror(errno));
close(fd);
return -1;
}
@@ -130,7 +131,8 @@ bind_to_unix_socket(int display)
size = offsetof(struct sockaddr_un, sun_path) + name_size;
unlink(addr.sun_path);
if (bind(fd, (struct sockaddr *) &addr, size) < 0) {
weston_log("failed to bind to %s: %m\n", addr.sun_path);
weston_log("failed to bind to %s: %s\n", addr.sun_path,
strerror(errno));
close(fd);
return -1;
}
+5 -3
View File
@@ -30,6 +30,7 @@
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include "xwayland.h"
#include "shared/helpers.h"
@@ -59,7 +60,7 @@ writable_callback(int fd, uint32_t mask, void *data)
wl_event_source_remove(wm->property_source);
wm->property_source = NULL;
close(fd);
weston_log("write error to target fd: %m\n");
weston_log("write error to target fd: %s\n", strerror(errno));
return 1;
}
@@ -401,7 +402,8 @@ weston_wm_read_data_source(int fd, uint32_t mask, void *data)
len = read(fd, p, available);
if (len == -1) {
weston_log("read error from data source: %m\n");
weston_log("read error from data source: %s\n",
strerror(errno));
weston_wm_send_selection_notify(wm, XCB_ATOM_NONE);
if (wm->property_source)
wl_event_source_remove(wm->property_source);
@@ -494,7 +496,7 @@ weston_wm_send_data(struct weston_wm *wm, xcb_atom_t target, const char *mime_ty
int p[2];
if (pipe2(p, O_CLOEXEC | O_NONBLOCK) == -1) {
weston_log("pipe2 failed: %m\n");
weston_log("pipe2 failed: %s\n", strerror(errno));
weston_wm_send_selection_notify(wm, XCB_ATOM_NONE);
return;
}