# /etc/brintos-rc — brintOS dev-machine-2 interactive shell rc (HWJS-C-1).
#
# busybox ash sources $ENV for EVERY interactive shell. pid 1 here is
# `/bin/sh -i` (init=/bin/sh, argv0="/bin/sh" -> NOT a login shell, so it reads
# no /etc/profile). We use $ENV=/etc/brintos-rc (set in LaunchMachine's
# initEnvp) to get a hook that runs once, in pid 1, WITHOUT touching pid 1's
# own pts/xterm stdio (A-2 stays byte-identical).
#
# It spawns an ADDITIONAL interactive shell on /dev/tty1 — the foreground
# virtual console that fbcon (CONFIG_FRAMEBUFFER_CONSOLE) renders onto the
# LaunchMachine <canvas>. Keystrokes reach it via canvas -> virtio-input ->
# VT keyboard -> tty1 (fg_console). setsid+cttyhack give it its own session
# with /dev/tty1 as the controlling terminal (job control, Ctrl-C). TERM=linux
# because tty1 is a real VT (the pts shell keeps TERM=dumb). The guard
# (BRINTOS_FBCON_STARTED + pid==1) makes this fire exactly once — the tty1
# shell itself re-sources this rc but is skipped.
#
# REQUIRES a machineSpec.cpu with pool headroom (dev-machine-2 uses cpu=6 ->
# 5 pool Workers): the default in-kernel blocking tty read PINS a pool
# Worker's JS thread while a shell idles at its prompt, so TWO interactive
# shells pin two Workers and every fork child needs a further un-pinned
# Worker to instantiate on. On a cpu=2 machine (1 pool Worker) the two
# readers starve each other — the HWJS-C-1 "crossed wires" wedge. Canonical
# copy: distros/linux+musl+busybox/tools/fbcon-rc (staged to /etc/brintos-rc;
# exercised by hardwarejs/test/dualcon-gate.test.ts).
if [ -z "${BRINTOS_FBCON_STARTED-}" ] && [ "$$" = 1 ] && [ -c /dev/tty1 ]; then
	export BRINTOS_FBCON_STARTED=1
	TERM=linux PS1='$ ' setsid cttyhack /bin/sh -i <>/dev/tty1 >&0 2>&0 &
fi
