コード例 #1
0
//--------------------------------------------------------------------------//
//                                                                          //
//--------------------------------------------------------------------------//
int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpszLine, int nShow)
{
    WebServer::SetInstance(hInst);
    if (!lpszLine || !lpszLine[0])
    {
        LogErrorEvent(NULL, EVENTLOG_ERROR_TYPE, 0, MSG_BAD_STARTUP, 
      	      "Malformed Command Line", "");
	return TRUE;
    }

    StartHttpService(__argc, __argv);
    return TRUE;
}
コード例 #2
0
ファイル: PService.cpp プロジェクト: yushaona/SCManager
	void Run()
	{
		//SetConsoleCtrlHandler (ConsoleHandler,TRUE);

		SERVICE_TABLE_ENTRY tables[2];
		tables[0].lpServiceName = PServiceManage::Instance()->ServiceName();
		tables[0].lpServiceProc = ServiceMain;
		tables[1].lpServiceName = NULL;
		tables[1].lpServiceProc = NULL;
		BOOL success = ::StartServiceCtrlDispatcher(tables);
		if (!success)
		{
			_TCHAR *buf = (_TCHAR*)calloc(MAX_PATH*2,sizeof(_TCHAR));
			memcpy(buf,GetSysErrorMessage(),MAX_PATH*2);
			//buf = GetSysErrorMessage();			
			printf_s("错误%s",buf);
			LogErrorEvent(_T("Register Service Main Function Error!"));
			return;
		}
	}
コード例 #3
0
//--------------------------------------------------------------------------//
//                                                                          //
//--------------------------------------------------------------------------//
BOOL StartHttpService(int argc, char *argv[])
{
    HANDLE hEventLog = NULL;
    BOOL bReturn = FALSE;
    char szReconfigEvent[MAX_PATH];
    char szDoneEvent[MAX_PATH];
    PRStatus webserver_run_status = PR_SUCCESS;

    // Process the argv and extract config_root into unique_name. 
    // Use this to name events.

    int c;
    char *serverconfig = NULL;
    while ((c = getopt(argc, argv, "s:n:d:r:f:cvi")) != -1) {
        switch(c) {
        case 'd':
            serverconfig = optarg;
            break;
        default:
            break;
        }
    }
    if (!serverconfig || !serverconfig[0])
        goto cleanup;

    // canonicalize the server config dir path in case it is a relative
    // path and use it to generate a unique id that is used for all server
    // to watchdog communication
    serverconfig = file_canonicalize_path(serverconfig);
    unique_name = set_uniquename(serverconfig);
    FREE(serverconfig);

    hEventLog = InitializeLogging(unique_name);

    wsprintf(szDoneEvent, "NS_%s", unique_name);

    phEvents[WS_SHUTDOWN] = OpenEvent(EVENT_ALL_ACCESS, FALSE, szDoneEvent);
    if (phEvents[WS_SHUTDOWN] != NULL)
    {
        // should not exist
        goto cleanup;
    }

    phEvents[WS_SHUTDOWN] = CreateEvent(NULL, TRUE, FALSE, szDoneEvent);
    if (phEvents[WS_SHUTDOWN] == NULL)
	goto cleanup;

    wsprintf(szReconfigEvent, "NR_%s", unique_name);

    phEvents[WS_RECONFIG] = OpenEvent(EVENT_ALL_ACCESS, FALSE, szReconfigEvent);
    if (phEvents[WS_RECONFIG] != NULL)
    {
        // should not exist
        goto cleanup;
    }

    phEvents[WS_RECONFIG] = CreateEvent(NULL, TRUE, FALSE, szReconfigEvent);
    if (phEvents[WS_RECONFIG] == NULL)
	goto cleanup;

    if (WebServer::Init(argc, argv) == PR_FAILURE)
        goto cleanup;

    MainThread = PR_CreateThread(PR_USER_THREAD,
				 webserver_run,
				 &webserver_run_status,
				 PR_PRIORITY_NORMAL,
				 PR_GLOBAL_THREAD,
				 PR_UNJOINABLE_THREAD,
				 65536);
    if (MainThread == NULL)
	goto cleanup;

    PRThread *thread;
			
    /* In NSPR20, the first thread becomes a user thread.
     * You can't go to sleep on a blocking call like WaitForSingleObject
     * or you'll kill the whole process.
     * So send it off to a native thread before Wait()ing.
     */
    thread = PR_CreateThread(PR_USER_THREAD,
				_WaitSignalThread,
				NULL,
				PR_PRIORITY_NORMAL,
				PR_GLOBAL_THREAD,
				PR_JOINABLE_THREAD,
				0);
			
    if (thread == NULL)
	goto cleanup;

    // the MainThread runs the server at this point, while we wait for
    // the WaitSignalThread to end

    PR_JoinThread(thread);

    if (webserver_run_status == PR_SUCCESS) {
        SuspendHttpdService();
        bReturn = TRUE;
    }
	
cleanup:
    if(!bReturn)
        LogErrorEvent(NULL, EVENTLOG_ERROR_TYPE, 0, MSG_BAD_STARTUP, "Initialization Failed", "");

    WebServer::Cleanup();

    TerminateLogging(hEventLog);

    if (phEvents[WS_SHUTDOWN])
        CLOSEHANDLE(phEvents[WS_SHUTDOWN]);

    if (phEvents[WS_RECONFIG])
        CLOSEHANDLE(phEvents[WS_RECONFIG]);

    return bReturn;
}