Files
podman/pkg/systemd/activation.go
Jhon Honce c0c44ae8a3 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>
2020-02-17 10:29:32 -07:00

41 lines
771 B
Go

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
}