int ipc_initip(u32 input_width, u32 input_height,  ipc_2d ipc2d)
{
	if(input_width > IN_SC_MAX_WIDTH || input_height > IN_SC_MAX_HEIGHT) {
		err("IPC input size error\n");
		ipc_off();
		return -EINVAL;
	}

	ipc_input_src.imghsz = input_width;
	ipc_input_src.imgvsz = input_height;
	ipc_input_src.srchsz = input_width;
	ipc_input_src.srcvsz = input_height;

	ipc_output_dst.scanmode = PROGRESSIVE;
			
	if(ipc2d == IPC_2D) {
		ipc_output_dst.dsthsz = input_width;
		ipc_output_dst.dstvsz = input_height*2;		
	} else {
		ipc_output_dst.dsthsz = input_width*2;
		ipc_output_dst.dstvsz = input_height;		
	}

	ipc_con_var.modeval = ipc2d;

	ipc_init(ipc_input_src, ipc_output_dst, ipc_con_var);

	return 0;
}
static void adapter_ready(int err, const bdaddr_t *addr)
{
	if (err < 0) {
		error("Adapter initialization failed: %s", strerror(-err));
		exit(EXIT_FAILURE);
	}

	bacpy(&adapter_bdaddr, addr);

	if (quit_timeout > 0) {
		g_source_remove(quit_timeout);
		quit_timeout = 0;
	}

	info("Adapter initialized");

	hal_ipc = ipc_init(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH),
						HAL_SERVICE_ID_MAX, true,
						ipc_disconnected, NULL);
	if (!hal_ipc) {
		error("Failed to initialize IPC");
		exit(EXIT_FAILURE);
	}

	ipc_register(hal_ipc, HAL_SERVICE_ID_CORE, cmd_handlers,
						G_N_ELEMENTS(cmd_handlers));
}
Esempio n. 3
0
/**
 * Initialize IPC stuff
 *
 * @return zero on success, non-zero otherwise
 */
int
wt_ipc_init (void)
{
  read_config ();

  if (blacklisting)
    {
      if (ipc_blacklist_init (blacklist_file, reset_timeout))
        {
          blacklisting_error = TRUE;
          return -1;
        }
    }

  if (ipc_init (host, port))
    {
      return -1;
    }

  ipc_enabled = TRUE;

  hook_register (CORE_ACTIVATE, wt_ipc_start, 0, HOOK_PRIORITY_NORMAL);
  hook_register (CORE_DEACTIVATE, wt_ipc_stop, 0, HOOK_PRIORITY_NORMAL);

  mutex = mutex_create ();

  wt_ipc_builtin_init ();

  return 0;
}
Esempio n. 4
0
static int idaapi init(void)
{
	if (!strcmp(inf.procName, "metapc"))
	{
		if (inf.is_64bit())
			patchdiff_cpu = CPU_X8664;
		else
			patchdiff_cpu = CPU_X8632;
	}
	else if (!strcmp(inf.procName, "PPC"))
	{
		patchdiff_cpu = CPU_PPC;
	}
	else
		patchdiff_cpu = CPU_DEFAULT;

	d_engine = NULL;
	
	// handle IPC
	ipc_init(NULL, 0, 0);

	d_opt = options_init();
	if (!d_opt)
		return PLUGIN_SKIP;

	return PLUGIN_OK;
}
Esempio n. 5
0
int platform_init(struct sof *sof)
{
	int ret;
	struct dai *esai;

	clock_init();
	scheduler_init();

	platform_timer_start(platform_timer);
	sa_init(sof);

	clock_set_freq(CLK_CPU(cpu_get_id()), CLK_MAX_CPU_HZ);

	/* init DMA */
	ret = edma_init();
	if (ret < 0)
		return -ENODEV;

	/* initialize the host IPC mechanims */
	ipc_init(sof);

	ret = dai_init();
	if (ret < 0)
		return -ENODEV;

	esai = dai_get(SOF_DAI_IMX_ESAI, 0, DAI_CREAT);
	if (!esai)
		return -ENODEV;

	dai_probe(esai);

	return 0;
}
Esempio n. 6
0
int main(int argc, char **argv) {

  char *mon_dg;


  /* decode command line */
  decode_command_line(argc,argv);
  
  /* set application */
  ipc_set_application(application);
  
  /* set destination */
  if(destination==NULL)destination=strdup(application);
  
  /* inhibit boilerplate for brief mode */
  if(brief==1)TutSetOutputFunc(ipc_output_dummy);

  /*  connect to server */
  ipc_init("","ipc test monitor");
  
  /*  define callback to add user information to status_poll_result message */
  ipc_set_user_status_poll_callback(mystatuspollcallback);
  
  /* receive status_poll_result message group */
  ipc_get_status_poll_group(&mon_dg);
  TipcSrvDgSetRecv(mon_dg,TRUE);
  
  /*  define callback to handle (i.e. print) status_poll_result messages */
  TipcSrvProcessCbCreate(TipcMtLookup("status_poll_result"),print_status_result,NULL);
  
  /* set alarm if polltime > 0 */
  if(polltime>0) {
    
    /* declare SIGALRM handler */
    signal(SIGALRM,alarm_handler);
    
    /* set alarm */
    alarm(polltime);

  } else if (once==1) {
    T_IPC_MSG msg=TipcMsgCreate(TipcMtLookupByNum(T_MT_CONTROL));
    TipcMsgSetDest(msg,destination);
    TipcMsgAppendStr(msg,"status_poll");
    TipcSrvMsgSend(msg,TRUE);
    TipcSrvFlush();
    TipcMsgDestroy(msg);
  }
  
  /* process messages */
  if(brief==1)TutSetOutputFunc(NULL);
  for (;;) {
    TipcSrvMainLoop((double)waittime);
    if(once==1)break;
  }
  if(brief==1)TutSetOutputFunc(ipc_output_dummy);
  
  exit(EXIT_SUCCESS);
}
Esempio n. 7
0
// The kernel main function. Initialize everything and start the kernel
// debugger. The two arguments are the physical address of the Multiboot info
// structure and the bootloader magic number respectively.
void
init()
{
    int r;

    // Initialize the console first to print messages during the initialization
    cons_init();

    kprintf("Argentum Operating System\n");

    arch_init();

    kmem_cache_init();
    kmem_cache_sizes_init();

    vm_init();
    process_init();
    thread_init();
    ipc_init();
    scheduler_init();
    sync_init();
    clock_init();

    if ((r = process_create_system(system_main, NULL)) < 0)
        kprintf("Cannot create system process: %s\n", strerror(-r));

    if (module_start) {
        Boot_image *image = (Boot_image *) module_start;
    
        if(image->magic != 0x12345678)
            panic("invalid bootimage");

        for (unsigned i = 0; i < image->length; i++) {
            uint8_t *binary = (uint8_t *) image + image->headers[i].offset;
            size_t size = image->headers[i].length;

            if (binary < module_start || binary >= module_end)
                panic("invalid bootimage");
            if ((binary + size) <= module_start || (binary + size) > module_end)
                panic("invalid bootimage");

            r = process_create((uint8_t *) image + image->headers[i].offset,
                    image->headers[i].length, PROCESS_TYPE_USER, NULL);
            if (r < 0)
                panic("Cannot create process: %s", strerror(-r));
        }

    }

    scheduler_start();

    for (;;) {
        kdb_main(NULL);
    }
}
Esempio n. 8
0
/*
 * Allocate memory and IPC for a plugin. init the IPC.
 */
