Skip to contentSkip to conversation

Unhandled asynchronous SIGIO

DISCUSSION GitHub issues - opened 1 participant 1 message Apr 23, 2024 1 message not in the archive

lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive

alsa-project/alsa-lib issue #394 was opened from jansenmd:

When using libasound.so on embedded systems, I've come across several instances where an unhandled SIGIO is detected. This can occur when closing a hardware microphone device that was set up to use asynchronous calls backs via snd_async_add_pcm_handler.

Example: when opening a hardware device with asynchronous callbacks:

* Sets up a signal handler for SIGIO via sigaction.
* Enable generation of signals from the fd by setting the O_ASYNC flag: fcntl(fd, F_SETFL, flags | O_ASYNC)
* Sets the signal to be generated: fcntl(fd, F_SETSIG, (long)SIGIO)

Now, when data is available to be read from the fd, SIGIO should be generated and handled by the signal handler set in sigaction. That appears to work fine.

The current teardown process looks like this:

* Clear/reset the signal handler via sigaction.
* Disable generation of signals from the fd by clearing the O_ASYNC flag: fcntl(fd, F_SETFL, flags & ~O_ASYNC)
* Close the fd.

This teardown process seems to set up a race condition where an unhandled SIGIO can be generated between unregistering the signal handler and actually stopping any more signals from occurring. Since the default action for SIGIO is termination, this can cause an application to unexpectedly terminate.

Issue URL : https://github.com/alsa-project/alsa-lib/issues/394
Repository URL: https://github.com/alsa-project/alsa-lib