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

Libraries are missing when launching GUI applications #2

Closed
wants to merge 3 commits into from

Conversation

tunix
Copy link

@tunix tunix commented Jul 16, 2021

Fixes #19

  • Removed desktop-helpers as most of it is for strictly confined apps, causing trouble for classic confinement
  • Moved GL related customizations inside desktop-helpers into custom-wrapper
  • Updated README for Testing part -- (ideas are welcome)

Fixes

  • Curses based apps now work (test via nano)
  • GUI apps now work (test via gedit)

Issues (WIP)

  • X applications cannot work (test via xeyes or xcalc)

I'm still working on this to understand why X applications don't work. They work with sudo btw.

@tunix tunix requested review from a team, AlanGriffiths, merlijn-sebrechts, kenvandine, brlin-tw and om26er and removed request for a team July 16, 2021 11:34
@tunix tunix added bug Something isn't working help wanted Extra attention is needed work in progress labels Jul 16, 2021
@kenvandine
Copy link

I think this all looks good, the only question I have is __EGL_VENDOR_LIBRARY_DIRS. This might not be ideal for a classic snap, but it could be harmless, just something to think about.

@tunix
Copy link
Author

tunix commented Jul 16, 2021

I think this all looks good, the only question I have is __EGL_VENDOR_LIBRARY_DIRS. This might not be ideal for a classic snap, but it could be harmless, just something to think about.

I think I need this as I remember having issues on a computer with NVIDIA GPU. (intel+nvidia -- prime?)

Also, Sergio Schvezov says that changing LD_LIBRARY_PATH is the main cause of the problems. I never heard of RPATH nor RUNPATH. Reading stuff that explains it.

@lucyllewy
Copy link
Member

I've had a look through the rust issue tracker after some googling when I saw this PR. It looks like cargo and rust can't be configured to set an appropriate rpath just yet, but there's an issue over there to get it implemented. The alternative, in the meantime until that is sorted upstream, is to look into setting the rpath on the executable after it's been built. There's a utility in the archive called patchelf that can be added to build-packages so that we can use it in an override-build or an override-stage block.

@tunix
Copy link
Author

tunix commented Jul 17, 2021

@diddledan - I replaced LD_LIBRARY_PATH modifications with your suggestion but I'm not exactly sure if I did it right. Unfortunetely it cannot find included libraries.

libGL: Can't open configuration file /etc/drirc: No such file or directory.
libGL: Can't open configuration file /home/tunix/.drirc: No such file or directory.
libGL: using driver i915 for 7
libGL: Can't open configuration file /etc/drirc: No such file or directory.
libGL: Can't open configuration file /home/tunix/.drirc: No such file or directory.
libGL: using driver i915 for 7
libGL: pci id for fd 7: 8086:9a49, driver iris
libGL: MESA-LOADER: failed to open /snap/alacritty/x2/usr/lib/x86_64-linux-gnu/dri/iris_dri.so: libffi.so.7: cannot open shared object file: No such file or directory
libGL error: MESA-LOADER: failed to open iris (search paths /snap/alacritty/x2/usr/lib/x86_64-linux-gnu/dri)
libGL error: failed to load driver: iris
libGL: using driver i915 for 7
libGL: Can't open configuration file /etc/drirc: No such file or directory.
libGL: Can't open configuration file /home/tunix/.drirc: No such file or directory.
libGL: using driver i915 for 7
libGL: pci id for fd 7: 8086:9a49, driver iris
libGL: MESA-LOADER: failed to open /snap/alacritty/x2/usr/lib/x86_64-linux-gnu/dri/iris_dri.so: libffi.so.7: cannot open shared object file: No such file or directory
libGL error: MESA-LOADER: failed to open iris (search paths /snap/alacritty/x2/usr/lib/x86_64-linux-gnu/dri)
libGL error: failed to load driver: iris
libGL: MESA-LOADER: failed to open /snap/alacritty/x2/usr/lib/x86_64-linux-gnu/dri/swrast_dri.so: libffi.so.7: cannot open shared object file: No such file or directory
libGL error: MESA-LOADER: failed to open swrast (search paths /snap/alacritty/x2/usr/lib/x86_64-linux-gnu/dri)
libGL error: failed to load driver: swrast
libGL: Can't open configuration file /etc/drirc: No such file or directory.
libGL: Can't open configuration file /home/tunix/.drirc: No such file or directory.
libGL: Can't open configuration file /etc/drirc: No such file or directory.
libGL: Can't open configuration file /home/tunix/.drirc: No such file or directory.
libEGL warning: MESA-LOADER: failed to open iris (search paths /snap/alacritty/x2/usr/lib/x86_64-linux-gnu/dri)

