blob: e7cd8e4175e278f83f1ae977223f29c3571c01b8 (
plain)
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
|
// +build !windows
package bind
import (
"os"
"syscall"
)
const systemdMinFd = 3
var systemdNumFds int
// Unfortunately this can't be a normal init function, because their execution
// order is undefined, and we need to run before the init() in bind.go.
func systemdInit() {
pid, err := envInt("LISTEN_PID")
if err != nil || pid != os.Getpid() {
return
}
systemdNumFds, err = envInt("LISTEN_FDS")
if err != nil {
systemdNumFds = 0
return
}
// Prevent fds from leaking to our children
for i := 0; i < systemdNumFds; i++ {
syscall.CloseOnExec(systemdMinFd + i)
}
}
func usingSystemd() bool {
return systemdNumFds > 0
}
|