I got this code clip from APUE,
if (dup2(clfd, STDOUT_FILENO) != STDOUT_FILENO ||
dup2(clfd, STDERR_FILENO) != STDERR_FILENO) {
syslog(LOG_ERR, "ruptimed: unexpected error");
exit(1);
}
Which will redirect all output, stderr and stdout to remote socket, which is writable through clfd.
But how could that work ? You're redirecting two FDs to a single one.