libGL: Can't open configuration file /etc/drirc: No such file or directory.
libGL: Can't open configuration file /home/tunix/.drirc: No such file or directory.
libEGL warning: MESA-LOADER: failed to open iris (search paths /snap/alacritty/x2/usr/lib/x86_64-linux-gnu/dri)

libEGL warning: MESA-LOADER: failed to open swrast (search paths /snap/alacritty/x2/usr/lib/x86_64-linux-gnu/dri)

libEGL warning: MESA-LOADER: failed to open swrast (search paths /snap/alacritty/x2/usr/lib/x86_64-linux-gnu/dri)

libGL: Can't open configuration file /etc/drirc: No such file or directory.
libGL: Can't open configuration file /home/tunix/.drirc: No such file or directory.
libGL: Can't open configuration file /etc/drirc: No such file or directory.
libGL: Can't open configuration file /home/tunix/.drirc: No such file or directory.
libEGL warning: MESA-LOADER: failed to open iris (search paths /snap/alacritty/x2/usr/lib/x86_64-linux-gnu/dri)

libGL: Can't open configuration file /etc/drirc: No such file or directory.
libGL: Can't open configuration file /home/tunix/.drirc: No such file or directory.
libEGL warning: MESA-LOADER: failed to open iris (search paths /snap/alacritty/x2/usr/lib/x86_64-linux-gnu/dri)

libEGL warning: MESA-LOADER: failed to open swrast (search paths /snap/alacritty/x2/usr/lib/x86_64-linux-gnu/dri)

libEGL warning: MESA-LOADER: failed to open swrast (search paths /snap/alacritty/x2/usr/lib/x86_64-linux-gnu/dri)

Created log file at "/tmp/Alacritty-102179.log"
[2021-07-17 15:44:24.820005643] [ERROR] [alacritty] Alacritty encountered an unrecoverable error:
                                                    
                                                    	Error creating GL context; Received multiple errors. Errors: `[OsError("eglInitialize failed"), OsError("GL context creation failed")]`

@tunix tunix changed the title Removed desktop-helpers, updated README for testing Libraries are missing when launching GUI applications Jul 17, 2021
@AlanGriffiths
Copy link

Sorry for a drive-by comment, but this looks like a job for https://github.com/wmww/snap-out

@tunix
Copy link
Author

tunix commented Jul 19, 2021

Sorry for a drive-by comment, but this looks like a job for https://github.com/wmww/snap-out

Thanks for the suggestion. I added snap-out as a part to the snap and tried adding it into the command chain and into the custom-wrapper script but unfortunetely neither worked. I always got:

libGL error: MESA-LOADER: failed to open iris (search paths /usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri)
libGL error: failed to load driver: iris
libGL error: MESA-LOADER: failed to open iris (search paths /usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri)
libGL error: failed to load driver: iris
libGL error: MESA-LOADER: failed to open swrast (search paths /usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri)
libGL error: failed to load driver: swrast
libEGL warning: MESA-LOADER: failed to open iris (search paths /usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri)

libEGL warning: MESA-LOADER: failed to open iris (search paths /usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri)

libEGL warning: MESA-LOADER: failed to open swrast (search paths /usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri)

libEGL warning: MESA-LOADER: failed to open swrast (search paths /usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri)

libEGL warning: MESA-LOADER: failed to open iris (search paths /usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri)

libEGL warning: MESA-LOADER: failed to open iris (search paths /usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri)

libEGL warning: MESA-LOADER: failed to open swrast (search paths /usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri)

libEGL warning: MESA-LOADER: failed to open swrast (search paths /usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri)

Created log file at "/tmp/Alacritty-27172.log"
[2021-07-19 15:43:03.957869182] [ERROR] [alacritty] Alacritty encountered an unrecoverable error:
                                                    
                                                        Error creating GL context; Received multiple errors. Errors: `[OsError("eglInitialize failed"), OsError("GL context creation failed")]`

@cjp256
Copy link

cjp256 commented Jul 30, 2021

Pretty much every export that isn't restricted to alacritty itself is going to cause issues. The wrapper scripts are setting environment variables that will cause breakage seen above.

