Commit 39578636 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 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's avatarAntonio Borneo <borneo.antonio@gmail.com>
parent 45d38856
Pipeline #34696 passed with stages
in 1 minute
......@@ -32,6 +32,7 @@
#include <math.h>
#include <assert.h>
#include <getopt.h>
#include <errno.h>
#include <linux/input.h>
#include <wayland-client.h>
......@@ -290,7 +291,8 @@ main(int argc, char *argv[])
display = display_create(&argc, argv);
if (display == NULL) {
fprintf(stderr, "failed to create display: %m\n");
fprintf(stderr, "failed to create display: %s\n",
strerror(errno));
return -1;
}
......
......@@ -34,6 +34,7 @@
#include <assert.h>
#include <unistd.h>
#include <time.h>
#include <errno.h>
#include <linux/input.h>
#include <wayland-client.h>
......@@ -328,7 +329,8 @@ main(int argc, char *argv[])
display = display_create(&argc, argv);
if (display == NULL) {
fprintf(stderr, "failed to create display: %m\n");
fprintf(stderr, "failed to create display: %s\n",
strerror(errno));
return -1;
}
......
......@@ -45,6 +45,7 @@
#include <cairo.h>
#include <float.h>
#include <assert.h>
#include <errno.h>
#include <linux/input.h>
#include <wayland-client.h>
......@@ -621,7 +622,8 @@ main(int argc, char *argv[])
d = display_create(&argc, argv);
if (d == NULL) {
fprintf(stderr, "failed to create display: %m\n");
fprintf(stderr, "failed to create display: %s\n",
strerror(errno));
return -1;
}
......
......@@ -34,6 +34,7 @@
#include <math.h>
#include <assert.h>
#include <unistd.h>
#include <errno.h>
#include <linux/input.h>
#include <wayland-client.h>
......@@ -490,7 +491,8 @@ main(int argc, char *argv[])
display = display_create(&argc, argv);
if (display == NULL) {
fprintf(stderr, "failed to create display: %m\n");
fprintf(stderr, "failed to create display: %s\n",
strerror(errno));
return -1;
}
......
......@@ -212,7 +212,7 @@ panel_launcher_activate(struct panel_launcher *widget)
pid = fork();
if (pid < 0) {
fprintf(stderr, "fork failed: %m\n");
fprintf(stderr, "fork failed: %s\n", strerror(errno));
return;
}
......@@ -225,7 +225,8 @@ panel_launcher_activate(struct panel_launcher *widget)
exit(EXIT_FAILURE);
if (execve(argv[0], argv, widget->envp.data) < 0) {
fprintf(stderr, "execl '%s' failed: %m\n", argv[0]);
fprintf(stderr, "execl '%s' failed: %s\n", argv[0],
strerror(errno));
exit(1);
}
}
......@@ -1519,7 +1520,8 @@ int main(int argc, char *argv[])
desktop.display = display_create(&argc, argv);
if (desktop.display == NULL) {
fprintf(stderr, "failed to create display: %m\n");
fprintf(stderr, "failed to create display: %s\n",
strerror(errno));
return -1;
}
......
......@@ -35,6 +35,7 @@
#include <cairo.h>
#include <sys/epoll.h>
#include <stdbool.h>
#include <errno.h>
#include <wayland-client.h>
#include <wayland-cursor.h>
......@@ -848,7 +849,8 @@ main(int argc, char *argv[])
d = display_create(&argc, argv);
if (d == NULL) {
fprintf(stderr, "failed to create display: %m\n");
fprintf(stderr, "failed to create display: %s\n",
strerror(errno));
return -1;
}
......
......@@ -580,7 +580,7 @@ data_source_send(void *data,
struct editor *editor = data;
if (write(fd, editor->selected_text, strlen(editor->selected_text) + 1) < 0)
fprintf(stderr, "write failed: %m\n");
fprintf(stderr, "write failed: %s\n", strerror(errno));
close(fd);
}
......@@ -1609,7 +1609,8 @@ main(int argc, char *argv[])
text_buffer = read_file(argv[1]);
if (text_buffer == NULL) {
fprintf(stderr, "could not read file '%s': %m\n", argv[1]);
fprintf(stderr, "could not read file '%s': %s\n",
argv[1], strerror(errno));
return -1;
}
}
......@@ -1618,7 +1619,8 @@ main(int argc, char *argv[])
editor.display = display_create(&argc, argv);
if (editor.display == NULL) {
fprintf(stderr, "failed to create display: %m\n");
fprintf(stderr, "failed to create display: %s\n",
strerror(errno));
free(text_buffer);
return -1;
}
......
......@@ -37,6 +37,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <errno.h>
#include <cairo.h>
......@@ -515,14 +517,16 @@ main(int argc, char *argv[])
/* Connect to the display and have the arguments parsed */
d = display_create(&argc, argv);
if (d == NULL) {
fprintf(stderr, "failed to create display: %m\n");
fprintf(stderr, "failed to create display: %s\n",
strerror(errno));
return -1;
}
/* Create new eventdemo window */
e = eventdemo_create(d);
if (e == NULL) {
fprintf(stderr, "failed to create eventdemo: %m\n");
fprintf(stderr, "failed to create eventdemo: %s\n",
strerror(errno));
return -1;
}
......
......@@ -30,6 +30,7 @@
#include <time.h>
#include <math.h>
#include <cairo.h>
#include <errno.h>
#include <sys/time.h>
#include <linux/input.h>
......@@ -172,7 +173,8 @@ int main(int argc, char *argv[])
d = display_create(&argc, argv);
if (d == NULL) {
fprintf(stderr, "failed to create display: %m\n");
fprintf(stderr, "failed to create display: %s\n",
strerror(errno));
return -1;
}
......
......@@ -30,6 +30,7 @@
#include <stdarg.h>
#include <string.h>
#include <math.h>
#include <errno.h>
#include <cairo.h>
#include <linux/input.h>
......@@ -518,7 +519,8 @@ int main(int argc, char *argv[])
d = display_create(&argc, argv);
if (d == NULL) {
fprintf(stderr, "failed to create display: %m\n");
fprintf(stderr, "failed to create display: %s\n",
strerror(errno));
return -1;
}
......
......@@ -30,6 +30,7 @@
#include <string.h>
#include <math.h>
#include <time.h>
#include <errno.h>
#include <GL/gl.h>
#include <EGL/egl.h>
......@@ -488,7 +489,8 @@ int main(int argc, char *argv[])
d = display_create(&argc, argv);
if (d == NULL) {
fprintf(stderr, "failed to create display: %m\n");
fprintf(stderr, "failed to create display: %s\n",
strerror(errno));
return -1;
}
gears = gears_create(d);
......
......@@ -36,6 +36,7 @@
#include <time.h>
#include <cairo.h>
#include <assert.h>
#include <errno.h>
#include <linux/input.h>
#include <wayland-client.h>
......@@ -419,7 +420,8 @@ main(int argc, char *argv[])
d = display_create(&argc, argv);
if (d == NULL) {
fprintf(stderr, "failed to create display: %m\n");
fprintf(stderr, "failed to create display: %s\n",
strerror(errno));
return -1;
}
......
......@@ -35,6 +35,7 @@
#include <signal.h>
#include <sys/mman.h>
#include <getopt.h>
#include <errno.h>
#include <wayland-cursor.h>
#include <wayland-client-protocol.h>
#include "shared/cairo-util.h"
......@@ -806,8 +807,8 @@ createShmBuffer(struct wlContextStruct *p_wlCtx)
fd = os_create_anonymous_file(size);
if (fd < 0) {
fprintf(stderr, "creating a buffer file for %d B failed: %m\n",
size);
fprintf(stderr, "creating a buffer file for %d B failed: %s\n",
size, strerror(errno));
return ;
}
......@@ -815,7 +816,7 @@ createShmBuffer(struct wlContextStruct *p_wlCtx)
mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (MAP_FAILED == p_wlCtx->data) {
fprintf(stderr, "mmap failed: %m\n");
fprintf(stderr, "mmap failed: %s\n", strerror(errno));
close(fd);
return;
}
......@@ -828,7 +829,8 @@ createShmBuffer(struct wlContextStruct *p_wlCtx)
WL_SHM_FORMAT_ARGB8888);
if (NULL == p_wlCtx->wlBuffer) {
fprintf(stderr, "wl_shm_create_buffer failed: %m\n");
fprintf(stderr, "wl_shm_create_buffer failed: %s\n",
strerror(errno));
close(fd);
return;
}
......
......@@ -29,6 +29,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <linux/input.h>
#include <cairo.h>
......@@ -1019,7 +1020,8 @@ main(int argc, char *argv[])
virtual_keyboard.display = display_create(&argc, argv);
if (virtual_keyboard.display == NULL) {
fprintf(stderr, "failed to create display: %m\n");
fprintf(stderr, "failed to create display: %s\n",
strerror(errno));
return -1;
}
......
......@@ -97,8 +97,8 @@ attach_buffer(struct window *window, int width, int height)
fd = os_create_anonymous_file(size);
if (fd < 0) {
fprintf(stderr, "creating a buffer file for %d B failed: %m\n",
size);
fprintf(stderr, "creating a buffer file for %d B failed: %s\n",
size, strerror(errno));
return -1;
}
......
......@@ -34,6 +34,7 @@
#include <sys/epoll.h>
#include <sys/socket.h>
#include <unistd.h>
#include <errno.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
......@@ -330,8 +331,8 @@ launch_client(struct nested *nested, const char *path)
if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sv) < 0) {
fprintf(stderr, "launch_client: "
"socketpair failed while launching '%s': %m\n",
path);
"socketpair failed while launching '%s': %s\n",
path, strerror(errno));
free(client);
return NULL;
}
......@@ -342,7 +343,8 @@ launch_client(struct nested *nested, const char *path)
close(sv[1]);
free(client);
fprintf(stderr, "launch_client: "
"fork failed while launching '%s': %m\n", path);
"fork failed while launching '%s': %s\n", path,
strerror(errno));
return NULL;
}
......@@ -354,7 +356,8 @@ launch_client(struct nested *nested, const char *path)
* get a non-CLOEXEC fd to pass through exec. */
clientfd = dup(sv[1]);
if (clientfd == -1) {
fprintf(stderr, "compositor: dup failed: %m\n");
fprintf(stderr, "compositor: dup failed: %s\n",
strerror(errno));
exit(-1);
}
......@@ -363,8 +366,8 @@ launch_client(struct nested *nested, const char *path)
execl(path, path, NULL);
fprintf(stderr, "compositor: executing '%s' failed: %m\n",
path);
fprintf(stderr, "compositor: executing '%s' failed: %s\n",
path, strerror(errno));
exit(-1);
}
......@@ -1116,7 +1119,8 @@ main(int argc, char *argv[])
display = display_create(&argc, argv);
if (display == NULL) {
fprintf(stderr, "failed to create display: %m\n");
fprintf(stderr, "failed to create display: %s\n",
strerror(errno));
return -1;
}
......
......@@ -35,6 +35,7 @@
#include <sys/mman.h>
#include <signal.h>
#include <time.h>
#include <errno.h>
#include <wayland-client.h>
#include "shared/helpers.h"
......@@ -141,14 +142,14 @@ create_shm_buffers(struct display *display, struct buffer **buffers,
fd = os_create_anonymous_file(size);
if (fd < 0) {
fprintf(stderr, "creating a buffer file for %d B failed: %m\n",
size);
fprintf(stderr, "creating a buffer file for %d B failed: %s\n",
size, strerror(errno));
return -1;
}
data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (data == MAP_FAILED) {
fprintf(stderr, "mmap failed: %m\n");
fprintf(stderr, "mmap failed: %s\n", strerror(errno));
close(fd);
return -1;
}
......@@ -480,7 +481,7 @@ window_emulate_rendering(struct window *window)
ret = nanosleep(&delay, NULL);
if (ret)
printf("nanosleep failed: %m\n");
printf("nanosleep failed: %s\n", strerror(errno));
}
static void
......
......@@ -31,6 +31,7 @@
#include <cairo.h>
#include <math.h>
#include <assert.h>
#include <errno.h>
#include <linux/input.h>
#include <wayland-client.h>
......@@ -439,7 +440,8 @@ main(int argc, char *argv[])
display = display_create(&argc, argv);
if (display == NULL) {
fprintf(stderr, "failed to create display: %m\n");
fprintf(stderr, "failed to create display: %s\n",
strerror(errno));
return -1;
}
......
......@@ -28,6 +28,7 @@
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <cairo.h>
#include <linux/input.h>
......@@ -288,7 +289,8 @@ main(int argc, char *argv[])
d = display_create(&argc, argv);
if (d == NULL) {
fprintf(stderr, "failed to create display: %m\n");
fprintf(stderr, "failed to create display: %s\n",
strerror(errno));
return -1;
}
......
......@@ -173,14 +173,14 @@ screenshot_create_shm_buffer(int width, int height, void **data_out,
fd = os_create_anonymous_file(size);
if (fd < 0) {
fprintf(stderr, "creating a buffer file for %d B failed: %m\n",
size);
fprintf(stderr, "creating a buffer file for %d B failed: %s\n",
size, strerror(errno));
return NULL;
}
data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (data == MAP_FAILED) {
fprintf(stderr, "mmap failed: %m\n");
fprintf(stderr, "mmap failed: %s\n", strerror(errno));
close(fd);
return NULL;
}
......@@ -286,7 +286,8 @@ int main(int argc, char *argv[])
display = wl_display_connect(NULL);
if (display == NULL) {
fprintf(stderr, "failed to create display: %m\n");
fprintf(stderr, "failed to create display: %s\n",
strerror(errno));
return -1;
}
......
......@@ -35,6 +35,7 @@
#include <sys/mman.h>
#include <sys/time.h>
#include <signal.h>
#include <errno.h>
#include <wayland-client.h>
#include "shared/os-compatibility.h"
......@@ -123,14 +124,14 @@ create_shm_buffer(struct display *display, struct buffer *buffer,
fd = os_create_anonymous_file(size);
if (fd < 0) {
fprintf(stderr, "creating a buffer file for %d B failed: %m\n",
size);
fprintf(stderr, "creating a buffer file for %d B failed: %s\n",
size, strerror(errno));
return -1;
}
data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (data == MAP_FAILED) {
fprintf(stderr, "mmap failed: %m\n");
fprintf(stderr, "mmap failed: %s\n", strerror(errno));
close(fd);
return -1;
}
......
......@@ -28,6 +28,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/mman.h>
#include <linux/input.h>
......@@ -490,7 +491,8 @@ main(int argc, char *argv[])
simple_im.display = wl_display_connect(NULL);
if (simple_im.display == NULL) {
fprintf(stderr, "Failed to connect to server: %m\n");
fprintf(stderr, "Failed to connect to server: %s\n",
strerror(errno));
return -1;
}
......@@ -516,7 +518,7 @@ main(int argc, char *argv[])
ret = wl_display_dispatch(simple_im.display);
if (ret == -1) {
fprintf(stderr, "Dispatch error: %m\n");
fprintf(stderr, "Dispatch error: %s\n", strerror(errno));
return -1;
}
......
......@@ -33,6 +33,7 @@
#include <unistd.h>
#include <sys/mman.h>
#include <signal.h>
#include <errno.h>
#include <wayland-client.h>
#include "shared/os-compatibility.h"
......@@ -98,14 +99,14 @@ create_shm_buffer(struct display *display, struct buffer *buffer,
fd = os_create_anonymous_file(size);
if (fd < 0) {
fprintf(stderr, "creating a buffer file for %d B failed: %m\n",
size);
fprintf(stderr, "creating a buffer file for %d B failed: %s\n",
size, strerror(errno));
return -1;
}
data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (data == MAP_FAILED) {
fprintf(stderr, "mmap failed: %m\n");
fprintf(stderr, "mmap failed: %s\n", strerror(errno));
close(fd);
return -1;
}
......
......@@ -31,6 +31,7 @@
#include <stdbool.h>
#include <assert.h>
#include <unistd.h>
#include <errno.h>
#include <sys/mman.h>
#include <wayland-client.h>
......@@ -70,15 +71,15 @@ create_shm_buffer(struct touch *touch)
fd = os_create_anonymous_file(size);
if (fd < 0) {
fprintf(stderr, "creating a buffer file for %d B failed: %m\n",
size);
fprintf(stderr, "creating a buffer file for %d B failed: %s\n",
size, strerror(errno));
exit(1);
}
touch->data =
mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (touch->data == MAP_FAILED) {
fprintf(stderr, "mmap failed: %m\n");
fprintf(stderr, "mmap failed: %s\n", strerror(errno));
close(fd);
exit(1);
}
......
......@@ -29,6 +29,7 @@
#include <string.h>
#include <time.h>
#include <math.h>
#include <errno.h>
#include <cairo.h>
#include <wayland-client.h>
......@@ -273,7 +274,8 @@ int main(int argc, char *argv[])
d = display_create(&argc, argv);
if (d == NULL) {
fprintf(stderr, "failed to create display: %m\n");
fprintf(stderr, "failed to create display: %s\n",
strerror(errno));
return -1;
}
......
......@@ -29,6 +29,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <errno.h>
#include <linux/input.h>
#include <cairo.h>
......@@ -290,7 +291,8 @@ main(int argc, char *argv[])
stacking.display = display_create(&argc, argv);
if (stacking.display == NULL) {
fprintf(stderr, "Failed to create display: %m\n");
fprintf(stderr, "Failed to create display: %s\n",
strerror(errno));
return -1;
}
......
......@@ -32,6 +32,7 @@
#include <cairo.h>
#include <math.h>
#include <assert.h>
#include <errno.h>
#include <linux/input.h>
#include <wayland-client.h>
......@@ -788,7 +789,8 @@ main(int argc, char *argv[])
display = display_create(&argc, argv);
if (display == NULL) {
fprintf(stderr, "failed to create display: %m\n");
fprintf(stderr, "failed to create display: %s\n",
strerror(errno));
return -1;
}
......
......@@ -3087,11 +3087,12 @@ terminal_run(struct terminal *terminal, const char *path)
setenv("TERM", option_term, 1);
setenv("COLORTERM", option_term, 1);
if (execl(path, path, NULL)) {
printf("exec failed: %m\n");
printf("exec failed: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
} else if (pid < 0) {
fprintf(stderr, "failed to fork and create pty (%m).\n");
fprintf(stderr, "failed to fork and create pty (%s).\n",
strerror(errno));
return -1;
}
......@@ -3158,7 +3159,8 @@ int main(int argc, char *argv[])
d = display_create(&argc, argv);
if (d == NULL) {
fprintf(stderr, "failed to create display: %m\n");
fprintf(stderr, "failed to create display: %s\n",
strerror(errno));
return -1;
}
......
......@@ -29,6 +29,7 @@
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <errno.h>
#include <cairo.h>
#include <linux/input.h>
......@@ -263,7 +264,8 @@ int main(int argc, char *argv[])
d = display_create(&argc, argv);
if (d == NULL) {
fprintf(stderr, "failed to create display: %m\n");
fprintf(stderr, "failed to create display: %s\n",
strerror(errno));
return -1;
}
......
......@@ -276,8 +276,8 @@ setup_out_fd(const char *output, const char *outfd)
O_WRONLY | O_APPEND | O_CREAT, 0644);
if (fd < 0) {
fprintf(stderr,
"Error: opening file '%s' failed: %m\n",
output);
"Error: opening file '%s' failed: %s\n",
output, strerror(errno));
}
return fd;
}
......@@ -290,7 +290,8 @@ setup_out_fd(const char *output, const char *outfd)
flags = fcntl(fd, F_GETFL);
if (flags == -1) {
fprintf(stderr,
"Error: cannot use file descriptor %d: %m\n", fd);
"Error: cannot use file descriptor %d: %s\n", fd,
strerror(errno));
return -1;
}
......@@ -432,7 +433,8 @@ main(int argc, char **argv)
app.dpy = wl_display_connect(NULL);
if (!app.dpy) {
fprintf(stderr, "Error: Could not connect to Wayland display: %m\n");
fprintf(stderr, "Error: Could not connect to Wayland display: %s\n",
strerror(errno));
ret = 1;
goto out_parse;
}
......
......@@ -1856,7 +1856,8 @@ main(int argc, char **argv)
info.display = wl_display_connect(NULL);
if (!info.display) {
fprintf(stderr, "failed to create display: %m\n");
fprintf(stderr, "failed to create display: %s\n",
strerror(errno));
return -1;
}
......
......@@ -740,14 +740,14 @@ make_shm_pool(struct display *display, int size, void **data)
fd = os_create_anonymous_file(size);
if (fd < 0) {
fprintf(stderr, "creating a buffer file for %d B failed: %m\n",
size);
fprintf(stderr, "creating a buffer file for %d B failed: %s\n",
size, strerror(errno));
return NULL;
}
*data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (*data == MAP_FAILED) {
fprintf(stderr, "mmap failed: %m\n");
fprintf(stderr, "mmap failed: %s\n", strerror(errno));
close(fd);
return NULL;
}
......@@ -6168,7 +6168,8 @@ display_create(int *argc, char *argv[])