Commit graph

305 commits

Author SHA1 Message Date
Jaroslav Kysela
2bc595e7bd alsactl: check for error values from snd_config_get...()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-06-04 10:04:00 +02:00
Jaroslav Kysela
511dd7a597 alsactl: init() - return error value from snd_card_iterator_sinit() call
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-06-04 09:56:20 +02:00
Jaroslav Kysela
d6d566a9ee alsactl: return error value in dump_config_tree()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-06-04 09:53:56 +02:00
Jaroslav Kysela
78212445de alsactl: fix the nested iteration
There may be nested iterations for hw: card names.
Handle this card name in snd_card_iterator_sinit().

BugLink: https://github.com/alsa-project/alsa-lib/issues/142
Fixes: eefc2c6 ("alsactl: use card iterator functions for all card loops")
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-06-01 17:49:27 +02:00
Jaroslav Kysela
0fe5048a30 alsactl: ucm - try both fixed boot and boot sequences
The -ENOENT error means that there's no special configuration.
Try to fall-back to the legacy config.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-13 19:19:01 +02:00
Jaroslav Kysela
a589d88862 alsactl: clean the boot / hotplug card specific configuration directory
The /var/lib/alsa/card<NUMBER>.conf.d directories should be emptied
when the card is initialized. Implement this functionality directly
to alsactl.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-13 11:16:09 +02:00
Jaroslav Kysela
2c753a85a7 alsactl: snd_ctl_elem_id_compare was renamed to snd_ctl_elem_id_compare_set
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-23 17:52:13 +01:00
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
Jaroslav Kysela
9a2115b5cc alsactl: Add ucm support for the FixedBootSequence
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-11 09:23:31 +01:00
Jaroslav Kysela
7f5622c106 alsactl: fix possible memory leak for dump-cfg
Also remove extra snd_config_update_free_global() call for dump-state.
There's a global call in the main() function.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-10 18:13:16 +01:00
Jaroslav Kysela
c3f2344b72 alsactl: add 'clean' cmd to help, improve man page
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-07 20:18:12 +01:00
Jaroslav Kysela
b137145a92 alsactl: fix the compiler warning (uninitialized variable res)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-07 20:00:24 +01:00
Jaroslav Kysela
c1474594dc alsactl: add dump-cfg and dump-state commands
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-07 19:58:33 +01:00
MichaIng
09c04f8935 alsactl: init command now honors -g flag as well
BugLink: https://github.com/alsa-project/alsa-utils/issues/75
Signed-off-by: MichaIng <micha@dietpi.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-07 18:48:35 +01:00
Jaroslav Kysela
65453da000 alsactl: honor ignore_nocards flag in init()
BugLink: https://github.com/alsa-project/alsa-utils/issues/75
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-06 12:40:57 +01:00
Jaroslav Kysela
ade71cf8b0 alsactl: fix some compiler warnings
BugLink: https://github.com/alsa-project/alsa-utils/issues/17
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-05 21:43:47 +01:00
Jaroslav Kysela
17b4129e6c alsactl: add 'clean' command to remove the application controls
It is handy to remove all card controls created by applications.

This change allows to remove those controls for all cards, selected
card or selected card with a control id filter list like:

   alsactl clean 0 "name='PCM'" "name='Mic Phantom'"

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-04 21:15:56 +01:00
Jaroslav Kysela
c5ecfd9789 alsactl: init - parse() - fix possible double free
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-01-08 18:18:53 +01:00
Jaroslav Kysela
e55534d8a5 alsactl: init - set_ctl_value() - fix bytes parsing
Use the correct error value handling from hextodigit().

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-01-08 18:16:14 +01:00
Jaroslav Kysela
42ca978078 alsactl: daemon - read_pid_file() fix the returned code on read error
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-01-08 18:09:14 +01:00
Takashi Iwai
12487b40b6 alsactl: Remove asound.state file check from alsa-restore.service again
We added the check of asound.state file presence some time ago to
assure that alsactl gets called only if the state file is already
present.  Since then, the situation has changed significantly:
e.g. now alsactl does initialize if the state file isn't present, and
the same alsa-restore.service is used to save the state.  This means
that we should start this service no matter the state file exists at
the boot time or not.  So, revert the old change again.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2020-12-11 23:55:34 +01:00
Takashi Iwai
c53f7cd038 alsactl: Fix race at creating a lock file
A race at creating a lock file in state_lock() was discovered
recently: namely, between the first open(O_RDWR) and the second
open(O_RDWR|O_CREAT|O_EXCL) calls, another alsactl invocation may
already create a lock file, then the second open() will return EEXIST,
which isn't handled properly and treated as a fatal error.

