mirror of
https://github.com/systemd/systemd.git
synced 2024-11-06 08:26:52 +03:00
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.
This commit is contained in:
parent
49f997f3bc
commit
3d7dc8e4f9
@ -1439,7 +1439,7 @@ static int parse_argv(int argc, char *argv[]) {
|
|||||||
|
|
||||||
static int manager_new(Manager **ret) {
|
static int manager_new(Manager **ret) {
|
||||||
_cleanup_(manager_freep) Manager *manager = NULL;
|
_cleanup_(manager_freep) Manager *manager = NULL;
|
||||||
int r;
|
int r, fd_ctrl, fd_uevent;
|
||||||
|
|
||||||
assert(ret);
|
assert(ret);
|
||||||
|
|
||||||
@ -1464,18 +1464,6 @@ static int manager_new(Manager **ret) {
|
|||||||
udev_list_node_init(&manager->events);
|
udev_list_node_init(&manager->events);
|
||||||
udev_list_init(manager->udev, &manager->properties, true);
|
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);
|
r = systemd_fds(&fd_ctrl, &fd_uevent);
|
||||||
if (r >= 0) {
|
if (r >= 0) {
|
||||||
/* get control and netlink socket from systemd */
|
/* get control and netlink socket from systemd */
|
||||||
@ -1516,6 +1504,18 @@ static int manager_listen(Manager *manager) {
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_error_errno(EINVAL, "error binding udev control socket");
|
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 */
|
/* unnamed socket from workers to the main daemon */
|
||||||
r = socketpair(AF_LOCAL, SOCK_DGRAM|SOCK_CLOEXEC, 0, manager->worker_watch);
|
r = socketpair(AF_LOCAL, SOCK_DGRAM|SOCK_CLOEXEC, 0, manager->worker_watch);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
@ -1561,7 +1561,7 @@ static int manager_listen(Manager *manager) {
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_error_errno(r, "error creating watchdog event source: %m");
|
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)
|
if (r < 0)
|
||||||
return log_error_errno(r, "error creating ctrl event source: %m");
|
return log_error_errno(r, "error creating ctrl event source: %m");
|
||||||
|
|
||||||
@ -1577,7 +1577,7 @@ static int manager_listen(Manager *manager) {
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_error_errno(r, "error creating inotify event source: %m");
|
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)
|
if (r < 0)
|
||||||
return log_error_errno(r, "error creating uevent event source: %m");
|
return log_error_errno(r, "error creating uevent event source: %m");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user