github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/pkg/systemd/activation.go (about)

     1  package systemd
     2  
     3  import (
     4  	"os"
     5  	"strconv"
     6  	"strings"
     7  )
     8  
     9  // SocketActivated determine if podman is running under the socket activation protocol
    10  func SocketActivated() bool {
    11  	pid, pid_found := os.LookupEnv("LISTEN_PID")
    12  	fds, fds_found := os.LookupEnv("LISTEN_FDS")
    13  	fdnames, fdnames_found := os.LookupEnv("LISTEN_FDNAMES")
    14  
    15  	if !(pid_found && fds_found && fdnames_found) {
    16  		return false
    17  	}
    18  
    19  	p, err := strconv.Atoi(pid)
    20  	if err != nil || p != os.Getpid() {
    21  		return false
    22  	}
    23  
    24  	nfds, err := strconv.Atoi(fds)
    25  	if err != nil || nfds < 1 {
    26  		return false
    27  	}
    28  
    29  	// First available file descriptor is always 3.
    30  	if nfds > 1 {
    31  		names := strings.Split(fdnames, ":")
    32  		for _, n := range names {
    33  			if strings.Contains(n, "podman") {
    34  				return true
    35  			}
    36  		}
    37  	}
    38  
    39  	return true
    40  }