aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-03-29 17:40:21 +0000
committerGitHub <noreply@github.com>2021-03-29 17:40:21 +0000
commitaa96cb6739303a4bf76aeb6395e8ef79ff8ef0ee (patch)
tree99e4531c9d83b290dc6a74d8c16c26c44fb7a8c0 /cmd
parent26b0ebd22f0a516eae9daf2439697f1f793894cc (diff)
parentc064acd78e418943edae8ec2998f855721157f30 (diff)
downloadpodman-aa96cb6739303a4bf76aeb6395e8ef79ff8ef0ee.tar.gz
podman-aa96cb6739303a4bf76aeb6395e8ef79ff8ef0ee.tar.bz2
podman-aa96cb6739303a4bf76aeb6395e8ef79ff8ef0ee.zip
Merge pull request #9855 from giuseppe/fix-service-race-condition
service: use LISTEN_FDS
Diffstat (limited to 'cmd')
-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