udevadm-control: add --load-credentials option
When specified, credentials udev.conf.* and udev.rules.* are copied to the corresponding directories.
This commit is contained in:
+35
-16
@@ -8,6 +8,7 @@
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#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)
|
||||
|
||||
Reference in New Issue
Block a user