]> git.alsa-project.org Git - alsa-utils.git/commitdiff
alsactl: fix sysfsroot path and parser extensions
authorJaroslav Kysela <perex@perex.cz>
Thu, 30 Apr 2009 09:26:15 +0000 (11:26 +0200)
committerJaroslav Kysela <perex@perex.cz>
Thu, 30 Apr 2009 09:26:15 +0000 (11:26 +0200)
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>
alsactl/alsactl_init.xml
alsactl/init/00main
alsactl/init_parse.c

index 0e0d46b293530ab627a5531d0ef028648c8dbe3c..dd4239c9853a306aa89abe72182559a823683e28 100644 (file)
               <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>
               <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>
               </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>
index 942f3863871e1d22d2b7749db9d594f5a347d0ea..98e8711331649d2fe6cd4d945a1164bd673e64f1 100644 (file)
@@ -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"
index 335cb06d01ea1a757cf41dfe2dbdce421ecfb72a..756cf92706e269712f99e33e175c25b922db8589 100644 (file)
@@ -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)