SchOS/ports/fastfetch/Makefile
Nexoniarz 14f0e4d0e2 kernel: processes have an environment now, and zsh is the shell
Porting zsh found four defects in the kernel and one in the filesystem. None
of them were about zsh; all of them had been there the whole time.

**exec threw the environment away.** kernel/fs/exec.c wrote a single zero for
envp with the comment "(no environment)" -- not yet, but ever, for every
process. musl has been passing a perfectly good envp to execve (Linux 59, which
SchOS answers) and it was never read. So $TERM was unset, $PATH was whatever
each program invented, and a variable exported in a shell did not survive the
exec meant to carry it. exec() takes an envp, sys_exec reads argument three,
and schinit manifests grew an Environment key. The userland two-argument
exec(path, argv) stays as a wrapper that passes null explicitly -- the raw stub
is execve now, so a short caller cannot leave %rdx holding a stray pointer.

**Which overflowed the kernel stack.** Three pointer arrays, ~1.8 KB, on a
4096-byte stack, under exec -> loaduvm -> readi -> SchFS -> btree. Pid 1 went
down on the first exec. The canary caught it and named the process, which is
what it is for. They live in one kalloc'd page now.

**waitpid returned a bare -1** for both "no children" and "interrupted". musl
reads [-4095,-1] as -errno, so userspace saw EPERM; zsh printed "wait failed:
operation not permitted" and abandoned the rest of /etc/zsh/zshrc. -ECHILD and
-EINTR now. Third time a bare -1 has cost real time -- on a system with no
permission model, EPERM should be read as "a syscall returned -1".

**NVMA was 64.** musl's allocator takes a mapping per size class and does not
release them eagerly, so compinit ran out of slots and got -1, which is EPERM,
which malloc turns into NULL, which zsh reports as "fatal error: out of memory"
-- on a machine with 1000 MB free. 256 slots, and -ENOMEM.

**And a small write to SchFS costs 58 ms.** 200 writes to one open file take
11.75 s; the same to /dev/null take 0.14 s. That is the design stated at the
top of kmount.c -- one transaction group per operation, and a commit is two
flushes and an uberblock -- not a bug. But compdump writes its digest with
thousands of separate prints, so it takes minutes and looks like a hang.
compinit -D, which skips the dump, finishes in 3.6 s. This one is a decision
rather than a fix, so it is written up and left: /etc/zsh/zshrc keeps compinit
switched off and explains exactly why, with the measurements.

zsh runs as /bin/zsh and is the console shell. ZLE works -- arrow keys recall
history through terminfo, $COLUMNS reads the real 160 because TIOCGWINSZ was
fixed, colour and prompt expansion work, startup is 0.14 s. mksh keeps /bin/sh,
so schinit's no-jobs fallback is a different program from the one that could
have failed.

Also fixed while here: AT_CLKTCK was the literal 100 and is USER_HZ; the
extract rule in four ports could move a source tree inside itself when make
re-ran it, which is how zsh's configure came to write modfile=zsh-5.9/... into
config.modules and fail three steps later.

schfs-check passes. Full writeup in docs/history/kernel.md section 14.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VQ7Qx8E1q1M1bbCq8QLHS2
2026-09-12 23:26:50 +02:00

100 lines
4.4 KiB
Makefile

