[systemd-commits] 3 commits - src/udev
Tom Gundersen
tomegun at kemper.freedesktop.org
Sun May 31 15:03:05 PDT 2015
src/udev/udevd.c | 55 +++++++++++++++++++------------------------------------
1 file changed, 19 insertions(+), 36 deletions(-)
New commits:
commit 3d7dc8e4f9273ed0f14116ee7400718b7459df0d
Author: Tom Gundersen <teg at jklm.no>
Date: Sun May 31 23:58:39 2015 +0200
udevd: open sockets before forking
The communication channels must all be opened before forknig in daemon mode,
or we cannot guarantee that udevadm will work correctly as soon as udevd is
started.
diff --git a/src/udev/udevd.c b/src/udev/udevd.c
index 5717edd..34e88af 100644
--- a/src/udev/udevd.c
+++ b/src/udev/udevd.c
@@ -1439,7 +1439,7 @@ static int parse_argv(int argc, char *argv[]) {
static int manager_new(Manager **ret) {
_cleanup_(manager_freep) Manager *manager = NULL;
- int r;
+ int r, fd_ctrl, fd_uevent;
assert(ret);
@@ -1464,18 +1464,6 @@ static int manager_new(Manager **ret) {
udev_list_node_init(&manager->events);
udev_list_init(manager->udev, &manager->properties, true);
- *ret = manager;
- manager = NULL;
-
- return 0;
-}
-
-static int manager_listen(Manager *manager) {
- sigset_t mask;
- int r, fd_worker, fd_ctrl, fd_uevent, one = 1;
-
- assert(manager);
-
r = systemd_fds(&fd_ctrl, &fd_uevent);
if (r >= 0) {
/* get control and netlink socket from systemd */
@@ -1516,6 +1504,18 @@ static int manager_listen(Manager *manager) {
if (r < 0)
return log_error_errno(EINVAL, "error binding udev control socket");
+ *ret = manager;
+ manager = NULL;
+
+ return 0;
+}
+
+static int manager_listen(Manager *manager) {
+ sigset_t mask;
+ int r, fd_worker, one = 1;
+
+ assert(manager);
+
/* unnamed socket from workers to the main daemon */
r = socketpair(AF_LOCAL, SOCK_DGRAM|SOCK_CLOEXEC, 0, manager->worker_watch);
if (r < 0)
@@ -1561,7 +1561,7 @@ static int manager_listen(Manager *manager) {
if (r < 0)
return log_error_errno(r, "error creating watchdog event source: %m");
- r = sd_event_add_io(manager->event, &manager->ctrl_event, fd_ctrl, EPOLLIN, on_ctrl_msg, manager);
+ r = sd_event_add_io(manager->event, &manager->ctrl_event, udev_ctrl_get_fd(manager->ctrl), EPOLLIN, on_ctrl_msg, manager);
if (r < 0)
return log_error_errno(r, "error creating ctrl event source: %m");
@@ -1577,7 +1577,7 @@ static int manager_listen(Manager *manager) {
if (r < 0)
return log_error_errno(r, "error creating inotify event source: %m");
- r = sd_event_add_io(manager->event, &manager->uevent_event, fd_uevent, EPOLLIN, on_uevent, manager);
+ r = sd_event_add_io(manager->event, &manager->uevent_event, udev_monitor_get_fd(manager->monitor), EPOLLIN, on_uevent, manager);
if (r < 0)
return log_error_errno(r, "error creating uevent event source: %m");
commit 49f997f3bcf3ff6a1d794dfb8fbd3907d653dc33
Author: Tom Gundersen <teg at jklm.no>
Date: Sun May 31 23:52:53 2015 +0200
udevd: don't allocate sd_event object before fork
In daemon mode we would break sd-event as it cannot work accross different processes.
Simply delay the allocation to after the fork.
diff --git a/src/udev/udevd.c b/src/udev/udevd.c
index c021e80..5717edd 100644
--- a/src/udev/udevd.c
+++ b/src/udev/udevd.c
@@ -1451,10 +1451,6 @@ static int manager_new(Manager **ret) {
manager->worker_watch[WRITE_END] = -1;
manager->worker_watch[READ_END] = -1;
- r = sd_event_default(&manager->event);
- if (r < 0)
- return log_error_errno(errno, "could not allocate event loop: %m");
-
manager->udev = udev_new();
if (!manager->udev)
return log_error_errno(errno, "could not allocate udev context: %m");
@@ -1541,6 +1537,10 @@ static int manager_listen(Manager *manager) {
sigfillset(&mask);
sigprocmask(SIG_SETMASK, &mask, &manager->sigmask_orig);
+ r = sd_event_default(&manager->event);
+ if (r < 0)
+ return log_error_errno(errno, "could not allocate event loop: %m");
+
r = sd_event_add_signal(manager->event, NULL, SIGINT, on_sigterm, manager);
if (r < 0)
return log_error_errno(r, "error creating sigint event source: %m");
commit f6fd40d16adbd0f9ddbb1f24b4b8734fd8790ad0
Author: Tom Gundersen <teg at jklm.no>
Date: Sun May 31 22:38:30 2015 +0200
udevd: don't sanitize fd 0,1,2
Kay said: 'it is from ancient times, when we started udevd from the
kernel's usermodhelper which had no fd 0,1,2'.
diff --git a/src/udev/udevd.c b/src/udev/udevd.c
index fae8f78..c021e80 100644
--- a/src/udev/udevd.c
+++ b/src/udev/udevd.c
@@ -1628,23 +1628,6 @@ int main(int argc, char *argv[]) {
log_debug("set children_max to %u", arg_children_max);
}
- /* before opening new files, make sure std{in,out,err} fds are in a sane state */
- if (arg_daemonize) {
- int fd;
-
- fd = open("/dev/null", O_RDWR);
- if (fd < 0)
- log_error("cannot open /dev/null");
- else {
- if (write(STDOUT_FILENO, 0, 0) < 0)
- dup2(fd, STDOUT_FILENO);
- if (write(STDERR_FILENO, 0, 0) < 0)
- dup2(fd, STDERR_FILENO);
- if (fd > STDERR_FILENO)
- close(fd);
- }
- }
-
/* set umask before creating any file/directory */
r = chdir("/");
if (r < 0) {
More information about the systemd-commits
mailing list