예제 #1
0
파일: HelixSvc.cpp 프로젝트: smc314/helix
VOID ServiceMainProc()
{
	::InitializeCriticalSection(&myCS);
	// initialize variables for .exe and .log file names
	char pModuleFile[nBufferSize+1];
	DWORD dwSize = GetModuleFileName(NULL, pModuleFile, nBufferSize);
	pModuleFile[dwSize] = 0;
	if(dwSize>4 && pModuleFile[dwSize-4] == '.')
	{
		sprintf_s(pExeFile,"%s",pModuleFile);
		pModuleFile[dwSize-4] = 0;
		sprintf_s(pLogFile,"%s.log",pModuleFile);

		sprintf_s(pWorkDir,"%s",pModuleFile);
		PathRemoveFileSpec(pWorkDir);
	}

	strcpy_s(pServiceName,"Helix");

	if(_stricmp("-i",lpCmdLineData) == 0 || _stricmp("-I",lpCmdLineData) == 0)
		Install(pExeFile, pServiceName);
	else if(_stricmp("-k",lpCmdLineData) == 0 || _stricmp("-K",lpCmdLineData) == 0)
		KillService(pServiceName);
	else if(_stricmp("-u",lpCmdLineData) == 0 || _stricmp("-U",lpCmdLineData) == 0)
		UnInstall(pServiceName);
	else if(_stricmp("-s",lpCmdLineData) == 0 || _stricmp("-S",lpCmdLineData) == 0)
		RunService(pServiceName);
	else
		ExecuteSubProcess();
}
예제 #2
0
extern	int
main(
	int		argc,
	char	**argv)
{
	struct sigaction sa_segv, sa_stop;
	FILE_LIST	*fl;
	int		rc;

ENTER_FUNC;
	InitNET();

	memset( &sa_segv, 0, sizeof(struct sigaction) );
	sa_segv.sa_flags = SA_SIGINFO;
	sa_segv.sa_sigaction = SegvProcess;
	sigemptyset (&sa_segv.sa_mask);	
	sigaction( SIGSEGV, &sa_segv, NULL );

	memset( &sa_stop, 0, sizeof(struct sigaction) );
	sigemptyset (&sa_stop.sa_mask);
	sa_stop.sa_flags = 0;
	sa_stop.sa_handler = StopProcess;
	sigaction( SIGHUP, &sa_stop, NULL );

	SetDefault();
	fl = GetOption(option,argc,argv,NULL);
	InitMessage("dbstub",NULL);
	InitNET();

	if		(  BD_Name  ==  NULL  ) {
		Error("BD name is not specified.");
	}
	if		( fl == NULL ) {
		Error("module name is not specified.");
	}
	snprintf(AppName, sizeof(AppName), "dbstub-%s",fl->name);
	InitSystem(fl->name);
	Message("module %s: %.20s", fl->name, CommandParameter);
	rc = ExecuteSubProcess(fl->name);
	StopProcess(rc);
	return	(rc);
}
예제 #3
0
파일: Service.cpp 프로젝트: airhigh/wdrbd
int _tmain(int argc, _TCHAR* argv[])
{
    TCHAR szPath[MAX_PATH] = { 0, };
    DWORD dwSize = GetModuleFileName(NULL, szPath, MAX_PATH);
    TCHAR * pdest = _tcsrchr(szPath, '\\');
    _tcsncpy_s(gServicePath, sizeof(gServicePath) / sizeof(TCHAR), szPath, (size_t)(pdest - szPath));

    if (argc < 2)
    {
        ExecuteSubProcess();
        return 0;
    }
    
    if (_tcsicmp(L"/i", argv[1]) == 0)
        return Install(szPath, ServiceName);
    else if (_tcsicmp(L"/k", argv[1]) == 0)
        return KillService(ServiceName);
    else if (_tcsicmp(L"/u", argv[1]) == 0)
        return UnInstall(ServiceName);
    else if (_tcsicmp(L"/s", argv[1]) == 0)
        return RunService(ServiceName);
    else if (_tcsicmp(L"/t", argv[1]) == 0)
    {
        DWORD dwPID;
        WCHAR *szServicePath;
        WCHAR *cmd = L"drbdadm.exe initial-split-brain minor-6";
        WCHAR fullName[MAX_PATH] = {0};

        size_t len;
        errno_t err = _wdupenv_s(&szServicePath, &len, L"DRBD_PATH");
        if (err)
        {
            // default
            szServicePath = L"C:\\Program Files\\drbd\\bin";
        }
        if ((wcslen(szServicePath) + wcslen(cmd) + 4) > MAX_PATH)
        {
            printf("szServicePath: too big!!\n");
        }
        wcsncpy_s(fullName, szServicePath, wcslen(szServicePath));
        wcscat_s(fullName, L"\\");
        wcsncat_s(fullName, cmd, wcslen(cmd)); //wnsprintf
        printf("fullName: %ws\n", fullName);

        // test!
        DWORD ret = RunProcess(EXEC_MODE_WIN, SW_NORMAL, NULL, cmd, szServicePath, dwPID, 0, NULL, NULL);
        free(szServicePath);
        return ERROR_SUCCESS;
    }
#if 1 // _WIN32_HANDLER_TIMEOUT: test by a separate application, not daemon. remove later
	else if (_tcsicmp(L"/n", argv[1]) == 0) 
	{
		// internal test only: no-daemon test

		unsigned short servPort = DRBD_DAEMON_TCP_PORT;
		DWORD threadID;

		if (CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) SockListener, &servPort, 0, (LPDWORD) &threadID) == NULL)
		{
			WriteLog(L"pthread_create() failed\n");
			return 0;
		}

		int i = 0;
		while (1)
		{
			printf("test main loop(%d)...\n", i++);
			Sleep(10000);
		}
	}
#endif
    else
    {
        TCHAR msg[256];
        _stprintf_s(msg, _T("Usage: drbdService.exe [/i|/k|/u|/s]\n"));
        WriteLog(msg);
        return ERROR_INVALID_PARAMETER;
    }

    return ERROR_SUCCESS;
}