diff options
author | Anthony G. Basile <blueness@gentoo.org> | 2014-01-13 18:16:50 -0500 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2014-01-13 18:16:50 -0500 |
commit | e33d2cfc5e0bafb10eb82bb32776c41e558a026c (patch) | |
tree | 619ae0451cd40f169d740a02f26bf46a17c854b1 /src/udev/udevd.c | |
parent | 248ea81923ce671979ccbe0bca5683d4239feb70 (diff) |
src/udev: bring up to date with upstream.
These commits were authored by
Zbigniew Jędrzejewski-Szmek
Tom Gundersen
Kay Sievers
Lennart Poettering
Shawn Landden
Daniel Buch
Martin Pitt
Karel Zak
Yang Zhiyong
Note: udev_builtin_net_setup_link has *not* been imported. Also
still missing from udev-builtin is udev_builtin_uaccess.
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'src/udev/udevd.c')
-rw-r--r-- | src/udev/udevd.c | 132 |
1 files changed, 66 insertions, 66 deletions
diff --git a/src/udev/udevd.c b/src/udev/udevd.c index b769be7451..224763eaa5 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -48,6 +48,7 @@ #include "def.h" #include "cgroup-util.h" #include "dev-setup.h" +#include "fileio.h" static bool debug; @@ -144,7 +145,7 @@ static void event_queue_delete(struct event *event, bool export) if (export) { udev_queue_export_device_finished(udev_queue_export, event->dev); - log_debug("seq %llu done with %i\n", udev_device_get_seqnum(event->dev), event->exitcode); + log_debug("seq %llu done with %i", udev_device_get_seqnum(event->dev), event->exitcode); } udev_device_unref(event->dev); free(event); @@ -169,7 +170,7 @@ static void worker_unref(struct worker *worker) worker->refcount--; if (worker->refcount > 0) return; - log_debug("worker [%u] cleaned up\n", worker->pid); + log_debug("worker [%u] cleaned up", worker->pid); worker_cleanup(worker); } @@ -234,14 +235,14 @@ static void worker_new(struct event *event) sigfillset(&mask); fd_signal = signalfd(-1, &mask, SFD_NONBLOCK|SFD_CLOEXEC); if (fd_signal < 0) { - log_error("error creating signalfd %m\n"); + log_error("error creating signalfd %m"); rc = 2; goto out; } fd_ep = epoll_create1(EPOLL_CLOEXEC); if (fd_ep < 0) { - log_error("error creating epoll fd: %m\n"); + log_error("error creating epoll fd: %m"); rc = 3; goto out; } @@ -257,7 +258,7 @@ static void worker_new(struct event *event) if (epoll_ctl(fd_ep, EPOLL_CTL_ADD, fd_signal, &ep_signal) < 0 || epoll_ctl(fd_ep, EPOLL_CTL_ADD, fd_monitor, &ep_monitor) < 0) { - log_error("fail to add fds to epoll: %m\n"); + log_error("fail to add fds to epoll: %m"); rc = 4; goto out; } @@ -266,14 +267,14 @@ static void worker_new(struct event *event) prctl(PR_SET_PDEATHSIG, SIGTERM); /* reset OOM score, we only protect the main daemon */ - write_one_line_file("/proc/self/oom_score_adj", "0"); + write_string_file("/proc/self/oom_score_adj", "0"); for (;;) { struct udev_event *udev_event; struct worker_message msg; int err; - log_debug("seq %llu running\n", udev_device_get_seqnum(dev)); + log_debug("seq %llu running", udev_device_get_seqnum(dev)); udev_event = udev_event_new(dev); if (udev_event == NULL) { rc = 5; @@ -308,7 +309,7 @@ static void worker_new(struct event *event) msg.pid = getpid(); send(worker_watch[WRITE_END], &msg, sizeof(struct worker_message), 0); - log_debug("seq %llu processed with %i\n", udev_device_get_seqnum(dev), err); + log_debug("seq %llu processed with %i", udev_device_get_seqnum(dev), err); udev_device_unref(dev); dev = NULL; @@ -330,7 +331,7 @@ static void worker_new(struct event *event) if (fdcount < 0) { if (errno == EINTR) continue; - log_error("failed to poll: %m\n"); + log_error("failed to poll: %m"); goto out; } @@ -372,7 +373,7 @@ out: udev_monitor_unref(worker_monitor); event->state = EVENT_QUEUED; free(worker); - log_error("fork of child failed: %m\n"); + log_error("fork of child failed: %m"); break; default: /* close monitor, but keep address around */ @@ -385,7 +386,7 @@ out: event->state = EVENT_RUNNING; udev_list_node_append(&worker->node, &worker_list); children++; - log_debug("seq %llu forked new worker [%u]\n", udev_device_get_seqnum(event->dev), pid); + log_debug("seq %llu forked new worker [%u]", udev_device_get_seqnum(event->dev), pid); break; } } @@ -403,7 +404,7 @@ static void event_run(struct event *event) count = udev_monitor_send_device(monitor, worker->monitor, event->dev); if (count < 0) { - log_error("worker [%u] did not accept message %zi (%m), kill it\n", worker->pid, count); + log_error("worker [%u] did not accept message %zi (%m), kill it", worker->pid, count); kill(worker->pid, SIGKILL); worker->state = WORKER_KILLED; continue; @@ -418,7 +419,7 @@ static void event_run(struct event *event) if (children >= children_max) { if (children_max > 1) - log_debug("maximum number (%i) of children reached\n", children); + log_debug("maximum number (%i) of children reached", children); return; } @@ -449,7 +450,7 @@ static int event_queue_insert(struct udev_device *dev) #endif udev_queue_export_device_queued(udev_queue_export, dev); - log_debug("seq %llu queued, '%s' '%s'\n", udev_device_get_seqnum(dev), + log_debug("seq %llu queued, '%s' '%s'", udev_device_get_seqnum(dev), udev_device_get_action(dev), udev_device_get_subsystem(dev)); event->state = EVENT_QUEUED; @@ -634,24 +635,24 @@ static struct udev_ctrl_connection *handle_ctrl_msg(struct udev_ctrl *uctrl) i = udev_ctrl_get_set_log_level(ctrl_msg); if (i >= 0) { - log_debug("udevd message (SET_LOG_PRIORITY) received, log_priority=%i\n", i); + log_debug("udevd message (SET_LOG_LEVEL) received, log_priority=%i", i); log_set_max_level(i); udev_set_log_priority(udev, i); worker_kill(udev); } if (udev_ctrl_get_stop_exec_queue(ctrl_msg) > 0) { - log_debug("udevd message (STOP_EXEC_QUEUE) received\n"); + log_debug("udevd message (STOP_EXEC_QUEUE) received"); stop_exec_queue = true; } if (udev_ctrl_get_start_exec_queue(ctrl_msg) > 0) { - log_debug("udevd message (START_EXEC_QUEUE) received\n"); + log_debug("udevd message (START_EXEC_QUEUE) received"); stop_exec_queue = false; } if (udev_ctrl_get_reload(ctrl_msg) > 0) { - log_debug("udevd message (RELOAD) received\n"); + log_debug("udevd message (RELOAD) received"); reload = true; } @@ -668,14 +669,14 @@ static struct udev_ctrl_connection *handle_ctrl_msg(struct udev_ctrl *uctrl) val[0] = '\0'; val = &val[1]; if (val[0] == '\0') { - log_debug("udevd message (ENV) received, unset '%s'\n", key); + log_debug("udevd message (ENV) received, unset '%s'", key); udev_add_property(udev, key, NULL); } else { - log_debug("udevd message (ENV) received, set '%s=%s'\n", key, val); + log_debug("udevd message (ENV) received, set '%s=%s'", key, val); udev_add_property(udev, key, val); } } else { - log_error("wrong key format '%s'\n", key); + log_error("wrong key format '%s'", key); } free(key); } @@ -684,15 +685,15 @@ static struct udev_ctrl_connection *handle_ctrl_msg(struct udev_ctrl *uctrl) i = udev_ctrl_get_set_children_max(ctrl_msg); if (i >= 0) { - log_debug("udevd message (SET_MAX_CHILDREN) received, children_max=%i\n", i); + log_debug("udevd message (SET_MAX_CHILDREN) received, children_max=%i", i); children_max = i; } if (udev_ctrl_get_ping(ctrl_msg) > 0) - log_debug("udevd message (SYNC) received\n"); + log_debug("udevd message (SYNC) received"); if (udev_ctrl_get_exit(ctrl_msg) > 0) { - log_debug("udevd message (EXIT) received\n"); + log_debug("udevd message (EXIT) received"); udev_exit = true; /* keep reference to block the client until we exit */ udev_ctrl_connection_ref(ctrl_conn); @@ -714,7 +715,7 @@ static int handle_inotify(struct udev *udev) buf = malloc(nbytes); if (buf == NULL) { - log_error("error getting buffer for inotify\n"); + log_error("error getting buffer for inotify"); return -1; } @@ -726,17 +727,17 @@ static int handle_inotify(struct udev *udev) ev = (struct inotify_event *)(buf + pos); dev = udev_watch_lookup(udev, ev->wd); if (dev != NULL) { - log_debug("inotify event: %x for %s\n", ev->mask, udev_device_get_devnode(dev)); + log_debug("inotify event: %x for %s", ev->mask, udev_device_get_devnode(dev)); if (ev->mask & IN_CLOSE_WRITE) { char filename[UTIL_PATH_SIZE]; int fd; - log_debug("device %s closed, synthesising 'change'\n", udev_device_get_devnode(dev)); + log_debug("device %s closed, synthesising 'change'", udev_device_get_devnode(dev)); strscpyl(filename, sizeof(filename), udev_device_get_syspath(dev), "/uevent", NULL); fd = open(filename, O_WRONLY); if (fd >= 0) { if (write(fd, "change", 6) < 0) - log_debug("error writing uevent: %m\n"); + log_debug("error writing uevent: %m"); close(fd); } } @@ -774,26 +775,26 @@ static void handle_signal(struct udev *udev, int signo) if (worker->pid != pid) continue; - log_debug("worker [%u] exit\n", pid); + log_debug("worker [%u] exit", pid); if (WIFEXITED(status)) { if (WEXITSTATUS(status) != 0) - log_error("worker [%u] exit with return code %i\n", + log_error("worker [%u] exit with return code %i", pid, WEXITSTATUS(status)); } else if (WIFSIGNALED(status)) { - log_error("worker [%u] terminated by signal %i (%s)\n", + log_error("worker [%u] terminated by signal %i (%s)", pid, WTERMSIG(status), strsignal(WTERMSIG(status))); } else if (WIFSTOPPED(status)) { - log_error("worker [%u] stopped\n", pid); + log_error("worker [%u] stopped", pid); } else if (WIFCONTINUED(status)) { - log_error("worker [%u] continued\n", pid); + log_error("worker [%u] continued", pid); } else { - log_error("worker [%u] exit with status 0x%04x\n", pid, status); + log_error("worker [%u] exit with status 0x%04x", pid, status); } if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { if (worker->event) { - log_error("worker [%u] failed while handling '%s'\n", + log_error("worker [%u] failed while handling '%s'", pid, worker->event->devpath); worker->event->exitcode = -32; event_queue_delete(worker->event, true); @@ -891,10 +892,15 @@ static void static_dev_create_from_modules(struct udev *udev) */ static void kernel_cmdline_options(struct udev *udev) { - char *line, *w, *state; + _cleanup_free_ char *line = NULL; + char *w, *state; size_t l; + int r; - if (read_one_line_file("/proc/cmdline", &line) < 0) + r = proc_cmdline(&line); + if (r < 0) + log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r)); + if (r <= 0) return; FOREACH_WORD_QUOTED(w, l, line, state) { @@ -924,8 +930,6 @@ static void kernel_cmdline_options(struct udev *udev) free(s); } - - free(line); } int main(int argc, char *argv[]) @@ -961,7 +965,7 @@ int main(int argc, char *argv[]) udev_set_log_fn(udev, udev_main_log); log_set_max_level(udev_get_log_priority(udev)); - log_debug("version %s\n", VERSION); + log_debug("version %s", VERSION); label_init("/dev"); for (;;) { @@ -995,7 +999,7 @@ int main(int argc, char *argv[]) resolve_names = -1; } else { fprintf(stderr, "resolve-names must be early, late or never\n"); - log_error("resolve-names must be early, late or never\n"); + log_error("resolve-names must be early, late or never"); goto exit; } break; @@ -1022,16 +1026,12 @@ int main(int argc, char *argv[]) if (getuid() != 0) { fprintf(stderr, "root privileges required\n"); - log_error("root privileges required\n"); + log_error("root privileges required"); goto exit; } /* set umask before creating any file/directory */ - if (chdir("/") == -1) { - fprintf(stderr, "Cannot chdir to /\n"); - log_error("Cannot chdir to /\n"); - goto exit; - } + chdir("/"); umask(022); mkdir("/run/udev", 0755); @@ -1053,7 +1053,7 @@ int main(int argc, char *argv[]) close(fd); } else { fprintf(stderr, "cannot open /dev/null\n"); - log_error("cannot open /dev/null\n"); + log_error("cannot open /dev/null"); } } @@ -1070,7 +1070,7 @@ int main(int argc, char *argv[]) monitor = udev_monitor_new_from_netlink(udev, "kernel"); if (monitor == NULL) { fprintf(stderr, "error initializing netlink socket\n"); - log_error("error initializing netlink socket\n"); + log_error("error initializing netlink socket"); rc = 3; goto exit; } @@ -1078,14 +1078,14 @@ int main(int argc, char *argv[]) if (udev_monitor_enable_receiving(monitor) < 0) { fprintf(stderr, "error binding netlink socket\n"); - log_error("error binding netlink socket\n"); + log_error("error binding netlink socket"); rc = 3; goto exit; } if (udev_ctrl_enable_receiving(udev_ctrl) < 0) { fprintf(stderr, "error binding udev control socket\n"); - log_error("error binding udev control socket\n"); + log_error("error binding udev control socket"); rc = 1; goto exit; } @@ -1095,7 +1095,7 @@ int main(int argc, char *argv[]) /* create queue file before signalling 'ready', to make sure we block 'settle' */ udev_queue_export = udev_queue_export_new(udev); if (udev_queue_export == NULL) { - log_error("error creating queue file\n"); + log_error("error creating queue file"); goto exit; } @@ -1107,7 +1107,7 @@ int main(int argc, char *argv[]) case 0: break; case -1: - log_error("fork of daemon failed: %m\n"); + log_error("fork of daemon failed: %m"); rc = 4; goto exit; default: @@ -1117,7 +1117,7 @@ int main(int argc, char *argv[]) setsid(); - write_one_line_file("/proc/self/oom_score_adj", "-1000"); + write_string_file("/proc/self/oom_score_adj", "-1000"); } print_kmsg("starting version " VERSION "\n"); @@ -1137,7 +1137,7 @@ int main(int argc, char *argv[]) fd_inotify = udev_watch_init(udev); if (fd_inotify < 0) { fprintf(stderr, "error initializing inotify\n"); - log_error("error initializing inotify\n"); + log_error("error initializing inotify"); rc = 4; goto exit; } @@ -1161,7 +1161,7 @@ int main(int argc, char *argv[]) fd_signal = signalfd(-1, &mask, SFD_NONBLOCK|SFD_CLOEXEC); if (fd_signal < 0) { fprintf(stderr, "error creating signalfd\n"); - log_error("error creating signalfd\n"); + log_error("error creating signalfd"); rc = 5; goto exit; } @@ -1169,7 +1169,7 @@ int main(int argc, char *argv[]) /* unnamed socket from workers to the main daemon */ if (socketpair(AF_LOCAL, SOCK_DGRAM|SOCK_CLOEXEC, 0, worker_watch) < 0) { fprintf(stderr, "error creating socketpair\n"); - log_error("error creating socketpair\n"); + log_error("error creating socketpair"); rc = 6; goto exit; } @@ -1179,7 +1179,7 @@ int main(int argc, char *argv[]) rules = udev_rules_new(udev, resolve_names); if (rules == NULL) { - log_error("error reading rules\n"); + log_error("error reading rules"); goto exit; } @@ -1205,7 +1205,7 @@ int main(int argc, char *argv[]) fd_ep = epoll_create1(EPOLL_CLOEXEC); if (fd_ep < 0) { - log_error("error creating epoll fd: %m\n"); + log_error("error creating epoll fd: %m"); goto exit; } if (epoll_ctl(fd_ep, EPOLL_CTL_ADD, fd_ctrl, &ep_ctrl) < 0 || @@ -1213,7 +1213,7 @@ int main(int argc, char *argv[]) epoll_ctl(fd_ep, EPOLL_CTL_ADD, fd_signal, &ep_signal) < 0 || epoll_ctl(fd_ep, EPOLL_CTL_ADD, fd_netlink, &ep_netlink) < 0 || epoll_ctl(fd_ep, EPOLL_CTL_ADD, fd_worker, &ep_worker) < 0) { - log_error("fail to add fds to epoll: %m\n"); + log_error("fail to add fds to epoll: %m"); goto exit; } @@ -1226,11 +1226,11 @@ int main(int argc, char *argv[]) children_max += CPU_COUNT(&cpu_set) * 2; } } - log_debug("set children_max to %u\n", children_max); + log_debug("set children_max to %u", children_max); rc = udev_rules_apply_static_dev_perms(rules); if (rc < 0) - log_error("failed to apply permissions on static device nodes - %s\n", strerror(-rc)); + log_error("failed to apply permissions on static device nodes - %s", strerror(-rc)); udev_list_node_init(&event_list); udev_list_node_init(&worker_list); @@ -1290,13 +1290,13 @@ int main(int argc, char *argv[]) /* timeout */ if (udev_exit) { - log_error("timeout, giving up waiting for workers to finish\n"); + log_error("timeout, giving up waiting for workers to finish"); break; } /* kill idle workers */ if (udev_list_node_is_empty(&event_list)) { - log_debug("cleanup idle workers\n"); + log_debug("cleanup idle workers"); worker_kill(udev); } @@ -1308,14 +1308,14 @@ int main(int argc, char *argv[]) continue; if ((now(CLOCK_MONOTONIC) - worker->event_start_usec) > 30 * 1000 * 1000) { - log_error("worker [%u] %s timeout; kill it\n", worker->pid, + log_error("worker [%u] %s timeout; kill it", worker->pid, worker->event ? worker->event->devpath : "<idle>"); kill(worker->pid, SIGKILL); worker->state = WORKER_KILLED; /* drop reference taken for state 'running' */ worker_unref(worker); if (worker && worker->event) { - log_error("seq %llu '%s' killed\n", + log_error("seq %llu '%s' killed", udev_device_get_seqnum(worker->event->dev), worker->event->devpath); worker->event->exitcode = -64; event_queue_delete(worker->event, true); |