예제 #1
0
void notmain(void) {
	int i;

	hardware_init();

	dmx_init();
	dmx_set_port_direction(DMX_PORT_DIRECTION_INP, true);

	rdm_device_info_init();

	printf("[V%s] %s Compiled on %s at %s\n", DEVICE_SOFTWARE_VERSION, hardware_board_get_model(), __DATE__, __TIME__);
	printf("RDM Responder / DMX Slave, Devices connected : %d\n", dmx_devices_get_devices_connected());
	const uint8_t *uid_device = rdm_device_info_get_uuid();
	printf("Device UUID : %.2x%.2x:%.2x%.2x%.2x%.2x, Label :", uid_device[0], uid_device[1], uid_device[2], uid_device[3], uid_device[4], uid_device[5]);
	monitor_print_root_device_label();

	hardware_watchdog_init();

	events_init();

	for (;;) {
		for (i = 0; i < (int)(sizeof(poll_table) / sizeof(poll_table[0])); i++) {
			poll_table[i].f();
			hardware_watchdog_feed();
		}

		events_check();
	}
}
예제 #2
0
/**
 * @ingroup firmware
 *
 *
 *
 * @param boot_dev
 * @param arm_m_type
 * @param atags
 * @return
 */
int notmain(uint32_t boot_dev, uint32_t arm_m_type, uint32_t atags) {
	int i = 0;

	hardware_init();
	dmx_init();
	dmx_devices_init();

	hardware_print_board_model();
	printf("Compiled on %s at %s\n", __DATE__, __TIME__);
	printf("DMX Slave-Analyzer, Devices connected : %d\n", dmx_devices_get_devices_connected());

	ui_start(0x00);			// User Interface
	ui_reinit();
	ui_text_line_1("DMX512 Receiver", 15);
	ui_text_line_2("Booting........", 15);

	dmx_devices_init();

	hardware_watchdog_init();

	events_init();

	for (;;) {
		hardware_watchdog_feed();

		for (i = 0; i < sizeof(poll_table) / sizeof(poll_table[0]); i++) {
			poll_table[i].f();
		}

		events_check();
	}

	return 0;
}
예제 #3
0
//! [quick_start_init_events_function]
static void init_events(void)
{
	struct events_conf    events_config;
	struct events_ch_conf ch_config;

	/* Initialize event module */
	events_get_config_defaults(&events_config);
	events_init(&events_config);
	events_enable();

	/*
	 * Configure an event channel
	 * - AST periodic event 0 --- Generator
	 * - PDCA channel 0       --- User
	 */
	events_ch_get_config_defaults(&ch_config);
	ch_config.channel_id = PEVC_ID_USER_PDCA_0;
	ch_config.generator_id = PEVC_ID_GEN_AST_2;
	ch_config.shaper_enable = true;
	ch_config.igf_edge = EVENT_IGF_EDGE_NONE;
	events_ch_configure(&ch_config);

	/* Enable the channel */
	events_ch_enable(PEVC_ID_USER_PDCA_0);
}
예제 #4
0
파일: main.c 프로젝트: glockwork/rpidmx512
/**
 * @ingroup firmware
 *
 *
 *
 * @param boot_dev
 * @param arm_m_type
 * @param atags
 * @return
 */
int notmain(uint32_t boot_dev, uint32_t arm_m_type, uint32_t atags)
{
	hardware_init();
	dmx_init();

	printf("Compiled on %s at %s\n", __DATE__, __TIME__);

	ui_start(0x00);			// User Interface
	ui_reinit();
	ui_text_line_1("DMX512 Receiver", 15);
	ui_text_line_2("Booting........", 15);

	dmx_devices_read_config();
	dmx_devices_init();

	watchdog_init();

	events_init();

	for (;;)
	{
		watchdog_feed();
		int i = 0;
		for (i = 0; i < sizeof(poll_table) / sizeof(poll_table[0]); i++)
		{
			poll_table[i].f();
		}

		events_check();
	}

	return 0;
}
예제 #5
0
/**
 * Initialize the PEVC for the example.
 */
static void init_events(void)
{
	struct events_conf    events_config;
	struct events_ch_conf ch_config;

	/* Initialize event module */
	events_get_config_defaults(&events_config);
	events_config.igf_divider = EVENT_IGF_DIVIDER_1024;
	events_init(&events_config);
	events_enable();

	/*
	 * Configure an event channel
	 * - GPIO PAD_EVT 1  --- Generator
	 * - PDCA channel 0  --- User
	 * - Enable falling edge detection for EVS
	 */
	events_ch_get_config_defaults(&ch_config);
	ch_config.channel_id = PEVC_ID_USER_PDCA_0;
	ch_config.generator_id = PEVC_ID_GEN_PAD_1;
	ch_config.sharper_enable = true;
	ch_config.igf_edge = EVENT_IGF_EDGE_FALLING;
	events_ch_configure(&ch_config);

	/* Enable the channel */
	events_ch_enable(PEVC_ID_USER_PDCA_0);
}
예제 #6
0
static ape_global *ape_init()
{
    ape_global *ape;
    struct _fdevent *fdev;

    if ((ape = malloc(sizeof(*ape))) == NULL) return NULL;

	inc_rlimit(64000);

    signal(SIGPIPE, SIG_IGN);
	signal(SIGINT, &signal_handler);
	signal(SIGTERM, &signal_handler);
	
    fdev = &ape->events;
    fdev->handler = EVENT_UNKNOWN;
    #ifdef USE_EPOLL_HANDLER
    fdev->handler = EVENT_EPOLL;
    #endif
    #ifdef USE_KQUEUE_HANDLER
    fdev->handler = EVENT_KQUEUE;
    #endif

    ape->basemem    = APE_BASEMEM;
    ape->is_running = 1;
    ape->timers.ntimers = 0;
    ape->timers.timers  = NULL;
	
	ape_ssl_init();
	
    if (ape_dns_init(ape) != 0) {
        goto error;
    }
    events_init(ape);

    ape->seed = _ape_seed = time(NULL) ^ (getpid() << 16);

    ape->hashs.servers    = hashtbl_init(APE_HASH_STR);
    ape->hashs.cmds       = hashtbl_init(APE_HASH_STR);
    ape->hashs.pipes.pub  = hashtbl_init(APE_HASH_INT);
    ape->hashs.pipes.priv = hashtbl_init(APE_HASH_INT);

    if ((ape->conf = ape_read_config("../../etc/ape.conf", ape)) == NULL) {
        goto error;
    }
    
    ape_cmd_init_core(ape);

    ape->extend = ape_array_new(8);
	
    return ape;

error:

    free(ape);

    return NULL;
}
예제 #7
0
void raise(const std::string& event,
           const entity_location& loc1,
           const entity_location& loc2,
           const config& data)
{
	if(!events_init())
		return;

	DBG_EH << "raising event: " << event << "\n";

	events_queue.push_back(queued_event(event, loc1, loc2, data));
}
예제 #8
0
/**
 * \brief Test events driver with AST trigger.
 *
 * \param test Current test case.
 */
static void run_events_ast_test(const struct test_case *test)
{
	uint32_t retry_times = 3;
	bool trigger_flag = false;
	struct events_conf    events_config;
	struct events_ch_conf ch_config;

	init_ast();
	init_dacc();

	/* Initialize event module */
	events_get_config_defaults(&events_config);
	events_init(&events_config);
	events_enable();

	/*
	 * Configure an event channel
	 * - AST periodic event 0  --- Generator
	 * - DAC                   --- User
	 */
	events_ch_get_config_defaults(&ch_config);
	ch_config.channel_id = CONF_TEST_USER_ID;
	ch_config.generator_id = CONF_TEST_GEN_ID;
	ch_config.shaper_enable = true;
	ch_config.igf_edge = EVENT_IGF_EDGE_NONE;
	events_ch_configure(&ch_config);

	/* Enable the channel */
	events_ch_enable(CONF_TEST_USER_ID);

	/* Set new DACC value */
	dacc_write_conversion_data(DACC, DACC_MAX_DATA / 2);


	/* Wait for AST event trigger */
	events_ch_clear_trigger_status(CONF_TEST_USER_ID);
	do {
		if (events_ch_is_triggered(CONF_TEST_USER_ID)) {
			trigger_flag = true;
			events_ch_clear_trigger_status(CONF_TEST_USER_ID);
			break;
		}
		delay_ms(1000);
	} while (retry_times--);

	/* Disable the AST */
	ast_disable(AST);

	test_assert_true(test, trigger_flag, "AST event not triggered!");
}
예제 #9
0
static void run_task_test(void)
{
    tasks_init();
    events_init();
    sleep(2);    /* wait for both threads to run */
    tasks_add(task_create(test, NULL));

    events_add(event_create(2, config_parse_event, (void *)"config_test"));
    events_add(event_create(2, test, NULL));
    sleep(5);

    events_add(event_create(3, test, NULL));
    events_stop();
    tasks_stop();
}
예제 #10
0
파일: io.c 프로젝트: LastRitter/mcuio
int bathos_setup(void)
{
	CPU_PRESCALE(0);

	console_early_init();

	/* Turn red led on */
	timer_init();
	events_init();

	do_initcalls();

	/* Interrupts are enabled by the calling assembly code */
	return 0;
}
    static rb_mt_loop*
