Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix running of GUI apps from toolboxes #564

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -33,6 +33,18 @@ import (
"github.com/spf13/cobra"
)

type initContainerMount struct {
containerPath string
source string
flags string
}

type initContainerSymlink struct {
containerPath string
source string
folder bool
}

var (
initContainerFlags struct {
home string
@@ -45,18 +57,22 @@ var (
user string
}

initContainerMounts = []struct {
containerPath string
source string
flags string
}{
initContainerMounts = []initContainerMount{
{"/etc/machine-id", "/run/host/etc/machine-id", "ro"},
{"/run/libvirt", "/run/host/run/libvirt", ""},
{"/run/systemd/journal", "/run/host/run/systemd/journal", ""},
{"/var/lib/flatpak", "/run/host/var/lib/flatpak", "ro"},
{"/var/log/journal", "/run/host/var/log/journal", "ro"},
{"/var/mnt", "/run/host/var/mnt", "rslave"},
}

initContainerX11Symlinks = []initContainerSymlink{

This comment has been minimized.

@debarshiray

debarshiray Oct 1, 2020
Member

It would be better to do it as a bind mount instead. Or is there a reason why they must be symbolic links? Did I miss something?

For individual regular files we prefer symbolic links instead of bind mounts, because symbolic links can track updates to the original file. Whereas, with bound mounts, if the original file was updated atomically, which is what most programs do, then the atomic rename changes the inode, and the two diverge.

However, symbolic links are always weird and introduce various oddities (eg., stat versus lstat), so bind mount is better when possible.

{"/tmp/.X11-unix", "/run/host/tmp/.X11-unix", true},
{"/tmp/.ICE-unix", "/run/host/tmp/.ICE-unix", true},
{"/tmp/.font-unix", "/run/host/tmp/.font-unix", true},
{"/tmp/.Test-unix", "/run/host/tmp/.Test-unix", true},
{"/tmp/.XIM-unix", "/run/host/tmp/.XIM-unix", true},
}
)

var initContainerCmd = &cobra.Command{
@@ -153,6 +169,12 @@ func initContainer(cmd *cobra.Command, args []string) error {
return fmt.Errorf("failed to mount tmpfs at /tmp: %s", err)
}

if utils.PathExists("/run/host/tmp") {
if err := setupX11(); err != nil {
return fmt.Errorf("Failed to set up hosts X environment: %w", err)
}
}

if initContainerFlags.monitorHost {
logrus.Debug("Monitoring host")

@@ -416,6 +438,36 @@ func configureUsers(targetUserUid int,
return nil
}

func setupX11() error {
var err error

logrus.Info("Setting up the host's X environment")

hostX11LockFiles, err := filepath.Glob("/run/host/tmp/.X*-lock")
if err != nil {
return err
}

for _, hostX11Lockfile := range hostX11LockFiles {
containerX11Lockfile := filepath.Join("/", "tmp", filepath.Base(hostX11Lockfile))
initContainerX11Symlinks = append(initContainerX11Symlinks, initContainerSymlink{
containerX11Lockfile,
hostX11Lockfile,
false})
}

for _, symlink := range initContainerX11Symlinks {
if _, err = os.Readlink(symlink.containerPath); err != nil {
if err = redirectPath(symlink.containerPath,
symlink.source,
symlink.folder); err != nil {
return err
}
}
}
return nil
}

func mountBind(containerPath, source, flags string) error {
fi, err := os.Stat(source)
if err != nil {
@@ -494,12 +546,14 @@ func redirectPath(containerPath, target string, folder bool) error {
logrus.Debugf("Preparing to redirect %s to %s", containerPath, target)
targetSanitized := sanitizeRedirectionTarget(target)

err := os.Remove(containerPath)
if folder {
if err != nil {
if utils.PathExists(containerPath) {
err := os.Remove(containerPath)
if err != nil && folder {
return fmt.Errorf("failed to redirect %s to %s: %w", containerPath, target, err)
}
}

if folder {
if err := os.MkdirAll(target, 0755); err != nil {
return fmt.Errorf("failed to redirect %s to %s: %w", containerPath, target, err)
}
ProTip! Use n and p to navigate between commits in a pull request.