udevd.c revision 6af5e6a4c918a68b196a04346732e094e5373a36
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack * Copyright (C) 2004-2012 Kay Sievers <kay@vrfy.org>
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack * Copyright (C) 2004 Chris Friesen <chris_friesen@sympatico.ca>
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack * Copyright (C) 2009 Canonical Ltd.
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack * Copyright (C) 2009 Scott James Remnant <scott@netsplit.com>
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack * This program is free software: you can redistribute it and/or modify
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack * it under the terms of the GNU General Public License as published by
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack * the Free Software Foundation, either version 2 of the License, or
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack * (at your option) any later version.
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack * This program is distributed in the hope that it will be useful,
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack * but WITHOUT ANY WARRANTY; without even the implied warranty of
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack * GNU General Public License for more details.
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack * You should have received a copy of the GNU General Public License
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack * along with this program. If not, see <http://www.gnu.org/licenses/>.
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mackstatic bool arg_debug = false;
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mackstatic int arg_daemonize = false;
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mackstatic usec_t arg_event_timeout_usec = 180 * USEC_PER_SEC;
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mackstatic usec_t arg_event_timeout_warn_usec = 180 * USEC_PER_SEC / 3;
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack unsigned long long int delaying_seqnum;
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack unsigned long long int seqnum;
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mackstatic inline struct event *node_to_event(struct udev_list_node *node) {
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mackstatic void event_queue_cleanup(struct udev *udev, enum event_state type);
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack/* passed from worker to main process */
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mackstatic inline struct worker *node_to_worker(struct udev_list_node *node) {
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mackstatic void event_queue_delete(struct event *event) {
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mackstatic struct worker *worker_ref(struct worker *worker) {
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mackstatic void worker_cleanup(struct worker *worker) {
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mackstatic void worker_unref(struct worker *worker) {
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack log_debug("worker ["PID_FMT"] cleaned up", worker->pid);
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mackstatic void worker_list_cleanup(struct udev *udev) {
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack udev_list_node_foreach_safe(loop, tmp, &worker_list) {
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mackstatic int worker_new(struct worker **ret, struct udev *udev, struct udev_monitor *worker_monitor, pid_t pid) {
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack /* close monitor, but keep address around */
children++;
switch (pid) {
int fd_monitor;
if (fd_signal < 0) {
goto out;
if (fd_ep < 0) {
goto out;
goto out;
r = -ENOMEM;
goto out;
if (arg_exec_delay > 0)
d = udev_device_get_parent(d);
log_debug_errno(errno, "Unable to flock(%s), skipping event handling: %m", udev_device_get_devnode(d));
r = -EAGAIN;
goto skip;
&sigmask_orig);
&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();
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))
} control = {};
bool found = false;
if (size < 0) {
found = true;
if (!found)
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;
struct inotify_event *e;
ssize_t l;
if (!dev)
switch (signo) {
case SIGINT:
case SIGTERM:
udev_exit = true;
case SIGCHLD:
int status;
bool found = false;
if (pid <= 0)
found = true;
if (!found)
case SIGHUP:
reload = true;
static void event_queue_update(void) {
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
if (!value)
int prio;
static void help(void) {
arg_daemonize = true;
arg_debug = true;
arg_resolve_names = 0;
help();
return -EINVAL;
if (!udev) {
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) {
if (!udev_ctrl) {
goto exit;
if (!monitor) {
goto exit;
if (!udev_ctrl) {
goto exit;
if (!monitor) {
goto exit;
goto exit;
goto exit;
if (!rules) {
goto exit;
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)
if (fdcount < 0)
if (fdcount == 0) {
if (udev_exit) {
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 (dev) {
if (is_signal) {
if (udev_exit)
if (is_inotify) {
if (is_ctrl)
exit:
if (fd_ep >= 0)
if (fd_signal >= 0)
log_close();