summaryrefslogtreecommitdiff
path: root/cmd/podman
diff options
context:
space:
mode:
authorGiuseppe Scrivano <gscrivan@redhat.com>2021-03-29 11:45:40 +0200
committerGiuseppe Scrivano <gscrivan@redhat.com>2021-03-29 13:51:06 +0200
commitc064acd78e418943edae8ec2998f855721157f30 (patch)
treeea96b6067ebade7dba83035ef9e1042f908471e7 /cmd/podman
parent2446bdc7bb1bc0f26642af8e3690eeafb3c3e563 (diff)
downloadpodman-c064acd78e418943edae8ec2998f855721157f30.tar.gz
podman-c064acd78e418943edae8ec2998f855721157f30.tar.bz2
podman-c064acd78e418943edae8ec2998f855721157f30.zip
service: use LISTEN_FDS
if LISTEN_FDS is specified by systemd, we need to use the first fd after the std files (so fd=3) to read from the activation socket instead of manually opening the UNIX socket. [NO TESTS NEEDED] Closes: https://github.com/containers/podman/issues/9251 Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Diffstat (limited to 'cmd/podman')
-rw-r--r--cmd/podman/system/service_abi.go30
1 files changed, 21 insertions, 9 deletions
diff --git a/cmd/podman/system/service_abi.go b/cmd/podman/system/service_abi.go
index 0e96e1fbb..9e8a9f9b4 100644
--- a/cmd/podman/system/service_abi.go
+++ b/cmd/podman/system/service_abi.go
@@ -24,16 +24,28 @@ func restService(opts entities.ServiceOptions, flags *pflag.FlagSet, cfg *entiti
)
if opts.URI != "" {
- fields := strings.Split(opts.URI, ":")
- if len(fields) == 1 {
- return errors.Errorf("%s is an invalid socket destination", opts.URI)
+ if os.Getenv("LISTEN_FDS") != "" {
+ // If it is activated by systemd, use the first LISTEN_FD (3)
+ // instead of opening the socket file.
+ f := os.NewFile(uintptr(3), "podman.sock")
+ l, err := net.FileListener(f)
+ if err != nil {
+ return err
+ }
+ listener = &l
+ } else {
+ fields := strings.Split(opts.URI, ":")
+ if len(fields) == 1 {
+ return errors.Errorf("%s is an invalid socket destination", opts.URI)
+ }
+ network := fields[0]
+ address := strings.Join(fields[1:], ":")
+ l, err := net.Listen(network, address)
+ if err != nil {
+ return errors.Wrapf(err, "unable to create socket")
+ }
+ listener = &l
}
- address := strings.Join(fields[1:], ":")
- l, err := net.Listen(fields[0], address)
- if err != nil {
- return errors.Wrapf(err, "unable to create socket")
- }
- listener = &l
}
// Close stdin, so shortnames will not prompt