I'd suggest narrowing down the variables to the minimum required (I think I had decent luck with just the two GL vars https://github.com/cjp256/alacritty/blob/snap-core20/extra/linux/snap/snapcraft.yaml#L83), and then perhaps add a tiny patch to alacritty to unset the remainder once initialized.

I need to update my intel graphics system to hirsuite, but this works fine for my nvidia hirsuite (shorted out desktop-launch and custom wrapper, no patching of alacritty).

@tunix
Copy link
Author

tunix commented Aug 3, 2021

@cjp256 - i tried a lot of different things but none of them have worked. i looked at your snapcraft.yml, removed custom-wrapper, left just the env vars you defined, removed some dependencies etc. And now I get this:

LIBGL_DEBUG=verbose alacritty                                                                                                                                                                         ⏎ [ gui_fix ✖ ] ✹ ]
libGL: Can't open configuration file /etc/drirc: No such file or directory.
libGL: Can't open configuration file /home/tunix/.drirc: No such file or directory.
libGL: using driver i915 for 7
libGL: Can't open configuration file /etc/drirc: No such file or directory.
libGL: Can't open configuration file /home/tunix/.drirc: No such file or directory.
libGL: using driver i915 for 7
libGL: pci id for fd 7: 8086:9a49, driver iris
libGL: MESA-LOADER: failed to open /snap/alacritty/x1/usr/lib/x86_64-linux-gnu/dri/iris_dri.so: libffi.so.7: cannot open shared object file: No such file or directory
libGL error: MESA-LOADER: failed to open iris (search paths /snap/alacritty/x1/usr/lib/x86_64-linux-gnu/dri)
libGL error: failed to load driver: iris
libGL: using driver i915 for 7
libGL: Can't open configuration file /etc/drirc: No such file or directory.
libGL: Can't open configuration file /home/tunix/.drirc: No such file or directory.
libGL: using driver i915 for 7
libGL: pci id for fd 7: 8086:9a49, driver iris
libGL: MESA-LOADER: failed to open /snap/alacritty/x1/usr/lib/x86_64-linux-gnu/dri/iris_dri.so: libffi.so.7: cannot open shared object file: No such file or directory
libGL error: MESA-LOADER: failed to open iris (search paths /snap/alacritty/x1/usr/lib/x86_64-linux-gnu/dri)
libGL error: failed to load driver: iris
libGL: MESA-LOADER: failed to open /snap/alacritty/x1/usr/lib/x86_64-linux-gnu/dri/swrast_dri.so: libffi.so.7: cannot open shared object file: No such file or directory
libGL error: MESA-LOADER: failed to open swrast (search paths /snap/alacritty/x1/usr/lib/x86_64-linux-gnu/dri)
libGL error: failed to load driver: swrast
Created log file at "/tmp/Alacritty-106114.log"
[2021-08-03 11:05:18.878101158] [ERROR] [alacritty] Alacritty encountered an unrecoverable error:
                                                    
                                                        Error creating GL context; Received multiple errors. Errors: `[OsError("Could not create EGL display object"), OsError("GL context creation failed")]`

libffi is included within the snap as it seems to be required for transparency but it cannot find it unless I pass some other env vars to specify where to look for it.

Also I probably will need to add back the custom wrapper because alacritty supports multiple archs and I couldn't find a proper way of constructing the triplet w/o it.

@tunix
Copy link
Author

tunix commented Aug 3, 2021

