udevd.c revision b5884878a2874447b2a9f07f324a7cd909d96d48
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering * Copyright (C) 2004-2012 Kay Sievers <kay@vrfy.org>
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering * Copyright (C) 2004 Chris Friesen <chris_friesen@sympatico.ca>
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering * Copyright (C) 2009 Canonical Ltd.
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering * Copyright (C) 2009 Scott James Remnant <scott@netsplit.com>
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering * This program is free software: you can redistribute it and/or modify
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering * it under the terms of the GNU General Public License as published by
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering * the Free Software Foundation, either version 2 of the License, or
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering * (at your option) any later version.
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering * This program is distributed in the hope that it will be useful,
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering * but WITHOUT ANY WARRANTY; without even the implied warranty of
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering * GNU General Public License for more details.
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering * You should have received a copy of the GNU General Public License
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering * along with this program. If not, see <http://www.gnu.org/licenses/>.
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poetteringvoid udev_main_log(struct udev *udev, int priority,
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering const char *file, int line, const char *fn,
7dbb1d08f66cd44b1296be3ee8e3629b989e19a8Zbigniew Jędrzejewski-Szmek log_metav(priority, file, line, fn, format, args);
7dbb1d08f66cd44b1296be3ee8e3629b989e19a8Zbigniew Jędrzejewski-Szmekstatic struct udev_monitor *monitor;
7dbb1d08f66cd44b1296be3ee8e3629b989e19a8Zbigniew Jędrzejewski-Szmekstatic int worker_watch[2] = { -1, -1 };
7dbb1d08f66cd44b1296be3ee8e3629b989e19a8Zbigniew Jędrzejewski-Szmekstatic bool arg_debug = false;
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poetteringstatic int arg_daemonize = false;
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poetteringstatic usec_t arg_event_timeout_usec = 180 * USEC_PER_SEC;
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poetteringstatic usec_t arg_event_timeout_warn_usec = 180 * USEC_PER_SEC / 3;
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering unsigned long long int delaying_seqnum;
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering unsigned long long int seqnum;
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poetteringstatic inline struct event *node_to_event(struct udev_list_node *node) {
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poettering return container_of(node, struct event, node);
8ea48dfcd33e8db0c01bf8c57c3bbcfdc3c86d4bLennart Poetteringstatic void event_queue_cleanup(struct udev *udev, enum event_state type);
bool event_warned;
struct worker_message {
int exitcode;
return worker;
children--;
switch (pid) {
int fd_monitor;
if (fd_signal < 0) {
goto out;
if (fd_ep < 0) {
goto out;
goto out;
int err = 0;
goto out;
if (arg_exec_delay > 0)
d = udev_device_get_parent(d);
goto skip;
udev_event_execute_rules(udev_event, arg_event_timeout_usec, arg_event_timeout_warn_usec, rules, &sigmask_orig);
udev_event_execute_run(udev_event, arg_event_timeout_usec, arg_event_timeout_warn_usec, &sigmask_orig);
skip:
goto out;
int fdcount;
if (fdcount < 0) {
goto out;
for (i = 0; i < fdcount; i++) {
case SIGTERM:
goto out;
out:
log_close();
children++;
if (count < 0) {
if (major(event->devnum) != 0 && event->devnum == loop_event->devnum && event->is_block == loop_event->is_block)
if (major(event->devnum) != 0 && (event->devnum != loop_event->devnum || event->is_block != loop_event->is_block))
const char *str;
goto out;
goto out;
stop_exec_queue = true;
stop_exec_queue = false;
reload = true;
char *key;
char *val;
arg_children_max = i;
udev_exit = true;
out:
bool part_table_read = false;
bool has_partitions = false;
int fd;
if (fd >= 0) {
part_table_read = true;
return -ENOMEM;
r = udev_enumerate_scan_devices(e);
has_partitions = true;
char *buf;
if (r < 0 || nbytes <= 0)
return -errno;
if (!buf) {
return -ENOMEM;
if (!dev)
switch (signo) {
case SIGINT:
case SIGTERM:
udev_exit = true;
case SIGCHLD:
int status;
if (pid <= 0)
case SIGHUP:
reload = true;
int fd, n;
n = sd_listen_fds(true);
if (ctrl >= 0)
if (netlink >= 0)
* udev.children-max=<number of workers> events are fully serialized if set to 1
size_t l;
opt = s;
int prio;
free(s);
static void help(void) {
arg_daemonize = true;
arg_debug = true;
arg_resolve_names = 0;
help();
return -EINVAL;
goto exit;
log_open();
goto exit;
if (arg_debug) {
if (getuid() != 0) {
goto exit;
goto exit;
goto exit;
goto exit;
if (arg_daemonize) {
int fd;
if (fd >= 0) {
goto exit;
goto exit;
goto exit;
goto exit;
goto exit;
goto exit;
goto exit;
if (rc < 0)
if (arg_daemonize) {
switch (pid) {
goto exit;
goto exit_daemonize;
setsid();
if (arg_children_max <= 0) {
if (fd_inotify < 0) {
goto exit;
if (fd_signal < 0) {
goto exit;
goto exit;
if (fd_ep < 0) {
goto exit;
goto exit;
int fdcount;
int timeout;
if (udev_exit) {
if (fd_ctrl >= 0) {
if (fd_inotify >= 0) {
if (udev_cgroup)
int fd;
if (fd >= 0)
if (fdcount < 0)
if (fdcount == 0) {
if (udev_exit) {
log_error("seq %llu '%s' killed", udev_device_get_seqnum(worker->event->dev), worker->event->devpath);
for (i = 0; i < fdcount; i++) {
is_worker = true;
is_netlink = true;
is_signal = true;
is_inotify = true;
is_ctrl = true;
reload = true;
reload = true;
if (reload) {
reload = false;
if (is_worker)
if (is_netlink) {
if (is_signal) {
if (udev_exit)
if (is_inotify)
if (is_ctrl)
exit:
if (fd_ep >= 0)
if (fd_signal >= 0)
log_close();
return rc;