mirror of
https://github.com/containers/podman.git
synced 2025-06-25 03:52:15 +08:00
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>
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user