]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev-rules: fix negative match rule for SYMLINK and TAG
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 25 Apr 2023 10:09:55 +0000 (19:09 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 26 Apr 2023 00:51:08 +0000 (09:51 +0900)
Fixes #27396.

man/udev.xml
src/udev/udev-rules.c

index 142f295f3e8f8324d531c2e791884e1878f6f6bf..332c7ac0967a071f23991046f3c3cdb56fc91208 100644 (file)
           <varlistentry>
             <term><varname>SYMLINK</varname></term>
             <listitem>
-              <para>Match the name of a symlink targeting the node. It can
-              be used once a SYMLINK key has been set in one of the preceding
-              rules. There may be multiple symlinks; only one needs to match.
-              </para>
+              <para>Match the name of a symlink targeting the node. It can be used once a SYMLINK key has
+              been set in one of the preceding rules. There may be multiple symlinks; only one needs to
+              match. If the operator is <literal>!=</literal>, the token returns true only if there is no
+              symlink matched.</para>
             </listitem>
           </varlistentry>
 
           <varlistentry>
             <term><varname>TAG</varname></term>
             <listitem>
-              <para>Match against a device tag.</para>
+              <para>Match against one of device tags. It can be used once a TAG key has been set in one of
+              the preceding rules. There may be multiple tags; only one needs to match. If the operator is
+              <literal>!=</literal>, the token returns true only if there is no tag matched.</para>
             </listitem>
           </varlistentry>
 
           <varlistentry>
             <term><varname>TAGS</varname></term>
             <listitem>
-              <para>Search the devpath upwards for a device with matching tag.</para>
+              <para>Search the devpath upwards for a device with matching tag. If the operator is
+              <literal>!=</literal>, the token returns true only if there is no tag matched.</para>
             </listitem>
           </varlistentry>
 
index e3d2adbafdd614dd2516a326227d55bfae0942f7..d6e701f3cc3248a9348196dc679f15b7351706f1 100644 (file)
@@ -1896,7 +1896,7 @@ static int udev_rule_apply_token_to_event(
                 const char *val;
 
                 FOREACH_DEVICE_DEVLINK(dev, val)
-                        if (token_match_string(token, strempty(startswith(val, "/dev/"))))
+                        if (token_match_string(token, strempty(startswith(val, "/dev/"))) == (token->op == OP_MATCH))
                                 return token->op == OP_MATCH;
                 return token->op == OP_NOMATCH;
         }
@@ -1926,7 +1926,7 @@ static int udev_rule_apply_token_to_event(
                 const char *val;
 
                 FOREACH_DEVICE_CURRENT_TAG(dev, val)
-                        if (token_match_string(token, val))
+                        if (token_match_string(token, val) == (token->op == OP_MATCH))
                                 return token->op == OP_MATCH;
                 return token->op == OP_NOMATCH;
         }