v0.19: port the remaining modules of std/os #1485
No reviewers
Labels
No labels
UX
active development
backlog
blocker
bootstrap
bounty
bug
dependencies
discussion
documentation
duplicate
enhancement
flaky test
help wanted
invalid
javascript
question
release
tendentious
wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
mighty-gerbils/gerbil!1485
Loading…
Reference in a new issue
No description provided.
Delete branch "v0.19-std-os"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
ports std/os modules flock, pipe and inotify.
done with sol with assistance from gerbilosaurus rex.
While it LGTM, GPT 5.6 High had this to say:
Blocker:
O_TRUNChappens before the lock is acquired. The newopen-file-writer/lockdefaults toO_CREAT|O_TRUNC, then eventually reachesopen/lock, which first callsopen(... flags ...)and only afterwards callsflock-fd/block.O_TRUNCtruncates an existing writable regular file as part ofopen()itself. Thus, suppose A holds the exclusive flock while preserving some valuable contents. B callsopen-file-writer/lockand waits for the lock—or even times out without ever obtaining it. B has already truncated the file underneath A. This rather defeats the point of the locked writer. The current timeout test only contends usingopen-file-reader/lock, so it cannot catch this. I would put the review comment on the__opencall insrc/std/os/flock.ss:131. I think the right fix is foropen/lockto stripO_TRUNC, acquire the lock, thenftruncate(fd, 0)if truncation was requested; fixing it at that level also handles callers ofopen-file/lockthat explicitly passO_TRUNC. A regression test should put contents in a file, hold an exclusive lock, try a default locked writer with a short timeout, then verify that the original contents survived.Blocker-ish:
flockcan operate on a stale, reused FD after itsOSDeviceis closed.flockandflock/blockimmediately extractdev.fdwithout doing the usualdo-check-device-open. Butdevice-closemarksdev.dirclosed and closes the raw port without changingdev.fd; the rest of the device API has explicit closed-device checks. Therefore(flock closed-dev ...)doesn't reliably mean EBADF: if that descriptor number has since been reused, it can lock an entirely unrelated file. More seriously,flock/blockfreezes the integer FD and then repeatedly sleeps and retries. During one of those cooperative sleeps another green thread can close the device and open something else that receives the same FD number; the next retry can then lock the wrong object. This does not require SMP. I would comment aroundsrc/std/os/flock.ss:50-59.flockshould checkdo-check-device-open;flock/blockneeds the check on each polling iteration, not merely once before entering it. The fd-only helper is still useful foropen/lock, since there the descriptor hasn't yet escaped.SMP/fork-exec:
pipehas the classicFD_CLOEXECrace. It doespipe()first and then two separateF_SETFD FD_CLOEXECoperations. ([cons.io git][5]) If another OS thread executesfork()+exec()in between, a pipe FD leaks into the child. This is exactly the race creation-time CLOEXEC flags are intended to prevent; the Linux documentation explicitly warns that post-creationF_SETFDis insufficient in multithreaded programs. On Linux,pipe2(..., O_CLOEXEC)sets it atomically on both ends. Given the SMP work, I'd mention this now. I wouldn't necessarily hold up this PR over portable handling: usepipe2(O_CLOEXEC)on Linux and retain thepipe()+fcntlfallback elsewhere, or leave a conspicuous TODO tied to fork/SMP semantics. I would put this comment on__pipe-syscallaroundsrc/std/os/pipe.ss:51.I'm impressed by the attention to detail and knowledge of the Unix API of GPT.
Asking for lock-on-open, GPT tells me it exists on FreeBSD and Darwin, with
O_EXLOCK/O_SHLOCK, but not on Linux or other BSDs.review issue addressed, please rereview.
4fc7cfb8cbto16452acdc3Followup: Leave a TODO for O_{EX|SH}LOCK on FreeBSD/Darwin ? Have a clanker do it?