Allow daemon mode
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user