SchOS/cmd
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Nexoniarz 3f13989883 unix: a bound socket is a file
Gate 1, item 3, and the last of foundations.md.

bind() creates a T_SOCK node at the path; connect() resolves the path and looks
for the socket bound to **that inode**. Matching on the inode rather than on
the path *string* is the part that matters: the name used to live only in the
socket table, so two spellings of one path missed each other, a relative path
never matched an absolute one, and there was nothing to stat() or unlink().
An inode is the thing a path resolves *to*, so connect() can walk the path
however it likes and arrive at the same socket.

    # ls -l /tmp
    srwxr-xr-x 1 root root 0 2026-09-22 08:04 socktest

The node is a marker, not the binding. It holds no data and the live
association stays in the socket table, so a socket file left by a crash is
what Linux leaves behind -- a dead file that connect() refuses until something
binds again -- and unlink()ing a live socket's path does not disturb anyone
already connected.

EADDRINUSE comes from the *directory* rather than from a scan of the table,
deliberately: a stale socket file has to refuse a rebind for the same reason a
running server's does, or two servers both believe they own it. The creation
lives in sys_bind() and not in unix.c, because that is the layer with both --
kernel/net/unix.c knows about sockets and has no business calling create().

T_SOCK is a compat addition to SchFS by the rule in schfs.h: a driver that does
not know SCHFS_T_SOCK maps it to a zero-length regular file, so nothing goes
stale and nothing becomes unreadable.

cmd/socktest section 15 asserts the plan's own wording -- bind, stat, see an
`s`, unlink -- plus the two a name table could never fail: a second bind to a
live path is refused, and connecting to a path that is a *regular file* is
refused rather than matched by name.

**And the semantics being real broke socktest on its second run**, correctly:
the socket files persisted and every bind() hit EADDRINUSE. Every real server
unlinks before binding; socktest now does too, which is the change the new
behaviour demands rather than a workaround for it.

Chasing that turned up something worse. `socktest` reported rc=1 with every
check passing, and so did every other first-party program:

  - **lib/start.S called main and threw %eax away.** sys_exit() reads the
    status from %rdi and nothing put it there, so every program exited with
    whatever that register happened to hold. Every test suite ends in
    `return failures ? 1 : 0` and none of it reached the shell.
  - **exit(void) passed no status either**, for the same reason: the
    declaration takes no argument, so %rdi was the caller's litter.

`if socktest; then` works now, and a failing command reports 1 -- checked both
ways, because a fix that makes everything return 0 would look identical from
the success side.

Also factored: unlink_path() out of sys_unlink, so a failed bind can take its
own node back out without going through the syscall entry, and create_sock()
as a named door rather than exporting create() with an arbitrary type.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-22 10:06:10 +02:00
..
chvt tty: AltGr+F1..F6 by default, and AltGr+-/+ to step 2026-09-13 13:22:01 +02:00
fbinfo hybrid: /dev/pci -- a driver can live outside the kernel now 2026-09-13 15:34:28 +02:00
httpd userland: 268 applets, an editor, names that resolve, and a web server 2026-09-14 19:24:55 +02:00
inputtest Initial commit: Schunix as it stands before the SchOS rename 2026-08-09 13:47:01 +02:00
ldlsd ldls: a second driver, and everything it found 2026-09-14 15:20:07 +02:00
loadkeys kbd: three layouts, and the arrow keys were sitting on top of UTF-8 2026-09-20 01:09:32 +02:00
memfdtest memfd: a shared memory object you reach by descriptor 2026-09-22 09:47:31 +02:00
netecho ldls: L4 was free after all, and the plan closes 2026-09-14 13:37:04 +02:00
nettest net: recvfrom says who sent it, and a datagram is delivered whole 2026-08-15 16:23:06 +02:00
pcitest hybrid: the driver is killed, and the driver comes back 2026-09-14 00:05:43 +02:00
ping net: the socket layer stops saying yes to things it did not do, and ping works 2026-09-12 17:14:35 +02:00
reflink schfs: the commit barrier, reflink, and attributes with an index over them 2026-08-15 16:02:02 +02:00
resolvconf font: the console draws outlines now, and a byte could not have held Ą 2026-09-20 00:35:34 +02:00
schattr schfs: the commit barrier, reflink, and attributes with an index over them 2026-08-15 16:02:02 +02:00
schdbg debugger: D5, the network transport -- and the plan closes 2026-09-14 15:33:53 +02:00
schdbgd debugger: D5, the network transport -- and the plan closes 2026-09-14 15:33:53 +02:00
schinit boot: one line when it works, all of it when it does not 2026-09-14 21:19:50 +02:00
schinitd tty: arrow keys, backspace, and four terminals nobody was home on 2026-09-14 22:43:54 +02:00
schmode hybrid: a modeset, from a process 2026-09-14 01:36:05 +02:00
shmtest Rename Schunix to SchOS; the kernel becomes SchIFT 2026-08-09 14:09:59 +02:00
sigtest signal: the return trampoline was Linux-only, and a test that proves the rest 2026-09-21 23:56:34 +02:00
socktest unix: a bound socket is a file 2026-09-22 10:06:10 +02:00
vgpud dma: the 4 MB cap was the refusal, not the arena 2026-09-14 22:52:20 +02:00