void
plugin_alloc(const char *name, struct agent_core_t *core)
{
	struct agent_plugin_t *plug;

	ALLOC_OBJ(plug);
	ALLOC_OBJ(plug->ipc);
	ipc_init(plug->ipc);
	plug->name = strdup(name);
	assert(plug->name);
	plug->next = core->plugins;
	core->plugins = plug;
}
Esempio n. 9
0
int danipc_ll_init(struct danipc_priv *priv)
{
	int		rc = -1;

	if (alloc_ipc_buffers(priv) != NULL) {
		prepare_nodes();
		remap_agent_table(priv);
		init_own_ipc_to_virt_map(priv);
		remap_apps_ipc_mux(priv);
		rc = ipc_init();
	}

	return rc;
}
Esempio n. 10
0
/* --------------------------------
 *		init_server_ipc
 *
 *		This routine initializes stuff needed for ipc, locking, etc.
 *		it should be called something more informative.
 * --------------------------------
 */
static void
init_server_ipc(void)
{
	/*
	 * initialize shared memory and semaphores appropriately.
	 */
	if (!child) {	/* postmaster already did this */ 
		/*
		 * We're running a postgres bootstrap process or a standalone backend.
		 * Create private "shmem" and semaphores.
		 */
		ipc_init(true, 0);
	}
}
Esempio n. 11
0
int main(int argc, char** argv) {

  int c;

  carmen_ipc_initialize(argc,argv);
  carmen_param_check_version(argv[0]);
  signal(SIGINT, shutdown_module);

  if (argc > 1 && !strcmp(argv[1], "-sim"))
    simulation = 1;

  if (carmen_map_get_hmap(&hmap) < 0)
    carmen_die("no hmap found\n");
  print_hmap(); //dbug
  carmen_map_change_map_zone(hmap.zone_names[0]);  //dbug: this should go in the map server
  map_zone = 0;

  ipc_init();

  carmen_terminal_cbreak(0);

  while(1) {
    carmen_ipc_sleep(0.01);
    c = getchar();
    /*
    if (c == EOF)
      break;
    */
    if (c != 27)
      continue;
    c = getchar();
    /*
    if (c == EOF)
      break;
    */
    if (c != 91)
      continue;
    c = getchar();
    /*
    if (c == EOF)
      break;
    */
    switch(c) {
    case 65: level_up(); break;
    case 66: level_down();
    }
  }
   
  return 0;
}
Esempio n. 12
0
static bool bt_audio_register(ipc_disconnect_cb disconnect)
{
	DBG("");

	audio_ipc = ipc_init(BLUEZ_AUDIO_SK_PATH, sizeof(BLUEZ_AUDIO_SK_PATH),
				AUDIO_SERVICE_ID_MAX, false, disconnect, NULL);
	if (!audio_ipc)
		return false;

	ipc_register(audio_ipc, AUDIO_SERVICE_ID, audio_handlers,
						G_N_ELEMENTS(audio_handlers));

	return true;
}
Esempio n. 13
0
int *ipc_init_(const char *uniq_dgrp, const char *id_str, int len1, int len2) {

  int i;

  char *uniq=strdupf(uniq_dgrp,len1);
  char *id=strdupf(id_str,len2);

  i=ipc_init(uniq,id);

  free(uniq);
  free(id);

  return ( (int*) i);
}
Esempio n. 14
0
void setup_kernel()
{
    setup_arch();

    /* Init IRQ and timer system */
    __disable_interrupts();
    irq_disable();
    irq_init();
//    scheduler_init();
    /* timer_init(); */
    ipc_init();
    irq_enable();

//    mmu_init();
}
Esempio n. 15
0
static void run_second_instance(const char * options)
{
	slist_t * sl;
	char file[QMAXPATH];
	ea_t ea = BADADDR;
	unsigned char opt = 0;
	long id;
	unsigned int v;
	bool cont;
	char tmp[QMAXPATH*4];
	
	qsscanf(options, "%lu:%" PRIea_t ":%u:%s", &id, &ea, &v, file);
	opt = (unsigned char)v;
	
	if (id)
	{
		if (ipc_init(file, 2, id))
		{
			do
			{
				cont = ipc_recv_cmd(tmp, sizeof(tmp));
				if (cont)
				{
					run_second_instance(tmp);
					ipc_recv_cmd_end();
				}

			}while(cont);
		}
	}
	else
	{
		if (ea == BADADDR)
		{
			sl = parse_idb ();
		}
		else
			sl = parse_fct(ea, opt);

		if (!sl) return;
		
		siglist_save(sl, file);

		siglist_free(sl);
	}
}
Esempio n. 16
0
static void adapter_ready(int err, const bdaddr_t *addr)
{
	if (err < 0) {
		error("Adapter initialization failed: %s", strerror(-err));
		exit(EXIT_FAILURE);
	}

	bacpy(&adapter_bdaddr, addr);

	if (bluetooth_start_timeout > 0) {
		g_source_remove(bluetooth_start_timeout);
		bluetooth_start_timeout = 0;
	}

	info("Adapter initialized");

	ipc_init();
}
Esempio n. 17
0
T_QUEUE ipc_setup(void)
{
	/* Framework initializations */
	T_QUEUE queue = queue_create(32, NULL);
	assert(queue);

	/* Initialize IPC: channels have been chosen arbitrarily */
	ipc_init(0, 5, 1, 6, CPU_ID_ARC);
	ipc_async_init(queue);

	set_cpu_id(CPU_ID_QUARK);
	set_cpu_message_sender(CPU_ID_ARC, ipc_async_send_message);
	set_cpu_free_handler(CPU_ID_ARC, ipc_async_free_message);
#ifdef CONFIG_IPC_UART
	set_cpu_message_sender(CPU_ID_BLE, send_message_ipc_uart);
	set_cpu_free_handler(CPU_ID_BLE, free_message_ipc_uart);
#endif
	return queue;
}
Esempio n. 18
0
/* 
 * Entry point of program execution 
 */ 
