dev: read /dev/zero and /dev/urandom from them, not from the keyboard

consoleinit() put consoleread/consolewrite in devsw[1], over memread and
memwrite. Major 1 holds the whole mem major (null, zero, full, random,
urandom) and memread already sends the console's minors to the console,
so the override only broke the others: a read of /dev/zero waited for a
typed line. dd and head on either device hung, and `head -c 10 /dev/zero`
only finished because it swallowed the next command.

The console now installs just its open and close hooks. /dev/keyboard
writes are discarded, as consolewrite used to do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S1giNvrHTrPMPw7V6x1kQ4
This commit is contained in:
Nexoniarz 2026-10-23 09:33:08 +02:00
commit d90a72e6d3
3 changed files with 15 additions and 2 deletions

View file

@ -820,8 +820,12 @@ consoleinit(void)
initlock(&cons.lock, "console");
initlock(&input_lock, "input");
devsw[CONSOLE].write = consolewrite;
devsw[CONSOLE].read = consoleread;
// Not read and write. Major 1 is the whole mem major -- null, zero, full,
// random, urandom as well as the console and the ttys -- and devsw[1] is
// memread/memwrite, which send the console's minors here and the rest
// where they belong. Installing consoleread over it made /dev/zero and
// /dev/urandom wait for a line from the keyboard, which is why neither
// had ever seemed to work.
devsw[CONSOLE].open = consoleopen;
devsw[CONSOLE].close = consoleclose;
cons.locking = 1;