Ejemplo n.º 1
0
bool CStartAggregate::CreateNtService(LPCWSTR szServiceName, LPCWSTR szPath)
{
    BOOL bRet = FALSE;
    SC_HANDLE schSCManager = _OpenSCManager();
    if ( schSCManager == NULL )
        return false;
    SC_HANDLE  schService = OpenService(schSCManager, szServiceName, SERVICE_ALL_ACCESS);
    if(schService)
    {
        _StopServer(schService);

        bRet = ChangeServiceConfig(
                   schService,//服务控制管理器 数据库
                   SERVICE_WIN32_OWN_PROCESS,//服务类型
                   SERVICE_AUTO_START,//启动类型,随系统自动//加载
                   SERVICE_ERROR_NORMAL,
                   szPath,
                   NULL,
                   NULL,
                   TEXT(""),
                   NULL,//本地系统帐号
                   NULL,// 没有口令
                   L"");
    }
    else
    {
        schService=CreateService(
                       schSCManager,//服务控制管理器 数据库
                       szServiceName,//后台服务名称
                       szServiceName,//在服务控制面板中显示的//服务名称
                       SERVICE_ALL_ACCESS,//访问权限
                       SERVICE_WIN32_OWN_PROCESS,//服务类型
                       SERVICE_AUTO_START,//启动类型,随系统自动//加载
                       SERVICE_ERROR_NORMAL,
                       szPath,
                       NULL,
                       NULL,
                       TEXT(""),
                       NULL,//本地系统帐号
                       NULL);// 没有口令
        if(schService)
            bRet  = TRUE;
    }
    CloseServiceHandle(schService);
    CloseServiceHandle(schSCManager);
    if(bRet)
        return true;
    return false;
}
Ejemplo n.º 2
0
int main(int argc, char** argv)
{
    const unsigned short PORT = 8888;
    Selector selector;
#if defined(HAVE_POSIX)
    Listener unixListener;
#endif
    Listener inetListener;
    char sockfileBuf[MAX_PATH_SIZE];
#if defined(ENABLE_PIDFILE)
    int pidfile;
    char pidfileBuf[MAX_PATH_SIZE];
#endif /* defined(ENABLE_PIDFILE) */

    arg0 = argv[0];
    ErrSetArg0(arg0);

    /* Set the default options */
    memset(&g_options, 0, sizeof(Options));
    g_options.sockfile = MakePath(ID_SOCKFILE, sockfileBuf);
    g_options.port = PORT;

    /* Set the default options */
#if defined(ENABLE_ROLES)
    /* Load roles.conf */
    {
        char buf[MAX_PATH_SIZE];
        char err[128];

        if (RolesLoad(MakePath(ID_ROLES_CONF, buf), err, sizeof(err)) != 0)
            Err("%s", err);
    }
#endif /* defined(ENABLE_ROLES) */

    /* Set the default options */
    /* Process the configuration file before the command-line options */
    _GetConfFileOptions();

    /* Get command line options */
    _GetOptions(&g_options, &argc, argv);

    /* Dump the paths? */
    if (g_options.paths)
    {
        DumpPaths();
        exit(0);
    }

    /* Dump the roles */
    if (g_options.roles)
    {
        RoleDump();
        exit(0);
    }

#if defined(ENABLE_PAM_AUTH)
    /* Check that the PAM plugin is installed */
    if (access("/etc/pam.d/phit", R_OK) != 0)
    {
        fprintf(stderr, "%s: /etc/pam.d/phit not found\n\n", arg0);
        exit(1);
    }
#endif

    /* Stop the server? */
    if (g_options.stop)
    {
#if defined(ENABLE_PIDFILE)
        _StopServer();
#else
        Err("use kill (-s option is diabled)");
#endif /* defined(ENABLE_PIDFILE) */
    }

    /* Check arguments */
    if (argc != 1)
    {
        fprintf(stderr, "Use -h for help\n");
        exit(1);
    }

#if defined(ENABLE_PIDFILE)
    /* Bail out if server is already running */
    if (PIDFileIsRunning() == 0)
    {
        Err("already running: %s", MakePath(ID_PIDFILE, pidfileBuf));
    }
#endif /* defined(ENABLE_PIDFILE) */

    /* Load the plugins file */
    {
        char error[128];

        if (PluginLoad(error, PHIT_ARRAY_SIZE(error)) != 0)
            Err("%s", error);
    }

    /* Initialize the selector */
    SelectorInit(&selector);

    /* Handle SIGTERM */
    signal(SIGTERM, _HandleSIGTERM);

    /* Ignore SIGPIPE */
#if defined(HAVE_POSIX)
    signal(SIGPIPE, SIG_IGN);
#endif

    /* Initialize the sockets layer */
    {
        int r = SockStart();
        (void)r;
        DEBUG_ASSERT(r == 0);
    }

#if defined(HAVE_POSIX)
    /* Create listener for Unix-domain sockets */
    if (ListenerInit(&unixListener, &selector, g_options.sockfile, 0) != 0)
    {
        char buf[MAX_PATH_SIZE];
        Err("listen failed (uds): %s", MakePath(ID_SOCKFILE, buf));
    }
#endif /* defined(HAVE_POSIX) */

    /* Create listener for internet sockets */
    if (ListenerInit(&inetListener, &selector, NULL, g_options.port) != 0)
    {
        Err("listen failed (inet): port %u", g_options.port);
    }

    /* Daemonize */
#if defined(HAVE_POSIX)
    if (!g_options.nodaemonize)
        ProcessDaemonize();
#endif

#if defined(ENABLE_PIDFILE)
    /* Create PID file (after daemonize) */
    if ((pidfile = PIDFileCreate()) == -1)
    {
        Err("failed to create %s", MakePath(ID_PIDFILE, pidfileBuf));
    }
#endif /* defined(ENABLE_PIDFILE) */

    /* Run the selector */
    while (!_terminated)
    {
        SelectorRun(&selector, 1, 0);
    }

    /* Unload the plugins */
    PluginUnload();

    /* Close and delete the PID file */
#if defined(ENABLE_PIDFILE)
    {
        close(pidfile);

        if (PIDFileDelete() != 0)
        {
            Err("delete failed: %s\n", MakePath(ID_PIDFILE, pidfileBuf));
        }
    }
#endif /* defined(ENABLE_PIDFILE) */

    /* Release the selector (and any surviving handlers) */
    SelectorDestroy(&selector);

    /* Remove the socket file */
#if defined(ENABLE_EXEC_PROVIDERS)
    unlink(MakePath(ID_SOCKFILE, sockfileBuf));
#endif

    /* Shutdown the sockets layer */
    SockStop();

    LOGI(("Terminated"));

    /* Call all cleanup handlers */
    Cleanup();

#if defined(ENABLE_ALLOCATOR)
    /* Print allocation statistics */
    AllocPrintStatsAssert();
#endif

#if defined(ENABLE_SOCKTRACE)
    printf("Bytes sent: %llu\n", SockGetBytesSent());
    printf("Bytes recv: %llu\n", SockGetBytesRecv());
#endif /* ENABLE_SOCKTRACE */

    return 0;
}
Ejemplo n.º 3
0
bool VideoPreview::checkEvents()
{
	while (m_video_task_semaphore.wait())
	{
		pair<Tasks, TaskData*> p;
		p.second = 0;
		{
			CFlyLock(cs);
			dcassert(!m_tasks.empty());
			if (m_tasks.empty())
				return false;
			p = m_tasks.front();
			m_tasks.pop_front();
		}
		try
		{
			if (failed && p.first != SHUTDOWN)
			{
				dcdebug("VideoPreview: New command when already failed: %d\n", p.first);
				fail(STRING(DISCONNECTED));
				goto check_events_clean_task_data; // [+] IRainman fix.
				// delete p.second; continue; [-] IRainman fix.
			}
			
			switch (p.first)
			{
				case START_PREVIEW_SERVER:
				{
					if (!IsServerStarted())
					{
						_StartServer();
					}
				}
				break;
				case STOP_PREVIEW_SERVER:
				{
					if (IsServerStarted())
						_StopServer();
				}
				break;
				case ADD_LOG_INFO:
				{
					_AddLogInfo(p.second->m_logInfo);
				}
				break;
				case SHUTDOWN:
				{
					if (IsServerStarted())
						_StopServer();
				}
				return false;
			}
			// delete p.second; [-] IRainman fix.
		}
		catch (const Exception& e)
		{
			// delete p.second; [-] IRainman fix.
			fail(e.getError());
		}
		// [+] IRainman fix.
check_events_clean_task_data:
		delete p.second;
		// [~] IRainman fix.
	}
	return true;
}