I'm struggling to understand if I'm able to do something.
In my very odd use case we are writing a websever that handles connections via a forked process.
I have a listener process that listens for TCP connections.
So each net.Conn that comes in we pull off its file descriptor:
fd, err := conn.(*net.TCPConn).File()
duplicate that file descriptor and then fork off a process passing in that file descriptor.
In my forked handler I'll reconstruct the HTTP connection and "do stuff".
The concern I'm having is that it appears when I fork a process I inherit all of the parent file descriptors so if I have say 5 incoming connections and then I fork my child process technically could write to a different connection.
I've played around with the various options:
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: false,}
and using cmd.ExtraFiles
No matter what I do I seem unable to limit the sub process to ONLY using the specific File Descriptor I want it to have access to.
I believe this is doable in C - but I'm not sure if I can do this in GoLang as-is without mods .
Thanks!!!