summaryrefslogtreecommitdiff
path: root/util-linux/uevent.c
diff options
context:
space:
mode:
authorDenys Vlasenko2019-06-03 14:16:52 +0200
committerDenys Vlasenko2019-06-03 14:16:52 +0200
commit45e3967c20b5020bf720b9497592e231104398f3 (patch)
tree364a53e80d1c2246e33fb00c4f6bb26e854912ae /util-linux/uevent.c
parent498cec202adbf69a7a72af5e204260682d614183 (diff)
downloadbusybox-45e3967c20b5020bf720b9497592e231104398f3.zip
busybox-45e3967c20b5020bf720b9497592e231104398f3.tar.gz
libbb: move netlink socket binding to the utility function
function old new delta create_and_bind_to_netlink - 134 +134 ifplugd_main 1117 1052 -65 uevent_main 399 306 -93 mdev_main 314 215 -99 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/3 up/down: 134/-257) Total: -123 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux/uevent.c')
-rw-r--r--util-linux/uevent.c37
1 files changed, 10 insertions, 27 deletions
diff --git a/util-linux/uevent.c b/util-linux/uevent.c
index 761743f..2f8990e 100644
--- a/util-linux/uevent.c
+++ b/util-linux/uevent.c
@@ -46,37 +46,19 @@ enum { RCVBUF = 2 * 1024 * 1024 };
int uevent_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int uevent_main(int argc UNUSED_PARAM, char **argv)
{
- struct sockaddr_nl sa;
int fd;
INIT_G();
argv++;
- // Subscribe for UEVENT kernel messages
- sa.nl_family = AF_NETLINK;
- sa.nl_pad = 0;
- sa.nl_pid = getpid();
- sa.nl_groups = 1 << 0;
- fd = xsocket(AF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT);
- xbind(fd, (struct sockaddr *) &sa, sizeof(sa));
- close_on_exec_on(fd);
-
+ // Subscribe for UEVENT kernel messages.
// Without a sufficiently big RCVBUF, a ton of simultaneous events
// can trigger ENOBUFS on read, which is unrecoverable.
// Reproducer:
// uevent mdev &
// find /sys -name uevent -exec sh -c 'echo add >"{}"' ';'
- //
- // SO_RCVBUFFORCE (root only) can go above net.core.rmem_max sysctl
- setsockopt_SOL_SOCKET_int(fd, SO_RCVBUF, RCVBUF);
- setsockopt_SOL_SOCKET_int(fd, SO_RCVBUFFORCE, RCVBUF);
- if (0) {
- int z;
- socklen_t zl = sizeof(z);
- getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &z, &zl);
- bb_error_msg("SO_RCVBUF:%d", z);
- }
+ fd = create_and_bind_to_netlink(NETLINK_KOBJECT_UEVENT, /*groups:*/ 1 << 0, RCVBUF);
for (;;) {
char *netbuf;
@@ -118,14 +100,15 @@ int uevent_main(int argc UNUSED_PARAM, char **argv)
}
env[idx] = NULL;
- idx = 0;
- while (env[idx])
- putenv(env[idx++]);
- if (argv[0])
+ if (argv[0]) {
+ idx = 0;
+ while (env[idx])
+ putenv(env[idx++]);
spawn_and_wait(argv);
- idx = 0;
- while (env[idx])
- bb_unsetenv(env[idx++]);
+ idx = 0;
+ while (env[idx])
+ bb_unsetenv(env[idx++]);
+ }
munmap(netbuf, BUFFER_SIZE);
}