server: fix url parsing in info

When we are activated by systemd the code assumed that we had a valid
URL which was not the case so it failed to parse the URL which causes
the info call to fail all the time.
This fixes two problems first add the schema to the systemd activated
listener URL so it can be parsed correctly but second simply do not
parse it as url as all we care about in the info call is if it is unix
and the file path exists.

Fixes #24152

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
Paul Holzinger
2024-10-07 12:00:35 +02:00
parent e2e1996c6a
commit 45df394072
3 changed files with 12 additions and 9 deletions

View File

@ -48,7 +48,7 @@ func restService(flags *pflag.FlagSet, cfg *entities.PodmanConfig, opts entities
if listener == nil { if listener == nil {
return errors.New("unexpected fd received from systemd: cannot listen on it") return errors.New("unexpected fd received from systemd: cannot listen on it")
} }
libpodRuntime.SetRemoteURI(listeners[0].Addr().String()) libpodRuntime.SetRemoteURI(listeners[0].Addr().Network() + "://" + listeners[0].Addr().String())
} else { } else {
uri, err := url.Parse(opts.URI) uri, err := url.Parse(opts.URI)
if err != nil { if err != nil {

View File

@ -10,6 +10,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"strings"
"github.com/containers/podman/v5/libpod/define" "github.com/containers/podman/v5/libpod/define"
"github.com/containers/podman/v5/pkg/domain/entities" "github.com/containers/podman/v5/pkg/domain/entities"
@ -48,19 +49,16 @@ func (ic *ContainerEngine) Info(ctx context.Context) (*define.Info, error) {
info.Host.RemoteSocket.Path = uri.Path info.Host.RemoteSocket.Path = uri.Path
} }
uri, err := url.Parse(ic.Libpod.RemoteURI()) // check if the unix path exits, if not unix socket we always we assume it exists, i.e. tcp socket
if err != nil { path, found := strings.CutPrefix(info.Host.RemoteSocket.Path, "unix://")
return nil, err if found {
} err := fileutils.Exists(path)
if uri.Scheme == "unix" {
err := fileutils.Exists(uri.Path)
info.Host.RemoteSocket.Exists = err == nil info.Host.RemoteSocket.Exists = err == nil
} else { } else {
info.Host.RemoteSocket.Exists = true info.Host.RemoteSocket.Exists = true
} }
return info, err return info, nil
} }
// SystemPrune removes unused data from the system. Pruning pods, containers, networks, volumes and images. // SystemPrune removes unused data from the system. Pruning pods, containers, networks, volumes and images.

View File

@ -82,6 +82,11 @@ var _ = Describe("Systemd activate", func() {
return testUtils.SystemExec(podmanTest.PodmanBinary, args) return testUtils.SystemExec(podmanTest.PodmanBinary, args)
} }
// regression check for https://github.com/containers/podman/issues/24152
session := podmanRemote("info", "--format", "{{.Host.RemoteSocket.Path}}--{{.Host.RemoteSocket.Exists}}")
Expect(session).Should(testUtils.ExitCleanly())
Expect(session.OutputToString()).To(Equal("tcp://" + addr + "--true"))
containerName := "top_" + testUtils.RandomString(8) containerName := "top_" + testUtils.RandomString(8)
apiSession := podmanRemote( apiSession := podmanRemote(
"create", "--tty", "--name", containerName, "--entrypoint", "top", "create", "--tty", "--name", containerName, "--entrypoint", "top",