loop_create()
{
    rb_mt_loop *loop = calloc(1, sizeof(*loop));
    if (loop == NULL) return NULL;
    if (!events_init(&loop->events)) goto free_loop;
    if (!timers_init(&loop->timers)) goto free_events;
    if (!callbacks_init(&loop->callbacks)) goto free_timers;
    return loop;

free_timers:
    timers_finalize(&loop->timers);
free_events:
    events_finalize(&loop->events);
free_loop:
    free(loop);
    return NULL;
}
예제 #12
0
static ape_global *ape_init()
{
    ape_global *ape;
    struct _fdevent *fdev;

    if ((ape = malloc(sizeof(*ape))) == NULL) return NULL;

    signal(SIGPIPE, SIG_IGN);

    fdev = &ape->events;
    fdev->handler = EVENT_UNKNOWN;
    #ifdef USE_EPOLL_HANDLER
    fdev->handler = EVENT_EPOLL;
    #endif
    #ifdef USE_KQUEUE_HANDLER
    fdev->handler = EVENT_ KQUEUE;
    #endif

    ape->basemem    = APE_BASEMEM;
    ape->is_running = 1;

    if (ape_dns_init(ape) != 0) {
        goto error;
    }
    events_init(ape);

    ape->seed = _ape_seed = time(NULL) ^ (getpid() << 16);

    ape->hashs.servers = hashtbl_init();

    if ((ape->conf = ape_read_config("../../etc/ape.conf", ape)) == NULL) {
        goto error;
    }

    return ape;

error:

    free(ape);

    return NULL;
}
예제 #13
0
static void init_uc ( )
{
	// config ports
	init_ports ( );

	// conifg timer
	timer_init ( );

	// config the ADC
	adc_init ( );

	// configure external interrupt request (keypress)
	init_ext_irq ( );

	events_init ( );

	dia_cntrl_init ( );

	return;
}
예제 #14
0
/**
 * Initialize the PEVC for the example.
 */
