summaryrefslogtreecommitdiff
path: root/src/udev/udevd.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2015-06-02 23:14:34 +0200
committerTom Gundersen <teg@jklm.no>2015-06-03 02:10:58 +0200
commit11b1dd8cecd486d5b1dd8fb27373ac79ea467ff8 (patch)
tree8825e14beb2f9060a0c17914867829532174c0dc /src/udev/udevd.c
parent7500cd5e96cff52a726d03194e3b927771ddb1d4 (diff)
udevd: merge manager_new() and manager_listen() again
Now that listen_fds() have been split out, we can safely move the allocation of the manager object after doing the forking (the fork is done to notify legcay init-systems that the fds are ready). Subsequently, we can merge manager_listen() back into managre_new(). This entails a minor behaviour change: the application of permissions to static device nodes now happens after the fork (but still before notifying systemd about being ready).
Diffstat (limited to 'src/udev/udevd.c')
-rw-r--r--src/udev/udevd.c39
1 files changed, 16 insertions, 23 deletions
diff --git a/src/udev/udevd.c b/src/udev/udevd.c
index 5fee67d8df..eb43091190 100644
--- a/src/udev/udevd.c
+++ b/src/udev/udevd.c
@@ -1492,8 +1492,11 @@ static int parse_argv(int argc, char *argv[]) {
static int manager_new(Manager **ret, int fd_ctrl, int fd_uevent, const char *cgroup) {
_cleanup_(manager_freep) Manager *manager = NULL;
+ int r, fd_worker, one = 1;
assert(ret);
+ assert(fd_ctrl >= 0);
+ assert(fd_uevent >= 0);
manager = new0(Manager, 1);
if (!manager)
@@ -1526,17 +1529,6 @@ static int manager_new(Manager **ret, int fd_ctrl, int fd_uevent, const char *cg
if (!manager->monitor)
return log_error_errno(EINVAL, "error taking over netlink socket");
- *ret = manager;
- manager = NULL;
-
- return 0;
-}
-
-static int manager_listen(Manager *manager) {
- 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)
@@ -1581,7 +1573,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, udev_ctrl_get_fd(manager->ctrl), EPOLLIN, on_ctrl_msg, manager);
+ r = sd_event_add_io(manager->event, &manager->ctrl_event, fd_ctrl, EPOLLIN, on_ctrl_msg, manager);
if (r < 0)
return log_error_errno(r, "error creating ctrl event source: %m");
@@ -1597,7 +1589,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, udev_monitor_get_fd(manager->monitor), EPOLLIN, on_uevent, manager);
+ r = sd_event_add_io(manager->event, &manager->uevent_event, fd_uevent, EPOLLIN, on_uevent, manager);
if (r < 0)
return log_error_errno(r, "error creating uevent event source: %m");
@@ -1609,6 +1601,9 @@ static int manager_listen(Manager *manager) {
if (r < 0)
return log_error_errno(r, "error creating post event source: %m");
+ *ret = manager;
+ manager = NULL;
+
return 0;
}
@@ -1687,14 +1682,6 @@ int main(int argc, char *argv[]) {
goto exit;
}
- r = manager_new(&manager, fd_ctrl, fd_uevent, cgroup);
- if (r < 0)
- goto exit;
-
- r = udev_rules_apply_static_dev_perms(manager->rules);
- if (r < 0)
- log_error_errno(r, "failed to apply permissions on static device nodes: %m");
-
if (arg_daemonize) {
pid_t pid;
@@ -1718,9 +1705,15 @@ int main(int argc, char *argv[]) {
write_string_file("/proc/self/oom_score_adj", "-1000");
}
- r = manager_listen(manager);
+ r = manager_new(&manager, fd_ctrl, fd_uevent, cgroup);
+ if (r < 0) {
+ r = log_error_errno(r, "failed to allocate manager object: %m");
+ goto exit;
+ }
+
+ r = udev_rules_apply_static_dev_perms(manager->rules);
if (r < 0)
- return log_error_errno(r, "failed to set up fds and listen for events: %m");
+ log_error_errno(r, "failed to apply permissions on static device nodes: %m");
(void) sd_notify(false,
"READY=1\n"