/*static*/ bool
uGlobalMenuService::RegisterGlobalMenuBar(uGlobalMenuBar *aMenuBar,
                                          GCancellable *aCancellable,
                                          PRUint32 aXID, nsACString& aPath)
{
  if (!InitService()) {
    NS_ERROR("Failed to register menubar - service not initialized");
    return false;
  }

  NS_ASSERTION(sService->mOnline, "Trying to register menubar when service is offline");
  if (sService->mOnline != true) {
    return false;
  }

  if (aXID == 0 || aPath.IsEmpty()) {
    return false;
  }

  RegisterWindowCbData *data = new RegisterWindowCbData(aMenuBar, aCancellable);

  g_dbus_proxy_call(sService->mDbusProxy,
                    "RegisterWindow",
                    g_variant_new("(uo)", aXID, PromiseFlatCString(aPath).get()),
                    G_DBUS_CALL_FLAGS_NONE,
                    -1,
                    aCancellable,
                    RegisterWindowCallback,
                    data);

  return true;
}
void CService::ServiceMain(DWORD argc, LPTSTR *argv)
{
    BOOL res;

    if (!m_StatusHandle) {
        terminate(GetLastError());
        return;
    }

    res = SendStatusToSCM(SERVICE_START_PENDING, NO_ERROR, 0 , 1, 5000);
    if (!res) {
        terminate(GetLastError());
        return;
    }

    m_pDev = new CDevice();
    if (!m_pDev || !m_pDev->Init(m_StatusHandle) || !m_pDev->Start()) {
        terminate(GetLastError());
        return;
    }

    DEV_BROADCAST_DEVICEINTERFACE filter;

    ZeroMemory(&filter, sizeof(filter));
    filter.dbcc_size = sizeof(filter);
    filter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
    filter.dbcc_classguid = GUID_DEVINTERFACE_BALLOON;

    m_hDevNotify = RegisterDeviceNotification(m_StatusHandle, &filter,
        DEVICE_NOTIFY_SERVICE_HANDLE);

    if (!m_hDevNotify) {
        terminate(GetLastError());
        return;
    }

    m_evTerminate = CreateEvent(NULL, TRUE, FALSE, NULL);
    if (!m_evTerminate) {
        terminate(GetLastError());
        return;
    }

    res = InitService();
    if (!res) {
        terminate(GetLastError());
        return;
    }

    res = SendStatusToSCM(SERVICE_RUNNING, NO_ERROR, 0 , 0, 0);
    if (!res) {
        terminate(GetLastError());
        return;
    }

    WaitForSingleObject(m_evTerminate, INFINITE);
    terminate(0);
}
void OBSBasic::ResetProfileData()
{
	ResetVideo();
	service = nullptr;
	InitService();
	ResetOutputs();
	ClearHotkeys();
	CreateHotkeys();
}
Beispiel #4
0
void ServiceMain(int argc, char** argv) 
{ 
   int error; 
 
   ServiceStatus.dwServiceType = SERVICE_WIN32; 
   ServiceStatus.dwCurrentState = SERVICE_START_PENDING; 
   ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
   ServiceStatus.dwWin32ExitCode = 0; 
   ServiceStatus.dwServiceSpecificExitCode = 0; 
   ServiceStatus.dwCheckPoint = 0; 
   ServiceStatus.dwWaitHint = 0; 
 
   hStatus = RegisterServiceCtrlHandler(PACKAGE_STRING, (LPHANDLER_FUNCTION)ControlHandler); 
   if (hStatus == (SERVICE_STATUS_HANDLE)0) { 
      // Registering Control Handler failed
      return; 
   }  
   // Initialize Service 
   error = InitService(); 
   if (error) {
      // Initialization failed
      ServiceStatus.dwCurrentState = SERVICE_STOPPED; 
      ServiceStatus.dwWin32ExitCode = -1; 
      SetServiceStatus(hStatus, &ServiceStatus); 
      return; 
   } 
   // We report the running status to SCM. 
   ServiceStatus.dwCurrentState = SERVICE_RUNNING; 
   SetServiceStatus (hStatus, &ServiceStatus);
 
   /* Here we do the work */

   	int		argc2 = 3;
	char*	argv2 [4];

    argv2 [0] = argv[0];
    argv2 [1] = "-c";
    if (argc < 2)
        argv2 [2] = "icecast.xml";
    else
        argv2 [2] = argv[1];
    argv2[3] = NULL;

	int ret = mainService(argc2, (char **)argv2);

	ServiceStatus.dwCurrentState = SERVICE_STOPPED;
	ServiceStatus.dwWin32ExitCode = -1;
	SetServiceStatus(hStatus, &ServiceStatus);
	return; 
}
void CService::ServiceMain(DWORD argc, LPTSTR *argv)
{
    BOOL res;

    if (!m_StatusHandle) {
        terminate(GetLastError());
        return;
    }

    res = SendStatusToSCM(SERVICE_START_PENDING, NO_ERROR, 0 , 1, 5000);
    if (!res) {
        terminate(GetLastError());
        return;
    }

    m_pDev = new CDevice();
    if (!m_pDev || !m_pDev->Init(this) || !m_pDev->Start()) {
        terminate(GetLastError());
        return;
    }

    m_hDevNotify = RegisterDeviceInterfaceNotification();
    if (m_hDevNotify == NULL) {
        terminate(GetLastError());
        return;
    }

    m_evTerminate = CreateEvent(NULL, TRUE, FALSE, NULL);
    if (!m_evTerminate) {
        terminate(GetLastError());
        return;
    }

    res = InitService();
    if (!res) {
        terminate(GetLastError());
        return;
    }

    res = SendStatusToSCM(SERVICE_RUNNING, NO_ERROR, 0 , 0, 0);
    if (!res) {
        terminate(GetLastError());
        return;
    }

    WaitForSingleObject(m_evTerminate, INFINITE);
    terminate(0);
}
Beispiel #6
0
void initdatabases(void)
{
    if (!init) {
	clr_index();
	working(1, 0, 0);
	set_color(WHITE, BLACK);
	ftnd_mvprintw( 5, 6, "     INIT DATABASES");
	IsDoing("Init Databases");
    }

    config_read();

    InitArchive();
    InitDomain();
    InitFilearea();
    InitFilefind();
    InitFGroup();
    InitFidonetdb();
    InitFidonet();
    InitHatch();
    InitLanguage();
    InitLimits();
    InitMagics();
    InitMsgarea();
    InitMGroup();
    InitModem();
    InitNewfiles();
    InitNGroup();
    InitNodes();
    InitOneline();
    InitProtocol();
    InitService();
    InitTicarea();
    InitTtyinfo();
    InitUsers();
    InitVirus();
    InitRoute();
    InitFDB();
    InitIBC();
    if (!init) {
	clr_index();
    }
}
Beispiel #7
0
void  ServiceMain(int argc, char** argv)
{
    int error;
    ServiceStatus.dwServiceType = 
        SERVICE_WIN32;
    ServiceStatus.dwCurrentState = 
        SERVICE_START_PENDING;
    ServiceStatus.dwControlsAccepted = 
        SERVICE_ACCEPT_SHUTDOWN | 
        SERVICE_ACCEPT_STOP;
    ServiceStatus.dwWin32ExitCode = 0;
    ServiceStatus.dwServiceSpecificExitCode = 0;
    ServiceStatus.dwCheckPoint = 0;
    ServiceStatus.dwWaitHint = 0;

    hStatus = RegisterServiceCtrlHandler(SVC_NAME, (LPHANDLER_FUNCTION)CtrlHandler);
    if (hStatus == (SERVICE_STATUS_HANDLE)0)
    {
        return;
    }
    // Initialize Service 
    error = InitService();
    if (error) 
    {
        // Initialization failed
        ServiceStatus.dwCurrentState = 
            SERVICE_STOPPED; 
        ServiceStatus.dwWin32ExitCode = -1; 
        SetServiceStatus(hStatus, &ServiceStatus); 
        return; 
    } 

    ServiceStatus.dwCurrentState = 
        SERVICE_RUNNING;
    SetServiceStatus (hStatus, &ServiceStatus);
    
    MEMORYSTATUS memstatus;
    while (ServiceStatus.dwCurrentState == SERVICE_RUNNING)
    {
        Sleep(SLEEP_TIME);
        start_hickwall_if_not_running();
    }
}
void ServiceMain(int argc, char** argv) 
{ 
   int error; 

   ServiceStatus.dwServiceType        = SERVICE_WIN32; 
   ServiceStatus.dwCurrentState       = SERVICE_START_PENDING; 
   ServiceStatus.dwControlsAccepted   = 0;
   ServiceStatus.dwWin32ExitCode      = 0; 
   ServiceStatus.dwServiceSpecificExitCode = 0; 
   ServiceStatus.dwCheckPoint         = 0; 
   ServiceStatus.dwWaitHint           = 0; 

   hStatus = RegisterServiceCtrlHandler(L"MemoryStatus", (LPHANDLER_FUNCTION)ControlHandler); 
   if (hStatus == (SERVICE_STATUS_HANDLE)0) 
   { 
      // Registering Control Handler failed
      return; 
   }  
   // Initialize Service 
   error = InitService(); 
   if (error) 
   {
      // Initialization failed
      ServiceStatus.dwCurrentState       = SERVICE_STOPPED; 
      ServiceStatus.dwWin32ExitCode      = -1; 
      SetServiceStatus(hStatus, &ServiceStatus); 
      return; 
   } 
   // We report the running status to SCM. 
   ServiceStatus.dwCurrentState = SERVICE_RUNNING;
   ServiceStatus.dwControlsAccepted   = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
   SetServiceStatus (hStatus, &ServiceStatus);

   // Start a thread that will perform the main task of the service
   HANDLE hThread = CreateThread (NULL, 0, ServiceWorkerThread, NULL, 0, NULL);

   // Wait until our worker thread exits signaling that the service needs to stop
   WaitForSingleObject (hThread, INFINITE);

   return; 
}
Beispiel #9
0
int main(void)
{
    printf(" ---------------------------------------------------------------- \n");
    printf(" APPLE MAC MINI AppleIntelHD3000Graphics EXPLOIT OSX 10.11 \n"); 
    printf(" by Piotr Bania / CISCO TALOS \n");
    printf(" ---------------------------------------------------------------- \n\n\n");
    
    
    IOServiceClose(0);                      
    IOServiceOpen(0, 0, 0, 0);                 
    
    // if this fails and we are done 
    mem = Alloc(0, MEM_SIZE);
    
    
    printf("Mapping the kernel \n");
    
    if (MapKernel() == -1)
        return -1;
 
    printf("Initializing service \n");
    
    if (InitService("Gen6Accelerator") == -1)
        return -1;
    
    printf("Commencing stage 1 \n");
    
    if (Stage1() == -1)
        return -1;

    if (ResolveApi() == -1)
        return -1;

    printf("Commencing stage 2 \n");
     
    Stage2();
 
 
    return 1;
}
Beispiel #10
0
static void WINAPI ServiceInit(DWORD argc, LPTSTR *argv)
{
	if(!(ServiceStatusHandle = RegisterServiceCtrlHandler(service_name, &ServiceSignal)))
		return;
	ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
	ServiceStatus.dwCurrentState = SERVICE_START_PENDING;
	ServiceStatus.dwControlsAccepted = 0;
	ServiceStatus.dwWin32ExitCode = NO_ERROR;
	ServiceStatus.dwServiceSpecificExitCode = 0;
	ServiceStatus.dwCheckPoint = 1;
	ServiceStatus.dwWaitHint = 1000;

	if(!SetServiceStatus(ServiceStatusHandle, &ServiceStatus))
		return;

	RLOG(ThreadId() << "initializing service");
	bool inited = InitService();
	if(inited) {
		RLOG(ThreadId() << "service successfully initialized");
		ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_PAUSE_CONTINUE
			| SERVICE_ACCEPT_SHUTDOWN | SERVICE_ACCEPT_STOP;
		ServiceStatus.dwCurrentState = SERVICE_RUNNING;
	}
	else {
		RLOG(ThreadId() << "service initialization failed");
		ServiceStatus.dwControlsAccepted = 0;
		ServiceStatus.dwCurrentState = SERVICE_STOPPED;
	}

	ServiceStatus.dwCheckPoint = 0;
	if(!SetServiceStatus(ServiceStatusHandle,&ServiceStatus))
		return;

	if(inited) {
		RLOG(ThreadId() << "running service");
		RunService();
		RLOG(ThreadId() << "exiting service thread");
		service_exited = true;
	}
}
void ServiceMain(int argc, char** argv) 
{ 
   int error; 
 
   ServiceStatus.dwServiceType = SERVICE_WIN32; 
   ServiceStatus.dwCurrentState = SERVICE_START_PENDING; 
   ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
   ServiceStatus.dwWin32ExitCode = 0; 
   ServiceStatus.dwServiceSpecificExitCode = 0; 
   ServiceStatus.dwCheckPoint = 0; 
   ServiceStatus.dwWaitHint = 0; 
 
   hStatus = RegisterServiceCtrlHandler("StreamTranscoderV3", (LPHANDLER_FUNCTION)ControlHandler); 
   if (hStatus == (SERVICE_STATUS_HANDLE)0) { 
      // Registering Control Handler failed
      return; 
   }  
   // Initialize Service 
   error = InitService(); 
   if (error) {
      // Initialization failed
      ServiceStatus.dwCurrentState = SERVICE_STOPPED; 
      ServiceStatus.dwWin32ExitCode = -1; 
      SetServiceStatus(hStatus, &ServiceStatus); 
      return; 
   } 
   // We report the running status to SCM. 
   ServiceStatus.dwCurrentState = SERVICE_RUNNING; 
   SetServiceStatus (hStatus, &ServiceStatus);
 
   /* Here we do the work */

   int ret = mainService(argc, (char **)argv);

	ServiceStatus.dwCurrentState = SERVICE_STOPPED;
	ServiceStatus.dwWin32ExitCode = -1;
	SetServiceStatus(hStatus, &ServiceStatus);
	return; 
}
Beispiel #12
0
void ServiceMain(int argc, char** argv)
{
	ServiceStatus.dwServiceType        = SERVICE_WIN32;
    ServiceStatus.dwCurrentState       = SERVICE_START_PENDING;
    ServiceStatus.dwControlsAccepted   = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
    ServiceStatus.dwWin32ExitCode      = NO_ERROR; 
    ServiceStatus.dwServiceSpecificExitCode = NO_ERROR; 
    ServiceStatus.dwCheckPoint         = 0; 
    ServiceStatus.dwWaitHint           = 0; 
 
    hStatus = RegisterServiceCtrlHandler(
		L"FileChecker", 
		(LPHANDLER_FUNCTION)ControlHandler); 
    if (hStatus == (SERVICE_STATUS_HANDLE)0) 
    { 
        // Registering Control Handler failed
        g_errorCode = ERROR_REGISTER_SERVICE_CTRL_HANDLER;
		return;
    }  
    // Initialize Service 
    if (!InitService()) 
    {
		// Initialization failed
        ServiceStatus.dwCurrentState       = SERVICE_STOPPED; 
        ServiceStatus.dwWin32ExitCode      = -1; 
        SetServiceStatus(hStatus, &ServiceStatus); 
		g_errorCode = ERROR_INIT_SERVICE;
        return; 
    } 
    // We report the running status to SCM. 
    ServiceStatus.dwCurrentState = SERVICE_RUNNING; 
    SetServiceStatus (hStatus, &ServiceStatus);
 
	Run();

    return; 
}
/* Handle an HTTP request. Works out whether Tomcat will be interested then either
 * despatches it to Tomcat or passes it back to Domino.
 */