Btw, I found out that if I patchelf alacritty binary during staging, it somehow reverts back all modifications during priming. (checking via readelf at both staging and priming stages: readelf /path/to/part/and/alacritty | grep RPATH) So I applied patchelf at the priming stage. (you can check the code that is currently commited into the branch) but it segfaults right away. :(

(This is just another thing I tried aside from the things I tried in above comment)

@AlanGriffiths
Copy link

So I applied patchelf at the priming stage. (you can check the code that is currently commited into the branch) but it segfaults right away

I'm not entirely clear which binaries you experimented with patching, but some lead directly to problems. E.g. mesa's dri directory content breaks because stuff gets stripped in the process (C.f. https://github.com/MirServer/egmde-snap/blob/78f0dbcc02a56c6a656ca496a6165cf8a527a8e2/snap/snapcraft.yaml#L108)

@tunix
Copy link
Author

tunix commented Aug 3, 2021

@AlanGriffiths - please check this line. Within that block, I tried to change certain parts of the binary to look for libraries within the snap itself and not to the host system. And this is only done for alacritty binary. For GL libraries, I added no-patchelf at line 30.

@AlanGriffiths
Copy link

please check this line

If I read that correctly, you should drop :/snap/alacritty/current/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/dri - mesa will crash if you mess with those binaries.

@tunix
Copy link
Author

tunix commented Aug 3, 2021

please check this line

If I read that correctly, you should drop :/snap/alacritty/current/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/dri - mesa will crash if you mess with those binaries.

As far as I understand, that line replaces RPATH within the binary so that it'll search for GL libraries inside the snap. To my understanding, it should have nothing to do with patching GL libraries in that path. Am I wrong?

@AlanGriffiths
Copy link

AlanGriffiths commented Aug 3, 2021

Am I wrong?

No I am. Sorry. But it still shouldn't be needed. These libs should be found via __EGL_VENDOR_LIBRARY_DIRS, not rpath

Copy link

@AlanGriffiths AlanGriffiths left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are problems with and without this PR.

When launching applications from outside the snap they should not inherit any of the snap's environment.

  • There are no layouts (which is good)
  • There are environment variables (which is bad)

The default "patch-elf" behaviour should be correct for most things (you shouldn't need to run it "by hand") and avoid the need to set LD_LIBRARY_PATH.

Most of mesa (I think you have more of mesa than likely needed) should be packaged without - no-patchelf. See an example here: https://github.com/MirServer/egmde-snap/blob/78f0dbcc02a56c6a656ca496a6165cf8a527a8e2/snap/snapcraft.yaml#L108

You will likely need to set LIBGL_DRIVERS_PATH and __EGL_VENDOR_LIBRARY_DIRS when launching alacritty for it to run correctly except on 20.04.

The problem this causes is that when launching applications any environment variables set must be restored to what the host environment needs. That presumably needs a patch to alacritty. (Likely unsetting them will be sufficient for most cases, but a more complete solution is https://github.com/wmww/snap-out).

@tunix
Copy link
Author

tunix commented Aug 7, 2021

I pushed latest changes but still can't make it work. Removed most of the libraries I added and removed most of the env vars. Removed wrapper as well to simplify. The GL drivers are looking for libffi (probably for transparency).

image

Unfortunetely I don't know how to patch alacritty. I tried snap-out before but don't know if I've done it properly because it didn't work as well. I don't know what else to try.

@AlanGriffiths
Copy link

Unfortunetely I don't know how to patch alacritty. I tried snap-out before but don't know if I've done it properly because it didn't work as well. I don't know what else to try.

Alacritty links to the mesa version from the snap and that needs different environment variables than the native mesa version used by the applications it launches. So at the point where it executes applications alacritty needs to restore the session environment.

Unless it already has that capability, this cannot work without patching alacritty.

@redtux
Copy link

redtux commented Oct 15, 2022

Hi there, I just read the whole thread but still don't understand how to fix the issue. Is the current release simply not usable? I am on Ubuntu 22.04 using alacritty 0.8.0 from 2021-06-17, but alacritty/alacritty#5064 indicates that the issue with the snap release already existed in earlier releases. Thanks for this app and for your help!

@smcv
Copy link

smcv commented Dec 15, 2023

when launching applications any environment variables set must be restored to what the host environment needs

I think it's more fundamental than that. When launching a third-party application that is not part of Alacritty, the entire execution environment should be restored to what that third-party application needs. Environment variables are just the most immediately-visible thing, but there are many other aspects of the execution environment, and each new version of Linux adds more, such as AppArmor context, resource limits, the capability bounding set, and various inheritable process properties like the ones set by PR_SET_CHILD_SUBREAPER and PR_SET_NO_NEW_PRIVS.

In practice, restoring the execution environment is not actually possible, because many of these process properties are one-way: for example after PR_SET_NO_NEW_PRIVS has been set, it is intentionally not possible to unset it again.

The other way to get a similar result is to launch applications via an IPC request, so that the terminal emulator itself is running inside the sandbox, but the interactive shell and any third-party applications that it launches are unconfined. This is how terminal emulators packaged as Flatpak apps usually work: they are given the necessary permissions flags to be able to send a request to org.freedesktop.Flatpak.SessionHelper.HostCommand() and ask it to run an unconfined shell for them, forwarding input and output to/from the terminal.

Obviously, that's a big sandbox hole: it's arbitrary code execution on the host. However, for terminal emulators, I don't really see any alternative: the whole point of a terminal emulator is to use it to run arbitrary third-party commands, and if a terminal emulator packaged with Snap or Flatpak can't do that, then it can't do its job.

This appears to have caused at least ValveSoftware/steam-for-linux#9195 and one of several of the reports in flatpak/flatpak#1207. I'm confident that it will also be causing similar issue reports in other random applications that I'm not aware of. Sorry, but expecting the maintainers of all third-party projects to diagnose and support end-user issue reports from a Snap-packaged version of Alacritty that gives them an incomplete or broken execution environment is just not reasonable.

If launching apps via an IPC request is not possible in the Snap ecosystem, then something like https://github.com/wmww/snap-out seems like the least-bad alternative.

Is the current release simply not usable?

As a maintainer of third-party software, I would have to say: yes.

@compuguy
Copy link

compuguy commented Feb 21, 2024

Wondering if this is still an issue with release v0.13.1 via #10?

I'm not seeing anything come up in the verbose logs:

Created log file at "/tmp/Alacritty-371654.log"
[0.000000949s] [INFO ] [alacritty] Welcome to Alacritty
[0.000976414s] [INFO ] [alacritty] Version 0.13.1 (fe2a3c56)
[0.001001692s] [INFO ] [alacritty] Running on Wayland
[0.001103342s] [INFO ] [alacritty_config_derive] No config file found; using default
[0.087327165s] [INFO ] [alacritty] Using EGL 1.5
[0.087411676s] [DEBUG] [alacritty] Picked GL Config:
                                     buffer_type: Some(Rgb { r_size: 8, g_size: 8, b_size: 8 })
                                     alpha_size: 8
                                     num_samples: 0
                                     hardware_accelerated: true
                                     supports_transparency: Some(true)
                                     config_api: Api(OPENGL | GLES1 | GLES2 | GLES3)
                                     srgb_capable: true
[0.278319726s] [DEBUG] [crossfont] Loaded Face Face { ft_face: Font Face: Medium, load_flags: TARGET_LIGHT, render_mode: "Normal", lcd_filter: 1 }
[0.365647976s] [INFO ] [alacritty] Window scale factor: 1
[0.375554178s] [DEBUG] [alacritty] Loading "monospace" font
[0.377207949s] [DEBUG] [crossfont] Loaded Face Face { ft_face: Font Face: Book, load_flags: TARGET_LIGHT, render_mode: "Normal", lcd_filter: 1 }
[0.379486800s] [DEBUG] [crossfont] Loaded Face Face { ft_face: Font Face: Bold, load_flags: TARGET_LIGHT, render_mode: "Normal", lcd_filter: 1 }
[0.381681705s] [DEBUG] [crossfont] Loaded Face Face { ft_face: Font Face: Book, load_flags: NO_BITMAP | TARGET_LIGHT, render_mode: "Normal", lcd_filter: 1 }
[0.383901483s] [DEBUG] [crossfont] Loaded Face Face { ft_face: Font Face: Bold, load_flags: NO_BITMAP | TARGET_LIGHT, render_mode: "Normal", lcd_filter: 1 }
[0.440237603s] [INFO ] [alacritty] Running on AMD Radeon RX 560 Series (polaris11, LLVM 15.0.7, DRM 3.56, 6.5.0-18-generic)
[0.440283506s] [INFO ] [alacritty] OpenGL version 4.6 (Core Profile) Mesa 23.2.1-1ubuntu3.1~22.04.2, shader_version 4.60
[0.440298941s] [INFO ] [alacritty] Using OpenGL 3.3 renderer
[0.448080636s] [DEBUG] [alacritty] Enabled debug logging for OpenGL
[0.463776665s] [DEBUG] [alacritty] Filling glyph cache with common glyphs
[0.476854823s] [INFO ] [alacritty] Cell size: 9 x 18
[0.476904524s] [INFO ] [alacritty] Padding: 0 x 0
[0.476914908s] [INFO ] [alacritty] Width: 800, Height: 600
[0.476957635s] [INFO ] [alacritty] PTY dimensions: 33 x 88
[0.487868528s] [INFO ] [alacritty] Initialisation complete
[33.541744778s] [INFO ] [alacritty] Goodbye
Deleted log file at "/tmp/Alacritty-371654.log"

@jnsgruk
Copy link
Member

jnsgruk commented Feb 26, 2024

Indeed, I can't repro this issue at all using the latest revision. I just spent ~15mins or so launching as many different things as I could on a couple of different versions of Ubuntu. I'll close this for now, we can reopen if needed. Thanks for the prompt!

@jnsgruk jnsgruk closed this Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] `NCURSES6_TINFO_6.2.current' not found on Ubuntu Hirsute
9 participants