int main( void ) 
{ 
  prvSetupHardware(); 
  IOE_Config(); 

#ifdef CONFIG_ENABLE_PRINTER
  printQueue = xQueueCreate(128, 1);
#endif

  setup_buttons();
  initDisplay();  
  ipc_measure_init();


  if(pdFALSE == ipc_init()) 
  { 
    ipc_watchdog_signal_error(0);
  }

  if(pdFALSE == task_measure_init())
  { 
    ipc_watchdog_signal_error(0);
  }

#ifdef CONFIG_ENABLE_PRINTER
  xTaskCreate(printTask, "print", 100, NULL, 1, NULL); 
#endif

  xTaskCreate(task_controller, "Controller", 100, NULL, 1, NULL); 
  xTaskCreate(task_watchdog, "Watchdog driver", 100, NULL, 1, NULL); 
  xTaskCreate(task_input_gpio, "Input driver for GPIO", 100, NULL, 1, NULL); 
  xTaskCreate(task_input_touch, "Input driver for touchscreen", 200, NULL, 1, NULL); 
  xTaskCreate(task_display, "Display", 300, NULL, 1, NULL); 
  xTaskCreate(task_measure_cmd, "ADC-driver: controller", 100, NULL, 1, NULL); 
  xTaskCreate(task_measure, "ADC-driver: IRQ interface", 100, NULL, 1, NULL); 

  vTaskStartScheduler(); 

  ipc_watchdog_signal_error(0);
  while(1);
} 
Esempio n. 19
0
int APE_frame_init( aduio_info *ai, unsigned char *codecdata ,int codecdata_len,int channels ,int bitpersample  ){
    
         int init = 1 , ret;
         union smc *sc = (union smc *)sm_com;
         play_init *pi = &sc->pinit;
         serv_init *si = &sc->sinit;
      


         //send to server 
         //some parameters to server for ini   
         pi->paremeter2 = channels ; 
         pi->paremeter3 = bitpersample ;  



          memcpy(sm_in,codecdata, codecdata_len); 
       
         if(!ipc_init(sc, APE_ID, codecdata_len, id, sm_data_id, 0)) //init server
	    return -1;//break;		//IPC Error 
         if (si->codec_id == APE_ID)
            ret = 0;
         else
            ret = si->codec_id;   //error code

         init = 0;
     
			*ai = si->ai;
#ifndef  EngineMode
	if(sm_out == NULL || sm_out == (void *)-1)
		sm_out = (void*)shmat(sc->sinit.shmid, (void *)0, 0);		//只有initial成功才會allocate sm_out
#endif


          

       return ret; // OK!!!
     

}
Esempio n. 20
0
File: ldmc.c Progetto: LemonBoy/ldm
int
main (int argc, char **argv)
{
	int opt;
	int ipc_fd;
	int ret;

	if (argc == 1) {
		usage ();
		return EXIT_FAILURE;
	}

	ret = EXIT_SUCCESS;

	while ((opt = getopt(argc, argv, "hlr:")) != -1) {
		switch (opt) {
			case 'l':
			case 'r':
				ipc_fd = ipc_init(0);

				// Could not open the ipc socket
				if (ipc_fd < 0)
					return EXIT_FAILURE;

				// Propagate the error code to the exit status
				if (!ipc_send(ipc_fd, (char)opt, optarg))
					ret = EXIT_FAILURE;

				close(ipc_fd);
				break;

			default:
			case 'h':
				usage ();
		}
	}

	return ret;
}
Esempio n. 21
0
// TODO: To standard this scenario
void start_dooloo(void)
{
    interrupt_disable();

    os_hw_init();

    kprintf("\n\nProbability core Version %s\n", OS_VERSION);
    kprintf("Author: Puhui Xiong ([email protected]) \n\n");

    /* trace irq stack */
    _irq_stack_start[0] = _irq_stack_start[1] = '#';

    memory_inita();

    task_init();
    kprintf("  Task subsystem inited.\n");

    ipc_init();
    kprintf("  IPC subsystem inited.\n");

    memory_initb();
    kprintf("  Memory subsystem inited.\n");

    idletask_init();
    root_task_init();
    kprintf("  Create task tidle and troot.\n");

    task_set_schedule_hook(default_sched_hook);

    /* set current to an invalid tcb, then begin to schedule */
    current = &systask[0];
    kprintf("  Ready to first scheduling, go!!\n\n");
    /* before schedule, we have to enable interrupt for pendsv() used */
    interrupt_enable();
    task_schedule();

    kprintf("\nSystem halted.\n");
    while(1);
}
Esempio n. 22
0
int
main(
	int		         argc,
	char		       **argv)
{
	int		         ret;
	Ipc_msg_qid	      queueA;
   char              c;

   loop_normal = MAX_NORMAL_MSGS;

   while ((c = getopt(argc, argv, "i:n:")) != EOF)
   {
      switch(c)
      {
         case 'i':
            sprintf(instance_name, "%s", optarg);
            break;
         case 'n':
            loop_normal = atol(optarg);
            break;
         default:
            usage();
            exit(1);
      }
   }

	if (argc < 2)
		usage();

	ipc_init();
	queue_create(&queueA);
	test_generic_message(queueA, 0);

   printf("\n\nFAST PATH\n\n");
	test_generic_message(queueA, IPC_MSG_FASTPATH);
	queue_destroy(queueA);
	return(0);
}
Esempio n. 23
0
main()
{
  int err;
  char *name;
  T_IPC_MT mt;
  char *monitor_group;
  char *uniq_dgrp;
  T_OPTION opt;


  err=ipc_set_quit_callback(myquitcallback); 
  if(err!=0)ipc_perror(err);

  err=ipc_set_user_status_poll_callback(mystatuspollcallback);

  err=ipc_set_alarm_poll_time(1);
  if(err!=0)ipc_perror(err);

  err=ipc_init("","ipc system test");
  if(err!=0)ipc_perror(err);

  opt=TutOptionLookup("Unique_Datagroup");
  err=TutOptionGetEnum(opt,&uniq_dgrp);

  err=tclipc_init(NULL);

  err=ipc_get_application(&name);

  err=ipc_get_unique_datagroup(&name);

  err=ipc_get_status_poll_group(&monitor_group);


  for(;;){
    TutSleep(1000.0);
  }
}
Esempio n. 24
0
/**
 * Showtime main
 */
