mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-05 13:30:00 -05:00
ucm: add Path condition type
Check for a file presence and mode.
Modes: exists, read, write, exec
Example:
If.0 {
Condition {
Type Path
Mode read
Path "/etc/alsa/something"
True {
...
}
}
}
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
0afa61e8f0
commit
2f57b404b1
1 changed files with 44 additions and 0 deletions
|
|
@ -269,6 +269,47 @@ static int if_eval_control_exists(snd_use_case_mgr_t *uc_mgr, snd_config_t *eval
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int if_eval_path(snd_use_case_mgr_t *uc_mgr, snd_config_t *eval)
|
||||||
|
{
|
||||||
|
const char *path, *mode = NULL;
|
||||||
|
int err, amode = F_OK;
|
||||||
|
|
||||||
|
if (uc_mgr->conf_format < 4) {
|
||||||
|
uc_error("Path condition is supported in v4+ syntax");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = get_string(eval, "Path", &path);
|
||||||
|
if (err < 0) {
|
||||||
|
uc_error("Path error (If.Condition.Path)");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = get_string(eval, "Mode", &mode);
|
||||||
|
if (err < 0 && err != -ENOENT) {
|
||||||
|
uc_error("Path error (If.Condition.Mode)");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strncasecmp(mode, "exist", 5) == 0) {
|
||||||
|
amode = F_OK;
|
||||||
|
} else if (strcasecmp(mode, "read") == 0) {
|
||||||
|
amode = R_OK;
|
||||||
|
} else if (strcasecmp(mode, "write") == 0) {
|
||||||
|
amode = W_OK;
|
||||||
|
} else if (strcasecmp(mode, "exec") == 0) {
|
||||||
|
amode = X_OK;
|
||||||
|
} else {
|
||||||
|
uc_error("Path unknown mode (If.Condition.Mode)");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (eaccess(path, amode))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int if_eval(snd_use_case_mgr_t *uc_mgr, snd_config_t *eval)
|
static int if_eval(snd_use_case_mgr_t *uc_mgr, snd_config_t *eval)
|
||||||
{
|
{
|
||||||
const char *type;
|
const char *type;
|
||||||
|
|
@ -297,6 +338,9 @@ static int if_eval(snd_use_case_mgr_t *uc_mgr, snd_config_t *eval)
|
||||||
if (strcmp(type, "RegexMatch") == 0)
|
if (strcmp(type, "RegexMatch") == 0)
|
||||||
return if_eval_regex_match(uc_mgr, eval);
|
return if_eval_regex_match(uc_mgr, eval);
|
||||||
|
|
||||||
|
if (strcmp(type, "Path") == 0)
|
||||||
|
return if_eval_path(uc_mgr, eval);
|
||||||
|
|
||||||
uc_error("unknown If.Condition.Type");
|
uc_error("unknown If.Condition.Type");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue