ucm: pass optional flag to config load functions to suppress spurious errors
Some checks failed
Build alsa-lib / fedora_latest_build (push) Has been cancelled
Build alsa-lib / ubuntu_last_build (push) Has been cancelled

Fixes: https://github.com/alsa-project/alsa-lib/issues/510
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
Jaroslav Kysela 2026-06-05 17:53:43 +02:00
parent 08b532cd3d
commit d983a9ccbc
4 changed files with 22 additions and 18 deletions

View file

@ -66,7 +66,7 @@ static void ucm_filename(char *fn, size_t fn_len, long version,
*
*/
int uc_mgr_config_load_file(snd_use_case_mgr_t *uc_mgr,
const char *file, snd_config_t **cfg)
const char *file, snd_config_t **cfg, bool optional)
{
char filename[PATH_MAX];
int err;
@ -74,8 +74,9 @@ int uc_mgr_config_load_file(snd_use_case_mgr_t *uc_mgr,
ucm_filename(filename, sizeof(filename), uc_mgr->conf_format,
file[0] == '/' ? NULL : uc_mgr->conf_dir_name,
file);
err = uc_mgr_config_load(uc_mgr->conf_format, filename, cfg);
err = uc_mgr_config_load(uc_mgr->conf_format, filename, cfg, optional);
if (err < 0) {
if (!optional || (err != -ENOENT && err != -EACCES))
snd_error(UCM, "failed to open file %s: %d", filename, err);
return err;
}
@ -825,7 +826,7 @@ static int parse_libconfig1(snd_use_case_mgr_t *uc_mgr, snd_config_t *cfg)
if (file) {
if (substfile) {
snd_config_t *cfg;
err = uc_mgr_config_load_file(uc_mgr, file, &cfg);
err = uc_mgr_config_load_file(uc_mgr, file, &cfg, false);
if (err < 0)
return err;
err = uc_mgr_substitute_tree(uc_mgr, cfg);
@ -844,7 +845,7 @@ static int parse_libconfig1(snd_use_case_mgr_t *uc_mgr, snd_config_t *cfg)
ucm_filename(filename, sizeof(filename), uc_mgr->conf_format,
file[0] == '/' ? NULL : uc_mgr->conf_dir_name,
file);
err = uc_mgr_config_load_into(uc_mgr->conf_format, filename, uc_mgr->local_config);
err = uc_mgr_config_load_into(uc_mgr->conf_format, filename, uc_mgr->local_config, false);
if (err < 0)
return err;
}
@ -2949,7 +2950,7 @@ static int parse_master_section(snd_use_case_mgr_t *uc_mgr, snd_config_t *cfg,
if (file) {
snd_config_t *cfg;
/* load config from file */
err = uc_mgr_config_load_file(uc_mgr, file, &cfg);
err = uc_mgr_config_load_file(uc_mgr, file, &cfg, false);
if (err < 0)
goto __error;
/* parse the config */
@ -3017,7 +3018,7 @@ static int parse_master_section(snd_use_case_mgr_t *uc_mgr, snd_config_t *cfg,
snd_config_t *cfg;
const char *fname = vfile ? vfile : file;
/* load config from file */
err = uc_mgr_config_load_file(uc_mgr, fname, &cfg);
err = uc_mgr_config_load_file(uc_mgr, fname, &cfg, false);
if (err >= 0) {
err = parse_verb_config(uc_mgr, id,
vcomment ? vcomment : comment,
@ -3576,7 +3577,7 @@ static int load_toplevel_config(snd_use_case_mgr_t *uc_mgr,
return -ENOENT;
}
err = uc_mgr_config_load(2, filename, &tcfg);
err = uc_mgr_config_load(2, filename, &tcfg, false);
if (err < 0)
goto __error;
@ -3586,7 +3587,7 @@ static int load_toplevel_config(snd_use_case_mgr_t *uc_mgr,
if (err < 0)
goto __error;
err = uc_mgr_config_load(uc_mgr->conf_format, filename, cfg);
err = uc_mgr_config_load(uc_mgr->conf_format, filename, cfg, false);
if (err < 0) {
snd_error(UCM, "could not parse configuration for card %s", uc_mgr->card_name);
goto __error;
@ -3792,7 +3793,7 @@ int uc_mgr_scan_master_configs(const char **_list[])
#endif
continue;
err = uc_mgr_config_load(2, filename, &cfg);
err = uc_mgr_config_load(2, filename, &cfg, false);
if (err < 0)
goto __err;
err = snd_config_search(cfg, "Syntax", &c);

View file

@ -90,7 +90,7 @@ static int include_eval_one(snd_use_case_mgr_t *uc_mgr,
err = uc_mgr_get_substituted_value(uc_mgr, &s, file);
if (err < 0)
return err;
err = uc_mgr_config_load_file(uc_mgr, s, result);
err = uc_mgr_config_load_file(uc_mgr, s, result, opt_bool);
if (opt_bool && (err == -ENOENT || err == -EACCES)) {
snd_trace(UCM, "optional file '%s' not found or readable", s);
err = 0;

View file

@ -300,9 +300,9 @@ void uc_mgr_stdout(const char *fmt, ...);
const char *uc_mgr_sysfs_root(void);
const char *uc_mgr_config_dir(int format);
int uc_mgr_config_load_into(int format, const char *file, snd_config_t *cfg);
int uc_mgr_config_load(int format, const char *file, snd_config_t **cfg);
int uc_mgr_config_load_file(snd_use_case_mgr_t *uc_mgr, const char *file, snd_config_t **cfg);
int uc_mgr_config_load_into(int format, const char *file, snd_config_t *cfg, bool optional);
int uc_mgr_config_load(int format, const char *file, snd_config_t **cfg, bool optional);
int uc_mgr_config_load_file(snd_use_case_mgr_t *uc_mgr, const char *file, snd_config_t **cfg, bool optional);
int uc_mgr_import_master_config(snd_use_case_mgr_t *uc_mgr);
int uc_mgr_scan_master_configs(const char **_list[]);

View file

@ -357,7 +357,7 @@ const char *uc_mgr_config_dir(int format)
return path;
}
int uc_mgr_config_load_into(int format, const char *file, snd_config_t *top)
int uc_mgr_config_load_into(int format, const char *file, snd_config_t *top, bool optional)
{
FILE *fp;
snd_input_t *in;
@ -369,7 +369,10 @@ int uc_mgr_config_load_into(int format, const char *file, snd_config_t *top)
if (!fp) {
err = -errno;
__err_open:
if (!optional || (err != -ENOENT && err != -EACCES))
snd_error(UCM, "could not open configuration file %s", file);
else
snd_trace(UCM, "could not open configuration file %s", file);
return err;
}
err = snd_input_stdio_attach(&in, fp, 1);
@ -391,7 +394,7 @@ int uc_mgr_config_load_into(int format, const char *file, snd_config_t *top)
return 0;
}
int uc_mgr_config_load(int format, const char *file, snd_config_t **cfg)
int uc_mgr_config_load(int format, const char *file, snd_config_t **cfg, bool optional)
{
snd_config_t *top;
int err;
@ -399,7 +402,7 @@ int uc_mgr_config_load(int format, const char *file, snd_config_t **cfg)
err = snd_config_top(&top);
if (err < 0)
return err;
err = uc_mgr_config_load_into(format, file, top);
err = uc_mgr_config_load_into(format, file, top, optional);
if (err < 0) {
snd_config_delete(top);
return err;