]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udevadm verify: load all rules from the system if no rules were given
authorDmitry V. Levin <ldv@strace.io>
Thu, 9 Mar 2023 08:00:00 +0000 (08:00 +0000)
committerDmitry V. Levin <ldv@strace.io>
Fri, 10 Mar 2023 17:10:41 +0000 (17:10 +0000)
When udevadm verify is invoked without positional arguments, that is,
when no udev rules files are specified, load all rules files from the system
like the udev daemon does, and verify them.

man/udevadm.xml
src/udev/udevadm-verify.c
test/units/testsuite-17.11.sh

index 95b8da2b0a48c3f97384a64e0f61ad080c429c7d..bafd5af0fb928466db0adda4ed55371782d14d25 100644 (file)
@@ -51,7 +51,7 @@
     <cmdsynopsis>
       <command>udevadm verify</command>
       <arg choice="opt" rep="repeat">options</arg>
-      <arg choice="plain" rep="repeat"><replaceable>file</replaceable></arg>
+      <arg choice="opt" rep="repeat"><replaceable>file</replaceable></arg>
     </cmdsynopsis>
     <cmdsynopsis>
       <command>udevadm wait <optional>options</optional> <replaceable>device|syspath</replaceable></command>
     <refsect2>
       <title>udevadm verify
       <arg choice="opt"><replaceable>options</replaceable></arg>
-      <arg choice="plain" rep="repeat"><replaceable>file</replaceable></arg>
+      <arg choice="opt" rep="repeat"><replaceable>file</replaceable></arg>
       …
       </title>
 
       <para>Verify syntactic and semantic correctness of udev rules files.</para>
 
-      <para>Positional arguments should be used to specify one or more files to check.</para>
+      <para>Positional arguments could be used to specify one or more files to check.
+      If no files are specified, the udev rules are read from the files located in
+      the same udev/rules.d directories that are processed by the udev daemon.</para>
 
       <para>The exit status is <constant>0</constant> if all specified udev rules files
       are syntactically and semantically correct, and a non-zero error code otherwise.</para>
index 8819b07238ead9f6cf33dfbef42053d16f4489ad..f4728927312b439dd4701fcc85ba366ed4e0cb9f 100644 (file)
@@ -7,6 +7,8 @@
 #include <stdlib.h>
 #include <unistd.h>
 
+#include "conf-files.h"
+#include "constants.h"
 #include "log.h"
 #include "pretty-print.h"
 #include "strv.h"
@@ -23,7 +25,7 @@ static int help(void) {
         if (r < 0)
                 return log_oom();
 
-        printf("%s verify [OPTIONS] FILE...\n"
+        printf("%s verify [OPTIONS] [FILE...]\n"
                "\n%sVerify udev rules files.%s\n\n"
                "  -h --help                            Show this help\n"
                "  -V --version                         Show package version\n"
@@ -75,9 +77,6 @@ static int parse_argv(int argc, char *argv[]) {
                         assert_not_reached();
                 }
 
-        if (optind == argc)
-                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "No rules file specified.");
-
         return 1;
 }
 
@@ -121,5 +120,16 @@ int verify_main(int argc, char *argv[], void *userdata) {
         if (!rules)
                 return -ENOMEM;
 
+        if (optind == argc) {
+                const char* const* rules_dirs = STRV_MAKE_CONST(CONF_PATHS("udev/rules.d"));
+                _cleanup_strv_free_ char **files = NULL;
+
+                r = conf_files_list_strv(&files, ".rules", NULL, 0, rules_dirs);
+                if (r < 0)
+                        return log_error_errno(r, "Failed to enumerate rules files: %m");
+
+                return verify_rules(rules, files);
+        }
+
         return verify_rules(rules, strv_skip(argv, optind));
 }
index 4abcae60a5170c4c3157ac86be70af97305c254d..eb6a00dfb7fb1932e17ff65bfe9fb737e9be7917 100755 (executable)
@@ -60,8 +60,6 @@ assert_0 -V
 assert_0 --version
 assert_0 /dev/null
 
-# No rules file specified.
-assert_1
 # unrecognized option '--unknown'
 assert_1 --unknown
 # option requires an argument -- 'N'