aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--util-linux/uevent.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/util-linux/uevent.c b/util-linux/uevent.c
index 2f1135f0c..045b35432 100644
--- a/util-linux/uevent.c
+++ b/util-linux/uevent.c
@@ -30,19 +30,19 @@
30#define INIT_G() do { setup_common_bufsiz(); } while (0) 30#define INIT_G() do { setup_common_bufsiz(); } while (0)
31enum { 31enum {
32 MAX_ENV = COMMON_BUFSIZE / sizeof(char*) - 1, 32 MAX_ENV = COMMON_BUFSIZE / sizeof(char*) - 1,
33 /* sizeof(env[0]) instead of sizeof(char*) 33 // ^^^sizeof(env[0]) instead of sizeof(char*)
34 * makes gcc-6.3.0 emit "strict-aliasing" warning. 34 // makes gcc-6.3.0 emit "strict-aliasing" warning.
35 */ 35
36}; 36 // socket receive buffer of 2MiB proved to be too small:
37 37 // http://lists.busybox.net/pipermail/busybox/2019-December/087665.html
38enum { 38 // udevd seems to use a whooping 128MiB.
39 /* socket receive buffer of 2MiB proved to be too small: 39 // The socket receive buffer size is just a resource limit.
40 * http://lists.busybox.net/pipermail/busybox/2019-December/087665.html 40 // The buffers are allocated lazily so the memory is not wasted.
41 * Udevd seems to use a whooping 128MiB.
42 * The socket receive buffer size is just a resource limit.
43 * The buffers are allocated lazily so the memory is not wasted.
44 */
45 KERN_RCVBUF = 128 * 1024 * 1024, 41 KERN_RCVBUF = 128 * 1024 * 1024,
42
43 // Might be made smaller: the kernel v5.4 passes up to 32 environment
44 // variables with a total of 2kb on each event.
45 // On top of that the action string and device path are added.
46 USER_RCVBUF = 16 * 1024, 46 USER_RCVBUF = 16 * 1024,
47}; 47};
48 48
@@ -61,6 +61,7 @@ int uevent_main(int argc UNUSED_PARAM, char **argv)
61 // Reproducer: 61 // Reproducer:
62 // uevent mdev & 62 // uevent mdev &
63 // find /sys -name uevent -exec sh -c 'echo add >"{}"' ';' 63 // find /sys -name uevent -exec sh -c 'echo add >"{}"' ';'
64 reopen:
64 fd = create_and_bind_to_netlink(NETLINK_KOBJECT_UEVENT, /*groups:*/ 1 << 0, KERN_RCVBUF); 65 fd = create_and_bind_to_netlink(NETLINK_KOBJECT_UEVENT, /*groups:*/ 1 << 0, KERN_RCVBUF);
65 66
66 for (;;) { 67 for (;;) {
@@ -82,8 +83,16 @@ int uevent_main(int argc UNUSED_PARAM, char **argv)
82 83
83 // Here we block, possibly for a very long time 84 // Here we block, possibly for a very long time
84 len = safe_read(fd, netbuf, USER_RCVBUF - 1); 85 len = safe_read(fd, netbuf, USER_RCVBUF - 1);
85 if (len < 0) 86 if (len < 0) {
87 if (errno == ENOBUFS) {
88 // Ran out of socket receive buffer
89 bb_simple_error_msg("uevent overrun");
90 close(fd);
91 munmap(netbuf, USER_RCVBUF);
92 goto reopen;
93 }
86 bb_simple_perror_msg_and_die("read"); 94 bb_simple_perror_msg_and_die("read");
95 }
87 end = netbuf + len; 96 end = netbuf + len;
88 *end = '\0'; 97 *end = '\0';
89 98