Commit graph

333 commits

Author SHA1 Message Date
Jaroslav Kysela
8116639e56 alsactl: 90-alsa-restore.rules - add support for AMD ACP digital microphone
The UCM configuration for AMD ACP digital microphones combines HDA analog card
with ASoC AMD ACP digital microphone card. When the ACP microphone card
is detected later than HDA analog card, the UCM initialization for HDA
analog card should be executed again.

Additional changes:

Added --with-alsactl-udev-extra-test argument to handle the tests for
directories. The default value was kept.

Added --alsactl-udev-args argument to pass extra arguments to alsactl
in the udev rule.

Note: The autoconf does not handle correctly spaces so configure
call like 'configure --alsactl-udev-args="-E ENV=abcd"' is not allowed.
Substitue '__' string as ' ' for this reason.

Example:

   configure --with-alsactl-udev-args="-E__ENV=abcd" \
             --with-alsactl-udev-extra-test='TEST=="/abcd",__TEST=="/xyz",'

Closes: https://github.com/alsa-project/alsa-utils/issues/278
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2024-11-11 16:27:40 +01:00
Jaroslav Kysela
966c559f04 alsactl: state: verify only control count not numids
The numids may change. Verify if a control is added or removed.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2024-10-15 17:24:31 +02:00
Jaroslav Kysela
e2fec28b65 alsactl: state: recode set_control() to use newer functions
The goal is to make the code more clean and separate elem id parsing.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2024-10-15 16:50:54 +02:00
Masatake YAMATO
ba2bc072dc alsactl: don't free a card pointing NULL
alsactl distributed as part of Fedora 40 got a SEGV:

    # journalctl
    ...
    May 17 00:55:58 dev64.localdomain kernel: alsactl[1923]: segfault at 28 ip 00005600705b3373 sp 00007ffd9712bef0 error 4 in alsactl[5600705af000+13000] likely on CPU 5 (core 8, socket 0)
    ...

