From: Dmitry V. Levin Date: Thu, 9 Mar 2023 08:00:00 +0000 (+0000) Subject: udevadm verify: load all rules from the system if no rules were given X-Git-Tag: v254-rc1~1062^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e8c53080c41e0e651bc33185148925b7f6be4441;p=thirdparty%2Fsystemd.git udevadm verify: load all rules from the system if no rules were given 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. --- diff --git a/man/udevadm.xml b/man/udevadm.xml index 95b8da2b0a4..bafd5af0fb9 100644 --- a/man/udevadm.xml +++ b/man/udevadm.xml @@ -51,7 +51,7 @@ udevadm verify options - file + file udevadm wait options device|syspath @@ -745,13 +745,15 @@ 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> … Verify syntactic and semantic correctness of udev rules files. - Positional arguments should be used to specify one or more files to check. + 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. The exit status is 0 if all specified udev rules files are syntactically and semantically correct, and a non-zero error code otherwise. diff --git a/src/udev/udevadm-verify.c b/src/udev/udevadm-verify.c index 8819b07238e..f4728927312 100644 --- a/src/udev/udevadm-verify.c +++ b/src/udev/udevadm-verify.c @@ -7,6 +7,8 @@ #include #include +#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)); } diff --git a/test/units/testsuite-17.11.sh b/test/units/testsuite-17.11.sh index 4abcae60a51..eb6a00dfb7f 100755 --- a/test/units/testsuite-17.11.sh +++ b/test/units/testsuite-17.11.sh @@ -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'