termux / termux-packages

A package build system for Termux.
https://termux.dev
Other
13.33k stars 3.06k forks source link

[Bug]: `just` uses an incorrect runtime directory causing recipes to fail. #22291

Open TomJo2000 opened 3 hours ago

TomJo2000 commented 3 hours ago

Problem description

Upon running any recipe defined in a justfile which runs any sort of command external to just, the recipe will fail with Read-only file system (os error 30).

What steps will reproduce the bug?

Minimal example:

bug:
    #!/usr/bin/env sh
    echo "hello world"

Output:

just bug
// error: I/O error in runtime dir `/run/user/10215/just`: Read-only file system (os error 30)

What is the expected behavior?

just bug
// hello world

System information

Termux Variables:
TERMUX_API_VERSION=0.50.1+4159c62
TERMUX_APK_RELEASE=GITHUB
TERMUX_APP_PACKAGE_MANAGER=apt
TERMUX_APP_PID=23767
TERMUX_IS_DEBUGGABLE_BUILD=1
TERMUX_MAIN_PACKAGE_FORMAT=debian
TERMUX_VERSION=0.118.1
TERMUX__USER_ID=0
Packages CPU architecture:
aarch64
Subscribed repositories:
# sources.list
deb https://packages.termux.dev/apt/termux-main stable main
# root-repo (sources.list.d/root.list)
deb https://packages.termux.dev/apt/termux-root root stable
# tur-repo (sources.list.d/tur.list)
deb https://tur.kcubeterm.com tur-packages tur tur-on-device tur-continuous
# x11-repo (sources.list.d/x11.list)
deb https://packages.termux.dev/apt/termux-x11 x11 main
Updatable packages:
All packages up to date
termux-tools version:
1.44.3
Android version:
14
Kernel build information:
Linux localhost 5.4.242-qgki-g07bc4ccc612b #1 SMP PREEMPT Fri Sep 20 17:45:34 CST 2024 aarch64 Android
Device manufacturer:
Fairphone
Device model:
FP5
LD Variables:
LD_LIBRARY_PATH=
LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so
Installed termux plugins:
com.termux.api versionCode:51
com.termux.x11 versionCode:14
TomJo2000 commented 2 hours ago

Turns out this is probably something we should patch in the rust package itself. just gets the value of the runtime_dir from dirs::runtime_dir() https://github.com/casey/just/blob/5db910f400b13daa87b5c37dc62fb1da1ff6533d/src/recipe.rs#L371

Which is part of the Rust standard library. https://docs.rs/dirs/latest/dirs/fn.runtime_dir.html

So any Rust program using this function would be affected.

TomJo2000 commented 2 hours ago

Okay, it looks like it uses the value of $XDG_RUNTIME_DIR, which makes sense. https://docs.rs/dirs/latest/src/dirs/lib.rs.html#173-175 https://docs.rs/dirs/latest/src/dirs/lin.rs.html#14

But I do not see where or how it is getting its fallback value if that environment variable is unset. We do not currently set it by default, though setting the XDG basedir variables to sane defaults as part of the profile.d/ scripts would be something we may want to consider

TomJo2000 commented 2 hours ago

On a related note. It looks like we will need to fix any shebangs in justfiles on the fly.

Otherwise the example given above fails with:

error: Recipe `bug` with shebang `#!/usr/bin/env sh` execution error: No such file or directory (os error 2)

I set $XDG_RUNTIME_DIR to /data/data/com.termux/files/usr/var/run/user for this example.

Edit: I think I found the place where we'd need to patch this. https://github.com/casey/just/blob/5db910f400b13daa87b5c37dc62fb1da1ff6533d/src/shebang.rs#L28 However, it took me 30 minutes to find this. And my very limited grasp of rust is at its end. So I'll leave figuring out a viable way to patch the shebangs as an exercise to the reader.