aboutsummaryrefslogtreecommitdiff
path: root/pkg/systemd/activation.go
blob: 8f75f9cca34753f0c8fedd398da39143d3f1618f (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
package systemd

import (
	"os"
	"strconv"
)

// SocketActivated determine if podman is running under the socket activation protocol
// Criteria is based on the expectations of "github.com/coreos/go-systemd/v22/activation"
func SocketActivated() bool {
	pid, found := os.LookupEnv("LISTEN_PID")
	if !found {
		return false
	}
	p, err := strconv.Atoi(pid)
	if err != nil || p != os.Getpid() {
		return false
	}

	fds, found := os.LookupEnv("LISTEN_FDS")
	if !found {
		return false
	}
	nfds, err := strconv.Atoi(fds)
	if err != nil || nfds == 0 {
		return false
	}

	// "github.com/coreos/go-systemd/v22/activation" will use and validate this variable's
	// value. We're just providing a fast fail
	if _, found = os.LookupEnv("LISTEN_FDNAMES"); !found {
		return false
	}
	return true
}