Exemple #1
0
static PyObject *
Py3Init_vim(void)
{
	/* The special value is removed from sys.path in Python3_Init(). */
	static wchar_t *(argv[2]) = {L"/must>not&exist/foo", NULL};

	if (init_types())
		return NULL;

	/* Set sys.argv[] to avoid a crash in warn(). */
	PySys_SetArgv(1, argv);

	if ((vim_module = PyModule_Create(&vimmodule)) == NULL)
		return NULL;

	if (populate_module(vim_module))
		return NULL;

	if (init_sys_path())
		return NULL;

	return vim_module;
}
Exemple #2
0
    static int
PythonMod_Init(void)
{
    /* The special value is removed from sys.path in Python_Init(). */
    static char	*(argv[2]) = {"/must>not&exist/foo", NULL};

    if (init_types())
	return -1;

    /* Set sys.argv[] to avoid a crash in warn(). */
    PySys_SetArgv(1, argv);

    vim_module = Py_InitModule4("vim", VimMethods, (char *)NULL,
				(PyObject *)NULL, PYTHON_API_VERSION);

    if (populate_module(vim_module))
	return -1;

    if (init_sys_path())
	return -1;

    return 0;
}
Exemple #3
0
int ACEApp::init(int argc, ACE_TCHAR* argv[])
{
    // get the program name
#ifdef WIN32
    char* ptr = ACE_OS::strrchr(argv[0], '\\');
#else
    char* ptr = ACE_OS::strrchr(argv[0], '/');
#endif    
    if (ptr)
    {
        // strip path name
        strcpy(program_, ptr + 1);
    }
    else
    {
        strcpy(program_, argv[0]);
    }
#ifdef WIN32
    // strip .exe extension on WIN32
    ptr = strchr(program_, '.');
    if (ptr)
    {
        *ptr = '\0';
    }
#endif

    int child_proc_num = 0;
    ACE_Get_Opt get_opt(argc, argv, "vdp:c:"); 
    char c;
    while ((c = get_opt()) != EOF)
    {
        switch (c)
        {
            case 'd': // run as daemon
                ACE::daemonize();
                break;
            case 'p': // specified program name
                strcpy(program_, get_opt.opt_arg());
                break;
            case 'c': // child process number
                child_proc_num = atoi(get_opt.opt_arg());
                break;
            case 'v':
                //disp version info
                disp_version();
                return 0;
            default:
                break;
        }
    }

    ACE_OS::signal (SIGPIPE, SIG_IGN);
    ACE_OS::signal (SIGTERM, SIG_IGN);
    ACE_OS::signal (SIGCHLD, SIG_IGN);
    ACE_Sig_Action sig_int((ACE_SignalHandler)daemon_quit, SIGINT);
    //ACE_Sig_Action sig_term((ACE_SignalHandler)daemon_quit, SIGTERM);
    //ACE_Sig_Action sig_chld((ACE_SignalHandler)child_sighdr, SIGCHLD);
    ACE_UNUSED_ARG(sig_int);
    //ACE_UNUSED_ARG(sig_term);
    //ACE_UNUSED_ARG(sig_chld);
    
    //在 init_log() 之前即可    
    if (init_reactor() != 0)
    {
        ACE_DEBUG((LM_ERROR, "[%D] init reactor failed, program exit\n"));
        return -1;
    }
    ACE_DEBUG((LM_INFO, "[%D] init reactor succ\n"));

    if (init_sys_path(program_) != 0)
    {
        ACE_DEBUG((LM_ERROR, "[%D] init sys path failed, program exit\n"));
        return -1;
    }

    if (init_conf() != 0)
    {
        ACE_DEBUG((LM_ERROR, "[%D] init conf failed, program exit\n"));
        return -1;
    }
    ACE_DEBUG((LM_INFO, "[%D] init conf succeed\n"));

    if (init_log() != 0)
    {
        ACE_DEBUG((LM_ERROR, "[%D] init log failed, program exit\n"));
        return -1;
    }
    ACE_DEBUG((LM_INFO, "[%D] init log succ\n"));
    
    //版本信息记录日志
    disp_version();

    if (init_app(argc, argv) != 0)
    {
        ACE_DEBUG((LM_ERROR, "[%D] init app failed, program exit\n"));
        return -1;
    }
    ACE_DEBUG((LM_INFO, "[%D] init app succ\n"));

    write_pid_file();
    ACE_DEBUG((LM_INFO, "[%D] write pid file succ\n"));

    if (child_proc_num > 0)
    {
        parent_main(child_proc_num);
    }
    else
    {
        ACE_DEBUG((LM_INFO, "[%D] enter daemon main pid: %d\n",
            ACE_OS::getpid()));

        daemon_main();

        ACE_DEBUG((LM_INFO, "[%D] leave daemon main pid: %d\n",
            ACE_OS::getpid()));
    }

    quit_app();

    return 0;
}