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);
|
||||
}
|
||||
|
@ -12,9 +12,12 @@
|
||||
#include <poll.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <netdb.h>
|
||||
#include <sys/time.h>
|
||||
#include <net/if.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
@ -92,6 +95,9 @@ void capwap_killall_timeout(struct timeout_control* timeout);
|
||||
int capwap_is_enable_timeout(struct timeout_control* timeout, unsigned long index);
|
||||
int capwap_is_timeout(struct timeout_control* timeout, unsigned long index);
|
||||
|
||||
/* */
|
||||
void capwap_daemon(void);
|
||||
|
||||
/* */
|
||||
#define capwap_outofmemory() capwap_logging_fatal("Out of memory %s(%d)", __FILE__, __LINE__); \
|
||||
capwap_exit(CAPWAP_OUT_OF_MEMORY);
|
||||
|
@ -6,5 +6,6 @@
|
||||
#define CAPWAP_OUT_OF_MEMORY -2
|
||||
#define CAPWAP_REQUEST_ROOT -3
|
||||
#define CAPWAP_CRYPT_ERROR -4
|
||||
#define CAPWAP_DAEMON_ERROR -5
|
||||
|
||||
#endif /* __CAPWAP_ERROR_HEADER__*/
|
||||
|
@ -81,6 +81,20 @@ void capwap_logging_enable_console(int error) {
|
||||
#endif
|
||||
}
|
||||
|
||||
/* */
|
||||
void capwap_logging_disable_console(void) {
|
||||
#ifdef CAPWAP_MULTITHREADING_ENABLE
|
||||
capwap_lock_enter(&l_loglock);
|
||||
#endif
|
||||
|
||||
loggingoutputstdout = 0;
|
||||
loggingoutputstderr = 0;
|
||||
|
||||
#ifdef CAPWAP_MULTITHREADING_ENABLE
|
||||
capwap_lock_exit(&l_loglock);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* */
|
||||
#ifdef ENABLE_LOGGING
|
||||
void capwap_logging_printf(int level, const char* format, ...) {
|
||||
|
@ -19,6 +19,7 @@ void capwap_logging_verboselevel(unsigned int level);
|
||||
/* */
|
||||
void capwap_logging_disable_allinterface();
|
||||
void capwap_logging_enable_console(int error);
|
||||
void capwap_logging_disable_console(void);
|
||||
|
||||
/* */
|
||||
#ifdef ENABLE_LOGGING
|
||||
|
Reference in New Issue
Block a user