From bdb492b2edca50d89f8d80900bda1156fb252a18 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 31 Aug 2021 22:32:41 +0900 Subject: [PATCH] udev: do not remove control socket on exit As we usually do, remove old unix socket before bind. Note that systemd-udevd-control.socket has `RemoveOnStop=yes`. So, it is not necessary to be removed when the service exits. Replaces #20584 and #20588. --- src/udev/udev-ctrl.c | 22 ++-------------------- src/udev/udev-ctrl.h | 1 - src/udev/udevd.c | 3 --- 3 files changed, 2 insertions(+), 24 deletions(-) diff --git a/src/udev/udev-ctrl.c b/src/udev/udev-ctrl.c index 00279ba3d87..179a1fdec3f 100644 --- a/src/udev/udev-ctrl.c +++ b/src/udev/udev-ctrl.c @@ -37,7 +37,6 @@ struct UdevCtrl { union sockaddr_union saddr; socklen_t addrlen; bool bound; - bool cleanup_socket; bool connected; bool maybe_disconnected; sd_event *event; @@ -82,28 +81,19 @@ int udev_ctrl_new_from_fd(UdevCtrl **ret, int fd) { } int udev_ctrl_enable_receiving(UdevCtrl *uctrl) { - int r; - assert(uctrl); if (uctrl->bound) return 0; - r = bind(uctrl->sock, &uctrl->saddr.sa, uctrl->addrlen); - if (r < 0 && errno == EADDRINUSE) { - (void) sockaddr_un_unlink(&uctrl->saddr.un); - r = bind(uctrl->sock, &uctrl->saddr.sa, uctrl->addrlen); - } - - if (r < 0) + (void) sockaddr_un_unlink(&uctrl->saddr.un); + if (bind(uctrl->sock, &uctrl->saddr.sa, uctrl->addrlen) < 0) return log_error_errno(errno, "Failed to bind udev control socket: %m"); if (listen(uctrl->sock, 0) < 0) return log_error_errno(errno, "Failed to listen udev control socket: %m"); uctrl->bound = true; - uctrl->cleanup_socket = true; - return 0; } @@ -129,14 +119,6 @@ static UdevCtrl *udev_ctrl_free(UdevCtrl *uctrl) { DEFINE_TRIVIAL_REF_UNREF_FUNC(UdevCtrl, udev_ctrl, udev_ctrl_free); -int udev_ctrl_cleanup(UdevCtrl *uctrl) { - if (!uctrl) - return 0; - if (uctrl->cleanup_socket) - sockaddr_un_unlink(&uctrl->saddr.un); - return 0; -} - int udev_ctrl_attach_event(UdevCtrl *uctrl, sd_event *event) { int r; diff --git a/src/udev/udev-ctrl.h b/src/udev/udev-ctrl.h index ca80c2aa4e0..d4bc0681271 100644 --- a/src/udev/udev-ctrl.h +++ b/src/udev/udev-ctrl.h @@ -36,7 +36,6 @@ static inline int udev_ctrl_new(UdevCtrl **ret) { int udev_ctrl_enable_receiving(UdevCtrl *uctrl); UdevCtrl *udev_ctrl_ref(UdevCtrl *uctrl); UdevCtrl *udev_ctrl_unref(UdevCtrl *uctrl); -int udev_ctrl_cleanup(UdevCtrl *uctrl); int udev_ctrl_attach_event(UdevCtrl *uctrl, sd_event *event); int udev_ctrl_start(UdevCtrl *uctrl, udev_ctrl_handler_t callback, void *userdata); sd_event_source *udev_ctrl_get_event_source(UdevCtrl *uctrl); diff --git a/src/udev/udevd.c b/src/udev/udevd.c index 4df08f21c5c..df720898ea1 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -227,9 +227,6 @@ static Manager* manager_free(Manager *manager) { udev_builtin_exit(); - if (manager->pid == getpid_cached()) - udev_ctrl_cleanup(manager->ctrl); - manager_clear_for_worker(manager); sd_netlink_unref(manager->rtnl);