diff options
| author | Jan Klötzke <jan@kloetzke.net> | 2020-11-22 14:17:56 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2020-11-22 14:33:58 +0100 |
| commit | e3f4759019544673d654ad8a1ea256ed481fa5e3 (patch) | |
| tree | d07dc3c6bc79bdd81d0a085c02bbab8d5941311b /util-linux/mdev.c | |
| parent | a569fd37fec970d8aeebca1c34a964502072d817 (diff) | |
| download | busybox-w32-e3f4759019544673d654ad8a1ea256ed481fa5e3.tar.gz busybox-w32-e3f4759019544673d654ad8a1ea256ed481fa5e3.tar.bz2 busybox-w32-e3f4759019544673d654ad8a1ea256ed481fa5e3.zip | |
mdev: move daemon setup to dedicated function
Signed-off-by: Jan Klötzke <jan@kloetzke.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux/mdev.c')
| -rw-r--r-- | util-linux/mdev.c | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/util-linux/mdev.c b/util-linux/mdev.c index 8b06d3456..4c00a2d7e 100644 --- a/util-linux/mdev.c +++ b/util-linux/mdev.c | |||
| @@ -1165,6 +1165,29 @@ static void initial_scan(char *temp) | |||
| 1165 | # define KERN_RCVBUF (128 * 1024 * 1024) | 1165 | # define KERN_RCVBUF (128 * 1024 * 1024) |
| 1166 | # define MAX_ENV 32 | 1166 | # define MAX_ENV 32 |
| 1167 | 1167 | ||
| 1168 | static int daemon_init(char *temp) | ||
| 1169 | { | ||
| 1170 | int fd; | ||
| 1171 | |||
| 1172 | /* Subscribe for UEVENT kernel messages */ | ||
| 1173 | /* Without a sufficiently big RCVBUF, a ton of simultaneous events | ||
| 1174 | * can trigger ENOBUFS on read, which is unrecoverable. | ||
| 1175 | * Reproducer: | ||
| 1176 | * mdev -d | ||
| 1177 | * find /sys -name uevent -exec sh -c 'echo add >"{}"' ';' | ||
| 1178 | */ | ||
| 1179 | fd = create_and_bind_to_netlink(NETLINK_KOBJECT_UEVENT, 1 << 0, KERN_RCVBUF); | ||
| 1180 | |||
| 1181 | /* | ||
| 1182 | * Make inital scan after the uevent socket is alive and | ||
| 1183 | * _before_ we fork away. Already open mdev.log because we work | ||
| 1184 | * in daemon mode. | ||
| 1185 | */ | ||
| 1186 | initial_scan(temp); | ||
| 1187 | |||
| 1188 | return fd; | ||
| 1189 | } | ||
| 1190 | |||
| 1168 | static void daemon_loop(char *temp, int fd) | 1191 | static void daemon_loop(char *temp, int fd) |
| 1169 | { | 1192 | { |
| 1170 | for (;;) { | 1193 | for (;;) { |
| @@ -1234,24 +1257,11 @@ int mdev_main(int argc UNUSED_PARAM, char **argv) | |||
| 1234 | #if ENABLE_FEATURE_MDEV_DAEMON | 1257 | #if ENABLE_FEATURE_MDEV_DAEMON |
| 1235 | if (opt & MDEV_OPT_DAEMON) { | 1258 | if (opt & MDEV_OPT_DAEMON) { |
| 1236 | /* | 1259 | /* |
| 1237 | * Daemon mode listening on uevent netlink socket. | 1260 | * Daemon mode listening on uevent netlink socket. Fork away |
| 1238 | */ | 1261 | * after initial scan so that caller can be sure everything |
| 1239 | int fd; | 1262 | * is up-to-date when mdev process returns. |
| 1240 | |||
| 1241 | /* Subscribe for UEVENT kernel messages */ | ||
| 1242 | /* Without a sufficiently big RCVBUF, a ton of simultaneous events | ||
| 1243 | * can trigger ENOBUFS on read, which is unrecoverable. | ||
| 1244 | * Reproducer: | ||
| 1245 | * mdev -d | ||
| 1246 | * find /sys -name uevent -exec sh -c 'echo add >"{}"' ';' | ||
| 1247 | */ | ||
| 1248 | fd = create_and_bind_to_netlink(NETLINK_KOBJECT_UEVENT, 1 << 0, KERN_RCVBUF); | ||
| 1249 | |||
| 1250 | /* | ||
| 1251 | * Make inital scan after the uevent socket is alive and | ||
| 1252 | * _before_ we fork away. | ||
| 1253 | */ | 1263 | */ |
| 1254 | initial_scan(temp); | 1264 | int fd = daemon_init(temp); |
| 1255 | 1265 | ||
| 1256 | if (!(opt & MDEV_OPT_FOREGROUND)) | 1266 | if (!(opt & MDEV_OPT_FOREGROUND)) |
| 1257 | bb_daemonize_or_rexec(0, argv); | 1267 | bb_daemonize_or_rexec(0, argv); |
