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
+14 -10
View File
@@ -365,7 +365,7 @@ sigchld_handler(int signal_number, void *data)
}
if (pid < 0 && errno != ECHILD)
weston_log("waitpid error %m\n");
weston_log("waitpid error %s\n", strerror(errno));
return 1;
}
@@ -391,7 +391,7 @@ child_client_exec(int sockfd, const char *path)
* non-CLOEXEC fd to pass through exec. */
clientfd = dup(sockfd);
if (clientfd == -1) {
weston_log("compositor: dup failed: %m\n");
weston_log("compositor: dup failed: %s\n", strerror(errno));
return;
}
@@ -399,8 +399,8 @@ child_client_exec(int sockfd, const char *path)
setenv("WAYLAND_SOCKET", s, 1);
if (execl(path, path, NULL) < 0)
weston_log("compositor: executing '%s' failed: %m\n",
path);
weston_log("compositor: executing '%s' failed: %s\n",
path, strerror(errno));
}
WL_EXPORT struct wl_client *
@@ -417,8 +417,8 @@ weston_client_launch(struct weston_compositor *compositor,
if (os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0, sv) < 0) {
weston_log("weston_client_launch: "
"socketpair failed while launching '%s': %m\n",
path);
"socketpair failed while launching '%s': %s\n",
path, strerror(errno));
return NULL;
}
@@ -427,7 +427,8 @@ weston_client_launch(struct weston_compositor *compositor,
close(sv[0]);
close(sv[1]);
weston_log("weston_client_launch: "
"fork failed while launching '%s': %m\n", path);
"fork failed while launching '%s': %s\n", path,
strerror(errno));
return NULL;
}
@@ -812,13 +813,15 @@ weston_create_listening_socket(struct wl_display *display, const char *socket_na
{
if (socket_name) {
if (wl_display_add_socket(display, socket_name)) {
weston_log("fatal: failed to add socket: %m\n");
weston_log("fatal: failed to add socket: %s\n",
strerror(errno));
return -1;
}
} else {
socket_name = wl_display_add_socket_auto(display);
if (!socket_name) {
weston_log("fatal: failed to add socket: %m\n");
weston_log("fatal: failed to add socket: %s\n",
strerror(errno));
return -1;
}
}
@@ -3083,7 +3086,8 @@ int main(int argc, char *argv[])
if (fd != -1) {
primary_client = wl_client_create(display, fd);
if (!primary_client) {
weston_log("fatal: failed to add client: %m\n");
weston_log("fatal: failed to add client: %s\n",
strerror(errno));
goto out;
}
primary_client_destroyed.notify =
+16 -11
View File
@@ -207,7 +207,7 @@ ss_seat_handle_keymap(void *data, struct wl_keyboard *wl_keyboard,
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;
}
@@ -462,13 +462,13 @@ shared_output_get_shm_buffer(struct shared_output *so)
fd = os_create_anonymous_file(height * stride);
if (fd < 0) {
weston_log("os_create_anonymous_file: %m\n");
weston_log("os_create_anonymous_file: %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("mmap: %m\n");
weston_log("mmap: %s\n", strerror(errno));
goto out_close;
}
@@ -940,7 +940,7 @@ shared_output_create(struct weston_output *output, int parent_fd)
so->parent.surface =
wl_compositor_create_surface(so->parent.compositor);
if (!so->parent.surface) {
weston_log("Screen share failed: %m\n");
weston_log("Screen share failed: %s\n", strerror(errno));
goto err_display;
}
@@ -950,7 +950,7 @@ shared_output_create(struct weston_output *output, int parent_fd)
so->parent.output,
output->current_mode->refresh);
if (!so->parent.mode_feedback) {
weston_log("Screen share failed: %m\n");
weston_log("Screen share failed: %s\n", strerror(errno));
goto err_display;
}
zwp_fullscreen_shell_mode_feedback_v1_add_listener(so->parent.mode_feedback,
@@ -964,7 +964,7 @@ shared_output_create(struct weston_output *output, int parent_fd)
wl_event_loop_add_fd(loop, epoll_fd, WL_EVENT_READABLE,
shared_output_handle_event, so);
if (!so->event_source) {
weston_log("Screen share failed: %m\n");
weston_log("Screen share failed: %s\n", strerror(errno));
goto err_display;
}
@@ -1033,7 +1033,8 @@ weston_output_share(struct weston_output *output, const char* command)
};
if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sv) < 0) {
weston_log("weston_output_share: socketpair failed: %m\n");
weston_log("weston_output_share: socketpair failed: %s\n",
strerror(errno));
return NULL;
}
@@ -1042,7 +1043,8 @@ weston_output_share(struct weston_output *output, const char* command)
if (pid == -1) {
close(sv[0]);
close(sv[1]);
weston_log("weston_output_share: fork failed: %m\n");
weston_log("weston_output_share: fork failed: %s\n",
strerror(errno));
return NULL;
}
@@ -1054,13 +1056,15 @@ weston_output_share(struct weston_output *output, const char* command)
/* Launch clients as the user. Do not launch clients with
* wrong euid. */
if (seteuid(getuid()) == -1) {
weston_log("weston_output_share: setuid failed: %m\n");
weston_log("weston_output_share: setuid failed: %s\n",
strerror(errno));
abort();
}
sv[1] = dup(sv[1]);
if (sv[1] == -1) {
weston_log("weston_output_share: dup failed: %m\n");
weston_log("weston_output_share: dup failed: %s\n",
strerror(errno));
abort();
}
@@ -1068,7 +1072,8 @@ weston_output_share(struct weston_output *output, const char* command)
setenv("WAYLAND_SERVER_SOCKET", str, 1);
execv(argv[0], argv);
weston_log("weston_output_share: exec failed: %m\n");
weston_log("weston_output_share: exec failed: %s\n",
strerror(errno));
abort();
} else {
close(sv[1]);
+5 -2
View File
@@ -27,6 +27,8 @@
#include "config.h"
#include <signal.h>
#include <string.h>
#include <errno.h>
#include <sys/socket.h>
#include <libweston/libweston.h>
@@ -128,9 +130,10 @@ spawn_xserver(void *user_data, const char *display, int abstract_fd, int unix_fd
NULL) < 0)
weston_log("exec of '%s %s -rootless "
"-listen %s -listen %s -wm %s "
"-terminate' failed: %m\n",
"-terminate' failed: %s\n",
xserver, display,
abstract_fd_str, unix_fd_str, wm_fd_str);
abstract_fd_str, unix_fd_str, wm_fd_str,
strerror(errno));
fail:
_exit(EXIT_FAILURE);