Commit graph

18 commits

Author SHA1 Message Date
Jaroslav Kysela
eefc2c61cf alsactl: use card iterator functions for all card loops
Take the card iterator idea from the monitor code and
use it for all card loops. It reduces the code duplications
and makes things easy to review.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-11 09:23:33 +01:00
Zev Weiss
5fe6b86659 alsactl: avoid needless wakeups in monitor loop.
The timeout wasn't really being used for anything; disabling it should
reduce idle energy consumption slightly.

Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Tested-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-04-14 15:34:00 +02:00
Zev Weiss
5830fc726a alsactl: don't exit on EINTR from epoll_wait().
Previously, things like attaching strace to a running 'alsactl monitor'
process would cause it to exit.

Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Tested-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-04-14 15:33:58 +02:00
Jaroslav Kysela
8c026b9562 alsactl: monitor - remove dead code in run_dispatcher() (coverity)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-03-13 14:46:33 +01:00
Takashi Sakamoto
46cb575b9b alsactl: use signalfd to catch UNIX signal
In a mode of 'monitor, event loop runs to dispatch asynchronous event
emitted by control node. In this case, UNIX signal is used to terminate
the event loop.

This commit uses signalfd to catch the UNIX signal.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2018-10-14 16:57:15 +02:00
Takashi Sakamoto
e57a0a0809 alsactl: handle detection of new sound card
At present, plug-and-play is not supported in a mode of 'monitor',
thus new sound card is not handled during runtime. This is not happy.

This commit uses Linux-specific inotify(7) to monitor '/dev/snd'
directory. When some files are newly added to the directory,
event dispatcher is suspended. Event sources are scanned again and the
dispatcher continue to run.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2018-10-14 16:57:15 +02:00
Takashi Sakamoto
440ea7d38d alsactl: handle disconnection of sound card
Once sound card becomes disconnection state, corresponding control node
becomes to emit error event for listeners. When catching this type of
event, event dispatcher should stop observation of the node. However,
at present, a mode of monitor can't handle this correctly. As a result,
poll(2) is executed quite frequently in loop with no wait. This results
100% consumption of CPU time.

This commit takes the dispatcher to remove the node from observation
list when detecting the disconnection state.

Reported-by: Thomas Gläßle <thomas@coldfix.de>
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2018-10-14 16:57:15 +02:00
Takashi Sakamoto
af14a2fab0 alsactl: obsolete array for maintenance of handlers
In former commits, handlers of control node are maintained by link list,
instead of one-dimensional array.

This commit obsoletes the array and split source preparation to a
function.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2018-10-14 16:57:15 +02:00
Takashi Sakamoto
89ab7146ba alsactl: use a list of source for event dispatcher instead of an array of source
In a previous commit, handlers of control nodes are maintained by link
list.

This commit uses the list to register/unregister event sources to
dispatcher.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2018-10-14 16:57:15 +02:00
Takashi Sakamoto
5e010366d3 alsactl: use link list to maintain source of events
At present, handlers for control nodes are maintained by one-dimensional
array. This is not necessarily useful to maintain handlers with
associated information.

This commit adds link-list for the maintenance.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2018-10-14 16:57:15 +02:00
Takashi Sakamoto
5c859fa649 alsactl: use epoll(7) instead of poll(2)
Linux kernel supports unique system call; epoll(7). This allows
applications to make associations for descriptor-unique data in a
easy way.

This commit uses epoll(7) instead of poll(2) for this point.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2018-10-14 16:57:15 +02:00
Takashi Sakamoto
fbc31a7593 alsactl: add an iterator of registered instances of sound card
In a mode of 'monitor', when given no argument, all of available control
node is observed for their events. At present, discovering the nodes is
done according to sound card number, instead of listing nodes in
configuration space of alsa-lib.

This commit adds a structure to discover sound cards with a simple
interface.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2018-10-14 16:57:15 +02:00
Takashi Sakamoto
0ef92b4ee7 alsactl: split event loop code to a function
In a mode of 'monitor', an event loop runs.

This commit applies a small refactoring to splits the loop into a
function for readability.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2018-10-14 16:57:15 +02:00
Jaroslav Kysela
b1e3d945b7 Change FSF address (Franklin Street)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2017-11-14 14:28:53 +01:00
Jaroslav Kysela
17d4a5dd35 monitor: fix clang warning - Declared variable-length array (VLA) has zero size 2014-09-24 10:50:54 +02:00
Takashi Iwai
5dfc232a9d alsactl: monitor all cards as default
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2013-11-26 14:27:30 +01:00
Takashi Iwai
bb3293c76e alsactl: Fix REMOVE event handling in monitor command
SND_CTL_EVENT_MASK_REMOVE has to be checked at first and ignore the
rest if it matches.  Suggested by Clemens.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2013-11-26 13:59:19 +01:00
Takashi Iwai
d2d9b6fc8d alsactl: Add monitor command
With monitor command, you can monitor the events received from the
given control device.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2013-11-26 11:45:34 +01:00