aboutsummaryrefslogtreecommitdiff
path: root/util-linux/mdev.c
diff options
context:
space:
mode:
Diffstat (limited to 'util-linux/mdev.c')
-rw-r--r--util-linux/mdev.c28
1 files changed, 8 insertions, 20 deletions
diff --git a/util-linux/mdev.c b/util-linux/mdev.c
index 88c82b6fb..9cb3586f1 100644
--- a/util-linux/mdev.c
+++ b/util-linux/mdev.c
@@ -1225,28 +1225,16 @@ int mdev_main(int argc UNUSED_PARAM, char **argv)
1225 /* 1225 /*
1226 * Daemon mode listening on uevent netlink socket. 1226 * Daemon mode listening on uevent netlink socket.
1227 */ 1227 */
1228 struct sockaddr_nl sa;
1229 int fd; 1228 int fd;
1230 1229
1231//TODO: reuse same code in uevent 1230 /* Subscribe for UEVENT kernel messages */
1232 // Subscribe for UEVENT kernel messages 1231 /* Without a sufficiently big RCVBUF, a ton of simultaneous events
1233 sa.nl_family = AF_NETLINK; 1232 * can trigger ENOBUFS on read, which is unrecoverable.
1234 sa.nl_pad = 0; 1233 * Reproducer:
1235 sa.nl_pid = getpid(); 1234 * mdev -d
1236 sa.nl_groups = 1 << 0; 1235 * find /sys -name uevent -exec sh -c 'echo add >"{}"' ';'
1237 fd = xsocket(AF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT); 1236 */
1238 xbind(fd, (struct sockaddr *) &sa, sizeof(sa)); 1237 fd = create_and_bind_to_netlink(NETLINK_KOBJECT_UEVENT, 1 << 0, RCVBUF);
1239 close_on_exec_on(fd);
1240
1241 // Without a sufficiently big RCVBUF, a ton of simultaneous events
1242 // can trigger ENOBUFS on read, which is unrecoverable.
1243 // Reproducer:
1244 // mdev -d
1245 // find /sys -name uevent -exec sh -c 'echo add >"{}"' ';'
1246 //
1247 // SO_RCVBUFFORCE (root only) can go above net.core.rmem_max sysctl
1248 setsockopt_SOL_SOCKET_int(fd, SO_RCVBUF, RCVBUF);
1249 setsockopt_SOL_SOCKET_int(fd, SO_RCVBUFFORCE, RCVBUF);
1250 1238
1251 /* 1239 /*
1252 * Make inital scan after the uevent socket is alive and 1240 * Make inital scan after the uevent socket is alive and