# SPDX-License-Identifier: Apache-2.0
# fastfetch -- system information, MIT: https://github.com/fastfetch-cli/fastfetch
#
# Here because it is a good acceptance test, not because SchOS needs a fetch
# tool. It is ~410 C files somebody else wrote, against Linux rather than
# against our bugs, and running it exercises procfs, per-process directories,
# uname, statfs, getpwuid, terminal detection by walking ppid, and an ANSI
# renderer -- all at once, and it notices when any of them lies.
#
# **It is built unpatched.** patches/ is empty and should stay that way: when
# fastfetch cannot detect something the right answer is to give the system the
# thing it is looking for, because every other program looks for the same
# things. What it could not find on the first run became work in the kernel and
# in sysroot/etc, not sed lines here.
include ../mk/port.mk
FF_VERSION := 2.30.0
FF_URL := https://github.com/fastfetch-cli/fastfetch/archive/refs/tags/$(FF_VERSION).tar.gz
FF_SHA256 := 5047f925e480e065e8b28da1e6cc5b31ffdc1ad205ec74a9ea709fb5bcaacd8a
TARBALL := $(DISTDIR)/fastfetch-$(FF_VERSION).tar.gz
# Linux UAPI headers. musl deliberately ships none -- a musl toolchain is
# normally paired with a separate linux-headers install -- and fastfetch's
# Linux detection includes linux/ethtool.h and friends directly. Overridable
# because the path is a property of the build host, not of this port.
LINUX_HEADERS ?= $(shell for d in /usr/include /nix/store/*-linux-headers-*/include; do \
test -f "$$d/linux/ethtool.h" && { echo "$$d"; break; }; done)
# gcc rather than port.mk's clang: this is the one port whose upstream expects
# a GNU-ish driver, and the two disagree about -print-libgcc-file-name.
HOSTCC_FF ?= gcc
# The compiler's own headers, which -nostdinc also removes. cpuid.h lives here,
# not in libc: it is emitted by the compiler and has no musl equivalent.
GCC_INC := $(shell $(HOSTCC_FF) -print-file-name=include)
LIBGCC := $(shell $(HOSTCC_FF) -print-libgcc-file-name)
# Every optional feature off. All 29 files that call dlopen are in optional
# detection modules, and ENABLE_THREADS=OFF removes the single pthread_create --
# which matters because SchOS's clone() does not share an address space.
FF_OFF := VULKAN WAYLAND XCB_RANDR XCB XRANDR X11 DRM DRM_AMDGPU GIO DCONF \
DBUS XFCONF SQLITE3 RPM IMAGEMAGICK7 IMAGEMAGICK6 CHAFA ZLIB EGL \
GLX OSMESA OPENCL FREETYPE PULSE DDCUTIL DIRECTX_HEADERS ELF \
THREADS LIBZFS PCIACCESS SYSTEM_YYJSON LTO
$(TARBALL): | $(DISTDIR)
curl -fsSL -o $@ $(FF_URL)
sh $(SHA256CHECK) "$(FF_SHA256)" "$@"
download: $(TARBALL)
$(SRCDIR): $(TARBALL)
mkdir -p $(PORTDIR)
rm -rf $@ $(PORTDIR)/fastfetch-$(FF_VERSION)
tar -xzf $< -C $(PORTDIR)
mv $(PORTDIR)/fastfetch-$(FF_VERSION) $@
touch $@
extract: $(SRCDIR)
# A toolchain file rather than a pile of -D flags on the command line: CMake
# only honours CMAKE_*_INIT variables when it creates the cache, so they have to
# be in place before the first configure. Reconfiguring an existing build
# directory silently ignores them, which costs an afternoon to notice.
$(BUILDDIR)/toolchain.cmake: | $(SRCDIR)
@mkdir -p $(BUILDDIR)
@test -n "$(LINUX_HEADERS)" || { \
echo "fastfetch: no linux/ethtool.h found -- set LINUX_HEADERS=" >&2; exit 1; }
@printf '%s\n' \
'set(CMAKE_SYSTEM_NAME Linux)' \
'set(CMAKE_SYSTEM_PROCESSOR x86_64)' \
'set(CMAKE_C_COMPILER $(HOSTCC_FF))' \
'set(CMAKE_C_FLAGS_INIT "-nostdinc -isystem $(LINUX_HEADERS) -isystem $(GCC_INC) -isystem $(MUSL)/include -D__SCHOS__ $(CFLAGS_BT)")' \
'set(CMAKE_EXE_LINKER_FLAGS_INIT "-static -nostdlib -L$(MUSL)/lib $(MUSL)/lib/crt1.o $(MUSL)/lib/crti.o")' \
'set(CMAKE_C_STANDARD_LIBRARIES "$(MUSL)/lib/libc.a $(LIBGCC) $(MUSL)/lib/libc.a $(MUSL)/lib/crtn.o")' \
'set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)' \
> $@
# libc appears twice on the link line on purpose: libgcc pulls symbols back out
# of it (__popcountdi2 is the one that shows up), and a static link resolves
# left to right.
$(BUILDDIR)/fastfetch: $(BUILDDIR)/toolchain.cmake
cd $(BUILDDIR) && cmake $(SRCDIR) \
-DCMAKE_TOOLCHAIN_FILE=$(BUILDDIR)/toolchain.cmake \
-DCMAKE_BUILD_TYPE=Release \
$(foreach o,$(FF_OFF),-DENABLE_$(o)=OFF)
$(MAKE) -C $(BUILDDIR) fastfetch
build: $(BUILDDIR)/fastfetch
install: $(BUILDDIR)/fastfetch | $(SYSROOT)/bin
install -m 0755 $(BUILDDIR)/fastfetch $(SYSROOT)/bin/fastfetch
clean:
rm -rf $(PORTDIR)
distclean: clean
rm -f $(TARBALL)