summaryrefslogtreecommitdiff
path: root/cmd/podman/system
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2022-04-27 15:48:04 -0400
committerDaniel J Walsh <dwalsh@redhat.com>2022-05-04 12:11:32 -0400
commit5fa6f686dbeaf04e1df8a888b9458c3d7f42eee8 (patch)
treec1700e0bbdfd923e6a76406bc6078df80f1d74b8 /cmd/podman/system
parentb1e9ea38e5a680afb9294cb8a451311991d94765 (diff)
downloadpodman-5fa6f686dbeaf04e1df8a888b9458c3d7f42eee8.tar.gz
podman-5fa6f686dbeaf04e1df8a888b9458c3d7f42eee8.tar.bz2
podman-5fa6f686dbeaf04e1df8a888b9458c3d7f42eee8.zip
Report correct RemoteURI
Rather than assuming a filesystem path, the API service URI is recorded in the libpod runtime configuration and then reported as requested. Note: All schemes other than "unix" are hard-coded to report URI exists. Fixes #12023 Signed-off-by: Jhon Honce <jhonce@redhat.com> Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'cmd/podman/system')
-rw-r--r--cmd/podman/system/service_abi.go37
1 files changed, 26 insertions, 11 deletions
diff --git a/cmd/podman/system/service_abi.go b/cmd/podman/system/service_abi.go
index f8abea3aa..9dc9de1c8 100644
--- a/cmd/podman/system/service_abi.go
+++ b/cmd/podman/system/service_abi.go
@@ -4,17 +4,18 @@
package system
import (
- "context"
+ "fmt"
"net"
"net/url"
"os"
"path/filepath"
+ "github.com/containers/podman/v4/cmd/podman/registry"
api "github.com/containers/podman/v4/pkg/api/server"
"github.com/containers/podman/v4/pkg/domain/entities"
"github.com/containers/podman/v4/pkg/domain/infra"
"github.com/containers/podman/v4/pkg/servicereaper"
- "github.com/containers/podman/v4/pkg/util"
+ "github.com/coreos/go-systemd/v22/activation"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/pflag"
@@ -27,7 +28,26 @@ func restService(flags *pflag.FlagSet, cfg *entities.PodmanConfig, opts entities
err error
)
- if opts.URI != "" {
+ libpodRuntime, err := infra.GetRuntime(registry.Context(), flags, cfg)
+ if err != nil {
+ return err
+ }
+
+ if opts.URI == "" {
+ if _, found := os.LookupEnv("LISTEN_PID"); !found {
+ return errors.New("no service URI provided and socket activation protocol is not active")
+ }
+
+ listeners, err := activation.Listeners()
+ if err != nil {
+ return fmt.Errorf("cannot retrieve file descriptors from systemd: %w", err)
+ }
+ if len(listeners) != 1 {
+ return fmt.Errorf("wrong number of file descriptors for socket activation protocol (%d != 1)", len(listeners))
+ }
+ listener = listeners[0]
+ libpodRuntime.SetRemoteURI(listeners[0].Addr().String())
+ } else {
uri, err := url.Parse(opts.URI)
if err != nil {
return errors.Errorf("%s is an invalid socket destination", opts.URI)
@@ -39,7 +59,6 @@ func restService(flags *pflag.FlagSet, cfg *entities.PodmanConfig, opts entities
if err != nil {
return err
}
- util.SetSocketPath(path)
if os.Getenv("LISTEN_FDS") != "" {
// If it is activated by systemd, use the first LISTEN_FD (3)
// instead of opening the socket file.
@@ -67,6 +86,7 @@ func restService(flags *pflag.FlagSet, cfg *entities.PodmanConfig, opts entities
default:
logrus.Debugf("Attempting API Service endpoint scheme %q", uri.Scheme)
}
+ libpodRuntime.SetRemoteURI(uri.String())
}
// Close stdin, so shortnames will not prompt
@@ -78,15 +98,10 @@ func restService(flags *pflag.FlagSet, cfg *entities.PodmanConfig, opts entities
if err := unix.Dup2(int(devNullfile.Fd()), int(os.Stdin.Fd())); err != nil {
return err
}
- rt, err := infra.GetRuntime(context.Background(), flags, cfg)
- if err != nil {
- return err
- }
servicereaper.Start()
-
- infra.StartWatcher(rt)
- server, err := api.NewServerWithSettings(rt, listener, opts)
+ infra.StartWatcher(libpodRuntime)
+ server, err := api.NewServerWithSettings(libpodRuntime, listener, opts)
if err != nil {
return err
}