File: systemd.go

package info (click to toggle)
golang-github-zenazn-goji 1.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 464 kB
  • sloc: makefile: 3
file content (36 lines) | stat: -rw-r--r-- 645 bytes parent folder | download | duplicates (3)
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
}