摘自pptp-1.7.2/pptp_compat.c
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <strings.h>
- #include <stdio.h>
- /*
- * daemon implementation from uClibc
- * nochdir:0设置为根目录
- * noclose:0关闭标准输入输出,一般调用daemon(0,0);
- */
- int daemon(int nochdir, int noclose)
- {
- int fd;
- switch (fork()) {
- case -1:
- return (-1);
- case 0:
- break;
- default:
- _exit(0);
- }
- if (setsid() == -1)
- return (-1);
- if (!nochdir)
- chdir("/");
- if (!noclose && (fd = open("/dev/null", O_RDWR, 0)) != -1) {
- dup2(fd, STDIN_FILENO);
- dup2(fd, STDOUT_FILENO);
- dup2(fd, STDERR_FILENO);
- if (fd > 2)
- close (fd);
- }
- return (0);
- }
阅读(1753) | 评论(0) | 转发(0) |