From: Yu Watanabe Date: Thu, 4 Apr 2024 18:55:25 +0000 (+0900) Subject: udevadm-control: add --load-credentials option X-Git-Tag: v256-rc1~178^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=51be364bbb3199b48afc2433ccbb3ee0132465ac;p=thirdparty%2Fsystemd.git udevadm-control: add --load-credentials option When specified, credentials udev.conf.* and udev.rules.* are copied to the corresponding directories. --- diff --git a/man/udevadm.xml b/man/udevadm.xml index 41c8ae7a12d..b515f3c79c0 100644 --- a/man/udevadm.xml +++ b/man/udevadm.xml @@ -727,6 +727,47 @@ + + + + When specified, the following credentials are used when passed in: + + + + udev.conf.* + + These credentials should contain valid + udev.conf5 + configuration data. From each matching credential a separate file is created. Example: a + passed credential udev.conf.50-foobar will be copied into a + configuration file /run/udev/udev.conf.d/50-foobar.conf. + + + + + + udev.rules.* + + These credentials should contain valid + udev7 + rules. From each matching credential a separate file is created. Example: a passed credential + udev.rules.50-foobar will be copied into a configuration file + /run/udev/rules.d/50-foobar.rules. + + + + + + + Note, this does not imply option. So, if + systemd-udevd is already running, please consider to also specify + to make the copied udev rules files used by + systemd-udevd. + + + + + diff --git a/src/udev/udevadm-control.c b/src/udev/udevadm-control.c index 428d5904135..29dc88330c6 100644 --- a/src/udev/udevadm-control.c +++ b/src/udev/udevadm-control.c @@ -8,6 +8,7 @@ #include #include +#include "creds-util.h" #include "parse-util.h" #include "process-util.h" #include "static-destruct.h" @@ -26,6 +27,7 @@ static bool arg_exit = false; static int arg_max_children = -1; static int arg_log_level = -1; static int arg_start_exec_queue = -1; +static bool arg_load_credentials = false; STATIC_DESTRUCTOR_REGISTER(arg_env, strv_freep); @@ -53,7 +55,8 @@ static int help(void) { " -p --property=KEY=VALUE Set a global property for all events\n" " -m --children-max=N Maximum number of children\n" " --ping Wait for udev to respond to a ping message\n" - " -t --timeout=SECONDS Maximum time to block for a reply\n", + " -t --timeout=SECONDS Maximum time to block for a reply\n" + " --load-credentials Load udev rules from credentials\n", program_invocation_short_name); return 0; @@ -62,23 +65,25 @@ static int help(void) { static int parse_argv(int argc, char *argv[]) { enum { ARG_PING = 0x100, + ARG_LOAD_CREDENTIALS, }; static const struct option options[] = { - { "exit", no_argument, NULL, 'e' }, - { "log-level", required_argument, NULL, 'l' }, - { "log-priority", required_argument, NULL, 'l' }, /* for backward compatibility */ - { "stop-exec-queue", no_argument, NULL, 's' }, - { "start-exec-queue", no_argument, NULL, 'S' }, - { "reload", no_argument, NULL, 'R' }, - { "reload-rules", no_argument, NULL, 'R' }, /* alias for -R */ - { "property", required_argument, NULL, 'p' }, - { "env", required_argument, NULL, 'p' }, /* alias for -p */ - { "children-max", required_argument, NULL, 'm' }, - { "ping", no_argument, NULL, ARG_PING }, - { "timeout", required_argument, NULL, 't' }, - { "version", no_argument, NULL, 'V' }, - { "help", no_argument, NULL, 'h' }, + { "exit", no_argument, NULL, 'e' }, + { "log-level", required_argument, NULL, 'l' }, + { "log-priority", required_argument, NULL, 'l' }, /* for backward compatibility */ + { "stop-exec-queue", no_argument, NULL, 's' }, + { "start-exec-queue", no_argument, NULL, 'S' }, + { "reload", no_argument, NULL, 'R' }, + { "reload-rules", no_argument, NULL, 'R' }, /* alias for -R */ + { "property", required_argument, NULL, 'p' }, + { "env", required_argument, NULL, 'p' }, /* alias for -p */ + { "children-max", required_argument, NULL, 'm' }, + { "ping", no_argument, NULL, ARG_PING }, + { "timeout", required_argument, NULL, 't' }, + { "load-credentials", no_argument, NULL, ARG_LOAD_CREDENTIALS }, + { "version", no_argument, NULL, 'V' }, + { "help", no_argument, NULL, 'h' }, {} }; @@ -141,6 +146,10 @@ static int parse_argv(int argc, char *argv[]) { return log_error_errno(r, "Failed to parse timeout value '%s': %m", optarg); break; + case ARG_LOAD_CREDENTIALS: + arg_load_credentials = true; + break; + case 'V': return print_version(); @@ -154,7 +163,7 @@ static int parse_argv(int argc, char *argv[]) { assert_not_reached(); } - if (!arg_has_control_commands()) + if (!arg_has_control_commands() && !arg_load_credentials) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "No control command option is specified."); @@ -241,6 +250,16 @@ int control_main(int argc, char *argv[], void *userdata) { if (r <= 0) return r; + if (arg_load_credentials) { + static const PickUpCredential table[] = { + { "udev.conf.", "/run/udev/udev.conf.d/", ".conf" }, + { "udev.rules.", "/run/udev/rules.d/", ".rules" }, + }; + r = pick_up_credentials(table, ELEMENTSOF(table)); + if (r < 0) + return r; + } + if (arg_has_control_commands()) { r = send_control_commands(); if (r < 0)