Allow daemon mode

This commit is contained in:
vemax78
2013-06-16 12:09:57 +02:00
parent 7b6bd52f48
commit 99b6373cd7
11 changed files with 106 additions and 8 deletions

View File

@ -160,3 +160,41 @@ void* capwap_clone(void* buffer, int buffersize) {
return memcpy(bufferclone, buffer, buffersize);
}
/* */
void capwap_daemon(void) {
int fd;
pid_t pid;
/* Fork off the parent process */
pid = fork();
if (pid < 0) {
capwap_exit(CAPWAP_DAEMON_ERROR);
} else if (pid > 0) {
capwap_exit(CAPWAP_SUCCESSFUL);
}
/* Change the file mode mask */
umask(0);
/* Create a new SID for the child process */
if (setsid() < 0) {
capwap_exit(CAPWAP_DAEMON_ERROR);
}
/* Change the current working directory */
if ((chdir("/")) < 0) {
capwap_exit(CAPWAP_DAEMON_ERROR);
}
/* Redirect the standard file descriptors to /dev/null */
fd = open("/dev/null", 0);
if (fd == -1) {
capwap_exit(CAPWAP_DAEMON_ERROR);
}
dup2(fd, STDIN_FILENO);
dup2(fd, STDOUT_FILENO);
dup2(fd, STDERR_FILENO);
close(fd);
}