I wrote a TCP daemon, that accepts clients connections on given port and after that it executes a command using execv(3). In every tutorial on writting daemons it is mentioned to close stdin, stdout, stderr to sucessfully daemonize the process.
However I found out that accept(2) reuses file descriptor numbers of already closed stdout/stderr so after calling fork(2) and execv(3), child process writes output to socket simply because stdout/stderr maps to file descriptor now associated with client socket.
Any ideas how can I avoid this without resorting to shell output redirection?