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
+5 -3
View File
@@ -33,6 +33,7 @@
#include <string.h>
#include <assert.h>
#include <limits.h>
#include <errno.h>
#include <libweston/libweston.h>
#include "compositor/weston.h"
@@ -198,7 +199,8 @@ idle_launch_client(void *data)
pid = fork();
if (pid == -1) {
weston_log("fatal: failed to fork '%s': %m\n", launcher->exe);
weston_log("fatal: failed to fork '%s': %s\n", launcher->exe,
strerror(errno));
weston_compositor_exit_with_code(launcher->compositor,
EXIT_FAILURE);
return;
@@ -208,8 +210,8 @@ idle_launch_client(void *data)
sigfillset(&allsigs);
sigprocmask(SIG_UNBLOCK, &allsigs, NULL);
execl(launcher->exe, launcher->exe, NULL);
weston_log("compositor: executing '%s' failed: %m\n",
launcher->exe);
weston_log("compositor: executing '%s' failed: %s\n",
launcher->exe, strerror(errno));
_exit(EXIT_FAILURE);
}
+1 -1
View File
@@ -104,7 +104,7 @@ exec_and_report_test(const struct weston_test *t, void *test_data, int iteration
run_test(t, test_data, iteration); /* never returns */
if (waitid(P_ALL, 0, &info, WEXITED)) {
fprintf(stderr, "waitid failed: %m\n");
fprintf(stderr, "waitid failed: %s\n", strerror(errno));
abort();
}
+3 -1
View File
@@ -31,6 +31,7 @@
#include <signal.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <libweston/libweston.h>
#include "compositor/weston.h"
@@ -649,7 +650,8 @@ idle_launch_client(void *data)
sigfillset(&allsigs);
sigprocmask(SIG_UNBLOCK, &allsigs, NULL);
execl(path, path, NULL);
weston_log("compositor: executing '%s' failed: %m\n", path);
weston_log("compositor: executing '%s' failed: %s\n", path,
strerror(errno));
exit(EXIT_FAILURE);
}