1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-01 17:51:22 +03:00

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.
This commit is contained in:
Yu Watanabe 2021-08-31 22:32:41 +09:00 committed by Lennart Poettering
parent 42ffc40ce3
commit bdb492b2ed
3 changed files with 2 additions and 24 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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);