Self-calling executables
7 points by oliverpool
7 points by oliverpool
I recently was working on code to do this and man I miss fork().
Descendants must be able to connect back to the main process. In jjui, the main process listens on a Unix socket.
why not open an os.Pipe() pair for communication? Communicate on higher numbered file descriptors, which allow communication without naming a socket that others might use
The child isn’t started directly by jjui. Jjui calls jj, which starts an ssh connection, which starts the (grand) child jjui.
I don’t know how an os.Pipe could be passed through those hops (unlike env variables, which go through without issue).
The grandchild isn't even on the same system, necessarily? I assume that's why there is an ssh connection involved. Yeah, that's a good reason you can't pass in a socket pair over numbered sockets.
File descriptors are inherited by child processes and remain open across exec by default. It isn’t normal for programs to close file descriptor proactively so it’s reasonable to open a pipe or socketpair in a parent process and expect it to remain open in a grandchild process (tho it should probably use an environment variable to say which fd it is, not rely on conventional numbers).
The main situation where it’s necessary to close stray file descriptors is when a daemon is detaching itself from its environment, in particular it needs to close any stray terminal fds to make sure it is detached from any controlling terminal.
Normal unix commands should leave stray fds undisturbed, like environment variables. But if you want to be robust against abnormal programs then a named pipe is safer.