From 3a74493e399d3c3bf5999d2f98ec31ebd7668950 Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Sun, 11 Oct 2026 09:35:43 +0000 Subject: [PATCH] The report, for review: Sys for rlX11 and rat (2026-10.4) Sys gains connect, for a Unix socket such as the X server's; readyOf, waiting on several files at once; openPty and setTermSize, for a pseudo-terminal; spawn, wait and kill, for the programs that run on it. PLAN.md: stage 7, the steps that make them, not started. --- diff --git a/PLAN.md b/PLAN.md index 3ab11b7..59ee5ed 100644 --- a/PLAN.md +++ b/PLAN.md @@ -460,3 +460,29 @@ `make bench` at 400,000 lines a second. Then the editors, rmacs and ravite, move their pin to this raz, in their own repositories, with their sources moved to the new operators. + +Stage 7: Sys for rlX11 and rat, report 2026-10.4 + +rlX11, an X11 client library written in raz, and rat, a terminal +emulator over it, are to need no C: they talk to the X server over a +socket, and rat runs its programs on a pseudo-terminal. Sys gains what +that takes. Not started: each step waits for the owner's word. + +- [x] 48. The report, version 2026-10.4: `connect`, `readyOf`, + `openPty`, `setTermSize`, `spawn`, `wait`, `kill` (section 11), + for review before any code. +- [ ] 49. On Linux by system calls: `socket` and `connect` for a Unix + socket; `poll` over several fds; `/dev/ptmx` with `TIOCSPTLCK` + and `TIOCGPTN` for the pseudo-terminal, `TIOCSWINSZ` for its + size; `fork`, then in the child `setsid`, the terminal opened as + its controlling one with `TIOCSCTTY`, `dup2` to 0, 1 and 2, + `close_range` for the rest, and `execve` with the environment + made from this one's; `wait4`, `kill`. Over C by POSIX's names + (`socket`, `poll`, `posix_openpt`, `grantpt`, `unlockpt`, + `ptsname`, `fork`, `execve`, `waitpid`, `kill`), what is glibc's + named in the file, as before. Both files' tests: a program + spawned on a pseudo-terminal that prints its size and its + arguments and ends with a status read back by `wait`; a program + stopped by `kill`; `readyOf` on two pipes; `connect` refused on + a path with nothing at it, and taken by a listener the test + makes with Python, in `test/libc` and beside the library's own. diff --git a/doc/raz.md b/doc/raz.md index 719153e..b3f8123 100644 --- a/doc/raz.md +++ b/doc/raz.md @@ -960,6 +960,15 @@ proc env*(name: []U8): []U8; (* the environment variable's value; "" if unset *) proc workDir*(var buf: [4096]U8): I64; (* the working directory into buf: its length *) + +proc connect*(path: []U8): I64; (* a stream socket, connected to the Unix socket at path: its fd *) +proc readyOf*(fds: []I64; ms: I64): I64; (* the first of fds with something to read within ms, or -1 *) + +proc openPty*: I64; (* a pseudo-terminal: the fd of its controlling side *) +proc setTermSize*(fd, cols, rows: I64): I64; (* the size its programs are told of *) +proc spawn*(path: []U8; args, env: [][]U8; tty: I64): I64; (* a program started: its process id *) +proc wait*(pid: I64; block: BOOL): (I64, I64); (* its status, and 1 if it has ended, 0 if not *) +proc kill*(pid, signal: I64): I64; ``` `nextEntry` gives every name in the directory except `.` and `..`, in @@ -969,6 +978,25 @@ CR to NL; and with output, NL to CR NL. A program that turns it on restores it before it ends: `Rt.atExit` is the place. +`connect` is for talking to a server on the same machine, an X server +at `/tmp/.X11-unix/X0` say; what is sent and received goes by `read` +and `write`, and `close` ends it. `readyOf` waits on several file +descriptors at once, as a program does that listens to a server and a +terminal both. + +`openPty` makes a pseudo-terminal, a terminal that a program, a +terminal emulator, plays the screen and the keyboard of: what it +writes to the fd is typed, and what the programs on the terminal +write it reads. `spawn` starts the program at `path`, with `args` as +its arguments, the first being its name, and the environment of this +one with each `NAME=value` of `env` added or put in place of the old +value. If `tty` is a pseudo-terminal's fd, the program runs on that +terminal: it is its controlling terminal, and the program's standard +input, output and error. The program gets no other open file. `wait` +says whether the program has ended, waiting for it if `block`, and how: +its exit status, or 128 and the number of the signal that stopped it. +`kill` sends it a signal, 15 to end it. + **Out and C's stdio.** `Out` keeps a buffer of 4 KB. It writes it out when it is full, at each line feed when standard output is a terminal, at `Out.flush`, and when the program ends by `Rt.exit`. C's `stdio` @@ -1014,3 +1042,6 @@ (section 6.5). A generic module's instance is made where it is first used, so its arguments may name types declared after the imports (section 3). +- **2026-10.4.** `Sys` gains a connection to a Unix socket, waiting on + several files at once, pseudo-terminals, and starting, waiting for + and stopping programs (section 11).