static unsigned int ParsedRequest(FilterContext *context, FilterParsedRequest *reqData)
{
	unsigned int errID;
	int rc;
	FilterRequest fr;
	int result = kFilterNotHandled;

	DEBUG(("\nParsedRequest starting\n"));

	rc = context->GetRequest(context, &fr, &errID);

	if (fr.URL && strlen(fr.URL))
	{
		char *uri = fr.URL;
		char *workerName, *qp, *turi;

		if (!initDone)
		{
			/* One time initialisation which is deferred so that we have the name of
			 * the server software to plug into worker_env
			 */
			int ok = JK_FALSE;
			jk_map_t *map = NULL;

			DEBUG(("Initialising worker map\n"));

			if (map_alloc(&map))
			{
				if (map_read_properties(map, workerMountFile))
					if (uri_worker_map_alloc(&uw_map, map, logger))
						ok = JK_TRUE;
				map_free(&map);
			}

			DEBUG(("Got the URI worker map\n"));

			if (ok)
			{
				ok = JK_FALSE;
				DEBUG(("About to allocate map\n"));
				if (map_alloc(&map))
				{
					DEBUG(("About to read %s\n", workerFile));
					if (map_read_properties(map, workerFile))
					{
#if defined(JK_VERSION) && JK_VERSION >= MAKEVERSION(1, 2, 0, 1)
						char server[256];

						worker_env.uri_to_worker = uw_map;
						if (context->GetServerVariable(context, "SERVER_SOFTWARE", server, sizeof(server)-1, &errID))
							worker_env.server_name = jk_pool_strdup(&cfgPool, server);
						else
							worker_env.server_name = SERVERDFLT;

						DEBUG(("Server name %s\n", worker_env.server_name));

						if (wc_open(map, &worker_env, logger))
							ok = JK_TRUE;
#else
						if (wc_open(map, logger))
							ok = JK_TRUE;
#endif
						DEBUG(("OK = %d\n", ok));
					}

					DEBUG(("Read %s, OK = %d\n", workerFile, ok));
					map_free(&map);
				}
			}

			if (!ok) return kFilterError;
			initDone = JK_TRUE;
                }

                turi = strdup(uri);
                if (qp = strchr(turi, '?'), tqp != NULL) *qp = '\0';
                workerName = map_uri_to_worker(uw_map, turi, logger);
                free(turi);

		DEBUG(("Worker for this URL is %s\n", workerName));

		if (NULL != workerName)
		{
			private_ws_t ws;
			jk_ws_service_t s;
			jk_pool_atom_t buf[SMALL_POOL_SIZE];

			if (BadURI(uri))
				return RejectBadURI(context);

			/* Go dispatch the call */

			jk_init_ws_service(&s);
			jk_open_pool(&ws.p, buf, sizeof (buf));

			ws.responseStarted	= JK_FALSE;
			ws.context			= context;
			ws.reqData			= reqData;

			ws.reqSize = context->GetRequestContents(context, &ws.reqBuffer, &errID);

			s.ws_private = &ws;
			s.pool = &ws.p;

			if (InitService(&ws, &s))
			{
				jk_worker_t *worker = wc_get_worker_for_name(workerName, logger);

				jk_log(logger, JK_LOG_DEBUG, "HttpExtensionProc %s a worker for name %s\n",
					   worker ? "got" : "could not get", workerName);

				if (worker)
				{
					jk_endpoint_t *e = NULL;

					if (worker->get_endpoint(worker, &e, logger))
					{
						int recover = JK_FALSE;

						if (e->service(e, &s, logger, &recover))
						{
							result = kFilterHandledRequest;
							jk_log(logger, JK_LOG_DEBUG, "HttpExtensionProc service() returned OK\n");
							DEBUG(("HttpExtensionProc service() returned OK\n"));
						}
						else
						{
							result = kFilterError;
							jk_log(logger, JK_LOG_ERROR, "HttpExtensionProc error, service() failed\n");
							DEBUG(("HttpExtensionProc error, service() failed\n"));
						}
						e->done(&e, logger);
					}
				}
				else
				{
					jk_log(logger, JK_LOG_ERROR,
						   "HttpExtensionProc error, could not get a worker for name %s\n",
						   workerName);
				}
			}

			jk_close_pool(&ws.p);
		}
	}

	return result;
}
void CService::ServiceMain(DWORD argc, LPTSTR *argv)
{
    BOOL res;

    if (!m_StatusHandle) {
        terminate(GetLastError());
        return;
    }

    m_pMemStat = new CMemStat;
    if (!m_pMemStat || !m_pMemStat->Init()) {
        terminate(GetLastError());
        return;
    }

    m_pDev = new CDevice;
    if (!m_pDev || !m_pDev->Init()) {
        terminate(GetLastError());
        return;
    }

    res = SendStatusToSCM(SERVICE_START_PENDING, NO_ERROR, 0 , 1, 5000);
    if (!res) {
        terminate(GetLastError());
        return;
    }

    m_evTerminate = CreateEvent(NULL, TRUE, FALSE, NULL);
    if (!m_evTerminate) {
        terminate(GetLastError());
        return;
    }

    m_evWakeUp = CreateEvent(NULL, TRUE, FALSE, NULL);
    if (!m_evWakeUp) {
        terminate(GetLastError());
        return;
    }

    InitializeCriticalSection(&m_scWrite);

    res = SendStatusToSCM(SERVICE_START_PENDING, NO_ERROR, 0 , 2, 1000);
    if (!res) {
        terminate(GetLastError());
        return;
    }

    res = SendStatusToSCM(SERVICE_START_PENDING, NO_ERROR, 0 , 3, 5000);
    if (!res) {
        terminate(GetLastError());
        return;
    }

    res = InitService();
    if (!res) {
        terminate(GetLastError());
        return;
    }

    res = SendStatusToSCM(SERVICE_RUNNING, NO_ERROR, 0 , 0, 0);
    if (!res) {
        terminate(GetLastError());
        return;
    }

    WaitForSingleObject(m_evTerminate, INFINITE);
    terminate(0);
}
Beispiel #15
0
int DoInitialize()
{
	cout << "Version:" << XVERSIONNO << endl;

	int iThreadPoolSize = 0;
	char *pThreadPoolSize = NULL;
#ifdef _WIN32
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#else
	signal(SIGCLD, SIG_IGN);
	signal(SIGPIPE, SIG_IGN);
	signal(SIGINT, exit);
	signal(SIGKILL, exit);
	signal(SIGTERM, exit);
	signal(SIGQUIT, exit);
#endif

	char szFileName[256 + 1] = { 0 };
#ifdef _WIN32
	DWORD dwResult = GetModuleFileName(NULL, szFileName, 256);
	if (dwResult <= 0 || dwResult > 256)
	{
		cout << "Windows GetModuleFileName Fail" << endl;
		return X_FAILURE;
	}
	g_xAppConfigInfo.m_strFileName = szFileName;
	int iTemp = g_xAppConfigInfo.m_strFileName.find_last_of("\\") + 1;
	g_xAppConfigInfo.m_strPath = g_xAppConfigInfo.m_strFileName.substr(0, iTemp);
	g_xAppConfigInfo.m_strFile = g_xAppConfigInfo.m_strFileName.substr(iTemp);
#else
	int iPathLen = readlink("/proc/self/exe", szFileName, 256);
	if (iPathLen <= 0 || iPathLen > 256)
	{
		cout << "Linux readlink Fail" << endl;
		return X_FAILURE;
	}
	g_xAppConfigInfo.m_strFileName = szFileName;
	int iTemp = g_xAppConfigInfo.m_strFileName.find_last_of("/") + 1;
	g_xAppConfigInfo.m_strPath = g_xAppConfigInfo.m_strFileName.substr(0, iTemp);
	g_xAppConfigInfo.m_strFile = g_xAppConfigInfo.m_strFileName.substr(iTemp);
#endif
	cout << "FileName:" + g_xAppConfigInfo.m_strFileName << endl;
	cout << "Path:" + g_xAppConfigInfo.m_strPath << endl;
	cout << "File:" + g_xAppConfigInfo.m_strFile << endl;

	int iResult = X_SUCCESS;
	//初始化日志
	iResult = XLogClass::Initialize(g_xAppConfigInfo.m_strPath, g_xAppConfigInfo.m_strFile, log4cpp::Priority::DEBUG);
	if (iResult != X_SUCCESS)
	{
		cout << "XLogClass::Initialize Fail" << endl;
		return X_FAILURE;
	}

	//读取配置
	iResult = XConfig::ReadConfig();
	if (iResult != X_SUCCESS)
	{
		XLogClass::error("XConfig::ReadConfig Fail");
		return X_FAILURE;
	}

	//设置配置中的日志级别
	XLogClass::SetPriority(g_xAppConfigInfo.m_xLoggerInfo.m_iLogPriority);

	//初始化线程池,要环境变量增加 UV_THREADPOOL_SIZE
	pThreadPoolSize = getenv("UV_THREADPOOL_SIZE");
	if (pThreadPoolSize != NULL)
		iThreadPoolSize = atoi(pThreadPoolSize);
	else
		iThreadPoolSize = 0;
	cout << "Before Set ThreadPoolSize:" << iThreadPoolSize << endl;
	if (g_xAppConfigInfo.m_xThreadPoolInfo.m_szSize > 0 && g_xAppConfigInfo.m_xThreadPoolInfo.m_szSize != (size_t)iThreadPoolSize)
	{
		string strSize = "UV_THREADPOOL_SIZE=" + convert<string>(g_xAppConfigInfo.m_xThreadPoolInfo.m_szSize);
		iResult = putenv((char *)strSize.c_str());
		if (iResult != X_SUCCESS)
		{
			XLogClass::error("ThreadPool Initialize Fail");
		}
	}

	pThreadPoolSize = getenv("UV_THREADPOOL_SIZE");
	if (pThreadPoolSize != NULL)
		iThreadPoolSize = atoi(pThreadPoolSize);
	else
		iThreadPoolSize = 0;
	cout << "After Set ThreadPoolSize:" << iThreadPoolSize << endl;

	InitOpensslLocks();
	cout << "InitOpensslLocks OK" << endl;

	//_CrtDumpMemoryLeaks();
	//初始化TcpClient连接
	iResult = InitTcpClientPool();
	if (iResult != X_SUCCESS)
	{
		XLogClass::error("InitTcpClientPool Fail");
	}

	//初始化数据库连接
	iResult = InitDataBase();
	if (iResult != X_SUCCESS)
	{
		XLogClass::error("InitDataBase Fail");
		return X_FAILURE;
	}

	iResult = InitService();
	if (iResult != X_SUCCESS)
	{
		XLogClass::error("InitService Fail");
		return X_FAILURE;
	}

	iResult = InitListener();
	if (iResult != X_SUCCESS)
	{
		XLogClass::error("InitListener Fail");
		return X_FAILURE;
	}

	//ReleaseOpensslLocks();
	return X_SUCCESS;
}
Beispiel #16
0
// ServiceMain is called when the SCM wants to
// start the service. When it returns, the service
// has stopped. It therefore waits on an event
// just before the end of the function, and
// that event gets set when it is time to stop. 
// It also returns on any error because the
// service cannot start if there is an eror.
VOID ServiceMain(DWORD argc, LPTSTR *argv) 
{
	BOOL success;

	// immediately call Registration function
	serviceStatusHandle =
		RegisterServiceCtrlHandler(
			SERVICE_NAME,
			(LPHANDLER_FUNCTION) ServiceCtrlHandler);
	if (!serviceStatusHandle)
	{
		terminate(GetLastError());
		return;
	}

	// Notify SCM of progress
	success = SendStatusToSCM(
		SERVICE_START_PENDING,
		NO_ERROR, 0, 1, 5000);
	if (!success)
	{
		terminate(GetLastError()); 
		return;
	}

	// create the termination event
	terminateEvent = CreateEvent (0, TRUE, FALSE,
		0);
	if (!terminateEvent)
	{
		terminate(GetLastError());
		return;
	}

	// Notify SCM of progress
	success = SendStatusToSCM(
		SERVICE_START_PENDING,
		NO_ERROR, 0, 2, 1000);
	if (!success)
	{
		terminate(GetLastError()); 
		return;
	}

	// Notify SCM of progress
	success = SendStatusToSCM(
		SERVICE_START_PENDING,
		NO_ERROR, 0, 3, 5000);
	if (!success)
	{
		terminate(GetLastError()); 
		return;
	}

	// Start the service itself
	success = InitService();
	if (!success)
	{
		terminate(GetLastError());
		return;
	}

	// The service is now running. 
	// Notify SCM of progress
	success = SendStatusToSCM(
		SERVICE_RUNNING,
		NO_ERROR, 0, 0, 0);
	if (!success)
	{
		terminate(GetLastError()); 
		return;
	}

	// Wait for stop signal, and then terminate
	WaitForSingleObject (terminateEvent, INFINITE);

	terminate(0);
}
Beispiel #17
0
XService::XService(void)
{
	InitService();
}