]> git.alsa-project.org Git - alsa-lib.git/commit
pcm_file: retry write(2) on short writes in safe_write()
authorKrishnanand G <krishnanandgeetheswaran@gmail.com>
Fri, 21 Aug 2026 09:47:12 +0000 (15:17 +0530)
committerJaroslav Kysela <perex@perex.cz>
Mon, 30 Nov 2026 20:00:38 +0000 (21:00 +0100)
commitb00b8f7a5a8620a0ed327ff04fd06c9ce93eb407
treea62af3601befc670a53aa2f44bac2cd78bc82743
parentef4327849cfb49d8944ce36bd7ea5b207fa6b9d3
pcm_file: retry write(2) on short writes in safe_write()

write(2) on a pipe or FIFO can return fewer bytes than requested.
This happens when a blocking write gets interrupted by a signal
after part of the buffer already went through: the kernel hands
back the partial count instead of -EINTR. safe_write() treated any
non-negative return as complete and passed that short count
straight back to the caller.

snd_pcm_file_write_bytes() then saw err != n, broke out of its
write loop, and returned success anyway, so the unwritten tail of
the period never reached the target file.

Writes to a FIFO block waiting for a reader far more often than
writes to a regular file do, which is exactly why the file plugin
only drops samples on pipes and works fine on plain files.

Make safe_write() loop until every byte is written or a real error
turns up.

Closes: https://github.com/alsa-project/alsa-lib/pull/521
Fixes: https://github.com/alsa-project/alsa-lib/issues/63
Signed-off-by: Krishnanand G <krishnanandgeetheswaran@gmail.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
src/pcm/pcm_file.c