compositor/shared: Suppress write(2) warnings

Fixes the following warnings when building with _FORTIFY_SOURCE
and optimizations enabled:

../shared/xalloc.h:49:9: error: ignoring return value of ‘write’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
   49 |         write(STDERR_FILENO, oommsg, strlen(oommsg));
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

or
../compositor/main.c:427:25: error: ignoring return value of ‘write’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
  427 |                         write(STDERR_FILENO, fail_seteuid,
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  428 |                               strlen(fail_seteuid));
      |                               ~~~~~~~~~~~~~~~~~~~~~
../compositor/main.c:434:25: error: ignoring return value of ‘write’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
  434 |                         write(STDERR_FILENO, fail_cloexec,
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  435 |                               strlen(fail_cloexec));
      |                               ~~~~~~~~~~~~~~~~~~~~~
../compositor/main.c:442:25: error: ignoring return value of ‘write’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
  442 |                         write(STDERR_FILENO, fail_exec, strlen(fail_exec));
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
(cherry picked from commit 8c4cdd782e17aa587bfccb6746998571ddc90dd7)
dev
Marius Vlad 2 years ago
parent 715eb67cd8
commit 00a78294b1
  1. 8
      compositor/main.c
  2. 3
      compositor/xwayland.c
  3. 5
      shared/xalloc.h

@ -385,6 +385,7 @@ weston_client_launch(struct weston_compositor *compositor,
sigset_t allsigs; sigset_t allsigs;
pid_t pid; pid_t pid;
bool ret; bool ret;
size_t written __attribute__((unused));
weston_log("launching '%s'\n", path); weston_log("launching '%s'\n", path);
str_printf(&fail_exec, "Error: Couldn't launch client '%s'\n", path); str_printf(&fail_exec, "Error: Couldn't launch client '%s'\n", path);
@ -424,14 +425,14 @@ weston_client_launch(struct weston_compositor *compositor,
/* Launch clients as the user. Do not launch clients with wrong euid. */ /* Launch clients as the user. Do not launch clients with wrong euid. */
if (seteuid(getuid()) == -1) { if (seteuid(getuid()) == -1) {
write(STDERR_FILENO, fail_seteuid, written = write(STDERR_FILENO, fail_seteuid,
strlen(fail_seteuid)); strlen(fail_seteuid));
_exit(EXIT_FAILURE); _exit(EXIT_FAILURE);
} }
ret = fdstr_clear_cloexec_fd1(&wayland_socket); ret = fdstr_clear_cloexec_fd1(&wayland_socket);
if (!ret) { if (!ret) {
write(STDERR_FILENO, fail_cloexec, written = write(STDERR_FILENO, fail_cloexec,
strlen(fail_cloexec)); strlen(fail_cloexec));
_exit(EXIT_FAILURE); _exit(EXIT_FAILURE);
} }
@ -439,7 +440,8 @@ weston_client_launch(struct weston_compositor *compositor,
execve(argp[0], argp, envp); execve(argp[0], argp, envp);
if (fail_exec) if (fail_exec)
write(STDERR_FILENO, fail_exec, strlen(fail_exec)); written = write(STDERR_FILENO, fail_exec,
strlen(fail_exec));
_exit(EXIT_FAILURE); _exit(EXIT_FAILURE);
default: default:

@ -110,6 +110,7 @@ spawn_xserver(void *user_data, const char *display, int abstract_fd, int unix_fd
char *const *envp; char *const *envp;
char *const *argp; char *const *argp;
bool ret; bool ret;
size_t written __attribute__ ((unused));
if (os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0, wayland_socket.fds) < 0) { if (os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0, wayland_socket.fds) < 0) {
weston_log("wl connection socketpair failed\n"); weston_log("wl connection socketpair failed\n");
@ -174,7 +175,7 @@ spawn_xserver(void *user_data, const char *display, int abstract_fd, int unix_fd
/* execve does not return on success, so it failed */ /* execve does not return on success, so it failed */
if (exec_failure_msg) { if (exec_failure_msg) {
write(STDERR_FILENO, exec_failure_msg, written = write(STDERR_FILENO, exec_failure_msg,
strlen(exec_failure_msg)); strlen(exec_failure_msg));
} }

@ -40,13 +40,14 @@ static inline void *
abort_oom_if_null(void *p) abort_oom_if_null(void *p)
{ {
static const char oommsg[] = ": out of memory\n"; static const char oommsg[] = ": out of memory\n";
size_t written __attribute__((unused));
if (p) if (p)
return p; return p;
write(STDERR_FILENO, program_invocation_short_name, written = write(STDERR_FILENO, program_invocation_short_name,
strlen(program_invocation_short_name)); strlen(program_invocation_short_name));
write(STDERR_FILENO, oommsg, strlen(oommsg)); written = write(STDERR_FILENO, oommsg, strlen(oommsg));
abort(); abort();
} }

Loading…
Cancel
Save