mirror of
https://github.com/alsa-project/alsa-utils
synced 2024-11-09 17:25:42 +01:00
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>
This commit is contained in:
parent
42ae1e6f1b
commit
94ac54bff1
3 changed files with 34 additions and 5 deletions
|
@ -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>
|
||||
|
@ -552,6 +552,13 @@
|
|||
</listitem>
|
||||
</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>
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue