Pseudo-terminals, and what tmux and htop needed around them

- /dev/ptmx and /dev/pts/N: Unix98 pairs with a full line discipline,
  window sizes, job control and hangup (kernel/dev/pty.c).
- The console speaks scroll regions, insert/delete line, SU/SD, RI/IND/NEL,
  DECSC/DECRC; swallows charset designations and private CSI sequences;
  and LF only returns the carriage under ONLCR.
- setsid() drops the controlling terminal, so a pane's pty becomes its ctty.
- pipe2() honours O_NONBLOCK and O_CLOEXEC (libevent's signal pipe).
- File modes are stored and enforced: chmod, fchmod(at), umask, creation
  modes; /tmp is 1777.
- /proc/stat has real user/system/idle; /proc/<pid>/task; kthread flag.
- SO_PEERCRED, IOV_MAX 1024.
- /proc/strace: name a program and its syscalls go to the kernel log.
- World gains htop, btop, tmux, mc, ncdu, fastfetch, games, X toys, NetSurf.

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-25 02:11:10 +01:00
commit fd9d392416
28 changed files with 1577 additions and 47 deletions

View file

@ -7,6 +7,7 @@
#include "fs/file.h"
#include "arch/x86.h"
#include "uapi/errno.h"
#include "dev/pty.h"
extern int consoleread(struct inode*, uint64, char*, int);
extern int consolewrite(struct inode*, uint64, char*, int);
@ -216,4 +217,10 @@ struct devsw devsw[] = {
// The close hook plays out what is still queued: a program that writes a
// sound and exits expects to hear the end of it.
[12] = { dspread, dspwrite, 0, dspclose },
// Pseudo-terminals, kernel/dev/pty.c. /dev/ptmx (13) is never read or
// written: open() swaps it for a new master (14) before it gets the chance.
// The slaves (15) are /dev/pts/N.
[PTMX_MAJOR] = { 0, 0 },
[PTM_MAJOR] = { ptm_read, ptm_write, ptm_ready, ptm_close, ptm_open },
[PTS_MAJOR] = { pts_read, pts_write, pts_ready, pts_close, pts_open },
};