GPSDproxy: send GPS data from gpsd to a remote server

Timo Juhani Lindfors timo.lindfors at iki.fi
Thu Jan 15 12:15:49 CET 2009


Jean-Philippe Andriot <jipey at jipey.no-ip.com> writes:
> man 3 daemon should do it better :)

It seems to fork only once:

int
daemon(nochdir, noclose)
        int nochdir, noclose;
{
        int fd;

        switch (__fork()) {
        case -1:
                return (-1);
        case 0:
                break;
        default:
                _exit(0);
        }

        if (__setsid() == -1)
                return (-1);

        if (!nochdir)
                (void)__chdir("/");

        if (!noclose && (fd = __open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
                struct stat64 st;

                if (__builtin_expect (__fxstat64 (_STAT_VER, fd, &st), 0) == 0
                    && __builtin_expect (S_ISCHR (st.st_mode), 1) != 0
#if defined DEV_NULL_MAJOR && defined DEV_NULL_MINOR
                    && st.st_rdev == makedev (DEV_NULL_MAJOR, DEV_NULL_MINOR)
#endif
                    ) {
                        (void)__dup2(fd, STDIN_FILENO);
                        (void)__dup2(fd, STDOUT_FILENO);
                        (void)__dup2(fd, STDERR_FILENO);
                        if (fd > 2)
                                (void)__close (fd);
                } else {
                        (void)__close (fd);
                        return -1;
                }
        }
        return (0);
}





More information about the community mailing list