Skip to content

flatpak-spawn cannot allocate TTy properly #3285

Open

Description

@yajo

Linux distribution and version

Fedora Silverblue 31

Flatpak version

flatpak-1.4.3-3.fc31.x86_64

Description of the problem

When calling flatpak-spawn --host bash from inside a flatpak, it cannot work properly:

sh-4.4$ flatpak-spawn --host --env=LANG=C bash
bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell

The final use case is to try to set the default terminal in flatpak'd VSCode to flatpak-spawn --host toolbox enter... and, of course, that it works.

Steps to reproduce

  1. Install https://flathub.org/apps/details/com.visualstudio.code.oss
  2. Open it.
  3. Open its integrated terminal (View > Terminal)
  4. Execute flatpak-spawn --host bash

Other shells are even worse. Just try with fish for example, it doesn't work.

Activity

  1. yajo commented on Dec 9, 2019

    @yajo
    Author

    Yikes, not sure how I managed to do this, but I fixed the issue in vscode with these settings, and they allocate a tty:

    // settings.json
        "terminal.integrated.shell.linux": "/usr/bin/flatpak-spawn",
        "terminal.integrated.shellArgs.linux": ["--host", "toolbox", "run", "env", "TERM=xterm-256color", "fish"],
  2. ranisalt commented on Apr 8, 2020

    @ranisalt

    I have this problem and I am not willing to install yet another dependency, in this case toolbox, as it pulls other packages that I'd rather not have installed.

  3. ibotty commented on Apr 29, 2020

    @ibotty

    I use

     flatpak-spawn --host --env=TERM="$TERM" ...
    

    That works beautifully if TERM is set correctly in the first place.

  4. yajo commented on Apr 30, 2020

    @yajo
    Author

    You cannot use that @ibotty.

    If you configure vscode as this:

        "terminal.integrated.env.linux": {
            "EDITOR": "code --wait",
        },
        "terminal.integrated.shell.linux": "flatpak-spawn",
        "terminal.integrated.shellArgs.linux": ["--host", "toolbox", "run", "env", "TERM=$TERM", "EDITOR=$EDITOR", "bash"],

    Then inside the terminal:

    ⬢[yajo@toolbox ~]$ echo $TERM
    $TERM
    ⬢[yajo@toolbox ~]$ echo $EDITOR
    $EDITOR

    No luck...

  5. yajo commented on Apr 30, 2020

    @yajo
    Author

    I have tried this and it opens a shell indeed:

        "terminal.integrated.shell.linux": "flatpak-spawn",
        "terminal.integrated.shellArgs.linux": ["--host", "toolbox", "enter"],

    It should be the desired way, however the problem seems to be the missing env variables, even those defined in terminal.integrated.env.linux setting. It makes TERM=dumb and makes fish unusable.

    Possibly due to containers/toolbox#29.

  6. ibotty commented on Apr 30, 2020

    @ibotty

    @yajo, it seems it does not work from within vscode (which totally makes sense). It does work perfectly from inside a shell. I have no idea what terminal vscode emulates. If bash works when called directly, vscode does set TERM for the calling process. If so, you might use something like bash -c 'exec flatpak-spawn --host --env TERM="$TERM" ...' This will set the environment variable.

  7. ibotty commented on Apr 30, 2020

    @ibotty

    And I am pretty sure it's unrelated to containers/toolbox#29. Because flatpak-spawn does not inherit TERM even without toolbox in sight.

  8. yajo commented on May 11, 2020

    @yajo
    Author

    Yes, indeed the problem seems to be inside flatpak-spawn itself. It's impossible for it to allocate a TTy. There should be an option for this for us to be able to workaround flathub/com.visualstudio.code#39, flathub/com.visualstudio.code.oss#5 and similar.

  9. reopened this on May 11, 2020
  10. refi64 commented on May 12, 2020

    @refi64
    Collaborator
  11. nyx-lyb3ra commented on May 23, 2020

    @nyx-lyb3ra

    I think this is a pretty good solution

    "terminal.integrated.shell.linux": "flatpak-spawn",
    "terminal.integrated.shellArgs.linux": [ "--host", "--env=TERM=xterm-256color", "toolbox", "enter" ]

    Thinking that flatpak-spawn just needs a way to simply expose already setted env vars, like docker or podman

  12. yajo commented on May 25, 2020

    @yajo
    Author

    OOooooOoh that works!

  13. rh-y0n1 commented on Jan 17, 2021

    @rh-y0n1

    I'm using zsh as my shell and this worked for me on GoLand and WebStorm /usr/bin/env -- flatpak-spawn --host --env=TERM=xterm-256color zsh

  14. ranisalt commented on Jan 17, 2021

    @ranisalt

    A rather ugly but usable workaround if you need something immediately could be to run a private (not exposed to the public network) ssh server on your host system, then drop a tiny, statically linked ssh client like dropbear in some directory your Flatpak can access and use it to open a terminal on the host.

    The problem with this approach is the loss of $PWD unless you do some more trickery to cd to the project folder.

  15. bonzini commented on May 11, 2021

    @bonzini

    For the specific case of Visual Studio Code, another ugly but usable workaround is to modify local files via ssh to localhost. Which maybe is not that ugly and would let you sandbox the flatpak even more.

  16. vwalek commented on Jun 16, 2021

    @vwalek

    I'm using zsh as my shell and this worked for me on GoLand and WebStorm /usr/bin/env -- flatpak-spawn --host --env=TERM=xterm-256color zsh

    Hey, thx, work as it should. I see that the vscode changed the way to integrate the shell, so use this config. Worked for me.

        "terminal.integrated.defaultProfile.linux": "zsh",
        "terminal.integrated.profiles.linux": {
            "zsh": {
              "path": "/usr/bin/env",
              "args": ["--", "flatpak-spawn", "--host", "--env=TERM=xterm-256color", "zsh"]
            }
    
  17. vteivans commented on Feb 15, 2022

    @vteivans

    I wonder what Tilix is doing differently. It seems to have access from flatpak to the host shell without flatpak-spawn. I just installed it from the Gnome software (thorugh flatpak fedora repo) and it seems to be working (mostly) fine.

    It has some issue now with the toolbox command and the UI sometimes crashes on it's own though.

    https://github.com/gnunn1/tilix

  18. refi64 commented on Feb 15, 2022

    @refi64
    Collaborator

    Tilix uses the same D-Bus APIs that flatpak-spawn uses, it just calls them directly.

    and the UI sometimes crashes on it's own though

    The Tilix Flatpak has always had some memory corruption / double free issues, likely tied somehow to the D-Bus calls it makes. I tried looking into it a long time ago but couldn't resolve it, which is why it was never published to Flathub.

  19. 1player commented on Jul 26, 2022

    @1player

    FWIW, I have an alternative implementation of flatpak-spawn --host that fixes this issue and a few others: https://github.com/1player/host-spawn

  20. chergert commented on Nov 16, 2023

    @chergert
    Contributor

    Coming across this I figured I might want to mention what the underlying issue is, because I didn't see it mentioned here.

    Years ago when doing the initial version of GNOME Builder which flatpak's everything, I had to change how PTY's were created. You need to O_NOCTTY for your PTY when going across the boundary. Otherwise, the child process with the FD's mapped as stdin/out/err will become the controlling terminal for that PTY.

    Why this likely works with something like toolbox is simply because podman, underneath, is creating a sub-PTY for you (just like tmux would).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions