udevd.c revision f96a5160c48574015cdd87d5991f65f8e03f0c72
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering * Copyright (C) 2004-2012 Kay Sievers <kay@vrfy.org>
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering * Copyright (C) 2004 Chris Friesen <chris_friesen@sympatico.ca>
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering * Copyright (C) 2009 Canonical Ltd.
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering * Copyright (C) 2009 Scott James Remnant <scott@netsplit.com>
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering * This program is free software: you can redistribute it and/or modify
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering * it under the terms of the GNU General Public License as published by
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering * the Free Software Foundation, either version 2 of the License, or
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering * (at your option) any later version.
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering * This program is distributed in the hope that it will be useful,
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering * but WITHOUT ANY WARRANTY; without even the implied warranty of
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering * GNU General Public License for more details.
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering * You should have received a copy of the GNU General Public License
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering * along with this program. If not, see <http://www.gnu.org/licenses/>.
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poetteringstatic bool arg_debug = false;
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poetteringstatic int arg_daemonize = false;
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poetteringstatic usec_t arg_event_timeout_usec = 180 * USEC_PER_SEC;
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poetteringstatic usec_t arg_event_timeout_warn_usec = 180 * USEC_PER_SEC / 3;
unsigned long long int delaying_seqnum;
unsigned long long int seqnum;
const char *devpath;
const char *devpath_old;
int ifindex;
bool is_block;
enum worker_state {
struct worker {
int refcount;
bool event_warned;
struct worker_message {
return worker;
children--;
switch (pid) {
int fd_monitor;
if (fd_signal < 0) {
goto out;
if (fd_ep < 0) {
goto out;
goto out;
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));
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();
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))
} 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
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)
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 (dev) {
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;