diff options
| author | Felix Hanley <felix@userspace.com.au> | 2016-12-05 08:16:58 +0000 |
|---|---|---|
| committer | Felix Hanley <felix@userspace.com.au> | 2016-12-05 08:16:58 +0000 |
| commit | b049991a46a2f619344bd6e915745703864d0134 (patch) | |
| tree | ec1d3897a7b69c7c63a3774d4c42dfbb8cb46432 /vendor/github.com/zenazn/goji/bind/systemd.go | |
| parent | e1c3d6f7db06d592538f1162b2b6b9f1b6efa330 (diff) | |
| download | go-dict2rest-b049991a46a2f619344bd6e915745703864d0134.tar.gz go-dict2rest-b049991a46a2f619344bd6e915745703864d0134.tar.bz2 | |
Diffstat (limited to 'vendor/github.com/zenazn/goji/bind/systemd.go')
| -rw-r--r-- | vendor/github.com/zenazn/goji/bind/systemd.go | 36 |
1 files changed, 36 insertions, 0 deletions
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 +} |
