From b049991a46a2f619344bd6e915745703864d0134 Mon Sep 17 00:00:00 2001 From: Felix Hanley Date: Mon, 5 Dec 2016 15:16:58 +0700 Subject: Clean up source structure and update vendor versions --- vendor/github.com/zenazn/goji/bind/systemd.go | 36 +++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 vendor/github.com/zenazn/goji/bind/systemd.go (limited to 'vendor/github.com/zenazn/goji/bind/systemd.go') diff --git a/vendor/github.com/zenazn/goji/bind/systemd.go b/vendor/github.com/zenazn/goji/bind/systemd.go new file mode 100644 index 0000000..e7cd8e4 --- /dev/null +++ b/vendor/github.com/zenazn/goji/bind/systemd.go @@ -0,0 +1,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 +} -- cgit v1.2.3