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
67
68
69
70
71
72
73
74
75
76
|
From: Jeremie Corbier <jeremie+debian@famille-corbier.net>
Date: Tue, 6 Apr 2010 15:51:08 +0200
Subject: Close inherited file descriptors
wide-dhcpv6 binaries should close inherited fds.
Signed-off-by: Jeremie Corbier <jeremie@famille-corbier.net>
---
dhcp6c.c | 7 ++++++-
dhcp6relay.c | 6 ++++++
dhcp6s.c | 5 +++++
3 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/dhcp6c.c b/dhcp6c.c
index 1caaaa5..b5f5ed7 100644
--- a/dhcp6c.c
+++ b/dhcp6c.c
@@ -159,6 +159,7 @@ main(argc, argv)
char *progname;
FILE *pidfp;
struct dhcp6_if *ifp;
+ int fd;
#ifndef HAVE_ARC4RANDOM
srandom(time(NULL) & getpid());
@@ -205,8 +206,12 @@ main(argc, argv)
exit(0);
}
- if (foreground == 0)
+ if (foreground == 0) {
+ for (fd = 3; fd < 1024; fd++)
+ close(fd);
+
openlog(progname, LOG_NDELAY|LOG_PID, LOG_DAEMON);
+ }
setloglevel(debug);
diff --git a/dhcp6relay.c b/dhcp6relay.c
index fb84ce3..eb0bce9 100644
--- a/dhcp6relay.c
+++ b/dhcp6relay.c
@@ -207,8 +207,14 @@ main(argc, argv)
}
if (foreground == 0) {
+ int fd;
+
if (daemon(0, 0) < 0)
err(1, "daemon");
+
+ for (fd = 3; fd < 1024; fd++)
+ close(fd);
+
openlog(progname, LOG_NDELAY|LOG_PID, LOG_DAEMON);
}
setloglevel(debug);
diff --git a/dhcp6s.c b/dhcp6s.c
index 544afff..494e571 100644
--- a/dhcp6s.c
+++ b/dhcp6s.c
@@ -316,8 +316,13 @@ main(argc, argv)
}
if (foreground == 0) {
+ int fd;
+
if (daemon(0, 0) < 0)
err(1, "daemon");
+
+ for (fd = 3; fd < 1024; fd++)
+ close(fd);
}
/* dump current PID */
|