From 2c4b574b8f9c6213399bfb58434b427459c04e3e Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 3 Nov 2022 17:34:00 +0100 Subject: [PATCH] v4l2: handle errors better Only store the eventfd when valid or else we will try to close an invalid fd. Keep the errno value around, just in case it gets overwritten by the free_file call. --- pipewire-v4l2/src/pipewire-v4l2.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pipewire-v4l2/src/pipewire-v4l2.c b/pipewire-v4l2/src/pipewire-v4l2.c index c2f5e1fe6..3d0160ed2 100644 --- a/pipewire-v4l2/src/pipewire-v4l2.c +++ b/pipewire-v4l2/src/pipewire-v4l2.c @@ -764,11 +764,13 @@ static int v4l2_openat(int dirfd, const char *path, int oflag, mode_t mode) } pw_thread_loop_unlock(file->loop); - res = file->fd = spa_system_eventfd_create(file->l->system, + res = spa_system_eventfd_create(file->l->system, SPA_FD_CLOEXEC | SPA_FD_NONBLOCK); if (res < 0) goto error; + file->fd = res; + pw_log_info("path:%s oflag:%d mode:%d -> %d (%s)", path, oflag, mode, res, strerror(res < 0 ? errno : 0)); @@ -780,11 +782,13 @@ static int v4l2_openat(int dirfd, const char *path, int oflag, mode_t mode) error_unlock: pw_thread_loop_unlock(file->loop); error: + res = -errno; if (file) free_file(file); pw_log_info("path:%s oflag:%d mode:%d -> %d (%s)", path, oflag, mode, - -1, strerror(errno)); + -1, spa_strerror(res)); + errno = -res; return -1; }