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
This commit is contained in:
parent
b6450d866d
commit
14f0e4d0e2
22 changed files with 684 additions and 24 deletions
209
ports/zsh/Makefile
Normal file
209
ports/zsh/Makefile
Normal file
|
|
@ -0,0 +1,209 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
# zsh -- the Z shell, MIT-like: https://www.zsh.org/
|
||||
#
|
||||
# Installed as /bin/zsh, *beside* mksh, which keeps /bin/sh.
|
||||
#
|
||||
# That is deliberate and it is not about taste. schinit's no-jobs fallback
|
||||
# execs /bin/sh. If zsh were /bin/sh and zsh failed to start, the fallback
|
||||
# would be the same broken binary and the machine would have no shell at all.
|
||||
# Two different programs means the recovery path is a different program.
|
||||
# It is also what real systems do: a small POSIX /bin/sh for scripts, a large
|
||||
# interactive shell for people. docs/history/kernel.md section 2 says "exactly
|
||||
# one name per role" -- these are two roles.
|
||||
#
|
||||
# ---------------------------------------------------------------------------
|
||||
# Licensing
|
||||
#
|
||||
# zsh's LICENCE is MIT-like, with one condition that has to be honoured rather
|
||||
# than noted: a handful of shell functions are GPL, and the licence says so
|
||||
# explicitly, adding that "none of the core functions are affected by this, so
|
||||
# those files may simply be omitted."
|
||||
#
|
||||
# So they are omitted. GPL_FILES below is that list -- four files, deleted
|
||||
# after extraction and verified absent before install. Every one completes a
|
||||
# command SchOS does not have (darcs, qdbus, osc, zypper), which is why this
|
||||
# costs nothing at all.
|
||||
|
||||
include ../mk/port.mk
|
||||
|
||||
ZSH_VERSION := 5.9
|
||||
ZSH_URL := https://sourceforge.net/projects/zsh/files/zsh/$(ZSH_VERSION)/zsh-$(ZSH_VERSION).tar.xz/download
|
||||
ZSH_SHA256 := 9b8d1ecedd5b5e81fbf1918e876752a7dd948e05c1a0dba10ab863842d45acd5
|
||||
|
||||
TARBALL := $(DISTDIR)/zsh-$(ZSH_VERSION).tar.xz
|
||||
|
||||
# The GPL-licensed functions. Removed from the source tree, not merely skipped
|
||||
# at install: a file that is not there cannot be shipped by a later edit to
|
||||
# this Makefile.
|
||||
#
|
||||
# This list is four files, and it was audited rather than grepped. The obvious
|
||||
# search -- `grep -rl GPL` -- returns three more, and all three are wrong:
|
||||
#
|
||||
# _composer completes SPDX licence identifiers, so the word
|
||||
# "licence" is data, not a licence
|
||||
# _luarocks has '--license=... (e.g. "MIT/X11" or "GNU GPL
|
||||
# v3")' as a completion string, same thing
|
||||
# VCS_INFO_get_data_hg says "Distributed under the same BSD-ish license
|
||||
# as zsh itself" -- it matched on HGPLAIN, a
|
||||
# Mercurial environment variable with GPL in the
|
||||
# middle of it
|
||||
#
|
||||
# Deleting those three would cost nothing and would still be a false claim in
|
||||
# a licensing file, which is the kind of thing that is believed later.
|
||||
GPL_FILES := \
|
||||
Completion/Unix/Command/_darcs \
|
||||
Completion/Linux/Command/_qdbus \
|
||||
Completion/openSUSE/Command/_osc \
|
||||
Completion/openSUSE/Command/_zypper
|
||||
|
||||
# Completion sets for systems that are not this one. Dropping them is size,
|
||||
# not licensing -- together they are most of Completion/ and none of them can
|
||||
# ever match a command that exists here.
|
||||
FOREIGN_COMP := Completion/openSUSE Completion/Mandriva Completion/Redhat \
|
||||
Completion/Debian Completion/Solaris Completion/Cygwin \
|
||||
Completion/AIX Completion/BSD Completion/Darwin
|
||||
|
||||
HOSTCC_ZSH ?= gcc
|
||||
GCC_INC := $(shell $(HOSTCC_ZSH) -print-file-name=include)
|
||||
LIBGCC := $(shell $(HOSTCC_ZSH) -print-libgcc-file-name)
|
||||
|
||||
# Split the way autoconf consumes them -- see ports/ncurses/Makefile, which
|
||||
# had to learn the same lesson: crt objects ride in LDFLAGS (before the object
|
||||
# being linked), libraries in LIBS (after it).
|
||||
ZSH_CPPFLAGS := -nostdinc -isystem $(MUSL)/include -isystem $(GCC_INC) \
|
||||
-isystem $(NCURSES)/include -D__SCHOS__
|
||||
# zsh 5.9 is from 2022; GCC 14 and 15 promoted three long-standing warnings to
|
||||
# errors by default, and old autoconf projects fail their own feature probes on
|
||||
# them. The probe that matters here is
|
||||
#
|
||||
# char **test = boolcodes; puts(*test);
|
||||
#
|
||||
# which ncurses answers with `const char * const boolcodes[]`. GCC 15 rejects
|
||||
# the conversion outright, so the test "fails", HAVE_BOOLCODES goes undefined,
|
||||
# and zsh helpfully declares its own `static char *boolcodes[]` -- which then
|
||||
# collides with the declaration in term.h that was there the whole time. The
|
||||
# error surfaces in termcap.c, three steps from the cause.
|
||||
#
|
||||
# These restore the diagnostic level the code was written against. They are
|
||||
# scoped to this port and nothing else in the tree relaxes them.
|
||||
ZSH_COMPAT := -Wno-incompatible-pointer-types -Wno-implicit-function-declaration \
|
||||
-Wno-int-conversion
|
||||
|
||||
ZSH_CFLAGS := -O2 $(CFLAGS_BT) $(ZSH_COMPAT)
|
||||
ZSH_LDFLAGS := -static -nostdlib -L$(MUSL)/lib -L$(NCURSES)/lib \
|
||||
$(MUSL)/lib/crt1.o $(MUSL)/lib/crti.o
|
||||
ZSH_LIBS := -lncursesw $(MUSL)/lib/libc.a $(LIBGCC) $(MUSL)/lib/libc.a \
|
||||
$(MUSL)/lib/crtn.o
|
||||
|
||||
# Answers configure cannot work out without running a program on the target.
|
||||
# Each one is a fact about SchOS, so each one is written down here rather than
|
||||
# guessed by autoconf's cross-compilation defaults.
|
||||
ZSH_CACHE := \
|
||||
zsh_cv_shared_environ=yes \
|
||||
zsh_cv_shared_tgetent=no \
|
||||
zsh_cv_shared_tigetstr=no \
|
||||
zsh_cv_sys_nis=no \
|
||||
zsh_cv_sys_nss=no \
|
||||
zsh_cv_func_realpath_accepts_null=yes \
|
||||
zsh_cv_sys_path_dev_fd=/dev/fd \
|
||||
zsh_cv_sys_fifo=yes \
|
||||
zsh_cv_sys_killesrch=no \
|
||||
zsh_cv_sys_signal_handler=void \
|
||||
zsh_cv_prog_tcsetpgrp=yes \
|
||||
ac_cv_func_mmap_fixed_mapped=yes \
|
||||
ac_cv_func_setpgrp_void=yes
|
||||
|
||||
# --disable-dynamic: SchOS links everything static, and zsh's module system
|
||||
# would otherwise want dlopen. Every module is compiled in instead.
|
||||
# --with-term-lib: name it, so configure cannot quietly decide it needs none
|
||||
# and leave the line editor unable to move a cursor.
|
||||
# --enable-etcdir: where zsh looks for zshenv/zshrc. NOT --sysconfdir, which
|
||||
# autoconf accepts, zsh ignores, and configure reports no complaint about --
|
||||
# the shell simply starts with its default prompt and no completion, looking
|
||||
# like a broken config file rather than a config file that was never read.
|
||||
ZSH_CONFIGURE := \
|
||||
--host=x86_64-linux-musl \
|
||||
--build=x86_64-pc-linux-gnu \
|
||||
--prefix=/usr \
|
||||
--bindir=/bin \
|
||||
--enable-etcdir=/etc/zsh \
|
||||
--disable-dynamic \
|
||||
--enable-multibyte \
|
||||
--with-term-lib="ncursesw" \
|
||||
--disable-gdbm \
|
||||
--disable-pcre \
|
||||
--disable-cap \
|
||||
--disable-largefile \
|
||||
--enable-zsh-secure-free \
|
||||
--enable-fndir=/usr/share/zsh/$(ZSH_VERSION)/functions \
|
||||
--enable-scriptdir=/usr/share/zsh/$(ZSH_VERSION)/scripts
|
||||
|
||||
$(TARBALL): | $(DISTDIR)
|
||||
curl -fsSL -o $@ $(ZSH_URL)
|
||||
sh $(SHA256CHECK) "$(ZSH_SHA256)" "$@"
|
||||
|
||||
download: $(TARBALL)
|
||||
|
||||
# rm -rf before the move, and touch after it. Both matter:
|
||||
#
|
||||
# Without the rm, `mv zsh-5.9 src` when src already exists moves the tree
|
||||
# *inside* it, producing src/zsh-5.9 -- and zsh's configure globs */*/*.mdd,
|
||||
# so it finds the nested copy and writes modfile=zsh-5.9/Src/zsh.mdd into
|
||||
# config.modules. The build then fails a long way from the cause.
|
||||
#
|
||||
# Without the touch, this rule re-runs whenever the directory's mtime is
|
||||
# older than the tarball's, which is how src came to exist in the first
|
||||
# place. Editing files *inside* a directory does not update the directory.
|
||||
$(SRCDIR): $(TARBALL)
|
||||
mkdir -p $(PORTDIR)
|
||||
rm -rf $@ $(PORTDIR)/zsh-$(ZSH_VERSION)
|
||||
tar -xJf $< -C $(PORTDIR)
|
||||
mv $(PORTDIR)/zsh-$(ZSH_VERSION) $@
|
||||
@echo "zsh: removing GPL-licensed functions named by zsh's own LICENCE"
|
||||
@cd $@ && rm -f $(GPL_FILES)
|
||||
@cd $@ && rm -rf $(FOREIGN_COMP)
|
||||
touch $@
|
||||
|
||||
extract: $(SRCDIR)
|
||||
|
||||
$(BUILDDIR)/config.status: | $(SRCDIR)
|
||||
@test -f $(NCURSES)/lib/libncursesw.a || { \
|
||||
echo "zsh: build ports/ncurses first -- no libncursesw.a" >&2; exit 1; }
|
||||
mkdir -p $(BUILDDIR)
|
||||
cd $(BUILDDIR) && \
|
||||
CC="$(HOSTCC_ZSH)" \
|
||||
CPPFLAGS="$(ZSH_CPPFLAGS)" \
|
||||
CFLAGS="$(ZSH_CFLAGS)" \
|
||||
LDFLAGS="$(ZSH_LDFLAGS)" \
|
||||
LIBS="$(ZSH_LIBS)" \
|
||||
$(ZSH_CACHE) \
|
||||
$(SRCDIR)/configure $(ZSH_CONFIGURE)
|
||||
|
||||
$(BUILDDIR)/Src/zsh: $(BUILDDIR)/config.status
|
||||
$(MAKE) -C $(BUILDDIR)
|
||||
|
||||
build: $(BUILDDIR)/Src/zsh
|
||||
|
||||
# Refuse to install if a GPL file is somehow present. The rm above should have
|
||||
# made this impossible; the check is here because "should have" is not a
|
||||
# licence audit, and this runs before every image is built.
|
||||
.PHONY: licence-check
|
||||
licence-check: | $(SRCDIR)
|
||||
@bad=0; for f in $(GPL_FILES); do \
|
||||
if [ -e "$(SRCDIR)/$$f" ]; then echo "zsh: GPL file present: $$f" >&2; bad=1; fi; \
|
||||
done; \
|
||||
if [ $$bad -ne 0 ]; then echo "zsh: refusing to install" >&2; exit 1; fi; \
|
||||
echo "zsh: no GPL-licensed files in the tree"
|
||||
|
||||
$(SYSROOT)/bin/zsh: $(BUILDDIR)/Src/zsh licence-check | $(SYSROOT)/bin
|
||||
$(MAKE) -C $(BUILDDIR) install DESTDIR=$(SYSROOT)
|
||||
rm -rf $(SYSROOT)/usr/share/man $(SYSROOT)/usr/share/zsh/$(ZSH_VERSION)/help
|
||||
chmod 755 $@
|
||||
|
||||
install: $(SYSROOT)/bin/zsh
|
||||
|
||||
clean:
|
||||
rm -rf $(PORTDIR)
|
||||
|
||||
distclean: clean
|
||||
rm -f $(TARBALL)
|
||||
Loading…
Reference in a new issue