int
main(int argc, char **argv)
{
    struct timeval tv;
    const char *settingspath = NULL;
    const char *uiargs[16];
    const char *argv0 = argc > 0 ? argv[0] : "showtime";
    const char *forceview = NULL;
    int nuiargs = 0;
    int can_standby = 0;
    int can_poweroff = 0;
    int r;

    trace_level = TRACE_INFO;

    gettimeofday(&tv, NULL);
    srand(tv.tv_usec);

    arch_set_default_paths(argc, argv);

    /* We read options ourselfs since getopt() is broken on some (nintento wii)
       targets */

    argv++;
    argc--;

    while(argc > 0) {
        if(!strcmp(argv[0], "-h") || !strcmp(argv[0], "--help")) {
            printf("HTS Showtime %s\n"
                   "Copyright (C) 2007-2010 Andreas Öman\n"
                   "\n"
                   "Usage: %s [options] [<url>]\n"
                   "\n"
                   "  Options:\n"
                   "   -h, --help        - This help text.\n"
                   "   -d                - Enable debug output.\n"
                   "   --ffmpeglog       - Print ffmpeg log messages.\n"
                   "   --with-standby    - Enable system standby.\n"
                   "   --with-poweroff   - Enable system power-off.\n"
                   "   -s <path>         - Non-default Showtime settings path.\n"
                   "   --ui <ui>         - Use specified user interface.\n"
                   "   -L <ip:host>      - Send log messages to remote <ip:host>.\n"
                   "   --syslog          - Send log messages to syslog.\n"
#if ENABLE_STDIN
                   "   --stdin           - Listen on stdin for events.\n"
#endif
                   "   -v <view>         - Use specific view for <url>.\n"
                   "   --cache <path>    - Set path for cache [%s].\n"
#if ENABLE_SERDEV
                   "   --serdev          - Probe service ports for devices.\n"
#endif
                   "\n"
                   "  URL is any URL-type supported by Showtime, "
                   "e.g., \"file:///...\"\n"
                   "\n",
                   htsversion_full,
                   argv0,
                   showtime_cache_path);
            exit(0);
            argc--;
            argv++;

        } else if(!strcmp(argv[0], "-d")) {
            trace_level++;
            argc -= 1;
            argv += 1;
            continue;
        } else if(!strcmp(argv[0], "--ffmpeglog")) {
            ffmpeglog = 1;
            argc -= 1;
            argv += 1;
            continue;
        } else if(!strcmp(argv[0], "--syslog")) {
            trace_to_syslog = 1;
            argc -= 1;
            argv += 1;
            continue;
        } else if(!strcmp(argv[0], "--stdin")) {
            listen_on_stdin = 1;
            argc -= 1;
            argv += 1;
            continue;
#if ENABLE_SERDEV
        } else if(!strcmp(argv[0], "--serdev")) {
            enable_serdev = 1;
            argc -= 1;
            argv += 1;
            continue;
#endif
        } else if(!strcmp(argv[0], "--with-standby")) {
            can_standby = 1;
            argc -= 1;
            argv += 1;
            continue;
        } else if(!strcmp(argv[0], "--with-poweroff")) {
            can_poweroff = 1;
            argc -= 1;
            argv += 1;
            continue;
        } else if(!strcmp(argv[0], "-s") && argc > 1) {
            settingspath = argv[1];
            argc -= 2;
            argv += 2;
            continue;
        } else if(!strcmp(argv[0], "--ui") && argc > 1) {
            if(nuiargs < 16)
                uiargs[nuiargs++] = argv[1];
            argc -= 2;
            argv += 2;
            continue;
        } else if(!strcmp(argv[0], "-L") && argc > 1) {
            showtime_logtarget = argv[1];
            argc -= 2;
            argv += 2;
            continue;
        } else if (!strcmp(argv[0], "-v") && argc > 1) {
            forceview = argv[1];
            argc -= 2;
            argv += 2;
        } else if (!strcmp(argv[0], "--cache") && argc > 1) {
            mystrset(&showtime_cache_path, argv[1]);
            argc -= 2;
            argv += 2;
#ifdef __APPLE__
            /* ignore -psn argument, process serial number */
        } else if(!strncmp(argv[0], "-psn", 4)) {
            argc -= 1;
            argv += 1;
            continue;
#endif
        } else
            break;
    }


    unicode_init();

    /* Initialize property tree */
    prop_init();
    init_global_info();

    /* Initiailize logging */
    trace_init();

    /* Callout framework */
    callout_init();

    /* Notification framework */
    notifications_init();

    /* Architecture specific init */
    arch_init();

    htsmsg_store_init();

    /* Try to create cache path */
    if(showtime_cache_path != NULL &&
            (r = makedirs(showtime_cache_path)) != 0) {
        TRACE(TRACE_ERROR, "cache", "Unable to create cache path %s -- %s",
              showtime_cache_path, strerror(r));
        showtime_cache_path = NULL;
    }

    /* Initializte blob cache */
    blobcache_init();

    /* Try to create settings path */
    if(showtime_settings_path != NULL &&
            (r = makedirs(showtime_settings_path)) != 0) {
        TRACE(TRACE_ERROR, "settings", "Unable to create settings path %s -- %s",
              showtime_settings_path, strerror(r));
        showtime_settings_path = NULL;
    }

    /* Initialize keyring */
    keyring_init();

    /* Initialize settings */
    settings_init();

    /* Initialize libavcodec & libavformat */
    av_lockmgr_register(fflockmgr);
    av_log_set_callback(fflog);
    av_register_all();

    /* Freetype keymapper */
#if ENABLE_LIBFREETYPE
    freetype_init();
#endif

    /* Global keymapper */
    keymapper_init();

    /* Initialize media subsystem */
    media_init();

    /* Service handling */
    service_init();

    /* Initialize backend content handlers */
    backend_init();

    /* Initialize navigator */
    nav_init();

    /* Initialize audio subsystem */
    audio_init();

    /* Initialize bookmarks */
    bookmarks_init();

    /* Initialize plugin manager and load plugins */
    plugins_init();

    /* Internationalization */
    i18n_init();


    nav_open(NAV_HOME, NULL);

    /* Open initial page */
    if(argc > 0)
        nav_open(argv[0], forceview);

    /* Various interprocess communication stuff (D-Bus on Linux, etc) */
    ipc_init();

    /* Service discovery. Must be after ipc_init() (d-bus and threads, etc) */
    sd_init();

    /* Initialize various external APIs */
    api_init();

    /* HTTP server and UPNP */
#if ENABLE_HTTPSERVER
    http_server_init();
    upnp_init();
#endif


    /* */
    runcontrol_init(can_standby, can_poweroff);

    TRACE(TRACE_DEBUG, "core", "Starting UI");

    /* Initialize user interfaces */
    ui_start(nuiargs, uiargs, argv0);

    finalize();
}
Esempio n. 25
0
void
kernel_bootstrap(void)
{
    kern_return_t	result;
    thread_t	thread;
    char		namep[16];

    printf("%s\n", version); /* log kernel version */

#define kernel_bootstrap_kprintf(x...) /* kprintf("kernel_bootstrap: " x) */

    if (PE_parse_boot_argn("-l", namep, sizeof (namep))) /* leaks logging */
        turn_on_log_leaks = 1;

    PE_parse_boot_argn("trace", &new_nkdbufs, sizeof (new_nkdbufs));

    /* i386_vm_init already checks for this ; do it aagin anyway */
    if (PE_parse_boot_argn("serverperfmode", &serverperfmode, sizeof (serverperfmode))) {
        serverperfmode = 1;
    }
    scale_setup();

    kernel_bootstrap_kprintf("calling vm_mem_bootstrap\n");
    vm_mem_bootstrap();

    kernel_bootstrap_kprintf("calling vm_mem_init\n");
    vm_mem_init();

    machine_info.memory_size = (uint32_t)mem_size;
    machine_info.max_mem = max_mem;
    machine_info.major_version = version_major;
    machine_info.minor_version = version_minor;

    kernel_bootstrap_kprintf("calling sched_init\n");
    sched_init();

    kernel_bootstrap_kprintf("calling wait_queue_bootstrap\n");
    wait_queue_bootstrap();

    kernel_bootstrap_kprintf("calling ipc_bootstrap\n");
    ipc_bootstrap();

#if CONFIG_MACF
    mac_policy_init();
#endif
    kernel_bootstrap_kprintf("calling ipc_init\n");
    ipc_init();

    /*
     * As soon as the virtual memory system is up, we record
     * that this CPU is using the kernel pmap.
     */
    kernel_bootstrap_kprintf("calling PMAP_ACTIVATE_KERNEL\n");
    PMAP_ACTIVATE_KERNEL(master_cpu);

    kernel_bootstrap_kprintf("calling mapping_free_prime\n");
    mapping_free_prime();						/* Load up with temporary mapping blocks */

    kernel_bootstrap_kprintf("calling machine_init\n");
    machine_init();

    kernel_bootstrap_kprintf("calling clock_init\n");
    clock_init();

    ledger_init();

    /*
     *	Initialize the IPC, task, and thread subsystems.
     */
    kernel_bootstrap_kprintf("calling task_init\n");
    task_init();

    kernel_bootstrap_kprintf("calling thread_init\n");
    thread_init();

    /*
     *	Create a kernel thread to execute the kernel bootstrap.
     */
    kernel_bootstrap_kprintf("calling kernel_thread_create\n");
    result = kernel_thread_create((thread_continue_t)kernel_bootstrap_thread, NULL, MAXPRI_KERNEL, &thread);

    if (result != KERN_SUCCESS) panic("kernel_bootstrap: result = %08X\n", result);

    thread->state = TH_RUN;
    thread_deallocate(thread);

    kernel_bootstrap_kprintf("calling load_context - done\n");
    load_context(thread);
    /*NOTREACHED*/
}
Esempio n. 26
0
/* Init everything before forking, so we can fail and return an
 * error code in the parent and the initscript will fail */
