コード例 #1
0
ファイル: main.c プロジェクト: pzoleex/syslog-ng
int
main(int argc, char *argv[])
{
  gint rc;
  GOptionContext *ctx;
  GError *error = NULL;

  z_mem_trace_init("syslog-ng.trace");

  g_process_set_argv_space(argc, (gchar **) argv);

  setup_caps();

  resolved_configurable_paths_init(&resolvedConfigurablePaths);

  ctx = g_option_context_new("syslog-ng");
  g_process_add_option_group(ctx);
  msg_add_option_group(ctx);
  g_option_context_add_main_entries(ctx, syslogng_options, NULL);
  main_loop_add_options(ctx);
  if (!g_option_context_parse(ctx, &argc, &argv, &error))
    {
      fprintf(stderr, "Error parsing command line arguments: %s\n", error ? error->message : "Invalid arguments");
      g_option_context_free(ctx);
      return 1;
    }
  g_option_context_free(ctx);
  if (argc > 1)
    {
      fprintf(stderr, "Excess number of arguments\n");
      return 1;
    }

  if (display_version)
    {
      interactive_mode();
      version();
      return 0;
    }
  if (display_module_registry)
    {
      interactive_mode();
      plugin_list_modules(stdout, TRUE);
      return 0;
    }

  if(startup_debug_flag && debug_flag)
    {
      startup_debug_flag = FALSE;
    }

  if(startup_debug_flag)
    {
      debug_flag = TRUE;
    }

  if (debug_flag)
    {
      log_stderr = TRUE;
    }

  if (syntax_only || debug_flag)
    {
      g_process_set_mode(G_PM_FOREGROUND);
    }
  g_process_set_name("syslog-ng");

  /* in this case we switch users early while retaining a limited set of
   * credentials in order to initialize/reinitialize the configuration.
   */
  g_process_start();
  app_startup();
  main_loop_init();
  rc = main_loop_read_and_init_config();

  if (rc)
    {
      g_process_startup_failed(rc, TRUE);
      return rc;
    }
  else
    {
      if (syntax_only)
        g_process_startup_failed(0, TRUE);
      else
        g_process_startup_ok();
    }

  /* we are running as a non-root user from this point */

  app_post_daemonized();
  app_post_config_loaded();

  if(startup_debug_flag)
    {
      debug_flag = FALSE;
      log_stderr = FALSE;
    }

  /* from now on internal messages are written to the system log as well */

  main_loop_run();
  main_loop_deinit();

  app_shutdown();
  z_mem_trace_dump();
  g_process_finish();
  return rc;
}
コード例 #2
0
ファイル: main.c プロジェクト: caoguanqiu/midir
int main()
{
    int ret;

    	
	modules_init();//模块的初始化
    
	user_init();
    /* system tag data  */
    store_or_retrive_taged_config();
    
    get_mcu_version_from_psm();

    LOG_DEBUG("rst cause is %x\r\n", boot_reset_cause());

#ifdef MIIO_COMMANDS
    mcmd_enqueue_raw("MIIO_model_req");
    mcmd_enqueue_raw("MIIO_mcu_version_req");
#endif

    ret = os_mutex_create(&network_state_mutex,"network_state",OS_MUTEX_INHERIT);
    if(WM_SUCCESS != ret) {
        LOG_ERROR("create network_state_mutex fail");
        goto main_error;
    }

    register_device_network_state_observer(led_network_state_observer);
    
    /*set wifi calbration data*/
    product_set_wifi_cal_data();

    /* Start the application framework */
    if ((ret = app_framework_start(common_event_handler)) != WM_SUCCESS) {
        LOG_ERROR("Failed to start application framework.\r\n");
#if defined(CONFIG_CPU_MC200)
        if (-WLAN_ERROR_FW_DNLD_FAILED == ret || -WLAN_ERROR_FW_NOT_DETECTED == ret
                || -WLAN_ERROR_FW_NOT_READY == ret) {
            LOG_WARN("Wifi firmware broken, trying to recover.\r\n");
            if (recover_wifi_fw() != WM_SUCCESS) {
                LOG_FATAL("Recovering wifi fw failed!!!\r\n");
            } else {
                LOG_WARN("Recovering wifi fw success.\r\n");
                pm_reboot_soc();
            }
        }
#endif
        appln_critical_error_handler((void *) -WM_FAIL);
    }

    ret = is_factory_mode_enable();
    LOG_DEBUG("factory mode magic is %x\r\n" ,get_factory_mode_enable());
    if (0 == ret) {
        // user mode
        static xTaskHandle task_handle;
        if (app_thread) {
            xTaskCreate(app_thread, (signed char*) "app", 2000, NULL, APPLICATION_PRIORITY,
                    &task_handle);
            xTaskCreate(app_uart_thread, (signed char*) "app_uart", 2000, NULL, APPLICATION_PRIORITY,
                    &task_handle);
            LOG_INFO("App thread and App uart thread started.\r\n");
        }
    } else {
        // factory mode
        static xTaskHandle task_handle;
        if (app_test_thread) {
            xTaskCreate(app_test_thread, (signed char*) "test", 2000, NULL, 2,
                    &task_handle);
            LOG_INFO("Test thread started.\r\n");
        }
    }
    
    // Initialize power management
	hp_pm_init();
    
    //enter main loop, main loop will be used as a worker thread
    main_loop_run();

    //main loop return means error
main_error: 
    pm_reboot_soc(); //error occure on main thread , reboot
	return 1;
}