# include "zbxwinservice.h"
static HANDLE system_log_handle = INVALID_HANDLE_VALUE;
static char log_filename[MAX_STRING_LEN];
static int log_type = ZBX_LOG_TYPE_UNDEFINED;
static zbx_mutex_t log_access = ZBX_MUTEX_NULL;
static int config_log_file_size = -1;
static int get_config_log_file_size(void)
if (-1 != config_log_file_size)
return config_log_file_size;
THIS_SHOULD_NEVER_HAPPEN;
# define LOCK_LOG zbx_mutex_lock(log_access)
# define UNLOCK_LOG zbx_mutex_unlock(log_access)
# define LOCK_LOG lock_log()
# define UNLOCK_LOG unlock_log()
# define STDIN_FILENO _fileno(stdin)
# define STDOUT_FILENO _fileno(stdout)
# define STDERR_FILENO _fileno(stderr)
# define ZBX_DEV_NULL "NUL"
# define dup2(fd1, fd2) _dup2(fd1, fd2)
# define ZBX_DEV_NULL "/dev/null"
int zbx_redirect_stdio(const char *filename)
const char default_file[] = ZBX_DEV_NULL;
int open_flags = O_WRONLY, fd;
if (NULL != filename && '\0' != *filename)
open_flags |= O_CREAT | O_APPEND;
if (-1 == (fd = open(filename, open_flags, 0666)))
zbx_error("cannot open \"%s\": %s", filename, zbx_strerror(errno));
if (-1 == dup2(fd, STDOUT_FILENO))
zbx_error("cannot redirect stdout to \"%s\": %s", filename, zbx_strerror(errno));
if (-1 == dup2(fd, STDERR_FILENO))
zbx_error("cannot redirect stderr to \"%s\": %s", filename, zbx_strerror(errno));
if (-1 == (fd = open(default_file, O_RDONLY)))