-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-init-close-all.patch
66 lines (60 loc) · 1.83 KB
/
run-init-close-all.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
--- kinit/Makefile.fix9 2014-07-18 17:06:00.057365937 +0400
+++ kinit/Makefile 2014-07-18 17:06:00.070365764 +0400
@@ -4,9 +4,9 @@ objs = name_to_dev.o devname.o getarg.o
objs += kinit.o do_mounts.o ramdisk_load.o initrd.o
objs += getintfile.o readfile.o xpio.o
objs += do_mounts_md.o do_mounts_mtd.o nfsroot.o
-CFLAGS += -Os -I. -D_GNU_SOURCE -ffunction-sections -fdata-sections
+CFLAGS += -Os -I. -D_GNU_SOURCE -DHAVE_SYSCONF -ffunction-sections -fdata-sections
LDFLAGS += -Wl,--gc-sections -Wl,--print-gc-sections
subdirs += ipconfig
subdirs += nfsmount
--- kinit/run-init/runinitlib.c.fix9 2014-07-18 17:06:00.061365884 +0400
+++ kinit/run-init/runinitlib.c 2014-07-23 20:07:55.767421275 +0400
@@ -48,13 +48,18 @@
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/mount.h>
+#include <sys/param.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/vfs.h>
#include "run-init.h"
+#ifndef OPEN_MAX
+# define OPEN_MAX 256
+#endif
+
/* Make it possible to compile on glibc by including constants that the
always-behind shipped glibc headers may not include. Classic example
on why the lack of ABI headers screw us up. */
#ifndef TMPFS_MAGIC
@@ -193,8 +198,9 @@ const char *run_init(const char *realroo
{
struct stat rst, cst;
struct statfs sfs;
int confd;
+ int maxfd;
if (envfile && set_environ(envfile))
return "can't setup environ";
@@ -238,9 +244,20 @@ const char *run_init(const char *realroo
return "opening console";
dup2(confd, 0);
dup2(confd, 1);
dup2(confd, 2);
- close(confd);
+
+#ifdef HAVE_SYSCONF
+ maxfd = (int) sysconf(_SC_OPEN_MAX);
+#else
+ maxfd = getdtablesize();
+#endif /* HAVE_SYSCONF */
+
+ if (maxfd < 0)
+ maxfd = OPEN_MAX;
+ maxfd--;
+ while (maxfd > 2)
+ close(maxfd--);
/* Spawn init */
execv(init, initargs);
return init; /* Failed to spawn init */