示例#1
0
static void test_rsyslog(void)
{
    int i;
    char tmp[32] = "abcd";
    log_deinit();
    log_init(LOG_RSYSLOG, "test_log");
    for (i = 0; i < 10; i++) {
        loge("test rsyslog\n");
        logw("debug msg %d, %s\n", i, tmp);
        logd("debug msg %d, %s\n", i, tmp);
        logi("debug msg %d, %s\n", i, tmp);
        logv("debug msg %d, %s\n", i, tmp);
    }
    log_deinit();
}
示例#2
0
文件: core.c 项目: svn2github/irssi
void core_deinit(void)
{
	chat_commands_deinit();

	nicklist_deinit();
	queries_deinit();
	channels_deinit();

	rawlog_deinit();
	log_deinit();
        write_buffer_deinit();
	servers_deinit();
	ignore_deinit();
        expandos_deinit();
	chatnets_deinit();
	chat_protocols_deinit();

        nickmatch_cache_deinit();
	commands_deinit();
	settings_deinit();
	signals_deinit();
	net_sendbuffer_deinit();
	net_disconnect_deinit();

#ifndef WIN32
	pidwait_deinit();
#endif
	modules_deinit();
}
示例#3
0
void test_file_name()
{
    int i;
    for (i = 0; i < 1; i++) {
        loge("debug msg i=%d\n", i);
        logw("debug msg i=%d\n", i);
        logi("debug msg i=%d\n", i);
        logd("debug msg i=%d\n", i);
        logv("debug msg i=%d\n", i);
    }
    log_deinit();
}
示例#4
0
文件: main.cpp 项目: DanSyor/hbas
/* Entry point */
extern "C" int Menu_Main(void)
{
    //!*******************************************************************
    //!                   Initialize function pointers                   *
    //!*******************************************************************
    //! do OS (for acquire) and sockets first so we got logging
    InitOSFunctionPointers();
    InitSocketFunctionPointers();

    log_init("192.168.1.103");
    log_print("Starting launcher\n");

    InitFSFunctionPointers();
    InitGX2FunctionPointers();
    InitSysFunctionPointers();
    InitVPadFunctionPointers();
    InitPadScoreFunctionPointers();
    InitAXFunctionPointers();
    InitCurlFunctionPointers();
    InstallExceptionHandler();

    log_print("Function exports loaded\n");

    //!*******************************************************************
    //!                    Initialize heap memory                        *
    //!*******************************************************************
    log_print("Initialize memory management\n");
    memoryInitialize();

    //!*******************************************************************
    //!                        Initialize FS                             *
    //!*******************************************************************
    log_printf("Mount SD partition\n");
    mount_sd_fat("sd");

    //!*******************************************************************
    //!                    Enter main application                        *
    //!*******************************************************************
    log_printf("Start main application\n");
    Application::instance()->exec();
    log_printf("Main application stopped\n");

    Application::destroyInstance();

    log_printf("Unmount SD\n");
    unmount_sd_fat("sd");
    log_printf("Release memory\n");
    memoryRelease();
    log_deinit();

    return 0;
}
示例#5
0
static void test(void)
{
    int i;
    log_init(LOG_STDERR, NULL);
    for (i = 0; i < 100; i++) {
        loge("%s:%s:%d: debug msg\n", __FILE__, __func__, __LINE__);
        logw("%s:%s:%d: debug msg\n", __FILE__, __func__, __LINE__);
        logi("%s:%s:%d: debug msg\n", __FILE__, __func__, __LINE__);
        logd("%s:%s:%d: debug msg\n", __FILE__, __func__, __LINE__);
        logv("%s:%s:%d: debug msg\n", __FILE__, __func__, __LINE__);
    }
    log_deinit();
}
示例#6
0
static void
dn_post_run(struct instance *nci)
{
    if (nci->pidfile) {
        dn_remove_pidfile(nci);
    }

    signal_deinit();

    dn_print_done();

    log_deinit();
}
示例#7
0
static void
nc_worker_post_run(struct instance *nci)
{
    if (nci->pidfile) {
        nc_remove_pidfile(nci);
    }

    signal_deinit();

    nc_print_done();

    log_deinit();
}
示例#8
0
static void test_file_noname(void)
{
    int i;
    log_init(LOG_FILE, NULL);
    log_set_split_size(1*1024*1024);
    for (i = 0; i < 100; i++) {
        loge("debug msg i = %d\n", i);
        logw("debug msg\n");
        logi("debug msg\n");
        logd("debug msg\n");
        logd("debug msg\n");
    }
    log_deinit();
}
示例#9
0
文件: core.c 项目: svn2github/irssi
void core_deinit(void)
{
	special_vars_deinit();
	rawlog_deinit();
	log_deinit();
	servers_deinit();

	commands_deinit();
	settings_deinit();
	signals_deinit();
	net_disconnect_deinit();

	pidwait_deinit();
	modules_deinit();
}
示例#10
0
static void test_file_name(void)
{
    int i;
    log_init(LOG_FILE, "tmp/foo.log");
    log_set_split_size(1*1024*1024);

    for (i = 0; i < 1; i++) {
        loge("debug msg i=%d\n", i);
        logw("debug msg i=%d\n", i);
        logi("debug msg i=%d\n", i);
        logd("debug msg i=%d\n", i);
        logv("debug msg i=%d\n", i);
    }
    log_deinit();
}
示例#11
0
static void
nc_master_post_run(struct env_master *env)
{
   // kill all the children process.


    if (env->pidfile) {
        nc_remove_master_pidfile(env);
    }

    signal_deinit();

    nc_print_done();

    log_deinit();
}
示例#12
0
int main()
{
    log_init(&logger,NULL,LOG_LEVEL_VERB);
    log_info("server test start");
    struct context *ctx;
    struct conn* conn;
    
    ctx = core_init();
    
    conn = server_create_conn("127.0.0.1", 80, ctx);
    conn->conn_parse = conn_parse1;
    conn->conn_close = conn_close1;
    
    core_loop(ctx);
    core_destory(ctx);

    //conn_close(conn);
    log_deinit(&logger);
    return 0;
}
示例#13
0
tSirRetStatus mac_close(tHalHandle hHal)
{

	tpAniSirGlobal pMac = (tpAniSirGlobal) hHal;

	if (!pMac)
		return eSIR_FAILURE;

	pe_close(pMac);

	/* Call routine to free-up all CFG data structures */
	cfg_de_init(pMac);

	log_deinit(pMac);

	/* Finally, de-allocate the global MAC datastructure: */
	cdf_mem_free(pMac);

	return eSIR_SUCCESS;
}
示例#14
0
文件: core.c 项目: ailin-nemui/irssi
void core_deinit(void)
{
	module_uniq_destroy("WINDOW ITEM TYPE");

	signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
	signal_remove("irssi init finished", (SIGNAL_FUNC) sig_irssi_init_finished);

	wcwidth_wrapper_deinit();
	chat_commands_deinit();

	nicklist_deinit();
	queries_deinit();
	channels_deinit();

	recode_deinit();
	rawlog_deinit();
	log_away_deinit();
	log_deinit();
        write_buffer_deinit();
	servers_deinit();
	ignore_deinit();
        expandos_deinit();
	chatnets_deinit();
	chat_protocols_deinit();

#ifdef HAVE_CAPSICUM
	capsicum_deinit();
#endif
        session_deinit();
        nickmatch_cache_deinit();
	commands_deinit();
	settings_deinit();
	signals_deinit();
	net_disconnect_deinit();

	pidwait_deinit();
	modules_deinit();

	g_free(irssi_dir);
        g_free(irssi_config_file);
}
示例#15
0
文件: test-fatal.c 项目: xinoir/dizzy
static int test_fatal() {
    int e;
    const char *mod_name = __func__;
    const char *prog_name = "./test-fatal-harness";
    char shell_command[0x40] = { 0 };

    memmove(shell_command, prog_name, strlen(prog_name));
    debug("shell command text: [%s]", shell_command);

    log_init(mod_name);

    if (atexit(terminate))
        error("a termination handler could not be registered, [%s]", mod_name);

    e = system(shell_command);
    assert(e == 256);

    log_deinit(mod_name);

    return 0;
}
示例#16
0
int main(int argc, char **argv)
{
#if 1
   setup_os_exceptions();
#else
   InstallExceptionHandler();
#endif
   ProcUIInit(&SaveCallback);

   socket_lib_init();
#if defined(PC_DEVELOPMENT_IP_ADDRESS) && defined(PC_DEVELOPMENT_TCP_PORT)
   log_init(PC_DEVELOPMENT_IP_ADDRESS, PC_DEVELOPMENT_TCP_PORT);
   devoptab_list[STD_OUT] = &dotab_stdout;
   devoptab_list[STD_ERR] = &dotab_stdout;
#endif
#ifndef IS_SALAMANDER
   VPADInit();
   WPADEnableURCC(true);
   WPADEnableWiiRemote(true);
   KPADInit();
#endif
   verbosity_enable();

   printf("starting\n");
   fflush(stdout);
   DEBUG_VAR(ARGV_PTR);
   if(ARGV_PTR && ((u32)ARGV_PTR < 0x01000000))
   {
      struct
      {
         u32 magic;
         u32 argc;
         char * argv[3];
      }*param = ARGV_PTR;
      if(param->magic == ARGV_MAGIC)
      {
         argc = param->argc;
         argv = param->argv;
      }
      ARGV_PTR = NULL;
   }

   DEBUG_VAR(argc);
   DEBUG_STR(argv[0]);
   DEBUG_STR(argv[1]);
   fflush(stdout);
#ifdef IS_SALAMANDER
   int salamander_main(int, char **);
   salamander_main(argc, argv);
#else
#if 1
#if 0
   int argc_ = 2;
//   char* argv_[] = {WIIU_SD_PATH "retroarch/retroarch.elf", WIIU_SD_PATH "rom.nes", NULL};
   char *argv_[] = {WIIU_SD_PATH "retroarch/retroarch.elf", WIIU_SD_PATH "rom.sfc", NULL};

   rarch_main(argc_, argv_, NULL);
#else
   rarch_main(argc, argv, NULL);
#endif
   do
   {
      unsigned sleep_ms = 0;
      int ret = runloop_iterate(&sleep_ms);

      if (ret == 1 && sleep_ms > 0)
         retro_sleep(sleep_ms);

      task_queue_ctl(TASK_QUEUE_CTL_WAIT, NULL);

      if (ret == -1)
         break;

   }
   while (1);

   main_exit(NULL);
#endif
#endif
   fflush(stdout);
   fflush(stderr);
   ProcUIShutdown();

#if defined(PC_DEVELOPMENT_IP_ADDRESS) && defined(PC_DEVELOPMENT_TCP_PORT)
   log_deinit();
#endif

   /* returning non 0 here can prevent loading a different rpx/elf in the HBL environment */
   return 0;
}
示例#17
0
文件: main.c 项目: ajd4096/ddd
/* Entry point */
int Menu_Main(void)
{
    //!*******************************************************************
    //!                   Initialize function pointers                   *
    //!*******************************************************************
    //! do OS (for acquire) and sockets first so we got logging
    InitOSFunctionPointers();
    InitSocketFunctionPointers();
    InitFSFunctionPointers();
    InitVPadFunctionPointers();
    InitSysFunctionPointers();
    InitAocFunctionPointers();

    log_init("192.168.178.3");
    log_deinit();
    log_init("192.168.178.3");
    log_printf("Started %s\n", cosAppXmlInfoStruct.rpx_name);

    if(strcasecmp("men.rpx", cosAppXmlInfoStruct.rpx_name) == 0)
    {
        CheckPendingMetaDump();
        return EXIT_RELAUNCH_ON_LOAD;
    }
    else if(strlen(cosAppXmlInfoStruct.rpx_name) > 0 && strcasecmp("ffl_app.rpx", cosAppXmlInfoStruct.rpx_name) != 0)
    {
        StartDumper();
        return EXIT_RELAUNCH_ON_LOAD;
    }

    // initialize memory tables once on start
    memoryInitAreaTable();
    rpxRplTableInit();
    SetupKernelCallback();
    PatchMethodHooks();

    memoryInitialize();

    VPADInit();

    // Prepare screen
    int screen_buf0_size = 0;
    int screen_buf1_size = 0;

    // Init screen and screen buffers
    OSScreenInit();
    screen_buf0_size = OSScreenGetBufferSizeEx(0);
    screen_buf1_size = OSScreenGetBufferSizeEx(1);

    unsigned char *screenBuffer = MEM1_alloc(screen_buf0_size + screen_buf1_size, 0x40);

    OSScreenSetBufferEx(0, screenBuffer);
    OSScreenSetBufferEx(1, (screenBuffer + screen_buf0_size));

    OSScreenEnableEx(0, 1);
    OSScreenEnableEx(1, 1);

    char msg[80];
    uint8_t sel_ip = 3;
    int launchMethod = 0;
    int update_screen = 1;
    int vpadError = -1;
    VPADData vpad_data;
    u_serv_ip ip;
    ip.full = GetServerIp();
    int delay = 0;

    while (1)
    {
        // Read vpad
        VPADRead(0, &vpad_data, 1, &vpadError);

        if(update_screen)
        {
            OSScreenClearBufferEx(0, 0);
            OSScreenClearBufferEx(1, 0);

            // Print message
            PRINT_TEXT2(14, 1, "-- DDD v0.2 by Dimok --");
            PRINT_TEXT2(0, 5, "1.    Setup IP address of server application.");

            // Print ip digit selector
            uint8_t x_shift = 17 + 4 * sel_ip;
            PRINT_TEXT2(x_shift, 6, "vvv");

            PRINT_TEXT2(0, 7, "      Server IP: %3d.%3d.%3d.%3d", ip.digit[0], ip.digit[1], ip.digit[2], ip.digit[3]);

            PRINT_TEXT2(0, 10, "2.   Press A to install dumper and try to launch disc.");
            PRINT_TEXT2(0, 11, "  or Press X to install dumper and return to system menu.");

            PRINT_TEXT2(0, 13, "3.   Start the title to be dumped.");

            PRINT_TEXT2(0, 17, "Press home button to exit ...");


            OSScreenFlipBuffersEx(0);
            OSScreenFlipBuffersEx(1);
        }

        u32 pressedBtns = vpad_data.btns_d | vpad_data.btns_h;

        // Check for buttons
        // Home Button
        if (pressedBtns & VPAD_BUTTON_HOME) {
            launchMethod = 0;
            break;
        }
        // A Button
        if (pressedBtns & VPAD_BUTTON_A) {
            SetServerIp(ip.full);
            launchMethod = 1;
            break;
        }
        // A Button
        if (pressedBtns & VPAD_BUTTON_X) {
            SetServerIp(ip.full);
            launchMethod = 2;
            break;
        }
        // Left/Right Buttons
        if (vpad_data.btns_d & VPAD_BUTTON_LEFT )
        {
            if(sel_ip == 0)
                sel_ip = 3;
            else
                --sel_ip;
        }

        if (vpad_data.btns_d & VPAD_BUTTON_RIGHT)
        {
            sel_ip = ((sel_ip + 1) % 4);
        }

        // Up/Down Buttons
        if (pressedBtns & VPAD_BUTTON_UP)
        {
            if(--delay <= 0) {
                ip.digit[sel_ip]++;
                delay = (vpad_data.btns_d & VPAD_BUTTON_UP) ? 6 : 0;
            }
        }
        else if (pressedBtns & VPAD_BUTTON_DOWN)
        {
            if(--delay <= 0) {
                ip.digit[sel_ip]--;
                delay = (vpad_data.btns_d & VPAD_BUTTON_DOWN) ? 6 : 0;
            }
        }
        else {
            delay = 0;
        }

        // Button pressed ?
        update_screen = (pressedBtns & (VPAD_BUTTON_LEFT | VPAD_BUTTON_RIGHT | VPAD_BUTTON_UP | VPAD_BUTTON_DOWN)) ? 1 : 0;
        usleep(20000);
    }

	MEM1_free(screenBuffer);
	screenBuffer = NULL;

    log_deinit();

    memoryRelease();

    if(launchMethod == 0)
    {
        RestoreInstructions();
        return EXIT_SUCCESS;
    }
    else if(launchMethod == 1)
    {
        char buf_vol_odd[20];
        snprintf(buf_vol_odd, sizeof(buf_vol_odd), "%s", "/vol/storage_odd03");
        _SYSLaunchTitleByPathFromLauncher(buf_vol_odd, 18, 0);
    }
    else
    {
        SYSLaunchMenu();
    }

    return EXIT_RELAUNCH_ON_LOAD;
}
示例#18
0
/* Entry point */
extern "C" int Menu_Main(void)
{
    //!*******************************************************************
    //!                   Initialize function pointers                   *
    //!*******************************************************************
    //! do OS (for acquire) and sockets first so we got logging
    InitOSFunctionPointers();
    InitSocketFunctionPointers();

    log_init(LOADIINE_LOGGER_IP);
    log_print("Starting Loadiine GX2 " LOADIINE_VERSION "\n");

    InitFSFunctionPointers();
    InitGX2FunctionPointers();
    InitSysFunctionPointers();
    InitVPadFunctionPointers();
    InitPadScoreFunctionPointers();
    InitAXFunctionPointers();
    InitCurlFunctionPointers();

    log_print("Function exports loaded\n");

    //!*******************************************************************
    //!                Initialize our kernel variables                   *
    //!*******************************************************************
    log_printf("Setup kernel variables\n");
    SetupKernelCallback();
    //!*******************************************************************
    //!                    Initialize heap memory                        *
    //!*******************************************************************
    log_print("Initialize memory management\n");
    memoryInitialize();

    //!*******************************************************************
    //!                        Initialize FS                             *
    //!*******************************************************************
    log_printf("Mount SD partition\n");
    mount_sd_fat("sd");

    //!*******************************************************************
    //!                       Patch Functions                            *
    //!*******************************************************************
    log_printf("Patch FS and loader functions\n");

    PatchMethodHooks();
    PatchSDK();

    //!*******************************************************************
    //!                    Setup exception handler                       *
    //!*******************************************************************
    log_printf("Setup exception handler\n");
    setup_os_exceptions();

    //!*******************************************************************
    //!                    Enter main application                        *
    //!*******************************************************************
    log_printf("Start main application\n");
    Application::instance()->exec();
    log_printf("Main application stopped\n");

    Application::destroyInstance();

    log_printf("Unmount SD\n");
    unmount_sd_fat("sd");
    log_printf("Release memory\n");
    memoryRelease();
    log_printf("Loadiine peace out...\n");
    log_deinit();

    return 0;
}
示例#19
0
int mpd_main(int argc, char *argv[])
{
	struct options options;
	clock_t start;
	bool create_db;
	GError *error = NULL;
	bool success;

	daemonize_close_stdin();

#ifdef HAVE_LOCALE_H
	/* initialize locale */
	setlocale(LC_CTYPE,"");
#endif

	g_set_application_name("Music Player Daemon");

	/* enable GLib's thread safety code */
	g_thread_init(NULL);

	io_thread_init();
	winsock_init();
	idle_init();
	tag_pool_init();
	config_global_init();

	success = parse_cmdline(argc, argv, &options, &error);
	if (!success) {
		g_warning("%s", error->message);
		g_error_free(error);
		return EXIT_FAILURE;
	}

	if (!glue_daemonize_init(&options, &error)) {
		g_warning("%s", error->message);
		g_error_free(error);
		return EXIT_FAILURE;
	}

	stats_global_init();
	tag_lib_init();

	if (!log_init(options.verbose, options.log_stderr, &error)) {
		g_warning("%s", error->message);
		g_error_free(error);
		return EXIT_FAILURE;
	}

	success = listen_global_init(&error);
	if (!success) {
		g_warning("%s", error->message);
		g_error_free(error);
		return EXIT_FAILURE;
	}

	daemonize_set_user();

	main_task = g_thread_self();
	main_loop = g_main_loop_new(NULL, FALSE);
	main_cond = g_cond_new();

	event_pipe_init();
	event_pipe_register(PIPE_EVENT_IDLE, idle_event_emitted);
	event_pipe_register(PIPE_EVENT_SHUTDOWN, shutdown_event_emitted);

	path_global_init();

	if (!glue_mapper_init(&error)) {
		g_warning("%s", error->message);
		g_error_free(error);
		return EXIT_FAILURE;
	}

	initPermissions();
	playlist_global_init();
	spl_global_init();
#ifdef ENABLE_ARCHIVE
	archive_plugin_init_all();
#endif

	if (!pcm_resample_global_init(&error)) {
		g_warning("%s", error->message);
		g_error_free(error);
		return EXIT_FAILURE;
	}

	decoder_plugin_init_all();
	update_global_init();

	create_db = !glue_db_init_and_load();

	glue_sticker_init();

	command_init();
	initialize_decoder_and_player();
	volume_init();
	initAudioConfig();
	audio_output_all_init(global_player_control);
	client_manager_init();
	replay_gain_global_init();

	if (!input_stream_global_init(&error)) {
		g_warning("%s", error->message);
		g_error_free(error);
		return EXIT_FAILURE;
	}

	playlist_list_global_init();

	daemonize(options.daemon);

	setup_log_output(options.log_stderr);

	initSigHandlers();

	if (!io_thread_start(&error)) {
		g_warning("%s", error->message);
		g_error_free(error);
		return EXIT_FAILURE;
	}

	initZeroconf();

	player_create(global_player_control);

	if (create_db) {
		/* the database failed to load: recreate the
		   database */
		unsigned job = update_enqueue(NULL, true);
		if (job == 0)
			MPD_ERROR("directory update failed");
	}

	if (!glue_state_file_init(&error)) {
		g_warning("%s", error->message);
		g_error_free(error);
		return EXIT_FAILURE;
	}

	success = config_get_bool(CONF_AUTO_UPDATE, false);
#ifdef ENABLE_INOTIFY
	if (success && mapper_has_music_directory())
		mpd_inotify_init(config_get_unsigned(CONF_AUTO_UPDATE_DEPTH,
						     G_MAXUINT));
#else
	if (success)
		g_warning("inotify: auto_update was disabled. enable during compilation phase");
#endif

	config_global_check();

	/* enable all audio outputs (if not already done by
	   playlist_state_restore() */
	pc_update_audio(global_player_control);

#ifdef WIN32
	win32_app_started();
#endif

	/* run the main loop */
	g_main_loop_run(main_loop);

#ifdef WIN32
	win32_app_stopping();
#endif

	/* cleanup */

	g_main_loop_unref(main_loop);

#ifdef ENABLE_INOTIFY
	mpd_inotify_finish();
#endif

	state_file_finish(global_player_control);
	pc_kill(global_player_control);
	finishZeroconf();
	client_manager_deinit();
	listen_global_finish();
	playlist_global_finish();

	start = clock();
	db_finish();
	g_debug("db_finish took %f seconds",
		((float)(clock()-start))/CLOCKS_PER_SEC);

#ifdef ENABLE_SQLITE
	sticker_global_finish();
#endif

	g_cond_free(main_cond);
	event_pipe_deinit();

	playlist_list_global_finish();
	input_stream_global_finish();
	audio_output_all_finish();
	volume_finish();
	mapper_finish();
	path_global_finish();
	finishPermissions();
	pc_free(global_player_control);
	command_finish();
	update_global_finish();
	decoder_plugin_deinit_all();
#ifdef ENABLE_ARCHIVE
	archive_plugin_deinit_all();
#endif
	config_global_finish();
	tag_pool_deinit();
	idle_deinit();
	stats_global_finish();
	io_thread_deinit();
	daemonize_finish();
#ifdef WIN32
	WSACleanup();
#endif

	log_deinit();
	return EXIT_SUCCESS;
}
示例#20
0
文件: main.c 项目: cnJun/httpgate
int main(int argc, char *argv[])
{
    int ret, i, cpu = 0, level;
    pid_t pid;
    char buf1[128], buf2[128], buf[8192];

    // argument parse
    if(argc != 2){
        USAGE();
        exit(-1);
    }

    if(!strcmp(argv[1], "-h")){
        USAGE();
        exit(0);
    }

    // config file parse
    if( (ret = conf_init(argv[1])) < 0 ){
        log(g_log, "conf[%s] init error\n", argv[1]);
        exit(-1);
    } else {
        log(g_log, "conf[%s] init success\n", argv[1]);
    }

    // log init
    if(!strncmp(g_global_conf.log_level, "log", 3)){
        level = LOG_LEVEL_LOG;
    } else if(!strncmp(g_global_conf.log_level, "debug", 5)){
        level = LOG_LEVEL_DEBUG;
    } else if(!strncmp(g_global_conf.log_level, "info", 4)){
        level = LOG_LEVEL_INFO;
    } else if(!strncmp(g_global_conf.log_level, "none", 4)){
        level = LOG_NONE;
    } else {
        log(g_log, "log_level[%s] unknown\n", g_global_conf.log_level);
        exit(-1);
    }

    if( (g_log = log_init(g_global_conf.log_path, level)) == NULL ){
        log(g_log, "log[%s] init error\n", g_global_conf.log_path);
        exit(-1);
    }

    // signal init
    if( (signal_init()) < 0 ){
        log(g_log, "signal init error\n");
        exit(-1);
    } else {
        log(g_log, "signal init success\n");
    }

    // timer init
    if( (timer_init()) < 0 ){
        log(g_log, "timer init error\n");
        exit(-1);
    } else {
        log(g_log, "timer init success\n");
    }

    // conneciont init
    if( (ret = connection_init(g_global_conf.max_connections)) < 0 ){
        log(g_log, "connection init error\n");
        exit(-1);
    } else {
        log(g_log, "connection init success\n");
    }

    // ipfilter init
    ret = ipfilter_conf_init(g_filter_conf.ipfilter_cycle1, g_filter_conf.ipfilter_cycle2, \
                        g_filter_conf.ipfilter_threshold1, g_filter_conf.ipfilter_threshold2, \
                        g_filter_conf.ipfilter_time1, g_filter_conf.ipfilter_time2);
    if(ret < 0){
        log(g_log, "ipfilter init error\n");
    } else {
        log(g_log, "ipfilter init success\n");
    }    

    // cookiefilter init
    ret = cookiefilter_conf_init(g_filter_conf.cookiefilter_cycle1, g_filter_conf.cookiefilter_cycle2, \
                        g_filter_conf.cookiefilter_threshold1, g_filter_conf.cookiefilter_threshold2, \
                        g_filter_conf.cookiefilter_time1, g_filter_conf.cookiefilter_time2);
    if(ret < 0){
        log(g_log, "cookiefilter init error\n");
    } else {
        log(g_log, "cookiefilter init success\n");
    }    

    // ippool & ipentry init
    if( (ret = ip_pool_init(g_global_conf.max_connections)) < 0 ){
        log(g_log, "ip pool init error\n");
        exit(-1);
    } else {
        log(g_log, "ip pool init success\n");
    }

    // cookie pool init
    if( (ret = cookie_pool_init(1000000)) < 0 ){
        log(g_log, "cookie pool init error\n");
        exit(-1);
    } else {
        log(g_log, "cookie pool init success\n");
    }

    // whitelist init
    if( (g_whitelist = iprange_init(g_filter_conf.whitelist, 1024)) == NULL ){
        log(g_log, "whitelist[%s] init error\n", g_filter_conf.whitelist);
        exit(-1);
    } else {
        log(g_log, "whitelist[%s] init success\n", g_filter_conf.whitelist);
    }

    // blacklist init
    if( (g_blacklist = iprange_init(g_filter_conf.blacklist, 1024)) == NULL ){
        log(g_log, "blacklist[%s] init error\n", g_filter_conf.blacklist);
        exit(-1);
    } else {
        log(g_log, "blacklist[%s] init success\n", g_filter_conf.blacklist);
    }

    // mempool init
    if( (ret = mempool_init(g_global_conf.buffer_size, g_global_conf.max_buffer)) < 0 ){
        log(g_log, "mempool init error\n");
        exit(-1);
    } else {
        log(g_log, "mempool init success\n");
    }

    log(g_log, "all init success\n");

    // make listen
    while(1){
        g_listenfd = make_listen_nonblock(g_global_conf.listen_addr, g_global_conf.listen_port);
        if(g_listenfd < 0){
            log(g_log, "make listen socket error\n");
        } else {
            log(g_log, "make listen socket success %s:%s\n", \
                                g_global_conf.listen_addr, g_global_conf.listen_port);
            break;
        }

        sleep(5);
    }

    if(g_global_conf.daemon){
        daemon(1, 0);
    }

    // fork children
    for(i = 0; i < g_global_conf.workers ; i++){
        if( (pid = fork()) < 0 ){
            log(g_log, "fork error: %s\n", strerror(errno));
            exit(-1);
        } else if(pid > 0) {
            if(g_global_conf.cpu_attach == 1){
                if(cpu_attach(pid, cpu++) == 0){
                    log(g_log, "cpu attach success\n");
                }
            }
            continue;
        } else {
            work();
            exit(-1);
        }
    }

    while(1){
        sleep(5);

        // reopen to release log file when deleted
        log_deinit(g_log);
        if( (g_log = log_init(g_global_conf.log_path, level)) == NULL ){
            log(g_log, "log init error\n");
        }

        pid = waitpid(-1, NULL, WNOHANG);

        if(pid > 0){
            log(g_log, "process[%d] exit, restart again\n", pid);

            while( (pid = fork()) == -1 ){
                log(g_log, "fork error: %s\n", strerror(errno));
                sleep(5);
            }

            if(pid > 0){
                log(g_log, "fork success\n");
                continue;
            } else {
                log(g_log, "goto work\n");
                work();
                exit(-1);
            }
        } else if(pid < 0) {
            log(g_log, "wait error: %s\n", strerror(errno));
        } else {
        }
    }

    return 0;
}
示例#21
0
int main(int argc, char **argv)
{
#else
int __entry_menu(int argc, char **argv)
{
   InitFunctionPointers();
#endif
#if 1
   setup_os_exceptions();
#else
   InstallExceptionHandler();
#endif
   socket_lib_init();
#if defined(PC_DEVELOPMENT_IP_ADDRESS) && defined(PC_DEVELOPMENT_TCP_PORT)
   log_init(PC_DEVELOPMENT_IP_ADDRESS, PC_DEVELOPMENT_TCP_PORT);
#endif
   devoptab_list[STD_OUT] = &dotab_stdout;
   devoptab_list[STD_ERR] = &dotab_stdout;
   memoryInitialize();
   mount_sd_fat("sd");
   VPADInit();

   verbosity_enable();
   DEBUG_VAR(argc);
   DEBUG_STR(argv[0]);
   DEBUG_STR(argv[1]);
#if 0
   int argc_ = 2;
//   char* argv_[] = {WIIU_SD_PATH "retroarch/retroarch.elf", WIIU_SD_PATH "rom.nes", NULL};
   char* argv_[] = {WIIU_SD_PATH "retroarch/retroarch.elf", WIIU_SD_PATH "rom.sfc", NULL};

   rarch_main(argc_, argv_, NULL);
#else
   rarch_main(argc, argv, NULL);
#endif
//   int frames = 0;
   do
   {
      unsigned sleep_ms = 0;
      int ret = runloop_iterate(&sleep_ms);

      if (ret == 1 && sleep_ms > 0)
       retro_sleep(sleep_ms);
      task_queue_ctl(TASK_QUEUE_CTL_WAIT, NULL);
      if (ret == -1)
       break;

   }while(1);
//   }while(frames++ < 300);

   main_exit(NULL);
   unmount_sd_fat("sd");
   memoryRelease();
   fflush(stdout);
   fflush(stderr);
#if defined(PC_DEVELOPMENT_IP_ADDRESS) && defined(PC_DEVELOPMENT_TCP_PORT)
   log_deinit();
#endif

   return 0;
}
示例#22
0
文件: thought.c 项目: jhawcroft/brain
static void thought_exec(int argc, char const *argv[])
{
    /* log the thought */
    lprintf(BRAIN_NOTICE, LOG_PREFIX_FORMAT ": Thinking %s: ", thought_id, time_elapsed(), thought_name);
    for (int a = 2; a < argc; a++)
    {
        if (a + 1 < argc)
            lprintf(BRAIN_NOTICE, "  %s,", argv[a]);
        else
            lprintf(BRAIN_NOTICE, "%s\n", argv[a]);
    }
    
    /* prepare arguments */
    static char **child_args;
    int actual_argc = argc - optind;
    child_args = calloc(actual_argc + 1, sizeof(char*));
    if (!child_args)
    {
        lprintf(BRAIN_ERROR, LOG_PREFIX_FORMAT ": Not enough memory preparing arguments.\n",
                              thought_id, time_elapsed());
        exit(EXIT_FAILURE);
    }
    for (int a = optind; a < argc; a++)
    {
        child_args[a - optind] = (char*)argv[a];
    }
    child_args[actual_argc + 1 - optind] = NULL;
    
    if (!g_debug)
    {
        /* create a pipe to receive output from the child */
        int pipedes[2];
        if (pipe(pipedes))
        {
            lprintf(BRAIN_ERROR, LOG_PREFIX_FORMAT ": Couldn't create a pipe to the thought process.\n",
                    thought_id, time_elapsed());
            exit(EXIT_FAILURE);
        }
        if (fcntl(pipedes[0], F_SETFL, O_NONBLOCK))
        {
            lprintf(BRAIN_ERROR, LOG_PREFIX_FORMAT ": Couldn't configure pipe to the thought process.\n",
                    thought_id, time_elapsed());
            exit(EXIT_FAILURE);
        }
        
        /* make sure we don't get duplicate entries after fork() */
        log_flush();
        
        /* fork the thought process */
        g_script_pid = fork();
        if (g_script_pid < 0)
        {
            lprintf(BRAIN_ERROR, LOG_PREFIX_FORMAT ": Couldn't create the thought process.\n",
                    thought_id, time_elapsed());
            exit(EXIT_FAILURE);
        }
        if (g_script_pid > 0)
        {
            /* monitor cleanup */
            close(pipedes[1]);
            g_fd_output = pipedes[0];
            free(child_args);
            return;
        }
        
        /* connect the pipe to stdout */
        close(pipedes[0]);
        log_deinit();
        dup2(pipedes[1], STDOUT_FILENO);
        dup2(pipedes[1], STDERR_FILENO);
    }
    
    /* execute the thought process */
    if (execve(child_args[0], child_args, environ))
    {
        switch (errno)
        {
            case E2BIG:
            case ENAMETOOLONG:
            case ENOTDIR:
                lprintf(BRAIN_ERROR, "Arguments of thought are too long for this system.\n");
                break;
            case EACCES:
                lprintf(BRAIN_ERROR, "Insufficient priviledges to execute thought process.\n");
                break;
            case ENOENT:
                lprintf(BRAIN_ERROR, "Thought process cannot be found.\n");
                break;
            case ENOMEM:
                lprintf(BRAIN_ERROR, "Insufficient memory to execute thought.\n");
                break;
            default:
                lprintf(BRAIN_ERROR, "Thought execution failed because of an unknown %d error.\n", errno);
                break;
        }
        exit(EXIT_FAILURE);
    }
    /* successful execution begins in child main();
     we never get here */
}
示例#23
0
/* Entry point */
extern "C" int Menu_Main(void)
{
    //!*******************************************************************
    //!                   Initialize function pointers                   *
    //!*******************************************************************
    //! do OS (for acquire) and sockets first so we got logging
    InitOSFunctionPointers();
    InitSocketFunctionPointers();

    log_init(LOADIINE_LOGGER_IP);
    log_print("Starting Loadiine GX2 " LOADIINE_VERSION "\n");

    InitFSFunctionPointers();
    InitGX2FunctionPointers();
    InitSysFunctionPointers();
    InitVPadFunctionPointers();
    InitPadScoreFunctionPointers();
    InitAXFunctionPointers();
    InitCurlFunctionPointers();

    log_print("Function exports loaded\n");

    //!*******************************************************************
    //!                Initialize our kernel variables                   *
    //!*******************************************************************
    log_printf("Setup kernel variables\n");
    SetupKernelCallback();
    //!*******************************************************************
    //!                    Initialize heap memory                        *
    //!*******************************************************************
    log_print("Initialize memory management\n");
    memoryInitialize();

    //!*******************************************************************
    //!                        Initialize FS                             *
    //!*******************************************************************
    log_printf("Mount SD partition\n");
    mount_sd_fat("sd");

    //!*******************************************************************
    //!                       Patch Functions                            *
    //!*******************************************************************
    // We need to check if padcon should be enabled before hooking the functions
    log_printf("Load settings\n");
    CSettings::instance()->Load();

    int padmode = 0;
    switch(CSettings::getValueAsU8(CSettings::PadconMode))
    {
        case PADCON_ENABLED: {
            padmode = 1;
            log_printf("Padcon enabled\n");
            break;
        }
        default:
            break;
    }
    
    log_printf("Patch FS and loader functions\n");
    PatchMethodHooks(padmode);

    //!*******************************************************************
    //!                    Setup exception handler                       *
    //!*******************************************************************
    log_printf("Setup exception handler\n");
    setup_os_exceptions();

    //!*******************************************************************
    //!                    Enter main application                        *
    //!*******************************************************************
    log_printf("Start main application\n");
    Application::instance()->exec();
    log_printf("Main application stopped\n");

    Application::destroyInstance();
    
    CSettings::instance()->Save();
    CSettings::destroyInstance();

    log_printf("Unmount SD\n");
    unmount_sd_fat("sd");
    log_printf("Release memory\n");
    memoryRelease();
    log_printf("Loadiine peace out...\n");
    log_deinit();

    return 0;
}
示例#24
0
int main(int argc, char **argv)
{
    daemonize_close_stdin();

    parse_cmdline(argc, argv);

    if (!file_read_config())
        g_error("cannot read configuration file\n");

    log_init(file_config.log, file_config.verbose);

    daemonize_init(file_config.daemon_user, file_config.pidfile);

    if (!file_config.no_daemon)
        daemonize_detach();

    daemonize_write_pidfile();
    daemonize_set_user();

#ifndef NDEBUG
    if (!file_config.no_daemon)
#endif
        daemonize_close_stdout_stderr();

    main_loop = g_main_loop_new(NULL, FALSE);

    lmc_connect(file_config.host, file_config.port);
    http_client_init();
    as_init(file_config.scrobblers);

    setup_signals();

    timer = g_timer_new();

    /* set up timeouts */

    save_source_id = g_timeout_add_seconds(file_config.journal_interval,
                                           timer_save_journal, NULL);

    /* run the main loop */

    g_main_loop_run(main_loop);

    /* cleanup */

    g_message("shutting down\n");

    g_source_remove(save_source_id);
    g_main_loop_unref(main_loop);

    g_timer_destroy(timer);

    as_save_cache();
    as_cleanup();
    http_client_finish();
    lmc_disconnect();
    file_cleanup();
    log_deinit();

    daemonize_finish();

    return 0;
}