static int start_server(void)
{
	int api = 2, busy = 0;

	if (geteuid() != 0) {
		smclog(LOG_ERR, "Need root privileges to start %s", prognm);
		return 1;
	}

	if (background) {
		if (daemon(0, 0) < 0) {
			smclog(LOG_ERR, "Failed daemonizing: %s", strerror(errno));
			return 1;
		}
	}

	/* Hello world! */
	smclog(LOG_NOTICE, "%s", version_info);

	if (startup_delay > 0) {
		smclog(LOG_INFO, "Startup delay requested, waiting %d sec before continuing.", startup_delay);
		sleep(startup_delay);
	}

	/*
	 * Timer API needs to be initilized before mroute4_enable()
	 */
	timer_init();

	/*
	 * Build list of multicast-capable physical interfaces
	 */
	iface_init();

	if (mroute4_enable(do_vifs, table_id, cache_tmo)) {
		if (errno == EADDRINUSE)
			busy++;
		api--;
	}

	if (mroute6_enable(do_vifs, table_id)) {
		if (errno == EADDRINUSE)
			busy++;
		api--;
	}

	/* At least one API (IPv4 or IPv6) must have initialized successfully
	 * otherwise we abort the server initialization. */
	if (!api) {
		if (busy)
			smclog(LOG_ERR, "Another multicast routing application is already running.");
		else
			smclog(LOG_ERR, "Kernel does not support multicast routing.");
		exit(1);
	}

	atexit(clean);
	signal_init();
	ipc_init();

	conf_read(conf_file, do_vifs);

	/* Everything setup, notify any clients waiting for us */
	notify_ready(pid_file, uid, gid);

	/* Drop root privileges before entering the server loop */
	cap_drop_root(uid, gid);

	return server_loop();
}
Esempio n. 27
0
File: main.c Progetto: wgc1212/pimd
int main(int argc, char *argv[])
{
    int foreground = 0, do_syslog = 1;
    fd_set fds;
    int nfds, fd, n = -1, i, ch;
    struct sigaction sa;
    struct option long_options[] = {
	{ "config",        1, 0, 'f' },
	{ "no-fallback",   0, 0, 500 },
	{ "disable-vifs",  0, 0, 'N' },
	{ "foreground",    0, 0, 'n' },
	{ "help",          0, 0, 'h' },
	{ "ident",         1, 0, 'I' },
	{ "loglevel",      1, 0, 'l' },
	{ "pidfile",       1, 0, 'P' },
	{ "syslog",        0, 0, 's' },
	{ "table-id",      1, 0, 't' },
	{ "version",       0, 0, 'v' },
	{ NULL, 0, 0, 0 }
    };

    snprintf(versionstring, sizeof (versionstring), "pimd version %s", PACKAGE_VERSION);

    prognm = ident = progname(argv[0]);
    while ((ch = getopt_long(argc, argv, "d:f:hI:l:nNP:rst:v", long_options, NULL)) != EOF) {
	const char *errstr;

	switch (ch) {
	    case 'd':
		{
		    char *p,*q;
		    size_t i, len;
		    struct debugname *d;

		    debug = 0;
		    p = optarg;
		    q = NULL;
		    while (p) {
			q = strchr(p, ',');
			if (q)
			    *q++ = '\0';
			len = strlen(p);
			for (i = 0, d = debugnames; i < ARRAY_LEN(debugnames); i++, d++) {
			    if (len >= d->nchars && strncmp(d->name, p, len) == 0)
				break;
			}

			if (i == ARRAY_LEN(debugnames))
			    return usage(1);

			debug |= d->level;
			p = q;
		    }
		}
		break;

	    case 'f':
		config_file = optarg;
		break;

	    case 500:
		no_fallback = 1;
		break;

	    case 'h':
		return usage(0);

	    case 'I':	/* --ident=NAME */
		ident = optarg;
		break;

	    case 'l':
		loglevel = loglvl(optarg);
		if (-1 == loglevel)
		    return usage(1);
		break;

	    case 'n':
		do_syslog--;
		foreground = 1;
		break;

	    case 'N':
		do_vifs = 0;
		break;

	    case 'P':	/* --pidfile=NAME */
		pid_file = strdup(optarg);
		break;

	    case 'r':
		retry_forever++;
		break;

	    case 's':
		do_syslog++;
		break;

	    case 't':
		mrt_table_id = strtonum(optarg, 0, 999999999, &errstr);
		if (errstr) {
		    fprintf(stderr, "Table ID %s!\n", errstr);
		    return usage(1);
		}
		break;

	    case 'v':
		printf("%s\n", versionstring);
		return 0;

	    default:
		return usage(1);
	}
    }

    argc -= optind;
    if (argc > 0)
	return usage(1);

    if (geteuid() != 0)
	errx(1, "Need root privileges to start.");

    compose_paths();
    setlinebuf(stderr);

    if (debug != 0) {
	struct debugname *d;
	char c;
	int tmpd = debug;

	fprintf(stderr, "debug level 0x%lx ", debug);
	c = '(';
	for (d = debugnames; d < debugnames + ARRAY_LEN(debugnames); d++) {
	    if ((tmpd & d->level) == d->level) {
		tmpd &= ~d->level;
		fprintf(stderr, "%c%s", c, d->name);
		c = ',';
	    }
	}
	fprintf(stderr, ")\n");
    }

    if (!debug && !foreground) {
	/* Detach from the terminal */
	haveterminal = 0;
	if (fork())
	    exit(0);

	close(STDIN_FILENO);
	close(STDOUT_FILENO);
	close(STDERR_FILENO);

	fd = open("/dev/null", O_RDWR, 0);
	if (fd >= 0) {
	    dup2(fd, STDIN_FILENO);
	    dup2(fd, STDOUT_FILENO);
	    dup2(fd, STDERR_FILENO);
	    close(fd);
	}
#ifdef SYSV
	setpgrp();
#else
#ifdef TIOCNOTTY
	fd = open("/dev/tty", 2);
	if (fd >= 0) {
	    (void)ioctl(fd, TIOCNOTTY, (char *)0);
	    close(fd);
	}
#else
	if (setsid() < 0)
	    perror("setsid");
#endif /* TIOCNOTTY */
#endif /* SYSV */
    } /* End of child process code */

    /*
     * Create directory for runtime files
     */
    if (-1 == mkdir(_PATH_PIMD_RUNDIR, 0755) && errno != EEXIST)
	err(1, "Failed creating %s directory for runtime files", _PATH_PIMD_RUNDIR);

    /*
     * Setup logging
     */
    log_init(haveterminal && do_syslog > 0);
    logit(LOG_NOTICE, 0, "%s starting ...", versionstring);

    do_randomize();

    callout_init();
    init_igmp();
    init_pim();
    init_routesock(); /* Both for Linux netlink and BSD routing socket */
    init_pim_mrt();
    init_timers();
    ipc_init();

    /* Start up the log rate-limiter */
    resetlogging(NULL);

    /* TODO: check the kernel DVMRP/MROUTED/PIM support version */

    init_vifs();
    init_rp_and_bsr();   /* Must be after init_vifs() */
    add_static_rp();	 /* Must be after init_vifs() */
#ifdef RSRR
    rsrr_init();
#endif /* RSRR */

    sa.sa_handler = handle_signals;
    sa.sa_flags = 0;	/* Interrupt system calls */
    sigemptyset(&sa.sa_mask);
    sigaction(SIGALRM, &sa, NULL);
    sigaction(SIGHUP, &sa, NULL);
    sigaction(SIGTERM, &sa, NULL);
    sigaction(SIGINT, &sa, NULL);
    sigaction(SIGUSR1, &sa, NULL);
    sigaction(SIGUSR2, &sa, NULL);

    IF_DEBUG(DEBUG_IF)
	dump_vifs(stderr);
    IF_DEBUG(DEBUG_PIM_MRT)
	dump_pim_mrt(stderr);

    /* schedule first timer interrupt */
    timer_setTimer(TIMER_INTERVAL, timer, NULL);

    if (pidfile(pid_file))
	warn("Cannot create pidfile");

    /*
     * Main receive loop.
     */
    while (1) {
	if (check_signals())
	    break;

	FD_ZERO(&fds);
	for (i = 0, nfds = 0; i < nhandlers; i++) {
	    FD_SET(ihandlers[i].fd, &fds);
	    if (ihandlers[i].fd >= nfds)
		nfds = ihandlers[i].fd + 1;
	}

	n = select(nfds, &fds, NULL, NULL, timeout(n));
	if (n < 0) {
	    if (errno != EINTR) /* SIGALRM is expected */
		logit(LOG_WARNING, errno, "select failed");
	    continue;
	}

	for (i = 0; n > 0 && i < nhandlers; i++) {
	    if (FD_ISSET(ihandlers[i].fd, &fds))
		ihandlers[i].func(ihandlers[i].fd);
	}
    }

    logit(LOG_NOTICE, 0, "%s exiting.", versionstring);
    cleanup();
    exit(0);
}
Esempio n. 28
0
int main(int argc, char **argv)
{
	int i, result;

	progname = strrchr(argv[0], '/');
	progname = progname ? progname + 1 : argv[0];

	is_module = 0;
	ipc_init_struct();
	gettimeofday(&self.start, NULL);


	/*
	 * Solaris doesn't support MSG_NOSIGNAL, so
	 * we ignore SIGPIPE globally instead
	 */
	signal(SIGPIPE, SIG_IGN);

	for (i = 1; i < argc; i++) {
		char *opt, *arg = argv[i];

		if (*arg != '-') {
			if (!merlin_conf) {
				merlin_conf = arg;
				continue;
			}
			goto unknown_argument;
		}

		if (!strcmp(arg, "-h") || !strcmp(arg, "--help"))
			usage(NULL);
		if (!strcmp(arg, "-k") || !strcmp(arg, "--kill")) {
			killing = 1;
			continue;
		}
		if (!strcmp(arg, "-d") || !strcmp(arg, "--debug")) {
			debug++;
			continue;
		}

		if ((opt = strchr(arg, '=')))
			opt++;
		else if (i < argc - 1)
			opt = argv[i + 1];
		else
			usage("Unknown argument, or argument '%s' requires a parameter", arg);

		i++;
		if (!strcmp(arg, "--config") || !strcmp(arg, "-c")) {
			merlin_conf = opt;
			continue;
		}
		unknown_argument:
		usage("Unknown argument: %s", arg);
	}

	if (!merlin_conf)
		usage("No config-file specified\n");

	if (!grok_config(merlin_conf)) {
		fprintf(stderr, "%s contains errors. Bailing out\n", merlin_conf);
		return 1;
	}

	if (!pidfile)
		pidfile = "/var/run/merlin.pid";

	if (killing)
		return kill_daemon(pidfile);

	if (use_database && !import_program) {
		lwarn("Using database, but no import program configured. Are you sure about this?");
		lwarn("If not, make sure you specify the import_program directive in");
		lwarn("the \"daemon\" section of your merlin configuration file");
	}

	ipc.action = ipc_action_handler;
	result = ipc_init();
	if (result < 0) {
		printf("Failed to initalize ipc socket: %s\n", strerror(errno));
		return 1;
	}
	if (net_init() < 0) {
		printf("Failed to initialize networking: %s\n", strerror(errno));
		return 1;
	}

	if (!debug) {
		if (daemonize(merlin_user, NULL, pidfile, 0) < 0)
			exit(EXIT_FAILURE);

		/*
		 * we'll leak these file-descriptors, but that
		 * doesn't really matter as we just want accidental
		 * output to go somewhere where it'll be ignored
		 */
		fclose(stdin);
		open("/dev/null", O_RDONLY);
		fclose(stdout);
		open("/dev/null", O_WRONLY);
		fclose(stderr);
		open("/dev/null", O_WRONLY);
	}

	signal(SIGINT, clean_exit);
	signal(SIGTERM, clean_exit);
	signal(SIGUSR1, sigusr_handler);
	signal(SIGUSR2, sigusr_handler);

	sql_init();
	if (use_database) {
		sql_query("TRUNCATE TABLE program_status");
		sql_query("INSERT INTO program_status(instance_id, instance_name, is_running) "
		          "VALUES(0, 'Local Nagios daemon', 0)");
		for (i = 0; i < (int)num_nodes; i++) {
			char *node_name;
			merlin_node *node = noc_table[i];

			sql_quote(node->name, &node_name);
			sql_query("INSERT INTO program_status(instance_id, instance_name, is_running) "
			          "VALUES(%d, %s, 0)", node->id + 1, node_name);
			safe_free(node_name);
		}
	}
	state_init();
	linfo("Merlin daemon %s successfully initialized", merlin_version);
	polling_loop();

	clean_exit(0);

	return 0;
}
Esempio n. 29
0
asmlinkage void __init start_kernel(void)
{
	char * command_line;
	extern char saved_command_line[];

/*
 * Interrupts are still disabled. Do necessary setups, then
 * enable them
 */
	lock_kernel();
	printk(linux_banner);
	setup_arch(&command_line);
	printk("Kernel command line: %s\n", saved_command_line);
	parse_options(command_line);
	trap_init();
	init_IRQ();
	sched_init();
	softirq_init();
	time_init();

	/*
	 * HACK ALERT! This is early. We're enabling the console before
	 * we've done PCI setups etc, and console_init() must be aware of
	 * this. But we do want output early, in case something goes wrong.
	 */
	console_init();
#ifdef CONFIG_MODULES
	init_modules();
#endif
	if (prof_shift) {
		unsigned int size;
		/* only text is profiled */
		prof_len = (unsigned long) &_etext - (unsigned long) &_stext;
		prof_len >>= prof_shift;
		
		size = prof_len * sizeof(unsigned int) + PAGE_SIZE-1;
		prof_buffer = (unsigned int *) alloc_bootmem(size);
	}

	kmem_cache_init();
	sti();
	calibrate_delay();
#ifdef CONFIG_BLK_DEV_INITRD
	if (initrd_start && !initrd_below_start_ok &&
			initrd_start < min_low_pfn << PAGE_SHIFT) {
		printk(KERN_CRIT "initrd overwritten (0x%08lx < 0x%08lx) - "
		    "disabling it.\n",initrd_start,min_low_pfn << PAGE_SHIFT);
		initrd_start = 0;
	}
#endif
	mem_init();
	kmem_cache_sizes_init();
	pgtable_cache_init();

	/*
	 * For architectures that have highmem, num_mappedpages represents
	 * the amount of memory the kernel can use.  For other architectures
	 * it's the same as the total pages.  We need both numbers because
	 * some subsystems need to initialize based on how much memory the
	 * kernel can use.
	 */
	if (num_mappedpages == 0)
		num_mappedpages = num_physpages;
  
	fork_init(num_mappedpages);
	proc_caches_init();
	vfs_caches_init(num_physpages);
	buffer_init(num_physpages);
	page_cache_init(num_physpages);
#if defined(CONFIG_ARCH_S390)
	ccwcache_init();
#endif
	signals_init();
#ifdef CONFIG_PROC_FS
	proc_root_init();
#endif
	check_bugs();
	printk("POSIX conformance testing by UNIFIX\n");

	/* 
	 *	We count on the initial thread going ok 
	 *	Like idlers init is an unlocked kernel thread, which will
	 *	make syscalls (and thus be locked).
	 */
	smp_init();
#if defined(CONFIG_SYSVIPC)
	ipc_init();
#endif
	rest_init();
}
Esempio n. 30
0
int ipc_reinit(void)
{
	ipc_deinit();

	return ipc_init();
}