github.com/rootless-containers/rootlesskit/v2@v2.3.4/pkg/systemd/activation/activation.go (about) 1 package activation 2 3 import ( 4 "os" 5 "os/exec" 6 "strconv" 7 "syscall" 8 ) 9 10 type Opt struct { 11 RunActivationHelperEnvKey string // needs to be set 12 TargetCmd []string // needs to be set 13 } 14 15 func ActivationHelper(opt Opt) error { 16 pid := os.Getpid() 17 os.Unsetenv(opt.RunActivationHelperEnvKey) 18 os.Setenv("LISTEN_PID", strconv.Itoa(pid)) 19 argsv := opt.TargetCmd 20 execPath, err := exec.LookPath(argsv[0]) 21 if err != nil { 22 return err 23 } 24 if err = syscall.Exec(execPath, argsv, os.Environ()); err != nil { 25 return err 26 } 27 panic("should not reach here") 28 }