From e78e97cb9954c251517627fae173c3a8d1ea96ce Mon Sep 17 00:00:00 2001 From: Jonas Holmberg Date: Mon, 19 Feb 2024 14:14:24 +0100 Subject: [PATCH] pipewire-alsa: Propagate errors from eventfd(). Propagate the error if spa_system_eventfd_create() fails. Also copy errno before calling spa_log_debug() in spa_system_eventfd_create() to make sure it is not overwritten. --- pipewire-alsa/alsa-plugins/ctl_pipewire.c | 4 ++-- pipewire-alsa/alsa-plugins/pcm_pipewire.c | 4 ++++ spa/plugins/support/system.c | 5 +++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pipewire-alsa/alsa-plugins/ctl_pipewire.c b/pipewire-alsa/alsa-plugins/ctl_pipewire.c index ea2d50674..76eed8461 100644 --- a/pipewire-alsa/alsa-plugins/ctl_pipewire.c +++ b/pipewire-alsa/alsa-plugins/ctl_pipewire.c @@ -1359,8 +1359,8 @@ SND_CTL_PLUGIN_DEFINE_FUNC(pipewire) ctl->system = loop->system; ctl->fd = spa_system_eventfd_create(ctl->system, SPA_FD_CLOEXEC | SPA_FD_NONBLOCK); - if (ctl->fd == -1) { - err = -errno; + if (ctl->fd < 0) { + err = ctl->fd; goto error; } diff --git a/pipewire-alsa/alsa-plugins/pcm_pipewire.c b/pipewire-alsa/alsa-plugins/pcm_pipewire.c index 84fc2d788..187248ab0 100644 --- a/pipewire-alsa/alsa-plugins/pcm_pipewire.c +++ b/pipewire-alsa/alsa-plugins/pcm_pipewire.c @@ -1260,6 +1260,10 @@ static int snd_pcm_pipewire_open(snd_pcm_t **pcmp, pw_thread_loop_unlock(pw->main_loop); pw->fd = spa_system_eventfd_create(pw->system, SPA_FD_CLOEXEC | SPA_FD_NONBLOCK); + if (pw->fd < 0) { + err = pw->fd; + goto error; + } pw->io.version = SND_PCM_IOPLUG_VERSION; pw->io.name = "ALSA <-> PipeWire PCM I/O Plugin"; diff --git a/spa/plugins/support/system.c b/spa/plugins/support/system.c index 12791ea03..767e0b43d 100644 --- a/spa/plugins/support/system.c +++ b/spa/plugins/support/system.c @@ -191,7 +191,7 @@ static int impl_timerfd_read(void *object, int fd, uint64_t *expirations) static int impl_eventfd_create(void *object, int flags) { struct impl *impl = object; - int fl = 0, res; + int fl = 0, res, err; if (flags & SPA_FD_CLOEXEC) fl |= EFD_CLOEXEC; if (flags & SPA_FD_NONBLOCK) @@ -199,8 +199,9 @@ static int impl_eventfd_create(void *object, int flags) if (flags & SPA_FD_EVENT_SEMAPHORE) fl |= EFD_SEMAPHORE; res = eventfd(0, fl); + err = -errno; /* save errno in case it is overwritten before return */ spa_log_debug(impl->log, "%p: new fd:%d", impl, res); - return res < 0 ? -errno : res; + return res < 0 ? err : res; } static int impl_eventfd_write(void *object, int fd, uint64_t count)