static void init_pevc(void)
{
	/* Set input glitch filter divider to 0x0A (2^10) */
	struct events_conf config;
	events_get_config_defaults(&config);
	events_init(&config);

	/*
	 * Setup and enable PEVC channel:
	 * - Generator: PAD_EVT 1
	 * - User: PDCA - channel 0 transfer one word
	 * - Enable falling edge detection for EVS
	 */
	struct events_ch_conf ch_config;
	events_ch_get_config_defaults(&ch_config);
	ch_config.channel_id = PEVC_ID_USER_PDCA_0;
	ch_config.generator_id = PEVC_ID_GEN_PAD_1;
	ch_config.shaper_enable = true;
	ch_config.igf_edge = EVENT_IGF_EDGE_FALLING;
	events_ch_configure(&ch_config);
	events_ch_enable(PEVC_ID_USER_PDCA_0);
}
예제 #15
0
bool pump()
{
	// Quick aborts:
	if(!events_init())
		return false;
	assert(resources::lua_kernel != NULL);
	if ( events_queue.empty() ) {
		DBG_EH << "Processing queued events, but none found.\n";
		return false;
	}
	if(pump_manager::count() >= game_config::max_loop) {
		ERR_NG << "game_events::pump() waiting to process new events because "
		       << "recursion level would exceed maximum: " << game_config::max_loop << '\n';
		return false;
	}
	if(!lg::debug.dont_log("event_handler")) {
		std::stringstream ss;
		BOOST_FOREACH(const queued_event& ev, events_queue) {
			ss << "name=" << ev.name << "; ";
		}
		DBG_EH << "processing queued events: " << ss.str() << "\n";
	}
예제 #16
0
void notmain(void) {
	int i;

	hardware_init();
	dmx_init();

	hardware_print_board_model();
	printf("Compiled on %s at %s\n", __DATE__, __TIME__);
	printf("Logic RDM Sniffer, DMX512 data analyzer for 32 channels");

	hardware_watchdog_init();

	events_init();

	for (;;) {
		hardware_watchdog_feed();
		for (i = 0; i < (int)(sizeof(poll_table) / sizeof(poll_table[0])); i++) {
			poll_table[i].f();
		}

		events_check();
	}
}
예제 #17
0
파일: main.c 프로젝트: glockwork/rpidmx512
int notmain(unsigned int earlypc) {
#ifdef ENABLE_FRAMEBUFFER
	fb_init();

	printf("Compiled on %s at %s\n", __DATE__, __TIME__);
	printf("DMX512 Sender\n");
#endif

#ifdef BW_I2C_UI
#endif

	led_init();
	led_set(1);

	bcm2835_gpio_fsel(ANALYZER_CH1, BCM2835_GPIO_FSEL_OUTP); // IDLE
	bcm2835_gpio_fsel(ANALYZER_CH2, BCM2835_GPIO_FSEL_OUTP); // BREAK
	bcm2835_gpio_fsel(ANALYZER_CH3, BCM2835_GPIO_FSEL_OUTP); // DATA
	bcm2835_gpio_fsel(ANALYZER_CH4, BCM2835_GPIO_FSEL_OUTP); // MAB

	bcm2835_gpio_set(ANALYZER_CH1); // IDLE
	bcm2835_gpio_clr(ANALYZER_CH2);	// BREAK
	bcm2835_gpio_clr(ANALYZER_CH3); // DATA
	bcm2835_gpio_clr(ANALYZER_CH4);	// MAB

	bcm2835_pl011_dmx512_begin();
	bcm2835_gpio_fsel(18, BCM2835_GPIO_FSEL_OUTP);
	bcm2835_gpio_set(18);

	events_init();

	for (;;) {
		events_check();
	}

	return (0);
}
예제 #18
0
파일: core.c 프로젝트: adrianlshaw/libvmi
static status_t
vmi_init_private(
    vmi_instance_t *vmi,
    uint32_t flags,
    unsigned long id,
    char *name,
    vmi_config_t *config)
{
    uint32_t access_mode = flags & 0x0000FFFF;
    uint32_t init_mode = flags & 0x00FF0000;
    uint32_t config_mode = flags & 0xFF000000;
    status_t status = VMI_FAILURE;

    /* allocate memory for instance structure */
    *vmi = (vmi_instance_t) safe_malloc(sizeof(struct vmi_instance));
    memset(*vmi, 0, sizeof(struct vmi_instance));

    /* initialize instance struct to default values */
    dbprint("LibVMI Version 0.9_alpha\n");  //TODO change this with each release

    /* save the flags and init mode */
    (*vmi)->flags = flags;
    (*vmi)->init_mode = init_mode;
    (*vmi)->config = config;
    (*vmi)->config_mode = config_mode;

    /* setup the caches */
    pid_cache_init(*vmi);
    sym_cache_init(*vmi);
    rva_cache_init(*vmi);
    v2p_cache_init(*vmi);

    /* connecting to xen, kvm, file, etc */
    if (VMI_FAILURE == set_driver_type(*vmi, access_mode, id, name)) {
        goto error_exit;
    }

    /* resolve the id and name */
    if (VMI_FAILURE == set_id_and_name(*vmi, access_mode, id, name)) {
        goto error_exit;
    }

    /* driver-specific initilization */
    if (VMI_FAILURE == driver_init(*vmi)) {
        goto error_exit;
    }
    dbprint("--completed driver init.\n");

    /* we check VMI_INIT_COMPLETE first as
       VMI_INIT_PARTIAL is not exclusive */
    if (init_mode & VMI_INIT_COMPLETE) {

        /* init_complete requires configuration */
        if(VMI_CONFIG_NONE & (*vmi)->config_mode) {
            /* falling back to VMI_CONFIG_GLOBAL_FILE_ENTRY is unsafe here
                as the config pointer is probably NULL */
            goto error_exit;
        }
        /* read and parse the config file */
        else if ( (VMI_CONFIG_STRING & (*vmi)->config_mode || VMI_CONFIG_GLOBAL_FILE_ENTRY & (*vmi)->config_mode)
                 && VMI_FAILURE == read_config_file(*vmi)) {
            goto error_exit;
        }
        /* read and parse the ghashtable */
        else if (VMI_CONFIG_GHASHTABLE & (*vmi)->config_mode
                 && VMI_FAILURE == read_config_ghashtable(*vmi)) {
            dbprint("--failed to parse ghashtable\n");
            goto error_exit;
        }

        /* setup the correct page offset size for the target OS */
        if (VMI_FAILURE == init_page_offset(*vmi)) {
            goto error_exit;
        }

        /* get the memory size */
        if (driver_get_memsize(*vmi, &(*vmi)->size) == VMI_FAILURE) {
            errprint("Failed to get memory size.\n");
            goto error_exit;
        }
        dbprint("**set size = %"PRIu64" [0x%"PRIx64"]\n", (*vmi)->size,
                (*vmi)->size);

        /* determine the page sizes and layout for target OS */

        // Find the memory layout. If this fails, then proceed with the
        // OS-specific heuristic techniques.
        (*vmi)->pae = (*vmi)->pse = (*vmi)->lme = (*vmi)->cr3 = 0;
        (*vmi)->page_mode = VMI_PM_UNKNOWN;

        status = get_memory_layout(*vmi,
                                        &((*vmi)->page_mode),
                                        &((*vmi)->cr3),
                                        &((*vmi)->pae),
                                        &((*vmi)->pse),
                                        &((*vmi)->lme));

        if (VMI_FAILURE == status) {
            dbprint
                ("**Failed to get memory layout for VM. Trying heuristic method.\n");
            // fall-through
        }   // if

        // Heuristic method
        if (!(*vmi)->cr3) {
            (*vmi)->cr3 = find_cr3((*vmi));
            dbprint("**set cr3 = 0x%.16"PRIx64"\n", (*vmi)->cr3);
        }   // if

        /* setup OS specific stuff */
        if (VMI_OS_LINUX == (*vmi)->os_type) {
            status = linux_init(*vmi);
        }
        else if (VMI_OS_WINDOWS == (*vmi)->os_type) {
            status = windows_init(*vmi);
        }

        /* Enable event handlers only if we're in a consistent state */
        if((status == VMI_SUCCESS) && (init_mode & VMI_INIT_EVENTS)){
            events_init(*vmi);
        }

        return status;
    } else if (init_mode & VMI_INIT_PARTIAL) {
        init_page_offset(*vmi);
        driver_get_memsize(*vmi, &(*vmi)->size);

        /* Enable event handlers */
        if(init_mode & VMI_INIT_EVENTS){
            events_init(*vmi);
        }

        return VMI_SUCCESS;
    }

error_exit:
    return status;
}
예제 #19
0
int main(int argc, char **argv) 
{
	apeconfig *srv;
	
	int random, im_r00t = 0, pidfd = 0, serverfd;
	unsigned int getrandom = 0, ct_id;
	const char *pidfile = NULL;
	char *confs_path = NULL;
	
	struct _fdevent fdev;
	
	char cfgfile[513] = APE_CONFIG_FILE;
	
	acetables *g_ape;
	
	if (argc > 1 && strcmp(argv[1], "--version") == 0) {
		printf("\n   AJAX Push Engine Server %s - (C) Anthony Catel <*****@*****.**>\n   http://www.ape-project.org/\n\n", _VERSION);
		return 0;
	}
	if (argc > 1 && strcmp(argv[1], "--help") == 0) {
		printf("\n   AJAX Push Engine Server %s - (C) Anthony Catel <*****@*****.**>\n   http://www.ape-project.org/\n", _VERSION);
		printf("\n   usage: aped [options]\n\n");
		printf("   Options:\n     --help             : Display this help\n     --version          : Show version number\n     --cfg <config path>: Load a specific config file (default is %s)\n\n", cfgfile);
		return 0;
	} else if (argc > 2 && strcmp(argv[1], "--cfg") == 0) {
		memset(cfgfile, 0, 513);
		strncpy(cfgfile, argv[2], 512);
		confs_path = get_path(cfgfile);
	} else if (argc > 1) {
		printf("\n   AJAX Push Engine Server %s - (C) Anthony Catel <*****@*****.**>\n   http://www.ape-project.org/\n\n", _VERSION);
		printf("   Unknown parameters - check \"aped --help\"\n\n");
		return 0;
	}
	if (NULL == (srv = ape_config_load(cfgfile))) {
		printf("\nExited...\n\n");
		exit(1);
	}
	
	if (getuid() == 0) {
		im_r00t = 1;
	}

	signal(SIGINT, &signal_handler);
	signal(SIGTERM, &signal_handler);
	
	if (VTICKS_RATE < 1) {
		printf("[ERR] TICKS_RATE cant be less than 1\n");
		return 0;
	}
	
	random = open("/dev/urandom", O_RDONLY);
	if (!random) {
		printf("Cannot open /dev/urandom... exiting\n");
		return 0;
	}
	read(random, &getrandom, 3);
	srand(getrandom);
	close(random);

	g_ape = xmalloc(sizeof(*g_ape));
	g_ape->basemem = 1; // set 1 for testing if growup works
	g_ape->srv = srv;
	g_ape->confs_path = confs_path;
	g_ape->is_daemon = 0;
	
	ape_log_init(g_ape);
	
	fdev.handler = EVENT_UNKNOWN;

	#ifdef USE_EPOLL_HANDLER
	fdev.handler = EVENT_EPOLL;
	#endif
	#ifdef USE_KQUEUE_HANDLER
	fdev.handler = EVENT_KQUEUE;
	#endif

	g_ape->co = xmalloc(sizeof(*g_ape->co) * g_ape->basemem);
	memset(g_ape->co, 0, sizeof(*g_ape->co) * g_ape->basemem);
	
	g_ape->bad_cmd_callbacks = NULL;
	g_ape->bufout = xmalloc(sizeof(struct _socks_bufout) * g_ape->basemem);
	
	g_ape->timers.timers = NULL;
	g_ape->timers.ntimers = 0;
	g_ape->events = &fdev;
	if (events_init(g_ape, &g_ape->basemem) == -1) {
		printf("Fatal error: APE compiled without an event handler... exiting\n");
		return 0;
	};
	
	serverfd = servers_init(g_ape);
	
	ape_log(APE_INFO, __FILE__, __LINE__, g_ape, 
		"APE starting up - pid : %i", getpid());
	
	if (strcmp(CONFIG_VAL(Server, daemon, srv), "yes") == 0 && (pidfile = CONFIG_VAL(Server, pid_file, srv)) != NULL) {
		if ((pidfd = open(pidfile, O_TRUNC | O_WRONLY | O_CREAT, 0655)) == -1) {
			ape_log(APE_WARN, __FILE__, __LINE__, g_ape, 
				"Cant open pid file : %s", CONFIG_VAL(Server, pid_file, srv));
		}
	}
	
	if (im_r00t) {
		struct group *grp = NULL;
		struct passwd *pwd = NULL;
		
		if (inc_rlimit(atoi(CONFIG_VAL(Server, rlimit_nofile, srv))) == -1) {
			ape_log(APE_WARN, __FILE__, __LINE__, g_ape, 
				"Cannot set the max filedescriptos limit (setrlimit) %s", strerror(errno));
		}
		
		/* Set uid when uid section exists */
		if (ape_config_get_section(srv, "uid")) {

			/* Get the user information (uid section) */
			if ((pwd = getpwnam(CONFIG_VAL(uid, user, srv))) == NULL) {
				ape_log(APE_ERR, __FILE__, __LINE__, g_ape, 
					"Can\'t find username %s", CONFIG_VAL(uid, user, srv));
				return -1;
			}
			if (pwd->pw_uid == 0) {
				ape_log(APE_ERR, __FILE__, __LINE__, g_ape, 
					"%s uid can\'t be 0", CONFIG_VAL(uid, user, srv));
				return -1;			
			}
			
			/* Get the group information (uid section) */
			if ((grp = getgrnam(CONFIG_VAL(uid, group, srv))) == NULL) {
				printf("[ERR] Can\'t find group %s\n", CONFIG_VAL(uid, group, srv));
				ape_log(APE_ERR, __FILE__, __LINE__, g_ape, 
					"Can\'t find group %s", CONFIG_VAL(uid, group, srv));
				return -1;
			}
			
			if (grp->gr_gid == 0) {
				ape_log(APE_ERR, __FILE__, __LINE__, g_ape, 
				"%s gid can\'t be 0", CONFIG_VAL(uid, group, srv));
			return -1;
			}
		
			setgid(grp->gr_gid);
			setgroups(0, NULL);

			initgroups(CONFIG_VAL(uid, user, srv), grp->gr_gid);
		
			setuid(pwd->pw_uid);
		}

	} else {
		printf("[WARN] You have to run \'aped\' as root to increase r_limit\n");
		ape_log(APE_WARN, __FILE__, __LINE__, g_ape, 
			"You have to run \'aped\' as root to increase r_limit");
	}
	
	if (strcmp(CONFIG_VAL(Server, daemon, srv), "yes") == 0) {
		ape_log(APE_INFO, __FILE__, __LINE__, g_ape, 
			"Starting daemon");
		ape_daemon(pidfd, g_ape);

		events_reload(g_ape->events);
		events_add(g_ape->events, serverfd, EVENT_READ);
	}
	
	if (!g_ape->is_daemon) {	
		printf("   _   ___ ___ \n");
		printf("  /_\\ | _ \\ __|\n");
		printf(" / _ \\|  _/ _| \n");
		printf("/_/ \\_\\_| |___|\nAJAX Push Engine\n\n");

		printf("Bind on port %i\n\n", atoi(CONFIG_VAL(Server, port, srv)));
		printf("Version : %s\n", _VERSION);
		printf("Build   : %s %s\n", __DATE__, __TIME__);
		printf("Author  : Weelya ([email protected])\n\n");		
	}
	signal(SIGPIPE, SIG_IGN);
	
	ape_dns_init(g_ape);
	
	g_ape->cmd_hook.head = NULL;
	g_ape->cmd_hook.foot = NULL;
	
	g_ape->hSessid = hashtbl_init();

	g_ape->hChannel = hashtbl_init();
	g_ape->hPubid = hashtbl_init();
	
	g_ape->proxy.list = NULL;
	g_ape->proxy.hosts = NULL;
	
	g_ape->hCallback = hashtbl_init();

	g_ape->uHead = NULL;
	g_ape->cHead = NULL;
	
	g_ape->nConnected = 0;
	g_ape->plugins = NULL;
	
	g_ape->properties = NULL;

	ct_id = add_ticked(check_timeout, g_ape)->identifier;
	
	do_register(g_ape);
	
	transport_start(g_ape);	
	
	findandloadplugin(g_ape);

	server_is_running = 1;
	server_is_shutdowning = 0;

	/* Starting Up */
	sockroutine(g_ape); /* loop */
	/* Shutdown */	
	
	if (pidfile != NULL) {
		unlink(pidfile);
	}
	
	free(confs_path);

	ape_dns_free(g_ape);

	del_timer_identifier(ct_id, g_ape);

	events_free(g_ape);

	transport_free(g_ape);

	hashtbl_free(g_ape->hSessid, 0);
	hashtbl_free(g_ape->hChannel, 0);
	hashtbl_free(g_ape->hPubid, 0);
	
	do_unregister(g_ape);
	hashtbl_free(g_ape->hCallback, 1);
	
	ape_config_free(srv);

	int i;
	for (i = 0; i < g_ape->basemem; i++) {
		if (g_ape->co[i] != NULL) {
			close_socket(i, g_ape);
			free(g_ape->co[i]);
		}
	}
	free(g_ape->co);

	free(g_ape->bufout);

	free_all_hook_cmd(g_ape);
	free_all_plugins(g_ape);

	free(g_ape);
	
	return 0;
}
예제 #20
0
//----------------------------------- Main -------------------------------------
int main(int argc, char *argv[])
{
    std::string cheat_string = "cheat";
    //std::locale::global( std::locale( "" ) );
    events_init();
    game.log.File_Set("Star.P.G..log");
    game.log.File_Clear();
    if (argc > 1)
    {
        for (int count = 0; count < (argc+1); count++)
        {
            //game.log.File_Write(argv[count]);
            if (cheat_string.compare(argv[count]) == 0) game_o.cheats_enabled = true;
        }
    }
    //game_o.cheats_enabled = true; /// test!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    game.log.File_Write("------------------");
    game.log.File_Write("| Star.P.G V1.01 |");
    game.log.File_Write("------------------\n");
    game.log.File_Write("Starting up!");
    game.log.File_Write("");
    game.log.File_Write("------------------\n");
    //if (game_o.cheats_enabled) game.log.File_Write("Cheating enabled!\n");
    game.config.File_Set("Star.P.G..cfg");
    game.config.Set_Defaults();
    game.log.File_Write("Loading config...");
    game.config.File_Set("Star.P.G..cfg");
    game.config.File_Read();
    game.log.File_Write("Loading language file -> data/configuration/languages/"+game.config.language+".txt");
    game_o.language.load("data/configuration/languages/"+game.config.language+".txt");
 //----------------------------------- Start the PhysicsFS ----------------------
    //game.log.File_Write("Starting PhysicsFS...");
    //PHYSFS_init(argv[0]);
    //PHYSFS_addToSearchPath("Star.P.G..spg", 1);
//----------------------------------- SDL Video --------------------------------
    game.log.File_Write("Starting SDL...");
    char SDL_VID_WIN_POS[] = "SDL_VIDEO_WINDOW_POS";
    char SDL_VID_CENTERD[] = "SDL_VIDEO_CENTERED=1";
    putenv(SDL_VID_WIN_POS);
    putenv(SDL_VID_CENTERD);
    getenv("SDL_VIDEO_WINDOW_POS");
    getenv("SDL_VIDEO_CENTERED");
    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTTHREAD);
    game.log.File_Write("Starting OpenGL...");
    if (game.config.Display_Fullscreen) SDL_SetVideoMode(game.config.Display_X_Resolution,game.config.Display_Y_Resolution,game.config.Display_BPS,SDL_OPENGL | SDL_FULLSCREEN);
    else SDL_SetVideoMode(game.config.Display_X_Resolution,game.config.Display_Y_Resolution,game.config.Display_BPS,SDL_OPENGL/* | SDL_NOFRAME */);
    SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
    App_Icon_Surface = SDL_LoadBMP(App_Icon);
    colorkey = SDL_MapRGB(App_Icon_Surface->format, 255, 0, 255);
    SDL_SetColorKey(App_Icon_Surface, SDL_SRCCOLORKEY, colorkey);
    SDL_WM_SetIcon(App_Icon_Surface,NULL);
    SDL_WM_SetCaption(App_Name, 0);
    //SDL_ShowCursor(SDL_DISABLE);
//----------------------------------- SDL Audio --------------------------------
    game.log.File_Write("Starting sound system...");
    SDL_Init(SDL_INIT_AUDIO);
    Mix_AllocateChannels(game.config.Audio_Channels);
    Mix_OpenAudio(game.config.Audio_Rate, AUDIO_S16, 2, game.config.Audio_Buffers);
    Mix_Volume(-1,game.config.Audio_Sound_Volume);
    Mix_VolumeMusic(game.config.Audio_Music_Volume);
    game.log.File_Write("Initializing joystick / gamepad...");
    SDL_Init(SDL_INIT_JOYSTICK);
    game.log.File_Write("Initializing game system...");
    init_game(false);
    game.log.File_Write("Initializing projectiles...");
    init_player_bullets();
    game.log.File_Write("Initializing explosions...");
    init_explosions();
    game.log.File_Write("Initializing NPCs...\n");
    init_active_npcs();
    init_npc_bullets();
    init_npcs(0);
    game_o.current_level = 0;
    game.log.File_Write("Initializing OpenGL...");
    game.graphics.init_gl(game.config.Display_X_Resolution,game.config.Display_Y_Resolution);
    seed_rand();
    TTF_Init();
    game.log.File_Write("Loading resources...");
    loading_screen_display("data/textures/misc/loading_screen.png");
    load_resources();
    game.log.File_Write("Initializing menu system...");
    init_menu();
    init_in_game_message_class();
    init_projectiles(false);
    init_powerups();
    init_shields(false);
    init_game(false);
    game.log.File_Write("Starting game...");
    game.log.File_Write("---------------\n");
//----------------------------------- Main loop --------------------------------
    game.timer.start();
    game.LastTicks = game.timer.getticks();
    for(int quit = 0; !quit;)
    {
        game.config.process(false);
        if (game.config.mouse_autohide) SDL_ShowCursor(SDL_DISABLE);
        else SDL_ShowCursor(SDL_ENABLE);
        proc_textures();
        events_process();
        if (game.status_quit_active) quit = 1;
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//****************************************** MENU *****************************************
        if (game.menu_active)
        {
            SDL_ShowCursor(SDL_ENABLE);
            if (game.music_next_track)
            {
                music.menu_00.play();
                game.music_next_track = false;
            }
            diplay_menu ();
            if (game.process_ready) game.background.process();
            if (game.process_ready) process_menu();
        }
//****************************************** GAME *****************************************
        if (game.game_active)
        {
            if (game.music_next_track)
            {
                game.music_next_track = false;
                if (game.music_track ==  0) music.level_00.play();
                if (game.music_track ==  1) music.level_01.play();
                if (game.music_track ==  2) music.level_02.play();
                if (game.music_track ==  3) music.level_03.play();
                if (game.music_track ==  4) music.level_04.play();
                if (game.music_track ==  5) music.level_05.play();
                if (game.music_track ==  6) music.level_06.play();
                if (game.music_track ==  7) music.level_07.play();
                if (game.music_track ==  8) music.level_08.play();
                if (game.music_track ==  9) music.level_09.play();
                if (game.music_track == 10) music.level_10.play();
                if (game.music_track == 11) music.level_11.play();
                if (game.music_track == 12) music.level_12.play();
                if (game.music_track == 13) music.level_13.play();
                if (game.music_track == 14) music.level_14.play();
                if (game.music_track == 15) music.level_15.play();
                if (game.music_track == 16) music.level_16.play();
                if (game.music_track == 17) music.level_17.play();
                if (game.music_track == 18) music.level_18.play();
                if (game.music_track == 19) music.level_19.play();
                if (game.music_track == 20) music.level_20.play();
                if (game.music_track == 21) music.level_21.play();
                if (game.music_track == 22) music.level_22.play();
                if (game.music_track == 23) music.level_23.play();
                if (game.music_track == 24) music.level_24.play();
                if (game.music_track == 25) music.level_25.play();
            }
            game.game_resume = true;
            if (game.process_ready) process_game();
            display_game();
            if ((game.config.Display_Touchscreen) && (game.process_ready))
            {
                if(game.physics.point_in_quadrangle(-0.875f,0.2f,-0.550f,0.2f,game.io.mouse_x,game.io.mouse_y)) game.io.left = true;
                if(game.physics.point_in_quadrangle(-0.475f,0.2f,-0.550f,0.2f,game.io.mouse_x,game.io.mouse_y)) game.io.right = true;
                if(game.physics.point_in_quadrangle(-0.675f,0.2f,-0.350f,0.2f,game.io.mouse_x,game.io.mouse_y)) game.io.up = true;
                if(game.physics.point_in_quadrangle(-0.675f,0.2f,-0.750f,0.2f,game.io.mouse_x,game.io.mouse_y)) game.io.down = true;
                if(game.physics.point_in_quadrangle( 0.875f,0.2f,-0.750f,0.2f,game.io.mouse_x,game.io.mouse_y)) game.io.shoot = true;
                if(game.physics.point_in_quadrangle( 0.575f,0.2f,-0.750f,0.2f,game.io.mouse_x,game.io.mouse_y)) game.io.key_b = true;
                if(game.physics.point_in_quadrangle( 0.875f,0.2f, 0.750f,0.2f,game.io.mouse_x,game.io.mouse_y)) game.io.escape = true;
            }
            if (game_o.player.health < 0)
            {
                sound.menu_select_00.play();
                game.game_active             = false;
                game.game_resume             = false;
                game.pdie_active             = true;
                game.menu_level              = 8;
                game.config.menu_delay_count = 0;
                music.level_pd.play();
                game.background.set_data  ( 2, 1, 1, 0.0f, 0.0f, 0.0050f, 0.0050f, texture.background_019.ref_number);
                game.background.set_data  ( 1, 1, 1, 0.0f, 0.0f, 0.0020f, 0.0020f, texture.background_008.ref_number);
                game.background.set_active( 3, false);
                game.background.set_active( 4, false);
                game.background.set_movement_type(BOUNCE);
                SDL_WarpMouse(game.graphics.gl_to_res(game_over_menu.get_button_x_pos(1),game.config.mouse_resolution_x),game.config.mouse_resolution_y-game.graphics.gl_to_res(game_over_menu.get_button_y_pos(1),game.config.mouse_resolution_y));
                game.log.File_Write("User terminated due to insufficient health...better luck next time buddy!");
            }
        if ((game.io.escape) && (game.process_ready))
        {
            sound.menu_select_01.play();
            game.music_next_track        = true;
            game.game_active             = false;
            game.menu_level              = 1;
            game.menu_active             = true;
            game.io.escape               = false;
            game.io.keyboard_delay_count = 0;
            game.config.menu_delay_count = 0;
            while (game.config.menu_delay_count < (game.config.menu_delay/2))
            {
                game.config.menu_delay_count++;
            }
        }

        if (game_o.bomb_delay_count < game_o.bomb_delay)//bomb delay counter
        {
            game_o.bomb_delay_count++;
            if (game_o.bomb_delay_count > game_o.bomb_delay) game_o.bomb_delay_count = game_o.bomb_delay;
        }
        if ((game.io.key_b) && (game.process_ready))//user pressed "b" for bomb
        {
            if ((game_o.number_bombs > 0) && (game_o.bomb_delay_count >= game_o.bomb_delay))
            {
                game_o.number_bombs--;
                use_bomb_powerup();
                game_o.bomb_delay_count = 0;
                if (!game_o.rumble.active) sound.explosion_001.play();
                if (!game_o.rumble.active) game_o.rumble.start(0.025f,45); // shake the screen about.
            }
        }
        if (game.io.pause)
        {
            if (!game.game_paused)
            {
                game_o.paused.spawn();
                game.game_paused = true;
                game.game_active = false;
                game.io.pause    = false;
                game.menu_level  = 11;
                SDL_WarpMouse(game.graphics.gl_to_res(pause_menu.get_button_x_pos(1),game.config.mouse_resolution_x),game.config.mouse_resolution_y-game.graphics.gl_to_res(pause_menu.get_button_y_pos(1),game.config.mouse_resolution_y));
                game.config.menu_delay_count = 0;
                while (game.config.menu_delay_count < (game.config.menu_delay*16))
                {
                    game.config.menu_delay_count++;
                }
            }
            else
            {
                game.menu_active = false;
                game.game_paused = false;
                game.game_active = true;
            }
        };

        if (game_o.cheats_enabled == true)
        {
            if (game.io.key_0) game_o.victory_kills = game_o.level_kills;  //complete level
            if (game.io.key_1) spawn_powerup(1.0f,random_GLcoord(), 1);//spawn health power-up
            if (game.io.key_2) spawn_powerup(1.0f,random_GLcoord(), 2);//spawn shield level power-up
            if (game.io.key_3) spawn_powerup(1.0f,random_GLcoord(), 3);//spawn shield new power-up
            if (game.io.key_4) spawn_powerup(1.0f,random_GLcoord(), 4);//spawn thruster level power-up
            if (game.io.key_5) spawn_powerup(1.0f,random_GLcoord(), 5);//spawn thruster new power-up
            if (game.io.key_6) spawn_powerup(1.0f,random_GLcoord(), 6);//spawn weapon level power-up
            if (game.io.key_7) spawn_powerup(1.0f,random_GLcoord(), 7);//spawn weapon new power-up
            if (game.io.key_8) unlock_levels();                        //unlock all levels
            if (game.io.key_9) spawn_powerup(1.0f,random_GLcoord(), 8);//spawn bomb power-up
            if (game.io.key_a) game_o.anc_enabled   = !game_o.anc_enabled; //toggle active NPC count display
            if (game.io.key_f) game_o.fps_enabled   = !game_o.fps_enabled; //toggle active NPC count display
            if (game.io.key_q) spawn_powerup(1.0f,random_GLcoord(), 9);//spawn support ship 0 power-up
            if (game.io.key_w) spawn_powerup(1.0f,random_GLcoord(),10);//spawn support ship 1 power-up
            if (game.io.key_e) spawn_powerup(1.0f,random_GLcoord(),11);//spawn support ship 2 power-up
            if (game.io.key_r) spawn_powerup(1.0f,random_GLcoord(),12);//spawn support ship 3 power-up
            if (game.io.key_s)
            {
                if (!game_o.rumble.active) sound.explosion_001.play();
                if (!game_o.rumble.active) game_o.rumble.start(); // shake the screen about.
            }
        }

        if (game.io.shoot)
        {
           process_supportships(true);
           if(game_o.fw_rof_count >= game_o.projectile[game_o.player.front_weapon].rate_of_fire)
           {
              spawn_player_bullet(0);
              game_o.fw_rof_count = 0;
           }
           if(game_o.sw_rof_count >= game_o.projectile[game_o.player.side_weapon].rate_of_fire)
           {
              spawn_player_bullet(1);
              game_o.sw_rof_count = 0;
           }
        }
        else
        {
            process_supportships(false);
        }
        if (game.process_ready)
        {
            if (game.io.up)    process_player(1);
            if (game.io.down)  process_player(2);
            if (game.io.right) process_player(3);
            if (game.io.left)  process_player(4);
        }
        if ((game.io.key_1) && (game_o.projectile[ 0].active))
        {
            game_o.player.front_weapon = 0;
        }
        if ((game.io.key_2) && (game_o.projectile[ 1].active))
        {
            game_o.player.front_weapon = 1;
        }
        if ((game.io.key_3) && (game_o.projectile[ 2].active))
        {
            game_o.player.front_weapon = 2;
        }
        if ((game.io.key_4) && (game_o.projectile[ 3].active))
        {
            game_o.player.front_weapon = 3;
        }
        if ((game.io.key_5) && (game_o.projectile[ 4].active))
        {
            game_o.player.front_weapon = 4;
        }
        if ((game.io.key_6) && (game_o.projectile[ 5].active))
        {
            game_o.player.front_weapon = 5;
        }
    }
//*********************************** Game paused *****************************************
        if (game.game_paused)
        {
            if ((game.io.pause) && (game.process_ready))
            {
                game.menu_active = false;
                game.game_paused = false;
                game.game_active = true;
            }
            if (game.music_next_track)
            {
                game.music_next_track = false;
                music.level_pd.play();
            }
            game.menu_level = 11;
            if (game.process_ready) game.background.process();
            if (game.process_ready) process_menu();
            display_game();
            diplay_menu ();
         }
//*********************************** PLAYER DEATH SCREEN *****************************************
        if (game.pdie_active)
        {
            if (game.music_next_track)
            {
                game.music_next_track = false;
                music.level_pd.play();
            }
            diplay_menu ();
            if (game.process_ready) game.background.process();
            if (game.process_ready) process_menu();
            if (!game.pdie_active)  init_game(true);
        }
//******************************* PLAYER NEXT LEVEL SCREEN *************************************
        if (game.nlvl_active)
        {
            if (game.music_next_track)
            {
                game.music_next_track = false;
                music.level_nl.play();
            }
            game.menu_level = 9;
            if (game.process_ready) game.background.process();
            if (game.process_ready) process_menu();
            diplay_menu ();
        }
//******************************* OUTRO SCREEN *************************************************
     if (game.outr_active)
        {
            if (game.music_next_track)
            {
                game.music_next_track = false;
                music.outro_00.play();
            }
            game.menu_level = 10;
            if (game.process_ready) game.background.process();
            if (game.process_ready) process_menu();
            diplay_menu ();
        }
//---------------------------- code for end of main loop -----------------------
        game.FPS = (game.timer.getticks() - game.LastTicks);
        if ((game.timer.getticks() - game.LastTicks) >= 2)
        {
            game.LastTicks = game.timer.getticks();
            game.process_ready = true;
        }
        else game.process_ready = false;
        SDL_GL_SwapBuffers();
    }
//----------------------------------- Exit -------------------------------------
    game.log.File_Write("Saving configuration...");
    game.config.File_Set("Star.P.G..cfg");
    game.config.File_Clear();
    game.config.File_Write();
    game.log.File_Write("\n");
    game.log.File_Write("Shutting down...");
    game.log.File_Write("---------------\n");
//    game.log.File_Write("PhysicsFS deinit...");
//    PHYSFS_deinit();
    game.log.File_Write("SDL deinit...");
    SDL_Quit();
    return(0);
}
예제 #21
0
파일: hypervisor.c 프로젝트: ryo/netbsd-src
/*
 * Attach the hypervisor.
 */
