diff options
author | emersion <contact@emersion.fr> | 2018-07-29 17:51:27 +0100 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2018-08-02 23:33:59 +0100 |
commit | c3afe4f42e3ddfbd51500d99416b51aee552b689 (patch) | |
tree | 8666ca733b965a50ac5ae6a892e62f48e1c207c8 | |
parent | bbd0fbe573bee16975eb30e7e680e50251a1b47b (diff) |
gamma-control-v1: improve error handling
-rw-r--r-- | types/wlr_gamma_control_v1.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/types/wlr_gamma_control_v1.c b/types/wlr_gamma_control_v1.c index 2163d356..54ab7e9d 100644 --- a/types/wlr_gamma_control_v1.c +++ b/types/wlr_gamma_control_v1.c @@ -67,22 +67,15 @@ static void gamma_control_handle_set_gamma(struct wl_client *client, uint32_t ramp_size = wlr_output_get_gamma_size(gamma_control->output); size_t table_size = ramp_size * 3 * sizeof(uint16_t); - off_t fd_size = lseek(fd, 0, SEEK_END); - // Skip checks if kernel does no support seek on buffer - if (fd_size != -1 && (size_t)fd_size != table_size) { - wl_resource_post_error(gamma_control_resource, - ZWLR_GAMMA_CONTROL_V1_ERROR_INVALID_GAMMA, - "The gamma ramps don't have the correct size"); - goto error_fd; - } - lseek(fd, 0, SEEK_SET); - + // Refuse to block when reading int fd_flags = fcntl(fd, F_GETFL, 0); if (fd_flags == -1) { + wlr_log_errno(WLR_ERROR, "failed to get FD flags"); gamma_control_send_failed(gamma_control); goto error_fd; } if (fcntl(fd, F_SETFL, fd_flags | O_NONBLOCK) == -1) { + wlr_log_errno(WLR_ERROR, "failed to set FD flags"); gamma_control_send_failed(gamma_control); goto error_fd; } @@ -95,9 +88,15 @@ static void gamma_control_handle_set_gamma(struct wl_client *client, } ssize_t n_read = read(fd, table, table_size); - if (n_read == -1 || (size_t)n_read != table_size) { + if (n_read < 0) { + wlr_log_errno(WLR_ERROR, "failed to read gamma table"); gamma_control_send_failed(gamma_control); goto error_table; + } else if ((size_t)n_read != table_size) { + wl_resource_post_error(gamma_control_resource, + ZWLR_GAMMA_CONTROL_V1_ERROR_INVALID_GAMMA, + "The gamma ramps don't have the correct size"); + goto error_table; } close(fd); fd = -1; |