udevd.c revision 614a823c4416467d324c3236f58bfac34da33979
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * Copyright (C) 2004-2012 Kay Sievers <kay@vrfy.org>
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * Copyright (C) 2004 Chris Friesen <chris_friesen@sympatico.ca>
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * Copyright (C) 2009 Canonical Ltd.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * Copyright (C) 2009 Scott James Remnant <scott@netsplit.com>
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * This program is free software: you can redistribute it and/or modify
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * it under the terms of the GNU General Public License as published by
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * the Free Software Foundation, either version 2 of the License, or
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * (at your option) any later version.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * This program is distributed in the hope that it will be useful,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * but WITHOUT ANY WARRANTY; without even the implied warranty of
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * GNU General Public License for more details.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * You should have received a copy of the GNU General Public License
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * along with this program. If not, see <http://www.gnu.org/licenses/>.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic bool arg_debug = false;
eed857b71702f8551b46b66b31fa0d08583cf23cLennart Poetteringstatic int arg_daemonize = false;
a51c10485af349eb15faa4d1a63b9818bcf3e589Lennart Poetteringstatic usec_t arg_event_timeout_usec = 180 * USEC_PER_SEC;
19b50b5ba7ee8c1bfb330377309e4bab7a7531d8Lennart Poetteringstatic usec_t arg_event_timeout_warn_usec = 180 * USEC_PER_SEC / 3;
2c27fbca2d88214bd305272308a370a962818f1eLennart Poettering unsigned long long int delaying_seqnum;
2c27fbca2d88214bd305272308a370a962818f1eLennart Poettering unsigned long long int seqnum;
enum worker_state {
struct worker {
int refcount;
struct worker_message {
return worker;
children--;
static int worker_new(struct worker **ret, struct udev *udev, struct udev_monitor *worker_monitor, pid_t pid) {
if (!worker)
return -ENOMEM;
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();
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;
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) {
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;