Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions libpod/container_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,12 +630,6 @@ func (c *Container) generateInspectContainerHostConfig(ctrSpec *spec.Spec, named
}
}

// Terminal size
// We can't actually get this for now...
// So default to something sane.
// TODO: Populate this.
hostConfig.ConsoleSize = []uint{0, 0}

return hostConfig, nil
}

Expand Down
6 changes: 6 additions & 0 deletions libpod/container_inspect_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,11 @@ func (c *Container) platformInspectContainerHostConfig(ctrSpec *spec.Spec, hostC
return err
}

// Console size
// We can't actually get this for now...
// So default to something sane.
// TODO: Populate this.
hostConfig.ConsoleSize = []uint{0, 0}

return nil
}
25 changes: 25 additions & 0 deletions libpod/container_inspect_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package libpod

import (
"fmt"
"os"
"sort"
"strings"

Expand All @@ -14,6 +15,7 @@ import (
"go.podman.io/podman/v6/libpod/define"
"go.podman.io/podman/v6/pkg/util"
"go.podman.io/storage/types"
"golang.org/x/term"
)

func (c *Container) platformInspectContainerHostConfig(ctrSpec *spec.Spec, hostConfig *define.InspectContainerHostConfig) error {
Expand Down Expand Up @@ -306,6 +308,29 @@ func (c *Container) platformInspectContainerHostConfig(ctrSpec *spec.Spec, hostC
return err
}

// ConsoleSize.
// Default to [0,0] if we can't get it for some reason,
// or if the container doesn't have a TTY.
hostConfig.ConsoleSize = []uint{0, 0}

if c.Terminal() {
procPath := fmt.Sprintf("/proc/%d/fd/0", c.state.PID)

f, err := os.Open(procPath)
if err != nil {
logrus.Debugf("unable to get console size for container %s: %v", c.ID(), err)
} else {
defer f.Close()

width, height, err := term.GetSize(int(f.Fd()))
if err != nil {
logrus.Debugf("could not get terminal size: %v", err)
} else {
hostConfig.ConsoleSize = []uint{uint(width), uint(height)}
}
}
}

return nil
}

Expand Down