udevd.c revision 638ca89c53e2b897cfb3f627f4acbc7d09af2f4c
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering * Copyright (C) 2004-2012 Kay Sievers <kay@vrfy.org>
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering * Copyright (C) 2004 Chris Friesen <chris_friesen@sympatico.ca>
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering * Copyright (C) 2009 Canonical Ltd.
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering * Copyright (C) 2009 Scott James Remnant <scott@netsplit.com>
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering * This program is free software: you can redistribute it and/or modify
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering * it under the terms of the GNU General Public License as published by
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering * the Free Software Foundation, either version 2 of the License, or
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering * (at your option) any later version.
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering * This program is distributed in the hope that it will be useful,
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering * but WITHOUT ANY WARRANTY; without even the implied warranty of
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering * GNU General Public License for more details.
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering * You should have received a copy of the GNU General Public License
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering * along with this program. If not, see <http://www.gnu.org/licenses/>.
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poetteringvoid udev_main_log(struct udev *udev, int priority,
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering const char *file, int line, const char *fn,
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering log_metav(priority, file, line, fn, format, args);
85e070c2b3f66d838c11f8f008106b9e42c9afafMichal Sekletar unsigned long long int delaying_seqnum;
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering unsigned long long int seqnum;
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poetteringstatic inline struct event *node_to_event(struct udev_list_node *node)
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering return container_of(node, struct event, node);
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poetteringstatic void event_queue_cleanup(struct udev *udev, enum event_state type);
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering/* passed from worker to main process */
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poetteringstatic inline struct worker *node_to_worker(struct udev_list_node *node)
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering return container_of(node, struct worker, node);
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poetteringstatic void event_queue_delete(struct event *event)
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poetteringstatic struct worker *worker_ref(struct worker *worker)
children--;
switch (pid) {
int fd_monitor;
if (fd_signal < 0) {
goto out;
if (fd_ep < 0) {
goto out;
goto out;
int err = 0;
goto out;
if (exec_delay > 0)
d = udev_device_get_parent(d);
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();
children++;
if (count < 0) {
#ifdef HAVE_FIRMWARE
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))
#ifdef HAVE_FIRMWARE
const char *str;
goto out;
goto out;
stop_exec_queue = true;
stop_exec_queue = false;
reload = true;
char *key;
char *val;
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;
char *buf;
if (r < 0 || nbytes <= 0)
return -errno;
if (!buf) {
return -ENOMEM;
if (!dev)
switch (signo) {
case SIGINT:
case SIGTERM:
udev_exit = true;
case SIGCHLD:
int status;
if (pid <= 0)
case SIGHUP:
reload = true;
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
char *w, *state;
size_t l;
char *s, *opt;
s = strndup(w, l);
opt = s;
int prio;
free(s);
int daemonize = false;
goto exit;
log_open();
int option;
switch (option) {
daemonize = true;
debug = true;
resolve_names = 0;
goto exit;
goto exit;
goto exit;
goto exit;
if (getuid() != 0) {
goto exit;
if (daemonize) {
int fd;
if (fd >= 0) {
goto exit;
goto exit;
goto exit;
goto exit;
goto exit;
goto exit;
if (daemonize) {
switch (pid) {
goto exit;
goto exit_daemonize;
setsid();
if (!debug) {
int fd;
if (fd >= 0) {
if (fd_inotify < 0) {
goto exit;
if (fd_signal < 0) {
goto exit;
goto exit;
goto exit;
if (fd_ep < 0) {
goto exit;
goto exit;
if (children_max <= 0) {
if (rc < 0)
int fdcount;
int timeout;
if (udev_exit) {
if (fd_ctrl >= 0) {
if (fd_inotify >= 0) {
if (udev_cgroup)
int fd;
if (fd >= 0)
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 (is_signal) {
if (udev_exit)
if (is_inotify)
if (is_ctrl)
exit:
if (fd_ep >= 0)
if (fd_signal >= 0)
label_finish();
log_close();
return rc;