summaryrefslogtreecommitdiff
path: root/pkg/systemd/activation.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-02-18 15:24:02 +0100
committerGitHub <noreply@github.com>2020-02-18 15:24:02 +0100
commitbc20cb9281434a95685bd95de0430a7c40b606e4 (patch)
tree6e2249acef7e470fbf717f279e665de412beb4d6 /pkg/systemd/activation.go
parent0bd29f89e9d26c9012c76e58050e1bdfd90faaf0 (diff)
parentc0c44ae8a36121dc13f7984cf8b3347c21f43f51 (diff)
downloadpodman-bc20cb9281434a95685bd95de0430a7c40b606e4.tar.gz
podman-bc20cb9281434a95685bd95de0430a7c40b606e4.tar.bz2
podman-bc20cb9281434a95685bd95de0430a7c40b606e4.zip
Merge pull request #5158 from jwhonce/issues/5151
Fix handler and systemd activation errors
Diffstat (limited to 'pkg/systemd/activation.go')
-rw-r--r--pkg/systemd/activation.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/pkg/systemd/activation.go b/pkg/systemd/activation.go
new file mode 100644
index 000000000..c8b2389dc
--- /dev/null
+++ b/pkg/systemd/activation.go
@@ -0,0 +1,40 @@
+package systemd
+
+import (
+ "os"
+ "strconv"
+ "strings"
+)
+
+// SocketActivated determine if podman is running under the socket activation protocol
+func SocketActivated() bool {
+ pid, pid_found := os.LookupEnv("LISTEN_PID")
+ fds, fds_found := os.LookupEnv("LISTEN_FDS")
+ fdnames, fdnames_found := os.LookupEnv("LISTEN_FDNAMES")
+
+ if !(pid_found && fds_found && fdnames_found) {
+ return false
+ }
+
+ p, err := strconv.Atoi(pid)
+ if err != nil || p != os.Getpid() {
+ return false
+ }
+
+ nfds, err := strconv.Atoi(fds)
+ if err != nil || nfds < 1 {
+ return false
+ }
+
+ // First available file descriptor is always 3.
+ if nfds > 1 {
+ names := strings.Split(fdnames, ":")
+ for _, n := range names {
+ if strings.Contains(n, "podman") {
+ return true
+ }
+ }
+ }
+
+ return true
+}