Commit graph

259 commits

Author SHA1 Message Date
Jaroslav Kysela
50140120c6 ucm: local_config may be NULL (error path)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-13 16:10:56 +02:00
Jaroslav Kysela
d65b1c7b52 ucm: add ${evali:} substitution
Example:

  Define.var1 2

  LibraryConfig.test.SubstiConfig {
          a "${evali:$var1+1}"
  }

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-13 16:10:51 +02:00
Jaroslav Kysela
c41d710a69 ucm: fix the '${eval:EXPR}' substitution
There was already a variable substitution. Skip it for the eval: case.

Fixes: 7b6da9ee ("ucm: add ${eval:EXPR} substitution (Syntax 5)")
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-02-22 09:51:29 +01:00
Jaroslav Kysela
d6adde0e32 ucm: top-level path - set directory from symlink
It is useful to read the top-level symlink and set the configuration
directory according this symlink for the relative paths.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-12-13 14:40:58 +01:00
Jaroslav Kysela
2623e4bb76 ucm: add initial doxygen documenation
This is an attempt to explain the UCM in a more verbose way.

BugLink: https://github.com/alsa-project/alsa-ucm-conf/issues/103
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-12-01 10:33:44 +01:00
Jaroslav Kysela
ebb8a6c7a1 conf: introduce snd_config_load_string()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-12-01 10:18:58 +01:00
Jaroslav Kysela
7b6da9ee6d ucm: add ${eval:EXPR} substitution (Syntax 5)
It is useful to do simple integer math in UCM configurations, too.
Use snd_config_evaluate_string() string for this job.

Example:

    ${eval:1+1}
    ${eval:100*$var1}
    ${eval:$[$var2+1]/5}

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-11-30 14:22:39 +01:00
Jaroslav Kysela
7ffe3d4162 ucm: fix parsing of the internal hexadecimal card identifier (2)
I forgot to change the passed variable name.

Fixes: 050f18c5 ("ucm: fix parsing of the internal hexadecimal card identifier")
Fixes: https://github.com/alsa-project/alsa-lib/issues/188
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-11-12 17:27:39 +01:00
Jaroslav Kysela
050f18c525 ucm: fix parsing of the internal hexadecimal card identifier
Too many code was removed.

Fixes: f547b2e3 ("conf: introduce safe_strtol_base()")
Fixes: https://github.com/alsa-project/alsa-lib/issues/188
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-11-12 16:00:59 +01:00
Jaroslav Kysela
ea5481296f ucm: fix DeviceModifier parser
The bellow commit caused regression for the SectionModifier parser. Revert
the single line change.

Fixes: 251bc204 ("ucm: implement RenameDevice and RemoveDevice verb management")

Fixes: https://github.com/alsa-project/alsa-lib/issues/167
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-11-07 18:41:43 +01:00
Jaroslav Kysela
f547b2e35f conf: introduce safe_strtol_base()
It is useful to parse hexadecimal strings, too.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-11-02 10:41:11 +01:00
Jaroslav Kysela
23198a72cd ucm: suppress the no device (no UCM card) errors on request
It seems that users are confused when the UCM configuration
is not ready for the particular hardware. Actually, we don't
allow a fine grained message classification in alsa-lib and
UCM API. Allow suppression of this specific type of messages
on the application request (typically alsactl).

BugLink: https://github.com/alsa-project/alsa-utils/issues/111
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-10-28 11:52:08 +02:00
Jaroslav Kysela
aa04023565 ucm: substitute the before/after identifiers
This allows to handle correctly declarations like:
  Before.SectionDevice "${var:DeviceMic}"

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-09-01 11:05:51 +02:00
Jaroslav Kysela
4a52ae4c32 ucm: fix the parsing of the hexadecimal prefix
The safe_strtol() function use strtol() which expects
to have the '0x' prefix for the hexadecimal number (when
base argument is zero).

