AppImageCrafters / AppRun

AppDir runtime components
MIT License
26 stars 10 forks source link

Support for hooking the statx syscall? #23

Open josh-richardson opened 3 years ago

josh-richardson commented 3 years ago

Hi,

I'm currently attempting to use appimagetool to package a binary which is using qt. Redirection is working fairly well, except for the fact the app in question (Albert) is using QFileInfo, which seems to use the statx syscall rather than the normal stat, which seems not to be hooked by this library.

I've got some past experience in userland function hooking, just wondering if this feature would be possible / beneficial before I run headlong into attempting to support it.

Thanks!

azubieta commented 3 years ago

Hi!

First, I have packed several Qt applications before and never had issues with this. Are you using appimagetool alone or appimage-builder? If you're using the first the you must make sure the .env file is properly generated.

About the statx support, I wasn't aware of it existence. I took inspiration from the https://github.com/project-portable/libunionpreload so most of the hooking code comes from there. If you want to make a PR we would have to make a check list in order to ensure that this doesn't affect existent apps or other technologies.

azubieta commented 3 years ago

According to the statx man page this is a Linux specific feature. I wonder if it's inclusion would affect the usage of the AppImage in other OS like FreeBSD.

There is work already on improving AppImages support on that OS. @probonopd you may have comments about this.

josh-richardson commented 3 years ago

Thanks for the speedy reply! I'm currently trying to package Albert as previous mentioned. Albert looks for plugins on startup (similar to gimp looking for required files), so I've set up a path redirection. I have reason to believe that this path direction works, looking in the extracted executable in the .env file as you mentioned, I find:

APPRUN_PATH_MAPPINGS=/usr/lib/x86_64-linux-gnu/albert/plugins:$APPDIR/usr/lib/x86_64-linux-gnu/albert/plugins;

Which is accurate as far as I can tell. I've also looked over the strace to make sure the hooking library is successfully loaded.

josh-richardson commented 3 years ago

I should mention - when I run Albert, everything is fine and syscalls are hooked, until we get to the following:

statx(AT_FDCWD, "/usr/lib/x86_64-linux-gnu/albert/plugins", AT_STATX_SYNC_AS_STAT, STATX_ALL, 0x7ffc260a8ec0) = -1 ENOENT (No such file or directory)
statx(AT_FDCWD, "/usr/lib/albert/plugins", AT_STATX_SYNC_AS_STAT, STATX_ALL, 0x7ffc260a8ec0) = -1 ENOENT (No such file or directory)
statx(AT_FDCWD, "/usr/lib64/albert/plugins", AT_STATX_SYNC_AS_STAT, STATX_ALL, 0x7ffc260a8ec0) = -1 ENOENT (No such file or directory)
statx(AT_FDCWD, "/usr/local/lib/albert/plugins", AT_STATX_SYNC_AS_STAT, STATX_ALL, 0x7ffc260a8ec0) = -1 ENOENT (No such file or directory)
statx(AT_FDCWD, "./albert/plugins", AT_STATX_SYNC_AS_STAT, STATX_ALL, 0x7ffc260a8ec0) = -1 ENOENT (No such file or directory)
statx(AT_FDCWD, "/home/joshua/.local/lib/albert/plugins", AT_STATX_SYNC_AS_STAT, STATX_ALL, 0x7ffc260a8ec0) = -1 ENOENT (No such file or directory)
statx(AT_FDCWD, "/home/joshua/.local/lib64/albert/plugins", AT_STATX_SYNC_AS_STAT, STATX_ALL, 0x7ffc260a8ec0) = -1 ENOENT (No such file or directory)

Where Albert is searching for plugins. As far as I can tell these syscalls roughly correspond to this source code where Albert is trying to enumerate plugins - but nothing is found as they're not looking within the $APPDIR path.

I'm using appimage-builder, but I've edited the generated yaml to work properly in a few places.

azubieta commented 3 years ago

It seems that I've been using Qt builds that doesn't use statx, that's why I haven't seen this issue. If you feel comfortable on implementing please make a PR and we could see if it has any side effects before merging it.

A simpler solution would be checking for the APPDIR environment variable from the Albert source code, but that would require write access to the project.

josh-richardson commented 3 years ago

A simpler solution would be checking for the APPDIR environment variable from the Albert source code, but that would require write access to the project.

Indeed yeah. I'll see if I can get any of the maintainers to help out, if so then I think all this won't be needed, however I'm not that hopeful that they'll want to change their logic just so that the app works with a specific build system. If I can't do this I'll work on a PR. Thanks for the guidance. Maybe I can also build Albert from source with statx disabled.