summaryrefslogtreecommitdiff
path: root/pkg/systemd/activation.go
diff options
context:
space:
mode:
authorJhon Honce <jhonce@redhat.com>2020-02-10 14:24:10 -0700
committerJhon Honce <jhonce@redhat.com>2020-02-17 10:29:32 -0700
commitc0c44ae8a36121dc13f7984cf8b3347c21f43f51 (patch)
tree489bc30b7987a1dcf31ca2e8ba96a370e72e4a86 /pkg/systemd/activation.go
parent640b11f0028057ca2090d61c4e460c1afadb226c (diff)
downloadpodman-c0c44ae8a36121dc13f7984cf8b3347c21f43f51.tar.gz
podman-c0c44ae8a36121dc13f7984cf8b3347c21f43f51.tar.bz2
podman-c0c44ae8a36121dc13f7984cf8b3347c21f43f51.zip
Fix handler and systemd activation errors
On panic from handler: log warning and stack trace, report InternalServerError to client When using `podman system service` make determining the listening endpoint deterministic. // When determining _*THE*_ listening endpoint -- // 1) User input wins always // 2) systemd socket activation // 3) rootless honors XDG_RUNTIME_DIR // 4) if varlink -- adapter.DefaultVarlinkAddress // 5) lastly adapter.DefaultAPIAddress Fixes #5150 Fixes #5151 Signed-off-by: Jhon Honce <jhonce@redhat.com>
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
+}