struct udev *udev = udev_device_get_udev(dev);
int i;
- if (!ctx)
- return EXIT_FAILURE;
+ if (!ctx) {
+ ctx = kmod_new(NULL, NULL);
+ if (!ctx)
+ return -ENOMEM;
- if (argc < 3) {
- err(udev, "missing command + argument\n");
+ info(udev, "load module index\n");
+ kmod_load_resources(ctx);
+ }
+
+ if (argc < 3 || strcmp(argv[1], "load")) {
+ err(udev, "expect: %s load <module>\n", argv[0]);
return EXIT_FAILURE;
}
static int builtin_kmod_init(struct udev *udev)
{
- kmod_unref(ctx);
+ if (ctx)
+ return 0;
+
ctx = kmod_new(NULL, NULL);
if (!ctx)
return -ENOMEM;
info(udev, "load module index\n");
+ kmod_load_resources(ctx);
return 0;
}
UDEV_CTRL_SET_LOG_LEVEL,
UDEV_CTRL_STOP_EXEC_QUEUE,
UDEV_CTRL_START_EXEC_QUEUE,
- UDEV_CTRL_RELOAD_RULES,
+ UDEV_CTRL_RELOAD,
UDEV_CTRL_SET_ENV,
UDEV_CTRL_SET_CHILDREN_MAX,
UDEV_CTRL_PING,
return ctrl_send(uctrl, UDEV_CTRL_START_EXEC_QUEUE, 0, NULL, timeout);
}
-int udev_ctrl_send_reload_rules(struct udev_ctrl *uctrl, int timeout)
+int udev_ctrl_send_reload(struct udev_ctrl *uctrl, int timeout)
{
- return ctrl_send(uctrl, UDEV_CTRL_RELOAD_RULES, 0, NULL, timeout);
+ return ctrl_send(uctrl, UDEV_CTRL_RELOAD, 0, NULL, timeout);
}
int udev_ctrl_send_set_env(struct udev_ctrl *uctrl, const char *key, int timeout)
return -1;
}
-int udev_ctrl_get_reload_rules(struct udev_ctrl_msg *ctrl_msg)
+int udev_ctrl_get_reload(struct udev_ctrl_msg *ctrl_msg)
{
- if (ctrl_msg->ctrl_msg_wire.type == UDEV_CTRL_RELOAD_RULES)
+ if (ctrl_msg->ctrl_msg_wire.type == UDEV_CTRL_RELOAD)
return 1;
return -1;
}
return rules;
}
-void udev_rules_unref(struct udev_rules *rules)
+struct udev_rules *udev_rules_unref(struct udev_rules *rules)
{
if (rules == NULL)
- return;
+ return NULL;
free(rules->tokens);
free(rules->buf);
free(rules->trie_nodes);
free(rules->uids);
free(rules->gids);
free(rules);
+ return NULL;
}
static int match_key(struct udev_rules *rules, struct token *token, const char *val)
/* udev-rules.c */
struct udev_rules;
struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names);
-void udev_rules_unref(struct udev_rules *rules);
+struct udev_rules *udev_rules_unref(struct udev_rules *rules);
int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event, const sigset_t *sigmask);
void udev_rules_apply_static_dev_perms(struct udev_rules *rules);
int udev_ctrl_send_set_log_level(struct udev_ctrl *uctrl, int priority, int timeout);
int udev_ctrl_send_stop_exec_queue(struct udev_ctrl *uctrl, int timeout);
int udev_ctrl_send_start_exec_queue(struct udev_ctrl *uctrl, int timeout);
-int udev_ctrl_send_reload_rules(struct udev_ctrl *uctrl, int timeout);
+int udev_ctrl_send_reload(struct udev_ctrl *uctrl, int timeout);
int udev_ctrl_send_ping(struct udev_ctrl *uctrl, int timeout);
int udev_ctrl_send_exit(struct udev_ctrl *uctrl, int timeout);
int udev_ctrl_send_set_env(struct udev_ctrl *uctrl, const char *key, int timeout);
int udev_ctrl_get_set_log_level(struct udev_ctrl_msg *ctrl_msg);
int udev_ctrl_get_stop_exec_queue(struct udev_ctrl_msg *ctrl_msg);
int udev_ctrl_get_start_exec_queue(struct udev_ctrl_msg *ctrl_msg);
-int udev_ctrl_get_reload_rules(struct udev_ctrl_msg *ctrl_msg);
+int udev_ctrl_get_reload(struct udev_ctrl_msg *ctrl_msg);
int udev_ctrl_get_ping(struct udev_ctrl_msg *ctrl_msg);
int udev_ctrl_get_exit(struct udev_ctrl_msg *ctrl_msg);
const char *udev_ctrl_get_set_env(struct udev_ctrl_msg *ctrl_msg);
/*
- * Copyright (C) 2005-2008 Kay Sievers <kay.sievers@vrfy.org>
+ * Copyright (C) 2005-2011 Kay Sievers <kay.sievers@vrfy.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
printf("Usage: udevadm control COMMAND\n"
" --exit instruct the daemon to cleanup and exit\n"
" --log-priority=<level> set the udev log level for the daemon\n"
- " --stop-exec-queue keep udevd from executing events, queue only\n"
+ " --stop-exec-queue do not execute events, queue only\n"
" --start-exec-queue execute events, flush queue\n"
- " --reload-rules reloads the rules files\n"
+ " --reload reload rules and databases\n"
" --property=<KEY>=<value> set a global property for all events\n"
" --children-max=<N> maximum number of children\n"
" --timeout=<seconds> maximum time to block for a reply\n"
{ "log-priority", required_argument, NULL, 'l' },
{ "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' },
{ "property", required_argument, NULL, 'p' },
{ "env", required_argument, NULL, 'p' },
rc = 0;
break;
case 'R':
- if (udev_ctrl_send_reload_rules(uctrl, timeout) < 0)
+ if (udev_ctrl_send_reload(uctrl, timeout) < 0)
rc = 2;
else
rc = 0;
.name = "test-builtin",
.cmd = adm_builtin,
.help = "test a built-in command",
+ .debug = true,
};
</listitem>
</varlistentry>
<varlistentry>
- <term><option>--reload-rules</option></term>
+ <term><option>--reload</option></term>
<listitem>
- <para>Signal udevd to reload the rules files.
- The udev daemon detects changes automatically, this option is
- usually not needed. Reloading rules does not apply any changes
- to already existing devices.</para>
+ <para>Signal udevd to reload the rules files and other databases like the kernel
+ module index. Reloading rules and databases does not apply any changes to already
+ existing devices; the new configuration will only be applied to new events.</para>
</listitem>
</varlistentry>
<varlistentry>
static int fd_ep = -1;
static int fd_inotify = -1;
static bool stop_exec_queue;
-static bool reload_config;
+static bool reload;
static int children;
static int children_max;
static int exec_delay;
stop_exec_queue = false;
}
- if (udev_ctrl_get_reload_rules(ctrl_msg) > 0) {
- info(udev, "udevd message (RELOAD_RULES) received\n");
- reload_config = true;
+ if (udev_ctrl_get_reload(ctrl_msg) > 0) {
+ info(udev, "udevd message (RELOAD) received\n");
+ reload = true;
}
str = udev_ctrl_get_set_env(ctrl_msg);
continue;
if (strlen(s) != strlen(".rules"))
continue;
- reload_config = true;
+ reload = true;
continue;
}
}
break;
case SIGHUP:
- reload_config = true;
+ reload = true;
break;
}
}
}
/* start new events */
- if (!udev_list_node_is_empty(&event_list) && !udev_exit && !stop_exec_queue)
- event_queue_start(udev);
+ if (!udev_list_node_is_empty(&event_list) && !udev_exit && !stop_exec_queue) {
+ if (rules == NULL)
+ rules = udev_rules_new(udev, resolve_names);
+ if (rules != NULL)
+ event_queue_start(udev);
+ }
if (is_signal) {
struct signalfd_siginfo fdsi;
ctrl_conn = handle_ctrl_msg(udev_ctrl);
/* rules changed, set by inotify or a HUP signal */
- if (reload_config) {
- struct udev_rules *rules_new;
-
+ if (reload) {
worker_kill(udev, 0);
- rules_new = udev_rules_new(udev, resolve_names);
- if (rules_new != NULL) {
- udev_rules_unref(rules);
- rules = rules_new;
- }
- reload_config = 0;
-
+ rules = udev_rules_unref(rules);
udev_builtin_exit(udev);
- udev_builtin_init(udev);
+ reload = 0;
}
}