udevd.c revision 86c3bece38bcf55da6387d20c6f01da9ad0284dc
2968644080fd103062f070e83edd620e0a58c44dZbigniew Jędrzejewski-Szmek * Copyright (C) 2004-2012 Kay Sievers <kay@vrfy.org>
2968644080fd103062f070e83edd620e0a58c44dZbigniew Jędrzejewski-Szmek * Copyright (C) 2004 Chris Friesen <chris_friesen@sympatico.ca>
2968644080fd103062f070e83edd620e0a58c44dZbigniew Jędrzejewski-Szmek * Copyright (C) 2009 Canonical Ltd.
2968644080fd103062f070e83edd620e0a58c44dZbigniew Jędrzejewski-Szmek * Copyright (C) 2009 Scott James Remnant <scott@netsplit.com>
2968644080fd103062f070e83edd620e0a58c44dZbigniew Jędrzejewski-Szmek * This program is free software: you can redistribute it and/or modify
2968644080fd103062f070e83edd620e0a58c44dZbigniew Jędrzejewski-Szmek * it under the terms of the GNU General Public License as published by
2968644080fd103062f070e83edd620e0a58c44dZbigniew Jędrzejewski-Szmek * the Free Software Foundation, either version 2 of the License, or
2968644080fd103062f070e83edd620e0a58c44dZbigniew Jędrzejewski-Szmek * (at your option) any later version.
2968644080fd103062f070e83edd620e0a58c44dZbigniew Jędrzejewski-Szmek * This program is distributed in the hope that it will be useful,
2968644080fd103062f070e83edd620e0a58c44dZbigniew Jędrzejewski-Szmek * but WITHOUT ANY WARRANTY; without even the implied warranty of
2968644080fd103062f070e83edd620e0a58c44dZbigniew Jędrzejewski-Szmek * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2968644080fd103062f070e83edd620e0a58c44dZbigniew Jędrzejewski-Szmek * GNU General Public License for more details.
2968644080fd103062f070e83edd620e0a58c44dZbigniew Jędrzejewski-Szmek * You should have received a copy of the GNU General Public License
2968644080fd103062f070e83edd620e0a58c44dZbigniew Jędrzejewski-Szmek * along with this program. If not, see <http://www.gnu.org/licenses/>.
1a7f1b385cd9de8a0da934fadc379860f914ef33Zbigniew Jędrzejewski-Szmekstatic bool arg_debug = false;
1a7f1b385cd9de8a0da934fadc379860f914ef33Zbigniew Jędrzejewski-Szmekstatic int arg_daemonize = false;
1a7f1b385cd9de8a0da934fadc379860f914ef33Zbigniew Jędrzejewski-Szmekstatic int arg_resolve_names = 1;
1a7f1b385cd9de8a0da934fadc379860f914ef33Zbigniew Jędrzejewski-Szmekstatic unsigned arg_children_max;
1a7f1b385cd9de8a0da934fadc379860f914ef33Zbigniew Jędrzejewski-Szmekstatic usec_t arg_event_timeout_usec = 180 * USEC_PER_SEC;
1a7f1b385cd9de8a0da934fadc379860f914ef33Zbigniew Jędrzejewski-Szmekstatic usec_t arg_event_timeout_warn_usec = 180 * USEC_PER_SEC / 3;
typedef struct Manager {
char *cgroup;
int fd_ep;
int fd_ctrl;
int fd_uevent;
int fd_signal;
int fd_inotify;
int fd_worker;
} 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;
bool warned;
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);
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));
r = -EAGAIN;
goto skip;
skip:
goto out;
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))
} 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;
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 (!manager)
return log_oom();
log_open();
goto exit;
if (arg_debug)
if (getuid() != 0) {
goto exit;
if (arg_children_max == 0) {
if (arg_daemonize) {
int fd;
if (fd < 0)
goto exit;
goto exit;
goto exit;
goto exit;
if (arg_daemonize) {
switch (pid) {
goto exit;
log_close();
setsid();
int fdcount;
int timeout;
if (fdcount < 0)
if (fdcount == 0) {
Iterator j;
for (i = 0; i < fdcount; i++) {
is_worker = true;
is_uevent = true;
is_signal = true;
is_inotify = true;
is_ctrl = true;
if (is_worker)
if (is_uevent)
if (is_signal) {
case SIGINT:
case SIGTERM:
case SIGHUP:
case SIGCHLD:
if (is_inotify)
if (is_ctrl)
exit:
if (manager)
log_close();