udevd.c revision 077fc5e2602effd9b0f46d8ae95271de2b5f2997
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering * Copyright (C) 2004-2012 Kay Sievers <kay@vrfy.org>
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering * Copyright (C) 2004 Chris Friesen <chris_friesen@sympatico.ca>
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering * Copyright (C) 2009 Canonical Ltd.
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering * Copyright (C) 2009 Scott James Remnant <scott@netsplit.com>
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering * This program is free software: you can redistribute it and/or modify
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering * it under the terms of the GNU General Public License as published by
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering * the Free Software Foundation, either version 2 of the License, or
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering * (at your option) any later version.
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering * This program is distributed in the hope that it will be useful,
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering * but WITHOUT ANY WARRANTY; without even the implied warranty of
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering * GNU General Public License for more details.
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering * You should have received a copy of the GNU General Public License
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering * along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "udev-util.h"
#include "formats-util.h"
#include "hashmap.h"
static bool arg_debug = false;
static int arg_daemonize = false;
static unsigned arg_children_max;
static int arg_exec_delay;
typedef struct Manager {
const char *cgroup;
int fd_inotify;
} Manager;
enum event_state {
struct event {
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;
struct worker_message {
if (!event)
if (!worker)
Iterator i;
static int worker_new(struct worker **ret, Manager *manager, struct udev_monitor *worker_monitor, pid_t pid) {
if (!worker)
return -ENOMEM;
log_warning("seq %llu '%s' is taking a long time", udev_device_get_seqnum(event->dev), event->devpath);
sd_event *e;
if (!manager)
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));
goto skip;
skip:
int fdcount;
if (fdcount < 0) {
goto out;
for (i = 0; i < fdcount; i++) {
case SIGTERM:
goto out;
out:
log_close();
Iterator i;
if (count < 0) {
if (!event)
return -ENOMEM;
Iterator i;
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))
sd_notify(false,
sd_notify(false,
sd_notify(false,
} control = {};
if (size < 0) {
if (!worker) {
if (dev) {
const char *str;
if (!ctrl_conn)
if (!ctrl_msg)
if (key) {
char *val;
arg_children_max = i;
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)
int status;
if (pid <= 0)
if (!worker) {
log_warning("worker ["PID_FMT"] terminated by signal %i (%s)", pid, WTERMSIG(status), strsignal(WTERMSIG(status)));
int fd, n, r;
n = sd_listen_fds(true);
if (ctrl_fd >= 0)
return -EINVAL;
if (netlink_fd >= 0)
return -EINVAL;
return -EINVAL;
if (ctrl_fd < 0) {
if (!udev)
return -ENOMEM;
if (!ctrl)
if (fd < 0)
if (ctrl_fd < 0)
if (netlink_fd < 0) {
if (!udev) {
if (!udev)
return -ENOMEM;
if (!monitor)
if (fd < 0)
if (ctrl_fd < 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 (!manager)
return log_oom();
r = sd_event_add_io(manager->event, &manager->inotify_event, manager->fd_inotify, EPOLLIN, on_inotify, manager);
r = sd_event_add_io(manager->event, &manager->uevent_event, fd_uevent, EPOLLIN, on_uevent, manager);
goto exit;
(void) sd_notify(false,
goto exit;
exit:
sd_notify(false,
if (manager)
log_open();
goto exit;
if (arg_debug)
if (getuid() != 0) {
goto exit;
if (arg_children_max == 0) {
goto exit;
goto exit;
goto exit;
if (r == -ENOENT)
goto exit;
if (arg_daemonize) {
(void) make_null_stdio();
switch (pid) {
goto exit;
log_close();
setsid();
exit:
log_close();