In this patch, we check EEXIST case and try again open() with O_RDWR.
This must succeed usually, and if it fails, handle finally as the
fatal error.

BugLink: https://bugzilla.opensuse.org/show_bug.cgi?id=1179904
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2020-12-11 23:46:23 +01:00
Takashi Iwai
878e1a7c0f alsactl: Fix double decrease of lock timeout
The state_lock() has a loop to wait for the lock file creation, and
the timeout value gets decremented twice mistakenly, which leads to a
half timeout (5 seconds) than expected 10 seconds.  Fix it.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2020-12-11 23:43:34 +01:00
Jaroslav Kysela
860b851639 alsactl: 00main - fix typo in goto label
BugLink: https://github.com/alsa-project/alsa-utils/issues/52
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-10-13 17:30:15 +02:00
Jaroslav Kysela
b348abcbfe alsactl: add new -U argument text to man page
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-10-06 13:05:12 +02:00
Andrew Hlynskyi
d7bf45edc3 alsactl: init - add -U option to disable UCM based init
The reason is to use it with internal init extra commands like:
  alsactl -U -E CMD=info init

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-10-06 13:03:03 +02:00
Jaroslav Kysela
225a9afbc3 alsactl: fix the syslog message - add : delimiter after function:line
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-06-20 08:47:01 +02:00
Jaroslav Kysela
f8a2aad5bb alsactl: ucm - rename _once command to _boot command
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-25 19:21:25 +02:00
Jaroslav Kysela
570ea6c455 alsactl: allow to compile alsactl without UCM support
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-14 19:54:04 +02:00
Jaroslav Kysela
0adca4cac7 alsactl: use the right priority for syslog messages
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-14 19:41:40 +02:00
Jaroslav Kysela
b68e854d28 alsactl: add -D argument to execute also the UCM defaults section
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-14 19:34:18 +02:00
Jaroslav Kysela
8fb4016a17 alsactl: redirect alsa-lib errors
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-14 19:09:53 +02:00
Jaroslav Kysela
4bea8fe3a7 alsactl: add initial support for UCM init
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-14 18:19:20 +02:00
Jaroslav Kysela
598488c4af alsactl: init - iterate through all cards for the initial settings
The generic initialization code returns error code 99 (-99). Take
all those codes equal or above (bellow) this value as non-fatal.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-14 18:18:22 +02:00
Jaroslav Kysela
f9abf36d34 alsactl: daemon.c - fix gcc warning in write_pid_file() 2020-05-14 16:49:06 +02:00
Oscar65
d2bf87608a alsactl: fix error handling for sched_setscheduler() call
As man page says: "If successful, the sched_setparam() function shall return zero."

Without update I got this output in the syslog (journalctl):
abr 16 09:25:30 mypc alsactl[1652]: alsactl 1.2.2 daemon started
abr 16 09:25:30 mypc alsactl[1652]: /usr/bin/alsactl: do_nice:165sched_setparam failed: No such file or directory

If sched_setscheduler() returns 0, so it means that the call was successful.

Signed-off-by: Oscar Megía <megia.oscar@gmail.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-04-17 09:29:24 +02: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
Michael Forney
646b3b1c0b Use %lli for long long in printf
The `L` length modifier only applies to floating-point conversion
specifiers, and `ll` is used for `long long` integers.

Although glibc accepts %Li, musl does not and returns EINVAL.

Signed-off-by: Michael Forney <mforney@mforney.org>
Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2020-02-10 12:39:17 +01:00
Michael Forney
f80a290153 Use __func__ instead of __FUNCTION__
They are equivalent, but __func__ is in C99. __FUNCTION__ exists only
for backwards compatibility with old gcc versions.

Signed-off-by: Michael Forney <mforney@mforney.org>
Reviewd-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2020-02-10 12:38:28 +01:00
Jaroslav Kysela
34e373d0b1 alsactl: fix --sched-idle (set it really to SCHED_IDLE)
Reported-by: tommy <tommy@kelsos.ptp>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-12-03 13:53:25 +01:00
Jaroslav Kysela
3c740d9049 alsactl: sysfs - add /sys/kernel/uevent_seqnum check to init
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-25 18:01:32 +01:00
Rosen Penev
80fd81f4a8 treewide: Fix printf formats
Found with cppcheck

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2019-11-20 19:46:17 +01: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
Jaroslav Kysela
cf2cc37502 alsactl: simple coverity fix
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-03-12 16:05:48 +01:00
Jaroslav Kysela
d751320608 alsactl: lock - fix the array size (gcc warning)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2018-10-14 17:01:38 +02: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