#include "zbxwinservice.h"
#include "zbxstr.h"
#include "zbxcfg.h"
#include "zbxlog.h"
#include <strsafe.h>
#define EVENTLOG_REG_PATH TEXT("SYSTEM\\CurrentControlSet\\Services\\EventLog\\")
static SERVICE_STATUS serviceStatus;
static SERVICE_STATUS_HANDLE serviceHandle;
#define ZBX_APP_STOPPED 0
#define ZBX_APP_RUNNING 1
static int application_status = ZBX_APP_RUNNING;
static zbx_on_exit_t zbx_on_exit_cb;
static zbx_get_config_str_f get_zbx_service_name_cb = NULL;
static zbx_get_config_str_f get_zbx_event_source_cb = NULL;
int ZBX_IS_RUNNING(void)
{
return application_status;
}
void ZBX_DO_EXIT(void)
{
application_status = ZBX_APP_STOPPED;
}
#undef ZBX_APP_STOPPED
#undef ZBX_APP_RUNNING
void zbx_free_service_resources(int ret);
static void parent_signal_handler(int sig)
{
switch (sig)
{
case SIGINT:
case SIGTERM:
ZBX_DO_EXIT();
zabbix_log(LOG_LEVEL_INFORMATION, "Got signal. Exiting ...");
zbx_on_exit_cb(SUCCEED);
break;
}
}
static VOID WINAPI ServiceCtrlHandler(DWORD ctrlCode)
{
serviceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
serviceStatus.dwCurrentState = SERVICE_RUNNING;
serviceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
serviceStatus.dwWin32ExitCode = 0;
serviceStatus.dwServiceSpecificExitCode = 0;
serviceStatus.dwCheckPoint = 0;
serviceStatus.dwWaitHint = 0;
switch (ctrlCode)
{
case SERVICE_CONTROL_STOP:
zabbix_log(LOG_LEVEL_INFORMATION, "Zabbix Agent received stop request.");
break;
case SERVICE_CONTROL_SHUTDOWN:
zabbix_log(LOG_LEVEL_INFORMATION, "Zabbix Agent received shutdown request.");
break;
default:
zabbix_log(LOG_LEVEL_DEBUG, "Zabbix Agent received request:%u.", ctrlCode);
break;
}
switch (ctrlCode)
{
case SERVICE_CONTROL_STOP: