Files
termux-packages/packages/fish/do-not-import-posix-spawn.patch
termux-pacman-bot 0b6c9023ee fix(main/fish): do not patch rust-lang/libc cargo crate
- Fixes https://github.com/termux/termux-packages/issues/24741

- Cherry-pick bbf678e718 to replace `libc-src-unix-linux_like-android-mod.rs.diff` (since `libandroid-spawn` does not currently work with `fish`)

- `libc-src-unix-linux_like-android.diff` is **causing** https://github.com/termux/termux-packages/issues/24741 because of the problems explained by **maurer** in https://github.com/rust-lang/libc/pull/4216#discussion_r1902125367

- I have rewritten `libc-src-unix-linux_like-android.diff` in **my own alternative way of solving [the errors](https://github.com/termux/termux-packages/pull/22609#issuecomment-2557037664)**
  - My personal belief is that these errors should be solved by **patching `fish`**, _not_ by patching the **`libc` cargo crate**.
  - The reason I believe that is because **`fish` is using the type `libc::ino_t` to represent a value for storing the `d_ino` member of a `dirent` struct, which **cannot work on 32-bit Android** because 32-bit Android's `d_ino` is **not** an `ino_t`. [It is a `uint64_t`](https://cs.android.com/android/platform/superproject/main/+/main:bionic/libc/include/dirent.h;l=64?q=d_ino&ss=android%2Fplatform%2Fsuperproject%2Fmain:bionic%2Flibc%2Finclude%2F&start=1).
  - Therefore, the logical conclusion is that any successful port of `fish` to 32-bit Android **must explicitly store the value of a `dirent` `d_ino` as a `u64` anywhere it appears in Rust code.**
  - The same concept applies to `st_mode` - `st_mode` of `stat` on 32-bit Android is **not** a `mode_t`. [It is an `unsigned int`](https://cs.android.com/android/platform/superproject/main/+/main:bionic/libc/include/sys/stat.h;l=87), and [on Android, `unsigned int` is a 32-bit integer](https://cs.android.com/android/platform/superproject/main/+/main:bionic/libc/include/stdint.h;l=42;drc=61197364367c9e404c7da6900658f1b16c42d0da;bpv=0;bpt=1?q=stdint.h&ss=android%2Fplatform%2Fsuperproject%2Fmain). Therefore, any successful port of `fish` to 32-bit Android must explicitly store the value of a `stat` `st_mode` as `u32`.
  - In C, `S_IFMT` is a pure typeless literal preprocessor definition, which is [`00170000` in Android](https://cs.android.com/android/kernel/superproject/+/common-android-mainline:common/include/uapi/linux/stat.h;l=9?q=S_IFMT), preprocessor definitions do not really exist in Rust so there is unfortunately no correct alternative to a hardcoded integer literal for this on 32-bit Android

- I previously read https://github.com/rust-lang/libc/pull/4216 in January 2025, however, I unfortunately did not have the experience necessary at the time to fully understand how to solve this specific problem, so at the time, I did not change the version written by thunder-coding because I did not know how to make a better way to bypass the errors
  - However, in April 2025, I [ported Steel Bank Common Lisp to 64-bit Android-x86](b54fa7f61e/packages/sbcl/fix-stat-st_nlink-x86.patch). In the process of doing that, I became more experienced with Android's `stat.h` and `dirent.h` files, and I have been able to use that experience to successfully create what appears to be a correct solution to https://github.com/termux/termux-packages/issues/24741

The original errors, repeated here for convenint reference by others:

```
error[E0308]: mismatched types
   --> src/wutil/dir_iter.rs:114:50
    |
114 |             self.typ.set(stat_mode_to_entry_type(s.st_mode));
    |                          ----------------------- ^^^^^^^^^ expected `u16`, found `u32`
    |                          |
    |                          arguments to this function are incorrect
    |
note: function defined here
   --> src/wutil/dir_iter.rs:151:4
    |
151 | fn stat_mode_to_entry_type(m: libc::mode_t) -> Option<DirEntryType> {
    |    ^^^^^^^^^^^^^^^^^^^^^^^ ---------------
help: you can convert a `u32` to a `u16` and panic if the converted value doesn't fit
    |
114 |             self.typ.set(stat_mode_to_entry_type(s.st_mode.try_into().unwrap()));
    |                                                           ++++++++++++++++++++

error[E0308]: mismatched types
   --> src/wutil/dir_iter.rs:292:32
    |
292 |             self.entry.inode = dent.d_ino;
    |             ----------------   ^^^^^^^^^^ expected `u32`, found `u64`
    |             |
    |             expected due to the type of this binding
```
2025-05-20 19:06:35 +00:00

60 lines
2.4 KiB
Diff

Cherry-pick of https://github.com/fish-shell/fish-shell/commit/bbf678e7185fedce955587afbb23d83d37a87344
From bbf678e7185fedce955587afbb23d83d37a87344 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= <Strawberry_Str@hotmail.com>
Date: Sat, 8 Mar 2025 02:09:45 +0800
Subject: [PATCH] Reduce warnings when posix_spawn disabled.
---
src/exec.rs | 8 ++++++--
src/fork_exec/mod.rs | 1 +
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/exec.rs b/src/exec.rs
index 89b8b86f462b..ba961e456e5f 100644
--- a/src/exec.rs
+++ b/src/exec.rs
@@ -12,6 +12,7 @@ use crate::common::{
ScopeGuard,
};
use crate::env::{EnvMode, EnvStack, Environment, Statuses, READ_BYTE_LIMIT};
+#[cfg(FISH_USE_POSIX_SPAWN)]
use crate::env_dispatch::use_posix_spawn;
use crate::fds::make_fd_blocking;
use crate::fds::{make_autoclose_pipes, open_cloexec, PIPE_ERROR};
@@ -34,10 +35,12 @@ use crate::null_terminated_array::{
null_terminated_array_length, AsNullTerminatedArray, OwningNullTerminatedArray,
};
use crate::parser::{Block, BlockId, BlockType, EvalRes, Parser};
+#[cfg(FISH_USE_POSIX_SPAWN)]
+use crate::proc::Pid;
use crate::proc::{
hup_jobs, is_interactive_session, jobs_requiring_warning_on_exit, no_exec,
- print_exit_warning_for_jobs, InternalProc, Job, JobGroupRef, Pid, ProcStatus, Process,
- ProcessType, TtyTransfer,
+ print_exit_warning_for_jobs, InternalProc, Job, JobGroupRef, ProcStatus, Process, ProcessType,
+ TtyTransfer,
};
use crate::reader::{reader_run_count, restore_term_mode};
use crate::redirection::{dup2_list_resolve_chain, Dup2List};
@@ -447,6 +450,7 @@ fn launch_process_nofork(vars: &EnvStack, p: &Process) -> ! {
// To avoid the race between the caller calling tcsetpgrp() and the client checking the
// foreground process group, we don't use posix_spawn if we're going to foreground the process. (If
// we use fork(), we can call tcsetpgrp after the fork, before the exec, and avoid the race).
+#[cfg(FISH_USE_POSIX_SPAWN)]
fn can_use_posix_spawn_for_job(job: &Job, dup2s: &Dup2List) -> bool {
// Is it globally disabled?
if !use_posix_spawn() {
diff --git a/src/fork_exec/mod.rs b/src/fork_exec/mod.rs
index 2c10fccd5202..c0d0de46e2b9 100644
--- a/src/fork_exec/mod.rs
+++ b/src/fork_exec/mod.rs
@@ -4,6 +4,7 @@
pub mod flog_safe;
pub mod postfork;
+#[cfg(FISH_USE_POSIX_SPAWN)]
pub mod spawn;
use crate::proc::Job;
use libc::{SIGINT, SIGQUIT};