diff options
author | Jaroslav Kysela <perex@perex.cz> | 2009-04-30 11:26:15 +0200 |
---|---|---|
committer | Jaroslav Kysela <perex@perex.cz> | 2009-04-30 11:26:15 +0200 |
commit | 94ac54bff1e15e69c7c722695c3b259a3bb5c6c0 (patch) | |
tree | 9aaeaddbf3209bbbcd428f746d12c0b69b21a263 | |
parent | 42ae1e6f1b874da090abe065c781a4f7b91ba67c (diff) | |
download | alsa-utils-94ac54bff1e15e69c7c722695c3b259a3bb5c6c0.tar.gz |
alsactl: fix sysfsroot path and parser extensions
The sysfsroot path is /sys/class/sound/cardX/device for recent kernels.
The ACCESS check honors the variable substutition now. Added $config{key}
substitution.
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
-rw-r--r-- | alsactl/alsactl_init.xml | 11 | ||||
-rw-r--r-- | alsactl/init/00main | 4 | ||||
-rw-r--r-- | alsactl/init_parse.c | 24 |
3 files changed, 34 insertions, 5 deletions
diff --git a/alsactl/alsactl_init.xml b/alsactl/alsactl_init.xml index 0e0d46b..dd4239c 100644 --- a/alsactl/alsactl_init.xml +++ b/alsactl/alsactl_init.xml @@ -279,7 +279,7 @@ <listitem> <para>The relative path to sysfs subsystem specifying the root directory of a soundcard device. Usually, - it should be set to "/class/sound/controlC$cardinfo{card}/device". + it should be set to "/class/sound/card$cardinfo{card}/device". </para> </listitem> </varlistentry> @@ -462,7 +462,7 @@ <listitem> <para>The relative path to sysfs subsystem specifying the root directory of a soundcard device. Usually, - it should be set to "/class/sound/controlC$cardinfo{card}/device". + it should be set to "/class/sound/card$cardinfo{card}/device". </para> </listitem> </varlistentry> @@ -553,6 +553,13 @@ </varlistentry> <varlistentry> + <term><option>$config{<replaceable>key</replaceable>}</option>, <option>%g{<replaceable>key</replaceable>}</option></term> + <listitem> + <para>The value of a configuration variable. See CONFIG{} for more details.</para> + </listitem> + </varlistentry> + + <varlistentry> <term><option>%%</option></term> <listitem> <para>The '%' character itself.</para> diff --git a/alsactl/init/00main b/alsactl/init/00main index 942f386..98e8711 100644 --- a/alsactl/init/00main +++ b/alsactl/init/00main @@ -2,7 +2,9 @@ # See 'man alsactl_init' for syntax. # set root device directory in sysfs for soundcard for ATTR{} command -CONFIG{sysfs_device}="/class/sound/controlC$cardinfo{card}/device" +CONFIG{sysfs_device}="/class/sound/card$cardinfo{card}/device" +ACCESS!="$sysfsroot$config{sysfs_device}", \ + CONFIG{sysfs_device}="/class/sound/controlC$cardinfo{card}/device" # test for extra commands ENV{CMD}=="help", INCLUDE="help", GOTO="00main_end" diff --git a/alsactl/init_parse.c b/alsactl/init_parse.c index 335cb06..756cf92 100644 --- a/alsactl/init_parse.c +++ b/alsactl/init_parse.c @@ -929,6 +929,7 @@ static void apply_format(struct space *space, char *string, size_t maxsize) SUBST_ATTR, SUBST_SYSFSROOT, SUBST_ENV, + SUBST_CONFIG, }; static const struct subst_map { char *name; @@ -941,6 +942,7 @@ static void apply_format(struct space *space, char *string, size_t maxsize) { .name = "attr", .fmt = 's', .type = SUBST_ATTR }, { .name = "sysfsroot", .fmt = 'r', .type = SUBST_SYSFSROOT }, { .name = "env", .fmt = 'E', .type = SUBST_ENV }, + { .name = "config", .fmt = 'g', .type = SUBST_CONFIG }, { NULL, '\0', 0 } }; enum subst_type type; @@ -1101,6 +1103,16 @@ found: dbg("substitute env '%s=%s'", attr, pos); strlcat(string, pos, maxsize); break; + case SUBST_CONFIG: + if (attr == NULL) { + dbg("missing attribute"); + break; + } + pair = value_find(space, attr); + if (pair == NULL) + break; + strlcat(string, pair->value, maxsize); + break; default: Perror(space, "unknown substitution type=%i", type); break; @@ -1520,15 +1532,23 @@ static int parse_line(struct space *space, char *line, size_t linesize) } if (strncasecmp(key, "ACCESS", 6) == 0) { if (op == KEY_OP_MATCH || op == KEY_OP_NOMATCH) { + if (value[0] == '$') { + strlcpy(string, value, sizeof(string)); + apply_format(space, string, sizeof(string)); + if (string[0] == '/') + goto __access1; + } if (value[0] != '/') { strlcpy(string, space->rootdir, sizeof(string)); strlcat(string, "/", sizeof(string)); strlcat(string, value, sizeof(string)); } else { - strlcat(string, value, sizeof(string)); + strlcpy(string, value, sizeof(string)); } + apply_format(space, string, sizeof(string)); + __access1: count = access(string, F_OK); - dbg("access(%s) = %i", value, count); + dbg("access(%s) = %i (%s)", string, count, value); if (op == KEY_OP_MATCH && count != 0) break; if (op == KEY_OP_NOMATCH && count == 0) |