From: Jaroslav Kysela Date: Fri, 5 Jun 2026 15:53:43 +0000 (+0200) Subject: ucm: pass optional flag to config load functions to suppress spurious errors X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=d983a9ccbc75d19e4a7b2cd51f42650bcfd84d91;p=alsa-lib.git ucm: pass optional flag to config load functions to suppress spurious errors Fixes: https://github.com/alsa-project/alsa-lib/issues/510 Signed-off-by: Jaroslav Kysela --- diff --git a/src/ucm/parser.c b/src/ucm/parser.c index 2d7833e9..4cde9194 100644 --- a/src/ucm/parser.c +++ b/src/ucm/parser.c @@ -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,9 +74,10 @@ 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) { - snd_error(UCM, "failed to open file %s: %d", filename, err); + if (!optional || (err != -ENOENT && err != -EACCES)) + snd_error(UCM, "failed to open file %s: %d", filename, err); return err; } return 0; @@ -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); diff --git a/src/ucm/ucm_include.c b/src/ucm/ucm_include.c index 8a47e748..d663ffc1 100644 --- a/src/ucm/ucm_include.c +++ b/src/ucm/ucm_include.c @@ -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; diff --git a/src/ucm/ucm_local.h b/src/ucm/ucm_local.h index 3015cca5..c00dd6da 100644 --- a/src/ucm/ucm_local.h +++ b/src/ucm/ucm_local.h @@ -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[]); diff --git a/src/ucm/utils.c b/src/ucm/utils.c index eb6bb4ab..011bdab3 100644 --- a/src/ucm/utils.c +++ b/src/ucm/utils.c @@ -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: - snd_error(UCM, "could not open configuration file %s", file); + 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;