mirror of
https://github.com/containers/podman.git
synced 2025-10-17 19:24:04 +08:00

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>
41 lines
771 B
Go
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
|
|
}
|