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

flatpak-spawn cannot allocate TTy properly #3285

Open
yajo opened this issue Dec 9, 2019 · 19 comments
Open

flatpak-spawn cannot allocate TTy properly #3285

yajo opened this issue Dec 9, 2019 · 19 comments

Comments

@yajo
Copy link

yajo commented Dec 9, 2019

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.

@yajo
Copy link
Author

yajo commented Dec 9, 2019

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"],

@yajo yajo closed this as completed Dec 9, 2019
@ranisalt
Copy link

ranisalt commented Apr 8, 2020

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.

@ibotty
Copy link

ibotty commented Apr 29, 2020

I use

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

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

@yajo
Copy link
Author

yajo commented Apr 30, 2020

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...

@yajo
Copy link
Author

yajo commented Apr 30, 2020

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.

@ibotty
Copy link

ibotty commented Apr 30, 2020

@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.

@ibotty
Copy link

ibotty commented Apr 30, 2020

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

@yajo
Copy link
Author

yajo commented May 11, 2020

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.

@yajo yajo reopened this May 11, 2020
@refi64
Copy link
Collaborator

refi64 commented May 12, 2020 via email

@naipotato
Copy link

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

@yajo
Copy link
Author

yajo commented May 25, 2020

OOooooOoh that works!

@jkilzi
Copy link

jkilzi commented Jan 17, 2021

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

@ranisalt
Copy link

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.

@bonzini
Copy link

bonzini commented May 11, 2021

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.

@vwalek
Copy link

vwalek commented Jun 16, 2021

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"]
        }

@vteivans
Copy link

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

@refi64
Copy link
Collaborator

refi64 commented Feb 15, 2022

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.

@1player
Copy link

1player commented Jul 26, 2022

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

@chergert
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests