ocaml-multicore / eio

Effects-based direct-style IO for multicore OCaml
Other
550 stars 66 forks source link

support for creating ptys and a login_tty fork_action #531

Open avsm opened 1 year ago

avsm commented 1 year ago

Just a draft to figure out the right way to support spawning a shell with a pty:

/cc @RyanGibb

RyanGibb commented 1 year ago

This looks great! Using login_tty is much nicer than manually doing tty setup.

[ ] do the pty fds need to created as cloexec, and then inherited in a fork_action to the subshell? Right now they are not cloexec, but there is no close Fork_action and so there is too much open on the other side.

I saw that they're manually closed in https://github.com/avsm/melange/blob/e92240e6dc8a440cafa91488a1fc367e2ba57de1/lib/ounix/ounix.ml#L66. Perhaps they should similarly be closed in a Pty.close after the fork returns? I think setting cloexec would require manually creating a pty by opening /dev/ptmx (/dev/pty on bsd I think), and calling ioctl TIOCGPTPEER, etc, as openpty doesn't doesn't support it.