In the file /usr/src/lib/libc/gen/daemon.c
if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
(void)dup2(fd, STDIN_FILENO);
(void)dup2(fd, STDOUT_FILENO);
(void)dup2(fd, STDERR_FILENO);
if (fd > 2)
(void)close (fd);
}
is same as:
if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
(void)dup2(fd, 0);
(void)dup2(fd, 1);
(void)dup2(fd, 2);
if (fd > 2)
(void)close (fd);
}
right? What is this last check (fd > 2) needed for? Isn't fd always > 2,
because the first 3 are already taken by the STDxxx streams at the
program start?
Thanks
Alex