void
hypervisor_attach(device_t parent, device_t self, void *aux)
{

#if NPCI >0
#ifdef PCI_BUS_FIXUP
	int pci_maxbus = 0;
#endif
#endif /* NPCI */
	union hypervisor_attach_cookie hac;
	char xen_extra_version[XEN_EXTRAVERSION_LEN];
	static char xen_version_string[20];
	int rc;
	const struct sysctlnode *node = NULL;

	xenkernfs_init();

	xen_version = HYPERVISOR_xen_version(XENVER_version, NULL);
	memset(xen_extra_version, 0, sizeof(xen_extra_version));
	HYPERVISOR_xen_version(XENVER_extraversion, xen_extra_version);
	rc = snprintf(xen_version_string, 20, "%d.%d%s", XEN_MAJOR(xen_version),
		XEN_MINOR(xen_version), xen_extra_version);
	aprint_normal(": Xen version %s\n", xen_version_string);
	if (rc >= 20)
		aprint_debug(": xen_version_string truncated\n");

	sysctl_createv(NULL, 0, NULL, &node, 0,
	    CTLTYPE_NODE, "xen",
	    SYSCTL_DESCR("Xen top level node"),
	    NULL, 0, NULL, 0, CTL_MACHDEP, CTL_CREATE, CTL_EOL);

	if (node != NULL) {
		sysctl_createv(NULL, 0, &node, NULL, CTLFLAG_READONLY,
		    CTLTYPE_STRING, "version",
		    SYSCTL_DESCR("Xen hypervisor version"),
		    NULL, 0, xen_version_string, 0, CTL_CREATE, CTL_EOL);
	}

	aprint_verbose_dev(self, "features: ");
#define XEN_TST_F(n) \
	if (xen_feature(XENFEAT_##n)) \
		aprint_verbose(" %s", #n);

	XEN_TST_F(writable_page_tables);
	XEN_TST_F(writable_descriptor_tables);
	XEN_TST_F(auto_translated_physmap);
	XEN_TST_F(supervisor_mode_kernel);
	XEN_TST_F(pae_pgdir_above_4gb);
	XEN_TST_F(mmu_pt_update_preserve_ad);
	XEN_TST_F(highmem_assist);
	XEN_TST_F(gnttab_map_avail_bits);
	XEN_TST_F(hvm_callback_vector);
	XEN_TST_F(hvm_safe_pvclock);
	XEN_TST_F(hvm_pirqs);
#undef XEN_TST_F
	aprint_verbose("\n");

	xengnt_init();
	events_init();

	memset(&hac, 0, sizeof(hac));
	hac.hac_vcaa.vcaa_name = "vcpu";
	hac.hac_vcaa.vcaa_caa.cpu_number = 0;
	hac.hac_vcaa.vcaa_caa.cpu_role = CPU_ROLE_BP;
	hac.hac_vcaa.vcaa_caa.cpu_func = NULL; /* See xen/x86/cpu.c:vcpu_attach() */
	config_found_ia(self, "xendevbus", &hac.hac_vcaa, hypervisor_print);

#ifdef MULTIPROCESSOR

	/*
	 * The xenstore contains the configured number of vcpus.
	 * The xenstore however, is not accessible until much later in
	 * the boot sequence. We therefore bruteforce check for
	 * allocated vcpus (See: cpu.c:vcpu_match()) by iterating
	 * through the maximum supported by NetBSD MP.
	 */
	cpuid_t vcpuid;

	for (vcpuid = 1; vcpuid < maxcpus; vcpuid++) {
		memset(&hac, 0, sizeof(hac));
		hac.hac_vcaa.vcaa_name = "vcpu";
		hac.hac_vcaa.vcaa_caa.cpu_number = vcpuid;
		hac.hac_vcaa.vcaa_caa.cpu_role = CPU_ROLE_AP;
		hac.hac_vcaa.vcaa_caa.cpu_func = NULL; /* See xen/x86/cpu.c:vcpu_attach() */
		if (NULL == config_found_ia(self, "xendevbus", &hac.hac_vcaa,
			hypervisor_vcpu_print)) {
			break;
		}
	}

#endif /* MULTIPROCESSOR */

#if NXENBUS > 0
	memset(&hac, 0, sizeof(hac));
	hac.hac_xenbus.xa_device = "xenbus";
	config_found_ia(self, "xendevbus", &hac.hac_xenbus, hypervisor_print);
#endif
#if NXENCONS > 0
	memset(&hac, 0, sizeof(hac));
	hac.hac_xencons.xa_device = "xencons";
	config_found_ia(self, "xendevbus", &hac.hac_xencons, hypervisor_print);
#endif
#ifdef DOM0OPS
#if NPCI > 0
#if NACPICA > 0
	if (acpi_present) {
		memset(&hac, 0, sizeof(hac));
		hac.hac_acpi.aa_iot = x86_bus_space_io;
		hac.hac_acpi.aa_memt = x86_bus_space_mem;
		hac.hac_acpi.aa_pc = NULL;
		hac.hac_acpi.aa_pciflags =
			PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY |
			PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY |
			PCI_FLAGS_MWI_OKAY;
		hac.hac_acpi.aa_ic = &x86_isa_chipset;
		hac.hac_acpi.aa_dmat = &pci_bus_dma_tag;
#ifdef _LP64
		hac.hac_acpi.aa_dmat64 = &pci_bus_dma64_tag;
#else
		hac.hac_acpi.aa_dmat64 = NULL;
#endif /* _LP64 */
		config_found_ia(self, "acpibus", &hac.hac_acpi, 0);
	}
#endif /* NACPICA */
	memset(&hac, 0, sizeof(hac));
	hac.hac_pba.pba_iot = x86_bus_space_io;
	hac.hac_pba.pba_memt = x86_bus_space_mem;
	hac.hac_pba.pba_dmat = &pci_bus_dma_tag;
#ifdef _LP64
	hac.hac_pba.pba_dmat64 = &pci_bus_dma64_tag;
#else
	hac.hac_pba.pba_dmat64 = NULL;
#endif /* _LP64 */
	hac.hac_pba.pba_flags = PCI_FLAGS_MEM_OKAY | PCI_FLAGS_IO_OKAY;
	hac.hac_pba.pba_bridgetag = NULL;
	hac.hac_pba.pba_bus = 0;
#if NACPICA > 0 && defined(ACPI_SCANPCI)
	if (mpacpi_active)
		mp_pci_scan(self, &hac.hac_pba, pcibusprint);
	else
#endif
#if defined(MPBIOS) && defined(MPBIOS_SCANPCI)
	if (mpbios_scanned != 0)
		mp_pci_scan(self, &hac.hac_pba, pcibusprint);
	else
#endif
	config_found_ia(self, "pcibus", &hac.hac_pba, pcibusprint);
#if NACPICA > 0
	if (mp_verbose)
		acpi_pci_link_state();
#endif
#if NISA > 0
	if (isa_has_been_seen == 0) {
		memset(&hac, 0, sizeof(hac));
		hac.hac_iba._iba_busname = "isa";
		hac.hac_iba.iba_iot = x86_bus_space_io;
		hac.hac_iba.iba_memt = x86_bus_space_mem;
		hac.hac_iba.iba_dmat = &isa_bus_dma_tag;
		hac.hac_iba.iba_ic = NULL; /* No isa DMA yet */
		config_found_ia(self, "isabus", &hac.hac_iba, isabusprint);
	}
#endif /* NISA */
#endif /* NPCI */

	if (xendomain_is_privileged()) {
		xenprivcmd_init();
		xen_shm_init();
	}
#endif /* DOM0OPS */

	hypervisor_machdep_attach();

	if (!pmf_device_register(self, hypervisor_suspend, hypervisor_resume))
		aprint_error_dev(self, "couldn't establish power handler\n");

}
예제 #22
0
파일: main.c 프로젝트: BrEacK/mc
int
main (int argc, char *argv[])
{
    GError *error = NULL;
    int exit_code = EXIT_FAILURE;

    /* We had LC_CTYPE before, LC_ALL includs LC_TYPE as well */
    (void) setlocale (LC_ALL, "");
    (void) bindtextdomain ("mc", LOCALEDIR);
    (void) textdomain ("mc");

    /* do this before args parsing */
    str_init_strings (NULL);

    if (!mc_args_parse (&argc, &argv, "mc", &error))
    {
      startup_exit_falure:
        fprintf (stderr, _("Failed to run:\n%s\n"), error->message);
        g_error_free (error);
        g_free (shell);
      startup_exit_ok:
        str_uninit_strings ();
        return exit_code;
    }

    /* do this before mc_args_show_info () to view paths in the --datadir-info output */
    OS_Setup ();

    if (!g_path_is_absolute (mc_config_get_home_dir ()))
    {
        error = g_error_new (MC_ERROR, 0, "%s: %s", _("Home directory path is not absolute"),
                             mc_config_get_home_dir ());
        mc_event_deinit (NULL);
        goto startup_exit_falure;
    }

    if (!mc_args_show_info ())
    {
        exit_code = EXIT_SUCCESS;
        goto startup_exit_ok;
    }

    if (!events_init (&error))
        goto startup_exit_falure;

    mc_config_init_config_paths (&error);
    if (error == NULL && mc_config_deprecated_dir_present ())
        mc_config_migrate_from_old_place (&error);
    if (error != NULL)
    {
        mc_event_deinit (NULL);
        goto startup_exit_falure;
    }

    vfs_init ();
    vfs_plugins_init ();
    vfs_setup_work_dir ();

    /* do this after vfs initialization due to mc_setctl() call in mc_setup_by_args() */
    if (!mc_setup_by_args (argc, argv, &error))
    {
        vfs_shut ();
        mc_event_deinit (NULL);
        goto startup_exit_falure;
    }

    /* check terminal type
     * $TEMR must be set and not empty
     * mc_global.tty.xterm_flag is used in init_key() and tty_init()
     * Do this after mc_args_handle() where mc_args__force_xterm is set up.
     */
    mc_global.tty.xterm_flag = tty_check_term (mc_args__force_xterm);

    /* NOTE: This has to be called before tty_init or whatever routine
       calls any define_sequence */
    init_key ();

    /* Must be done before installing the SIGCHLD handler [[FIXME]] */
    handle_console (CONSOLE_INIT);

#ifdef HAVE_SUBSHELL_SUPPORT
    /* Don't use subshell when invoked as viewer or editor */
    if (mc_global.mc_run_mode != MC_RUN_FULL)
        mc_global.tty.use_subshell = FALSE;

    if (mc_global.tty.use_subshell)
        subshell_get_console_attributes ();
#endif /* HAVE_SUBSHELL_SUPPORT */

    /* Install the SIGCHLD handler; must be done before init_subshell() */
    init_sigchld ();

    /* We need this, since ncurses endwin () doesn't restore the signals */
    save_stop_handler ();

    /* Must be done before init_subshell, to set up the terminal size: */
    /* FIXME: Should be removed and LINES and COLS computed on subshell */
    tty_init (!mc_args__nomouse, mc_global.tty.xterm_flag);

    load_setup ();

    /* start check mc_global.display_codepage and mc_global.source_codepage */
    check_codeset ();

    /* Removing this from the X code let's us type C-c */
    load_key_defs ();

    load_keymap_defs (!mc_args__nokeymap);

    macros_list = g_array_new (TRUE, FALSE, sizeof (macros_t));

    tty_init_colors (mc_global.tty.disable_colors, mc_args__force_colors);

    mc_skin_init (&error);
    if (error != NULL)
    {
        message (D_ERROR, _("Warning"), "%s", error->message);
        g_error_free (error);
        error = NULL;
    }

    mc_filehighlight = mc_fhl_new (TRUE);
    dlg_set_default_colors ();

#ifdef HAVE_SUBSHELL_SUPPORT
    /* Done here to ensure that the subshell doesn't  */
    /* inherit the file descriptors opened below, etc */
    if (mc_global.tty.use_subshell)
        init_subshell ();

#endif /* HAVE_SUBSHELL_SUPPORT */

    /* Also done after init_subshell, to save any shell init file messages */
    if (mc_global.tty.console_flag != '\0')
        handle_console (CONSOLE_SAVE);

    if (mc_global.tty.alternate_plus_minus)
        application_keypad_mode ();

#ifdef HAVE_SUBSHELL_SUPPORT
    if (mc_global.tty.use_subshell)
    {
        mc_prompt = strip_ctrl_codes (subshell_prompt);
        if (mc_prompt == NULL)
            mc_prompt = (geteuid () == 0) ? "# " : "$ ";
    }
    else
#endif /* HAVE_SUBSHELL_SUPPORT */
        mc_prompt = (geteuid () == 0) ? "# " : "$ ";

    /* Program main loop */
    if (mc_global.midnight_shutdown)
        exit_code = EXIT_SUCCESS;
    else
        exit_code = do_nc ()? EXIT_SUCCESS : EXIT_FAILURE;

    /* Save the tree store */
    (void) tree_store_save ();

    free_keymap_defs ();

    /* Virtual File System shutdown */
    vfs_shut ();

    flush_extension_file ();    /* does only free memory */

    mc_fhl_free (&mc_filehighlight);
    mc_skin_deinit ();
    tty_colors_done ();

    tty_shutdown ();

    done_setup ();

    if (mc_global.tty.console_flag != '\0' && (quit & SUBSHELL_EXIT) == 0)
        handle_console (CONSOLE_RESTORE);
    if (mc_global.tty.alternate_plus_minus)
        numeric_keypad_mode ();

    (void) signal (SIGCHLD, SIG_DFL);   /* Disable the SIGCHLD handler */

    if (mc_global.tty.console_flag != '\0')
        handle_console (CONSOLE_DONE);

    if (mc_global.mc_run_mode == MC_RUN_FULL && mc_args__last_wd_file != NULL
        && last_wd_string != NULL && !print_last_revert)
    {
        int last_wd_fd;

        last_wd_fd = open (mc_args__last_wd_file, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL,
                           S_IRUSR | S_IWUSR);
        if (last_wd_fd != -1)
        {
            ssize_t ret1;
            int ret2;
            ret1 = write (last_wd_fd, last_wd_string, strlen (last_wd_string));
            ret2 = close (last_wd_fd);
        }
    }
    g_free (last_wd_string);

    g_free (shell);

    done_key ();

    if (macros_list != NULL)
    {
        guint i;
        macros_t *macros;
        for (i = 0; i < macros_list->len; i++)
        {
            macros = &g_array_index (macros_list, struct macros_t, i);
            if (macros != NULL && macros->macro != NULL)
                (void) g_array_free (macros->macro, FALSE);
        }
        (void) g_array_free (macros_list, TRUE);
    }
예제 #23
0
파일: ling.c 프로젝트: DavidAlphaFox/ling
// 从汇编阶段,进入C语言的阶段,传承了Unix的典型思想
// 汇编只负责引导和必要的硬件打交道的阶段
void start_ling(start_info_t *si)
{
	//-------- init phase 1 --------
	//
	//start_info包含的是xen的初始化信息
	//是xen在启动GuestOS的时候,放在特定的地方
	memcpy(&start_info, si, sizeof(*si));
    
	phys_to_machine_mapping = (unsigned long *)start_info.mfn_list;

	HYPERVISOR_update_va_mapping((unsigned long)&shared_info,
		__pte(start_info.shared_info | 7), UVMF_INVLPG);
	HYPERVISOR_shared_info = &shared_info;
//进行时钟初始化
	time_init();	// sets start_of_day_wall_clock

	// use the time value to seed PRNG
	mt_seed(start_of_day_wall_clock);
	
#if defined(__x86_64__)
	HYPERVISOR_set_callbacks(0, 0, 0);
#else /* __x86_64__ */
	HYPERVISOR_set_callbacks(0, 0, 0, 0);
#endif

	mm_init(start_info.nr_pages, start_info.pt_base, start_info.nr_pt_frames);
	nalloc_init();

	events_init();
	grants_init();

	console_init(mfn_to_virt(start_info.console.domU.mfn),
			start_info.console.domU.evtchn);
	xenstore_init(mfn_to_virt(start_info.store_mfn),
		start_info.store_evtchn);

	xenstore_read("name", my_domain_name, sizeof(my_domain_name));
	//print_xenstore_values();

	if (disk_vbd_is_present())
		disk_init();

	lwip_init();
	netfe_init();

	//-------- init phase 2 --------
	//
	if (nalloc_no_memory())
		fatal_error("init phase 2: no memory"); 	

	sys_stats_init();

	atoms_init();
	embed_init();
	code_base_init();
	scheduler_init();
	ets_init();
	pcre_init();
	counters_init();

	//print_start_info();
	//print_xenmem_info();
	//run_alloc_tests();
	//run_mm_tests();
	//print_xenstore_values();
	//run_bignum_tests();
	
	//printk("\r\nLing %s is here\r\n", quote_and_expand(LING_VER));

	proc_main(0); // preliminary run

	spawn_init_start(start_info.cmd_line);

	//while (1)
	//	HYPERVISOR_sched_op(SCHEDOP_block, 0);

	/* UNREACHABLE */
}
예제 #24
0
ape_global *APE_init()
{
    ape_global *ape;
    struct _fdevent *fdev;

#ifndef __WIN32
    signal(SIGPIPE, SIG_IGN);
#else
    WORD wVersionRequested;
    WSADATA wsaData;
    int err;

    wVersionRequested = MAKEWORD(2, 2);

    err = WSAStartup(wVersionRequested, &wsaData);
    if (err != 0) {
        printf("[Error] WSA failed\n");
        return NULL;
    }
#endif

    if ((ape = malloc(sizeof(*ape))) == NULL) return NULL;
    fdev          = &ape->events;
    fdev->handler = EVENT_UNKNOWN;
#ifdef USE_EPOLL_HANDLER
    fdev->handler = EVENT_EPOLL;
#endif
#ifdef USE_KQUEUE_HANDLER
    fdev->handler = EVENT_KQUEUE;
#endif
#ifdef USE_SELECT_HANDLER
    fdev->handler = EVENT_SELECT;
#endif

    ape->is_running = 1;

    ape->timersng.run_in_low_resolution = 0;
    ape->timersng.head                  = NULL;
    ape->timersng.head_async            = NULL;
    ape->timersng.last_identifier       = 0;

    ape->ctx          = NULL;
    ape->kill_handler = NULL;

    ape_dns_init(ape);

    ape_ssl_library_init();
    if ((ape->ssl_global_ctx = ape_ssl_init_global_client_ctx()) == NULL) {
        printf("[Error] SSL: failed to init global CTX\n");
    }

    events_init(ape);

    ape->failed_write_count    = 0;
    ape->total_memory_buffered = 0;

    ape->urandom_fd = open("/dev/urandom", O_RDONLY);

    if (!ape->urandom_fd) {
        printf("Can not open /dev/urandom\n");
        return NULL;
    }
    memset(&ape->logger, 0, sizeof(ape->logger));

    /* Store ape in a Thread local storage */
    pthread_once(&g_InitOnce, ape_inittls);
    if (pthread_getspecific(g_APEThreadContextKey) != NULL) {
        printf("[Error] An instance of APE already exists in the current thread\n");
        return NULL;
    }

    pthread_setspecific(g_APEThreadContextKey, ape);

    return ape;
}
예제 #25
0
파일: core.c 프로젝트: LoongWin/libvmi
static status_t
vmi_init_private(
    vmi_instance_t *vmi,
    uint32_t flags,
    uint64_t id,
    const char *name,
    vmi_config_t config)
{
    uint32_t access_mode = flags & 0x0000FFFF;
    uint32_t init_mode = flags & 0x00FF0000;
    uint32_t config_mode = flags & 0xFF000000;
    status_t status = VMI_FAILURE;

    /* allocate memory for instance structure */
    *vmi = (vmi_instance_t) safe_malloc(sizeof(struct vmi_instance));
    memset(*vmi, 0, sizeof(struct vmi_instance));

    /* initialize instance struct to default values */
    dbprint(VMI_DEBUG_CORE, "LibVMI Version 0.11.0\n");  //TODO change this with each release

    /* save the flags and init mode */
    (*vmi)->flags = flags;
    (*vmi)->init_mode = init_mode;
    (*vmi)->config_mode = config_mode;

    /* the config hash table is set up later based on mode */
    (*vmi)->config = NULL;

    /* set page mode to unknown */
    (*vmi)->page_mode = VMI_PM_UNKNOWN;

    /* setup the caches */
    pid_cache_init(*vmi);
    sym_cache_init(*vmi);
    rva_cache_init(*vmi);
    v2p_cache_init(*vmi);

    if ( init_mode & VMI_INIT_SHM_SNAPSHOT ) {
#if ENABLE_SHM_SNAPSHOT == 1
        v2m_cache_init(*vmi);
#else
        errprint("LibVMI wasn't compiled with SHM support!\n");
        status = VMI_FAILURE;
        goto error_exit;
#endif
    }

    /* connecting to xen, kvm, file, etc */
    if (VMI_FAILURE == set_driver_type(*vmi, access_mode, id, name)) {
        goto error_exit;
    }

    /* driver-specific initilization */
    if (VMI_FAILURE == driver_init(*vmi)) {
        goto error_exit;
    }
    dbprint(VMI_DEBUG_CORE, "--completed driver init.\n");

    /* resolve the id and name */
    if (VMI_FAILURE == set_id_and_name(*vmi, access_mode, id, name)) {
        goto error_exit;
    }

    /* init vmi for specific file/domain through the driver */
    if (VMI_FAILURE == driver_init_vmi(*vmi)) {
        goto error_exit;
    }

    /* setup the page offset size */
    if (VMI_FAILURE == init_page_offset(*vmi)) {
        goto error_exit;
    }

    /* get the memory size */
    if (driver_get_memsize(*vmi, &(*vmi)->allocated_ram_size, &(*vmi)->max_physical_address) == VMI_FAILURE) {
        errprint("Failed to get memory size.\n");
        goto error_exit;
    }
    dbprint(VMI_DEBUG_CORE, "**set size = %"PRIu64" [0x%"PRIx64"]\n", (*vmi)->size,
        (*vmi)->size);

    // for file mode we need os-specific heuristics to deduce the architecture
    // for live mode, having arch_interface set even in VMI_PARTIAL mode
    // allows use of dtb-based translation methods.
    if (VMI_FILE != (*vmi)->mode) {
        if(VMI_FAILURE == arch_init(*vmi)) {
            if (init_mode & VMI_INIT_COMPLETE) {
                dbprint(VMI_DEBUG_CORE, "--failed to determine architecture of live vm and INIT_COMPLETE.\n");
                goto error_exit;
            } else {
                dbprint(VMI_DEBUG_CORE, "--failed to determine architecture of live vm and INIT_PARTIAL, continuing.\n");
            }
        } else {
            dbprint(VMI_DEBUG_CORE, "--succesfully completed architecture init.\n");
        }
    }


    /* we check VMI_INIT_COMPLETE first as
       VMI_INIT_PARTIAL is not exclusive */
    if (init_mode & VMI_INIT_COMPLETE) {
        switch((*vmi)->config_mode) {
            case VMI_CONFIG_STRING:
                /* read and parse the config string */
                if(VMI_FAILURE == read_config_string(*vmi, (char*)config)) {
                    goto error_exit;
                }
                break;
            case VMI_CONFIG_GLOBAL_FILE_ENTRY:
                /* read and parse the config file */
                if(VMI_FAILURE == read_config_file_entry(*vmi)) {
                    goto error_exit;
                }
                break;
            case VMI_CONFIG_GHASHTABLE:
                /* read and parse the ghashtable */
                if (!config) {
                    goto error_exit;
                }
                (*vmi)->config = (GHashTable*)config;
                break;
            case VMI_CONFIG_NONE:
            default:
                /* init_complete requires configuration
                   falling back to VMI_CONFIG_GLOBAL_FILE_ENTRY is unsafe here
                   as the config pointer is probably NULL */
                goto error_exit;
        }

        if(VMI_FAILURE == set_os_type_from_config(*vmi)) {
            dbprint(VMI_DEBUG_CORE, "--failed to determine os type from config\n");
            goto error_exit;
        }

        /* setup OS specific stuff */
        switch ( (*vmi)->os_type )
        {
#ifdef ENABLE_LINUX
        case VMI_OS_LINUX:
            if(VMI_FAILURE == linux_init(*vmi)) {
                goto error_exit;
            }
            break;
#endif
#ifdef ENABLE_WINDOWS
        case VMI_OS_WINDOWS:
            if(VMI_FAILURE == windows_init(*vmi)) {
                goto error_exit;
            }
            break;
#endif
        default:
            goto error_exit;
        }

        status = VMI_SUCCESS;

    } else if (init_mode & VMI_INIT_PARTIAL) {

        status = VMI_SUCCESS;

    } else {

        errprint("Need to specify either VMI_INIT_PARTIAL or VMI_INIT_COMPLETE.\n");
        goto error_exit;

    }

    if(init_mode & VMI_INIT_EVENTS) {
#if ENABLE_XEN_EVENTS == 1
        /* Enable event handlers */
        events_init(*vmi);
#else
        errprint("LibVMI wasn't compiled with events support!\n");
        status = VMI_FAILURE;
#endif
    }

error_exit:
    return status;
}
예제 #26
0
파일: main.c 프로젝트: V07D/mc
int
main (int argc, char *argv[])
{
    GError *mcerror = NULL;
    gboolean config_migrated = FALSE;
    char *config_migrate_msg;
    int exit_code = EXIT_FAILURE;

    mc_global.timer = mc_timer_new ();

    /* We had LC_CTYPE before, LC_ALL includs LC_TYPE as well */
#ifdef HAVE_SETLOCALE
    (void) setlocale (LC_ALL, "");
#endif
    (void) bindtextdomain (PACKAGE, LOCALEDIR);
    (void) textdomain (PACKAGE);

    /* do this before args parsing */
    str_init_strings (NULL);

    if (!mc_args_parse (&argc, &argv, "mc", &mcerror))
    {
      startup_exit_falure:
        fprintf (stderr, _("Failed to run:\n%s\n"), mcerror->message);
        g_error_free (mcerror);
        g_free (mc_global.tty.shell);
      startup_exit_ok:
        str_uninit_strings ();
        mc_timer_destroy (mc_global.timer);
        return exit_code;
    }

    /* do this before mc_args_show_info () to view paths in the --datadir-info output */
    OS_Setup ();

    if (!g_path_is_absolute (mc_config_get_home_dir ()))
    {
        mc_propagate_error (&mcerror, 0, "%s: %s", _("Home directory path is not absolute"),
                            mc_config_get_home_dir ());
        mc_event_deinit (NULL);
        goto startup_exit_falure;
    }

    if (!mc_args_show_info ())
    {
        exit_code = EXIT_SUCCESS;
        goto startup_exit_ok;
    }

    if (!events_init (&mcerror))
        goto startup_exit_falure;

    mc_config_init_config_paths (&mcerror);
    config_migrated = mc_config_migrate_from_old_place (&mcerror, &config_migrate_msg);
    if (mcerror != NULL)
    {
        mc_event_deinit (NULL);
        goto startup_exit_falure;
    }

    vfs_init ();
    vfs_plugins_init ();

    load_setup ();

    /* Must be done after load_setup because depends on mc_global.vfs.cd_symlinks */
    vfs_setup_work_dir ();

    /* Resolve the other_dir panel option. Must be done after vfs_setup_work_dir */
    {
        char *buffer;
        vfs_path_t *vpath;

        buffer = mc_config_get_string (mc_panels_config, "Dirs", "other_dir", ".");
        vpath = vfs_path_from_str (buffer);
        if (vfs_file_is_local (vpath))
            saved_other_dir = buffer;
        else
            g_free (buffer);
        vfs_path_free (vpath);
    }

    /* Set up temporary directory after VFS initialization */
    mc_tmpdir ();

    /* do this after vfs initialization and vfs working directory setup
       due to mc_setctl() and mcedit_arg_vpath_new() calls in mc_setup_by_args() */
    if (!mc_setup_by_args (argc, argv, &mcerror))
    {
        vfs_shut ();
        done_setup ();
        g_free (saved_other_dir);
        mc_event_deinit (NULL);
        goto startup_exit_falure;
    }

    /* check terminal type
     * $TEMR must be set and not empty
     * mc_global.tty.xterm_flag is used in init_key() and tty_init()
     * Do this after mc_args_handle() where mc_args__force_xterm is set up.
     */
    mc_global.tty.xterm_flag = tty_check_term (mc_args__force_xterm);

    /* NOTE: This has to be called before tty_init or whatever routine
       calls any define_sequence */
    init_key ();

    /* Must be done before installing the SIGCHLD handler [[FIXME]] */
    handle_console (CONSOLE_INIT);

#ifdef ENABLE_SUBSHELL
    /* Don't use subshell when invoked as viewer or editor */
    if (mc_global.mc_run_mode != MC_RUN_FULL)
        mc_global.tty.use_subshell = FALSE;

    if (mc_global.tty.use_subshell)
        subshell_get_console_attributes ();
#endif /* ENABLE_SUBSHELL */

    /* Install the SIGCHLD handler; must be done before init_subshell() */
    init_sigchld ();

    /* We need this, since ncurses endwin () doesn't restore the signals */
    save_stop_handler ();

    /* Must be done before init_subshell, to set up the terminal size: */
    /* FIXME: Should be removed and LINES and COLS computed on subshell */
    tty_init (!mc_args__nomouse, mc_global.tty.xterm_flag);

    /* start check mc_global.display_codepage and mc_global.source_codepage */
    check_codeset ();

    /* Removing this from the X code let's us type C-c */
    load_key_defs ();

    load_keymap_defs (!mc_args__nokeymap);

    macros_list = g_array_new (TRUE, FALSE, sizeof (macros_t));

    tty_init_colors (mc_global.tty.disable_colors, mc_args__force_colors);

    mc_skin_init (NULL, &mcerror);
    dlg_set_default_colors ();
    input_set_default_colors ();
    if (mc_global.mc_run_mode == MC_RUN_FULL)
        command_set_default_colors ();

    mc_error_message (&mcerror);

#ifdef ENABLE_SUBSHELL
    /* Done here to ensure that the subshell doesn't  */
    /* inherit the file descriptors opened below, etc */
    if (mc_global.tty.use_subshell)
        init_subshell ();
#endif /* ENABLE_SUBSHELL */

    /* Also done after init_subshell, to save any shell init file messages */
    if (mc_global.tty.console_flag != '\0')
        handle_console (CONSOLE_SAVE);

    if (mc_global.tty.alternate_plus_minus)
        application_keypad_mode ();

    /* Done after subshell initialization to allow select and paste text by mouse
       w/o Shift button in subshell in the native console */
    init_mouse ();

    /* Done after do_enter_ca_mode (tty_init) because in VTE bracketed mode is
       separate for the normal and alternate screens */
    enable_bracketed_paste ();

    /* subshell_prompt is NULL here */
    mc_prompt = (geteuid () == 0) ? "# " : "$ ";

    if (config_migrated)
    {
        message (D_ERROR, _("Warning"), "%s", config_migrate_msg);
        g_free (config_migrate_msg);
    }

    /* Program main loop */
    if (mc_global.midnight_shutdown)
        exit_code = EXIT_SUCCESS;
    else
        exit_code = do_nc ()? EXIT_SUCCESS : EXIT_FAILURE;

    /* Save the tree store */
    (void) tree_store_save ();

    free_keymap_defs ();

    /* Virtual File System shutdown */
    vfs_shut ();

    flush_extension_file ();    /* does only free memory */

    mc_skin_deinit ();
    tty_colors_done ();

    tty_shutdown ();

    done_setup ();

    if (mc_global.tty.console_flag != '\0' && (quit & SUBSHELL_EXIT) == 0)
        handle_console (CONSOLE_RESTORE);
    if (mc_global.tty.alternate_plus_minus)
        numeric_keypad_mode ();

    (void) signal (SIGCHLD, SIG_DFL);   /* Disable the SIGCHLD handler */

    if (mc_global.tty.console_flag != '\0')
        handle_console (CONSOLE_DONE);

    if (mc_global.mc_run_mode == MC_RUN_FULL && mc_args__last_wd_file != NULL
        && last_wd_string != NULL && !print_last_revert)
    {
        int last_wd_fd;

        last_wd_fd = open (mc_args__last_wd_file, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL,
                           S_IRUSR | S_IWUSR);
        if (last_wd_fd != -1)
        {
            ssize_t ret1;
            int ret2;
            ret1 = write (last_wd_fd, last_wd_string, strlen (last_wd_string));
            ret2 = close (last_wd_fd);
            (void) ret1;
            (void) ret2;
        }
    }
    g_free (last_wd_string);

    g_free (mc_global.tty.shell);

    done_key ();

    if (macros_list != NULL)
    {
        guint i;
        for (i = 0; i < macros_list->len; i++)
        {
            macros_t *macros;

            macros = &g_array_index (macros_list, struct macros_t, i);
            if (macros != NULL && macros->macro != NULL)
                (void) g_array_free (macros->macro, FALSE);
        }
        (void) g_array_free (macros_list, TRUE);
    }
예제 #27
0
before(): call(void init_domainsys())
{
    events_init();
}