BugLink: https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/1553
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-08-31 09:42:02 +02:00
Jaroslav Kysela
7d40a76ef5 ucm: avoid zero card instance number
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-08-31 09:25:12 +02:00
Chih-Wei Huang
76d1aa0cd7 configure: check if eaccess() is available
To fix the build error on Android:
  src/ucm/parser.c:2521:7: error: implicit declaration of function 'eaccess' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
                if (eaccess(filename, R_OK))
                    ^
  src/ucm/parser.c:2521:7: note: did you mean 'access'?

Signed-off-by: Chih-Wei Huang <cwhuang@linux.org.tw>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-06-14 10:10:58 +02:00
Chih-Wei Huang
01960fa856 ucm: include sys/wait.h to fix build on Android
src/ucm/main.c:788:8: error: implicit declaration of function 'WIFSIGNALED' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
                        if (WIFSIGNALED(err)) {
                            ^
    src/ucm/main.c:790:10: error: implicit declaration of function 'WIFEXITED' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
                        } if (WIFEXITED(err)) {
                              ^
    src/ucm/main.c:791:34: error: implicit declaration of function 'WEXITSTATUS' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
                                if (ignore_error == false && WEXITSTATUS(err) != 0) {

Signed-off-by: Chih-Wei Huang <cwhuang@linux.org.tw>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-06-14 10:10:02 +02:00
Andreas Müller
abe805ed6c ucm_exec.c: Include limits.h explicitly to fix build on musl
Fixes:
| ../../../alsa-lib-1.2.5/src/ucm/ucm_exec.c: In function 'find_exec':
| ../../../alsa-lib-1.2.5/src/ucm/ucm_exec.c:43:18: error: 'PATH_MAX' undeclared (first use in this function)
|    43 |         char bin[PATH_MAX];
|       |                  ^~~~~~~~
| ../../../alsa-lib-1.2.5/src/ucm/ucm_exec.c:43:18: note: each undeclared identifier is reported only once for each function it appears in
| ../../../alsa-lib-1.2.5/src/ucm/ucm_exec.c: In function 'uc_mgr_exec':
| ../../../alsa-lib-1.2.5/src/ucm/ucm_exec.c:177:18: error: 'PATH_MAX' undeclared (first use in this function)
|   177 |         char bin[PATH_MAX];
|       |                  ^~~~~~~~

Fixes: https://github.com/alsa-project/alsa-lib/pull/145
Signed-off-by: Andreas Müller <schnitzeltony@gmail.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-06-04 09:26:36 +02:00
Jaroslav Kysela
0325f4357d ucm: compound_merge() - fix use after free (and logic)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-06-03 09:00:51 +02:00
Jaroslav Kysela
e213309060 ucm: fix possible memory leak in parse_verb_file()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-06-03 07:30:27 +02:00
Jaroslav Kysela
30d1d256e7 ucm: fix out-of-array access in rval_device_lookup_init()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-06-02 20:01:08 +02:00
Jaroslav Kysela
64a6d4d1e8 ucm: check error value in parse_lookup_query()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-06-02 19:59:10 +02:00
Jaroslav Kysela
26ab7fc3e4 ucm: fix possible NULL pointer dereference in uc_mgr_exec()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-06-02 19:58:04 +02:00
Jaroslav Kysela
7fcb1aadd5 ucm: find_exec() - fix memory leak (dir)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-06-02 19:56:13 +02:00
Jaroslav Kysela
7764e3e621 ucm: fix if_eval_path() - access NULL pointer
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-06-02 19:53:24 +02:00
Jaroslav Kysela
9b71d53bde ucm: fix use after free in if_eval_regex_match()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-06-02 19:52:12 +02:00
Jaroslav Kysela
200d18cda7 ucm: fix error path in execute_cfgsave()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-06-02 19:51:13 +02:00
Jaroslav Kysela
9621d0bff2 ucm: fix _alibpref string (add '.' delimiter to the end)
Fixes: 0e4ba2ea ("ucm: add _alibpref to get the private device prefix")
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-06-02 11:21:54 +02:00
Jaroslav Kysela
0e4ba2ea8c ucm: add _alibpref to get the private device prefix
It may be useful to get the device prefix for the local configuration.

Link: https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/1251
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-06-02 11:09:46 +02:00
Jaroslav Kysela
6b72840569 ucm: compound_merge - use snd_config_merge()
It's useful to do the full tree merge (append).

Fixes: https://github.com/alsa-project/alsa-ucm-conf/pull/92
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-24 12:14:47 +02:00
Jaroslav Kysela
3fd1de5cbe ucm: recognize first '-' character as ignore error for exec/shell
It may be useful to ignore the returned errors (like modprobe etc).

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-18 16:37:17 +02:00
Jaroslav Kysela
0ee4642a69 ucm: cfg-save - allow to save the sub-tree including root keys
The leading '+' in the keys specification add the key prefix
(sub-tree root identification) to the saved configuration.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-18 12:33:43 +02:00
Jaroslav Kysela
225d3aecb6 ucm: libconfig - merge not override items
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-18 11:30:21 +02:00
Jaroslav Kysela
b2b3658fb9 ucm: libconfig parser - fix memory leaks
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-18 11:30:21 +02:00
Jaroslav Kysela
5e7c507152 ucm: add cfg-save command
Allow to save whole (or partial) local UCM alsa library configuration
to a file.

Syntax (saves key1.key2 sub-tree):

	Sequence [
		cfg-save "/tmp/my-file.conf:key1.key2"
	]

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-17 16:49:46 +02:00
Jaroslav Kysela
f821f09727 ucm: fix memory leak in execute_cset()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-14 12:49:14 +02:00
Jaroslav Kysela
d9658b7509 ucm: parse LibraryConfig also in the toplevel file
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-13 18:28:20 +02:00
Jaroslav Kysela
414e4a759b ucm: fix regexec() REG_NOMATCH state handling for define regex
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-12 09:53:18 +02:00
Jaroslav Kysela
590df3a5b1 ucm: add exec sequence command
This change renames the original exec command to shell which
is more appropriate. Implement a light version of the exec
command which calls directly the specified executable without
the shell interaction (man 3 system).

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-12 08:32:45 +02:00
Hans de Goede
06543e06e9 ucm: Fix sysw sequence command not working when requesting to ignore errors
When the user requests to ignore sysfs write errors by prefixing
the path with a '-' then we need to skip the '-' when building the
actual path otherwise the write will never work.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-04 10:36:22 +02:00
Jaroslav Kysela
6ddba54a07 ucm: fix the local ucm control device name caching
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-23 21:19:34 +02:00
Jaroslav Kysela
22dfb4bc20 ucm: limit the master config scan to conf.virt.d
The composition of the list of valid UCM cards is a bit
tricky. Scan only ucm2/conf.virt.d tree.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-22 11:47:52 +02:00
Jaroslav Kysela
508506a80c ucm: fixed find-device substitution (non-continuous PCM devices)
The PCM device numbers may be non-continous. Skip them when -ENOENT error
is returned.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-16 14:48:11 +02:00
Jaroslav Kysela
652ddf866f ucm: allow to escape the trailing variable substitution character
Example:

  ${find-device:ctl='hw:0',type=pcm,field=id,regex='USB A{1\\}'}

Unescaped find-device arguments:

  ctl='hw:0',type=pcm,field=id,regex='USB A{1}'

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-16 12:38:29 +02:00
Jaroslav Kysela
ddb0871ec6 ucm: find-device / pcm - the ctl_list may be empty
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-16 10:48:35 +02:00
Jaroslav Kysela
447a676ee5 ucm: add missing uc_mgr_card_close() call to snd_use_case_mgr_open()
Handle the error path correctly.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-15 16:58:29 +02:00
Jaroslav Kysela
02b234a39c ucm: cosmetic code reshuffle in rval_lookup_main()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-15 16:45:12 +02:00
Jaroslav Kysela
1237905559 ucm: fix uc_mgr_has_local_config()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-15 11:49:32 +02:00
Jaroslav Kysela
8e097fd14a ucm: rewrite device value only when the local config exists
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-15 11:38:39 +02:00
Jaroslav Kysela
c83ddd8e56 ucm: return error if fixedboot_list is empty
The application should know, that there is no special
initialization sequence. It's counterpart for
"ucm: return error if boot_list is empty".

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-13 19:13:20 +02:00