As the following output of the debug session, card_free() tried a card
pointing NULL:

    $ sudo coredumpctl debug alsactl
	       PID: 1923 (alsactl)
	       UID: 0 (root)
	       GID: 0 (root)
	    Signal: 11 (SEGV)
	 Timestamp: Fri 2024-05-17 00:55:58 JST (3h 34min ago)
      Command Line: /usr/sbin/alsactl -s -n 19 -c -E ALSA_CONFIG_PATH=/etc/alsa/alsactl.conf --initfile=/lib/alsa/init/00main rdaemon
	Executable: /usr/sbin/alsactl
     Control Group: /system.slice/alsa-state.service
	      Unit: alsa-state.service
	     Slice: system.slice
	   Boot ID: 241b5a2ef86f4940bb3d340583c80d88
	Machine ID: 437365709a8c488c9481ee4b6651c2ec
	  Hostname: dev64.localdomain
	   Storage: /var/lib/systemd/coredump/core.alsactl.0.241b5a2ef86f4940bb3d340583c80d88.1923.1715874958000000.zst (present)
      Size on Disk: 81.7K
	   Package: alsa-utils/1.2.11-1.fc40
	  build-id: 3b6fec58b3566d666d6e9fd48e8fcf04f03f0152
	   Message: Process 1923 (alsactl) of user 0 dumped core.

		    Module libasound.so.2 from rpm alsa-lib-1.2.11-2.fc40.x86_64
		    Module alsactl from rpm alsa-utils-1.2.11-1.fc40.x86_64
		    Stack trace of thread 1923:
		    #0  0x00005600705b3373 card_free (alsactl + 0xa373)
		    #1  0x00005600705c0e54 state_daemon (alsactl + 0x17e54)
		    #2  0x00005600705b2339 main (alsactl + 0x9339)
		    #3  0x00007f4c0b9b7088 __libc_start_call_main (libc.so.6 + 0x2a088)
		    #4  0x00007f4c0b9b714b __libc_start_main_impl (libc.so.6 + 0x2a14b)
		    #5  0x00005600705b2df5 _start (alsactl + 0x9df5)
		    ELF object binary architecture: AMD x86-64

    GNU gdb (Fedora Linux) 14.2-1.fc40
    Copyright (C) 2023 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.
    Type "show copying" and "show warranty" for details.
    This GDB was configured as "x86_64-redhat-linux-gnu".
    Type "show configuration" for configuration details.
    For bug reporting instructions, please see:
    <https://www.gnu.org/software/gdb/bugs/>.
    Find the GDB manual and other documentation resources online at:
	<http://www.gnu.org/software/gdb/documentation/>.

    For help, type "help".
    Type "apropos word" to search for commands related to "word"...
    Reading symbols from /usr/sbin/alsactl...
    Reading symbols from /usr/lib/debug/usr/sbin/alsactl-1.2.11-1.fc40.x86_64.debug...
    [New LWP 1923]
    [Thread debugging using libthread_db enabled]
    Using host libthread_db library "/lib64/libthread_db.so.1".
    Core was generated by `/usr/sbin/alsactl -s -n 19 -c -E ALSA_CONFIG_PATH=/etc/alsa/alsactl.conf --init'.
    Program terminated with signal SIGSEGV, Segmentation fault.
    #0  free_list (list=0x20) at /usr/src/debug/alsa-utils-1.2.11-1.fc40.x86_64/alsactl/daemon.c:73
    73		for (i = 0; i < list->size; i++)
    (gdb) where
    #0  free_list (list=0x20) at /usr/src/debug/alsa-utils-1.2.11-1.fc40.x86_64/alsactl/daemon.c:73
    #1  card_free (card=card@entry=0x5600707455f0) at /usr/src/debug/alsa-utils-1.2.11-1.fc40.x86_64/alsactl/daemon.c:82
    #2  0x00005600705c0e54 in state_daemon (file=file@entry=0x5600705c31a1 "/var/lib/alsa/asound.state", cardname=cardname@entry=0x0, period=period@entry=300,
	pidfile=pidfile@entry=0x5600705c3170 "/var/run/alsactl.pid") at /usr/src/debug/alsa-utils-1.2.11-1.fc40.x86_64/alsactl/daemon.c:455
    #3  0x00005600705b2339 in main (argc=<optimized out>, argv=<optimized out>) at /usr/src/debug/alsa-utils-1.2.11-1.fc40.x86_64/alsactl/alsactl.c:459
    (gdb) list
    68
    69	static void free_list(struct id_list *list)
    70	{
    71		int i;
    72
    73		for (i = 0; i < list->size; i++)
    74			free(list->list[i]);
    75		free(list->list);
    76	}
    77
    (gdb) up
    #1  card_free (card=card@entry=0x5600707455f0) at /usr/src/debug/alsa-utils-1.2.11-1.fc40.x86_64/alsactl/daemon.c:82
    82		free_list(&c->blacklist);
    (gdb) p c
    $1 = (struct card *) 0x0
    (gdb)

Closes: https://github.com/alsa-project/alsa-utils/pull/267
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2024-05-23 13:17:59 +02:00
Mingjie Shen
004d085c67 alsactl: fix potential buffer overwrite
The 'call to sprintf' operation on line 413 requires 21 bytes
but the destination is only 16 bytes.

Fixes: https://github.com/alsa-project/alsa-utils/pull/247
Signed-off-by: Mingjie Shen <shen497@purdue.edu>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2023-12-08 19:56:45 +01:00
Jaroslav Kysela
b5591747fd alsa-restore.rules: use devnode instead number atribute
Fixes: https://github.com/alsa-project/alsa-utils/issues/244
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2023-11-15 15:02:34 +01:00
Rudi Heitbaum
e4daea49d8 alsactl: fix compilation when building in a subdir
Fixes: 613372d
Fixes: cff2d1c

Compile errors when building in a subdir:
alsactl/alsactl.c:33:10: fatal error: os_compat.h: No such file or directory
   33 | #include "os_compat.h"
      |          ^~~~~~~~~~~~~
alsactl/lock.c:34:10: fatal error: os_compat.h: No such file or directory
   34 | #include "os_compat.h"
      |          ^~~~~~~~~~~~~

Fixes: https://github.com/alsa-project/alsa-utils/pull/213
Signed-off-by: Rudi Heitbaum <rudi@heitbaum.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2023-08-30 18:56:41 +02:00
Jaroslav Kysela
60bf4bb2af alsactl: fix the verbose compilation warnings for latest gcc
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2023-08-30 12:35:23 +02:00
Jaroslav Kysela
8ed9d7607f alsactl: fix the copy-n-paste typo (SND_RAWMIDI_STREAM_*)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2023-08-30 10:57:31 +02:00
Rudi Heitbaum
d6a71bfbde alsactl: add define to compile with glibc 2.38
strlcat and strlcpy have been added to glibc 2.38.
update the defines to use the glibc versions, and not conflict with
string.h.

ref:
- https://sourceware.org/git/?p=glibc.git;a=commit;h=454a20c8756c9c1d55419153255fc7692b3d2199

Fixes: https://github.com/alsa-project/alsa-utils/pull/225
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2023-08-01 09:36:04 +02:00
SASANO Takayoshi
cff2d1c210 alsactl: fix OpenBSD compilation (add include of os_compat.h)
Fixes: https://github.com/alsa-project/alsa-utils/pull/193
Signed-off-by: SASANO Takayoshi <uaa@uaa.org.uk>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2023-02-27 13:10:16 +01:00
SASANO Takayoshi
613372dc7c Add OpenBSD support
- ERESTART not supported platform: use EINTR instead
- add include/os_compat.h, well-used OS specific definition
- copied include/bswap.h from alsa-lib

- EPIPE and ESTRPIPE are different usage, but currently
  EPIPE is used when ESTRPIPE is not defined.

  To fix this problem, assign ESPIPE instead.

Fixes: https://github.com/alsa-project/alsa-utils/pull/186
Signed-off-by: SASANO Takayoshi <uaa@uaa.org.uk>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2023-02-03 13:08:44 +01:00
Jaroslav Kysela
f37ef4768c alsactl: Print driver name in info
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-09-27 19:06:04 +02:00
Jaroslav Kysela
bbc74a61ac alsactl: implement 'info' command
It may be useful to collect the basic sound card information.
The output is in the YAML structured syntax (human and machine readable).

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-10 09:08:26 +02:00
Jaroslav Kysela
8403967669 alsactl: add locking for per-card initialization
Introduce the -K,--lock-dir parameter to specify the locking
directory. If the locking is active, files card<NUM>.lock
are used to serialize the multiple initialization requests
(udev, service).

Allow the relative -O,--lock-file argument (it's default now).

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-02-02 15:34:40 +01:00
Jaroslav Kysela
64fa37f09b alsactl: lock - use alarm signal and F_SETLKW rather polling
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-02-01 20:45:48 +01:00
Jaroslav Kysela
ccb6d4612b alsactl: remove unused argument for state_lock_()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-02-01 20:01:08 +01:00
Jaroslav Kysela
f5997e15d6 alsactl: add dbg() prints to init_ucm()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-02-01 19:47:53 +01:00
Alex Xu (Hello71)
d05ac4a078 alsactl: flush stdout for monitor command
It may be useful to pipe the output to another program.

Fixes: https://github.com/alsa-project/alsa-utils/pull/109
Signed-off-by: Alex Xu (Hello71) <alex_y_xu@yahoo.ca>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-01-27 13:22:38 +01:00
Jaroslav Kysela
8adbb2c275 alsactl: fix typo in comment in 00main
Fixes: https://github.com/alsa-project/alsa-utils/issues/132
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-01-27 13:19:36 +01:00
Jaroslav Kysela
fca9d89bbc alsactl: fix the error path in set_controls()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-01-03 16:14:31 +01:00
Jaroslav Kysela
257f3063fa alsactl: fix the check for additional elements
The driver may export only write-only elements. The previous
heuristics code do not handle this use case correctly.
Iterate through all elements and skip the write-only ones.

Fixes: https://github.com/alsa-project/alsa-utils/issues/122
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-12-03 11:09:57 +01:00
Jaroslav Kysela
af62c72e2d alsactl: suppress no device 'errors' for UCM
This patch adds --ucm-nodev (or -X) option to get those
messages back. The code works only with library 1.2.6+.

By default, these messages are suppressed:

  alsactl[xxx]: alsa-lib parser.c:242:(error_node) UCM is not supported for this HDA model (HDA Intel PCH...)
  alsactl[xxx]: alsa-lib main.c:1405:(snd_use_case_mgr_open) error: failed to import hw:0 use case configuration -6

Fixes: https://github.com/alsa-project/alsa-utils/issues/111
Link: https://lore.kernel.org/alsa-devel/20211027144008.27002-1-tiwai@suse.de/
Link: 23198a72cd
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-10-28 12:16:11 +02:00
Andreas Müller
6a0d13ddb2 utils.c: Include limits.h explicitly to fix build on musl
Fixes:
| ../../alsa-utils-1.2.5/alsactl/utils.c: In function 'snd_card_clean_cfgdir':
| ../../alsa-utils-1.2.5/alsactl/utils.c:309:19: error: 'PATH_MAX' undeclared (first use in this function)
|   309 |         char path[PATH_MAX];
|       |                   ^~~~~~~~
| ../../alsa-utils-1.2.5/alsactl/utils.c:309:19: note: each undeclared identifier is reported only once for each function it appears in

Fixes: https://github.com/alsa-project/alsa-utils/pull/92
Signed-off-by: Andreas Müller <schnitzeltony@gmail.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-06-07 19:13:47 +02:00
Sören Tempel
6018c2014a alsactl: load_state: Only delete config if one was loaded
If load_configuration fails with open_failed == true, load_state will
jump to the out label without config being initialized and pass this
uninitialized config value to snd_config_delete. This commit fixes this
issue by initializing config with NULL and checking if it is non-null
before invoking snd_config_delete.

Fixes: https://github.com/alsa-project/alsa-utils/pull/94
Fixes: f138117 ("alsactl: load_state() - initialize config variable for the open_failed case")
BugLink: https://github.com/alsa-project/alsa-utils/issues/93
Signed-off-by: Sören Tempel <soeren+git@soeren-tempel.net>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-06-07 19:06:19 +02:00
Jaroslav Kysela
f138117a45 alsactl: load_state() - initialize config variable for the open_failed case
Fixes: https://github.com/alsa-project/alsa-utils/issues/93
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-06-07 17:21:58 +02:00
Jaroslav Kysela
cd2f779b8d alsactl: fix lock_fd unlock in load_configuration() - error path
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-06-04 10:08:18 +02:00
Jaroslav Kysela
646d6ff094 alsactl: state - fix ‘item’ may be used uninitialized gcc warning
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-06-04 10:04:50 +02:00
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