From 903893237a2105b05671fe87b8f5d5e7417040d2 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 8 Dec 2018 18:50:40 +0900 Subject: [PATCH] sd-device: do not change buffer size if the socket is already bound From the results of CIs in #11076, changing buffer size may cause issue #10754. So, let's prohibit to change the size if it is already bound. This also reverts commit 986ab0d2dc161dfa026e8fc7a609f9efb8cb4397. --- src/libsystemd/sd-device/device-monitor.c | 6 ++++++ src/udev/udevd.c | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/libsystemd/sd-device/device-monitor.c b/src/libsystemd/sd-device/device-monitor.c index 21dfb2bf39c..b86932663e7 100644 --- a/src/libsystemd/sd-device/device-monitor.c +++ b/src/libsystemd/sd-device/device-monitor.c @@ -93,6 +93,12 @@ _public_ int sd_device_monitor_set_receive_buffer_size(sd_device_monitor *m, siz assert_return(m, -EINVAL); assert_return((size_t) n == size, -EINVAL); + if (m->bound) + return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), + "sd-device-monitor: Socket fd is already bound. " + "It may be dangerous to change buffer size. " + "Refusing to change buffer size."); + if (setsockopt_int(m->sock, SOL_SOCKET, SO_RCVBUF, n) < 0) { r = setsockopt_int(m->sock, SOL_SOCKET, SO_RCVBUFFORCE, n); if (r < 0) diff --git a/src/udev/udevd.c b/src/udev/udevd.c index fa85f6e2632..024fa97ad08 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -1630,8 +1630,7 @@ static int manager_new(Manager **ret, int fd_ctrl, int fd_uevent, const char *cg if (r < 0) return log_error_errno(r, "Failed to initialize device monitor: %m"); - if (fd_uevent < 0) - (void) sd_device_monitor_set_receive_buffer_size(manager->monitor, 128 * 1024 * 1024); + (void) sd_device_monitor_set_receive_buffer_size(manager->monitor, 128 * 1024 * 1024); /* unnamed socket from workers to the main daemon */ r = socketpair(AF_LOCAL, SOCK_DGRAM|SOCK_CLOEXEC, 0, manager->worker_watch); -- 2.47.3