Exemplo n.º 1
0
int main() 
{
    static char *argv[] = 
          {   "client",   "-h", CYASSL_CALLEE_IP, "-p", CYASSL_CALLEE_PORT, 
                                   "-v",  CYASSL_SSL_VER,  CYASSL_HTTP_GET } ;
    static   func_args args  = 
          {  7 + CYASSL_HTTP_GET_COUNT, argv } ; 
        
    init_time() ;
    init_filesystem ();
    net_initialize() ;
    osThreadCreate (osThread (tcp_poll), NULL); 
    osDelay(50000) ;  /* wait for DHCP */
    #if defined(DEBUG_CYASSL)
         printf("Turning ON Debug message\n") ;
         CyaSSL_Debugging_ON() ;
    #endif
        
    if(args.argc == 7)
        printf("Simple SSL/TLS, ") ;
    else
        printf("HTTP GET, ") ;

    printf("Callee IP: %s, Port: %s, Version:%s\n", argv[2], argv[4], argv[6]) ; 

    while(1) {
          client_test(&args) ;
          printf("Enter any key to iterate.\n") ;
          getchar() ;
    }
}
Exemplo n.º 2
0
void
arch_init(void)
{
  setlocale(LC_ALL, "");
  concurrency = get_system_concurrency();
  decorate_trace = isatty(2);

  TRACE(TRACE_INFO, "core", "Using %d CPU(s)", concurrency);

#ifdef RLIMIT_AS
  do {
    struct rlimit rlim;
    getrlimit(RLIMIT_AS, &rlim);
    rlim.rlim_cur = 512 * 1024 * 1024;
    setrlimit(RLIMIT_AS, &rlim);
  } while(0);
#endif

#ifdef RLIMIT_DATA
  do {
    struct rlimit rlim;
    getrlimit(RLIMIT_DATA, &rlim);
    rlim.rlim_cur = 512 * 1024 * 1024;
    setrlimit(RLIMIT_DATA, &rlim);
  } while(0);
#endif

  net_initialize();

  if(trace_to_syslog)
    openlog("showtime", 0, LOG_USER);
}
Exemplo n.º 3
0
void
posix_init(void)
{
  struct timeval tv;
  gettimeofday(&tv, NULL);
  srand(tv.tv_usec);

#ifdef STOS
  gconf.cache_path = strdup("/stos/cache/showtime");
  gconf.persistent_path = strdup("/stos/persistent/showtime");
#else
  const char *homedir = getenv("HOME");

  if(homedir != NULL) {
    char buf[PATH_MAX];

    snprintf(buf, sizeof(buf), "%s/.cache/showtime", homedir);
    gconf.cache_path = strdup(buf);

    snprintf(buf, sizeof(buf), "%s/.hts/showtime", homedir);
    gconf.persistent_path = strdup(buf);
  }
#endif

  setlocale(LC_ALL, "");
  decorate_trace = isatty(2);

  signal(SIGPIPE, SIG_IGN);
  
  TRACE(TRACE_INFO, "core", "Using %d CPU(s)", gconf.concurrency);

#ifdef RLIMIT_AS
  do {
    struct rlimit rlim;
    getrlimit(RLIMIT_AS, &rlim);
    rlim.rlim_cur = 512 * 1024 * 1024;
    setrlimit(RLIMIT_AS, &rlim);
  } while(0);
#endif

#ifdef RLIMIT_DATA
  do {
    struct rlimit rlim;
    getrlimit(RLIMIT_DATA, &rlim);
    rlim.rlim_cur = 512 * 1024 * 1024;
    setrlimit(RLIMIT_DATA, &rlim);
  } while(0);
#endif

  net_initialize();

  if(gconf.trace_to_syslog)
    openlog("showtime", 0, LOG_USER);
}
Exemplo n.º 4
0
int main() 
{
    func_args args = { 0 } ;
    init_filesystem ();
    net_initialize() ;
    osThreadCreate (osThread (tcp_poll), NULL); 
    osDelay(10000) ;  /* wait for DHCP */
    #if defined(DEBUG_CYASSL)
        printf("Turning ON Debug message\n") ;
        CyaSSL_Debugging_ON() ;
    #endif

        printf("echoserver: Started\n") ;
    echoserver_test(&args) ;
    printf("echoserver: Terminated\n") ;
}
Exemplo n.º 5
0
int main() 
{
    void *args = NULL ;
    init_time() ;
    init_filesystem ();
    net_initialize() ;
    osThreadCreate (osThread (tcp_poll), NULL); 
    osDelay(30000) ;  /* wait for DHCP */
    #if defined(DEBUG_CYASSL)
         printf("Turning ON Debug message\n") ;
         CyaSSL_Debugging_ON() ;
    #endif

    echoclient_test(args) ;

}
Exemplo n.º 6
0
int net_string_to_address(int af, const char* src, void* dst)
{
#ifdef WINSOCK
	int ret, size;
	struct sockaddr_in  addr4;
	struct sockaddr_in6 addr6;
	struct sockaddr* addr = 0;
	if (af == AF_INET6)
	{
		if (net_is_ipv6_supported() != 1) return -1;
		size = sizeof(struct sockaddr_in6);
		addr = (struct sockaddr*) &addr6;
	}
	else
	{
		size = sizeof(struct sockaddr_in);
		addr = (struct sockaddr*) &addr4;
	}

	if (!net_initialized)
		net_initialize();

	ret = WSAStringToAddressA((char*) src, af, NULL, addr, &size);
	if (ret == -1)
	{
		return -1;
	}

	if (af == AF_INET6)
	{
		memcpy(dst, &addr6.sin6_addr, sizeof(addr6.sin6_addr));
	}
	else
	{
		memcpy(dst, &addr4.sin_addr, sizeof(addr4.sin_addr));
	}

	return 1;
#else
	return inet_pton(af, src, dst);
#endif
}
Exemplo n.º 7
0
Arquivo: app.c Projeto: rzel/dim3
bool app_start(char *err_str)
{
		// initialize timing

	game_time_initialize();
	
		// physics ray tracing
		
	if (!ray_trace_initialize(err_str)) return(FALSE);
	
		// OS network initialization
		
	net_initialize();
	
		// read setup preferences
		
	setup_xml_read();
	
		// client network defaults
		
	net_setup.mode=net_mode_none;
	
		// initialize server
		
	if (!server_initialize(err_str)) return(FALSE);

		// initialize view
		// if not running in dedicated host mode
	
	if (!app.dedicated_host) {

		if (!view_initialize(err_str)) {
			server_shutdown();
			return(FALSE);
		}

		console_initialize();
	}

	return(TRUE);
}
Exemplo n.º 8
0
int main() 
{
    static char *argv[]    = {  "server",   "-p", CYASSL_LISTEN_PORT, "-d"} ;
    static func_args args  = {  4, argv } ; 
        
    init_filesystem ();
    net_initialize() ;
    osThreadCreate (osThread (tcp_poll), NULL); 
    osDelay(10000) ;  /* wait for DHCP */
    #if defined(DEBUG_CYASSL)
         printf("Turning ON Debug message\n") ;
         CyaSSL_Debugging_ON() ;
    #endif
        
    printf("Simple Server: Started\n") ;
    while(1) {
       server_test(&args) ;
       printf("Enter any key to iterate.\n") ;
       getchar() ;
   }
}
Exemplo n.º 9
0
void os_start(void)
{
  int i;

  slldbg("Entry\n");

  /* Initialize all task lists */

  dq_init(&g_readytorun);
  dq_init(&g_pendingtasks);
  dq_init(&g_waitingforsemaphore);
#ifndef CONFIG_DISABLE_SIGNALS
  dq_init(&g_waitingforsignal);
#endif
#ifndef CONFIG_DISABLE_MQUEUE
  dq_init(&g_waitingformqnotfull);
  dq_init(&g_waitingformqnotempty);
#endif
#ifdef CONFIG_PAGING
  dq_init(&g_waitingforfill);
#endif
  dq_init(&g_inactivetasks);
  sq_init(&g_delayeddeallocations);

  /* Initialize the logic that determine unique process IDs. */

  g_lastpid = 0;
  for (i = 0; i < CONFIG_MAX_TASKS; i++)
    {
      g_pidhash[i].tcb = NULL;
      g_pidhash[i].pid = INVALID_PROCESS_ID;
    }

  /* Assign the process ID of ZERO to the idle task */

  g_pidhash[ PIDHASH(0)].tcb = &g_idletcb;
  g_pidhash[ PIDHASH(0)].pid = 0;

  /* Initialize a TCB for this thread of execution.  NOTE:  The default
   * value for most components of the g_idletcb are zero.  The entire
   * structure is set to zero.  Then only the (potentially) non-zero
   * elements are initialized. NOTE:  The idle task is the only task in
   * that has pid == 0 and sched_priority == 0.
   */

  bzero((void*)&g_idletcb, sizeof(_TCB));
  g_idletcb.task_state = TSTATE_TASK_RUNNING;
  g_idletcb.entry.main = (main_t)os_start;

#if CONFIG_TASK_NAME_SIZE > 0
  strncpy(g_idletcb.name, g_idlename, CONFIG_TASK_NAME_SIZE-1);
  g_idletcb.argv[0] = g_idletcb.name;
#else
  g_idletcb.argv[0] = (char*)g_idlename;
#endif /* CONFIG_TASK_NAME_SIZE */

  /* Then add the idle task's TCB to the head of the ready to run list */

  dq_addfirst((FAR dq_entry_t*)&g_idletcb, (FAR dq_queue_t*)&g_readytorun);

  /* Initialize the processor-specific portion of the TCB */

  g_idletcb.flags = TCB_FLAG_TTYPE_KERNEL;
  up_initial_state(&g_idletcb);

  /* Initialize the semaphore facility(if in link).  This has to be done
   * very early because many subsystems depend upon fully functional
   * semaphores.
   */

#ifdef CONFIG_HAVE_WEAKFUNCTIONS
  if (sem_initialize != NULL)
#endif
    {
      sem_initialize();
    }

  /* Initialize the memory manager */

#ifndef CONFIG_HEAP_BASE
  {
    FAR void *heap_start;
    size_t heap_size;
    up_allocate_heap(&heap_start, &heap_size);
    kmm_initialize(heap_start, heap_size);
  }
#else
  kmm_initialize((void*)CONFIG_HEAP_BASE, CONFIG_HEAP_SIZE);
#endif

  /* Initialize the interrupt handling subsystem (if included) */

#ifdef CONFIG_HAVE_WEAKFUNCTIONS
  if (irq_initialize != NULL)
#endif
    {
      irq_initialize();
    }

  /* Initialize the watchdog facility (if included in the link) */

#ifdef CONFIG_HAVE_WEAKFUNCTIONS
  if (wd_initialize != NULL)
#endif
    {
      wd_initialize();
    }

  /* Initialize the POSIX timer facility (if included in the link) */

#ifndef CONFIG_DISABLE_CLOCK
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
  if (clock_initialize != NULL)
#endif
    {
      clock_initialize();
    }
#endif

#ifndef CONFIG_DISABLE_POSIX_TIMERS
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
  if (timer_initialize != NULL)
#endif
    {
      timer_initialize();
    }
#endif

  /* Initialize the signal facility (if in link) */

#ifndef CONFIG_DISABLE_SIGNALS
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
  if (sig_initialize != NULL)
#endif
    {
      sig_initialize();
    }
#endif

  /* Initialize the named message queue facility (if in link) */

#ifndef CONFIG_DISABLE_MQUEUE
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
  if (mq_initialize != NULL)
#endif
    {
      mq_initialize();
    }
#endif

  /* Initialize the thread-specific data facility (if in link) */

#ifndef CONFIG_DISABLE_PTHREAD
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
  if (pthread_initialize != NULL)
#endif
    {
      pthread_initialize();
    }
#endif

  /* Initialize the file system (needed to support device drivers) */

#if CONFIG_NFILE_DESCRIPTORS > 0
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
  if (fs_initialize != NULL)
#endif
    {
      fs_initialize();
    }
#endif

  /* Initialize the network system */

#ifdef CONFIG_NET
#if 0
  if (net_initialize != NULL)
#endif
    {
      net_initialize();
    }
#endif

  /* The processor specific details of running the operating system
   * will be handled here.  Such things as setting up interrupt
   * service routines and starting the clock are some of the things
   * that are different for each  processor and hardware platform.
   */

  up_initialize();

  /* Initialize the C libraries (if included in the link).  This
   * is done last because the libraries may depend on the above.
   */

#ifdef CONFIG_HAVE_WEAKFUNCTIONS
  if (lib_initialize != NULL)
#endif
    {
      lib_initialize();
    }

  /* Create stdout, stderr, stdin on the IDLE task.  These will be
   * inherited by all of the threads created by the IDLE task.
   */

  (void)sched_setupidlefiles(&g_idletcb);

  /* Create initial tasks and bring-up the system */

  (void)os_bringup();

  /* When control is return to this point, the system is idle. */

  sdbg("Beginning Idle Loop\n");
  for (;;)
    {
      /* Perform garbage collection (if it is not being done by the worker
       * thread).  This cleans-up memory de-allocations that were queued
       * because they could not be freed in that execution context (for
       * example, if the memory was freed from an interrupt handler).
       */

#ifndef CONFIG_SCHED_WORKQUEUE
      /* We must have exclusive access to the memory manager to do this
       * BUT the idle task cannot wait on a semaphore.  So we only do
       * the cleanup now if we can get the semaphore -- this should be
       * possible because if the IDLE thread is running, no other task is!
       */

      if (kmm_trysemaphore() == 0)
        {
          sched_garbagecollection();
          kmm_givesemaphore();
        }
#endif

      /* Perform any processor-specific idle state operations */

      up_idle();
    }
}
Exemplo n.º 10
0
void os_start(void)
{
  int i;

  slldbg("Entry\n");

  /* Initialize RTOS Data ***************************************************/
  /* Initialize all task lists */

  dq_init(&g_readytorun);
  dq_init(&g_pendingtasks);
  dq_init(&g_waitingforsemaphore);
#ifndef CONFIG_DISABLE_SIGNALS
  dq_init(&g_waitingforsignal);
#endif
#ifndef CONFIG_DISABLE_MQUEUE
  dq_init(&g_waitingformqnotfull);
  dq_init(&g_waitingformqnotempty);
#endif
#ifdef CONFIG_PAGING
  dq_init(&g_waitingforfill);
#endif
  dq_init(&g_inactivetasks);
  sq_init(&g_delayed_kufree);
#if (defined(CONFIG_BUILD_PROTECTED) || defined(CONFIG_BUILD_KERNEL)) && \
     defined(CONFIG_MM_KERNEL_HEAP)
  sq_init(&g_delayed_kfree);
#endif

  /* Initialize the logic that determine unique process IDs. */

  g_lastpid = 0;
  for (i = 0; i < CONFIG_MAX_TASKS; i++)
    {
      g_pidhash[i].tcb = NULL;
      g_pidhash[i].pid = INVALID_PROCESS_ID;
    }

  /* Assign the process ID of ZERO to the idle task */

  g_pidhash[PIDHASH(0)].tcb = &g_idletcb.cmn;
  g_pidhash[PIDHASH(0)].pid = 0;

  /* Initialize the IDLE task TCB *******************************************/
  /* Initialize a TCB for this thread of execution.  NOTE:  The default
   * value for most components of the g_idletcb are zero.  The entire
   * structure is set to zero.  Then only the (potentially) non-zero
   * elements are initialized. NOTE:  The idle task is the only task in
   * that has pid == 0 and sched_priority == 0.
   */

  bzero((void*)&g_idletcb, sizeof(struct task_tcb_s));
  g_idletcb.cmn.task_state = TSTATE_TASK_RUNNING;
  g_idletcb.cmn.entry.main = (main_t)os_start;
  g_idletcb.cmn.flags      = TCB_FLAG_TTYPE_KERNEL;

  /* Set the IDLE task name */

#if CONFIG_TASK_NAME_SIZE > 0
  strncpy(g_idletcb.cmn.name, g_idlename, CONFIG_TASK_NAME_SIZE);
  g_idletcb.cmn.name[CONFIG_TASK_NAME_SIZE] = '\0';
#endif /* CONFIG_TASK_NAME_SIZE */

  /* Configure the task name in the argument list.  The IDLE task does
   * not really have an argument list, but this name is still useful
   * for things like the NSH PS command.
   *
   * In the kernel mode build, the arguments are saved on the task's stack
   * and there is no support that yet.
   */

#if CONFIG_TASK_NAME_SIZE > 0
  g_idleargv[0]  = g_idletcb.cmn.name;
#else
  g_idleargv[0]  = (FAR char *)g_idlename;
#endif /* CONFIG_TASK_NAME_SIZE */
  g_idleargv[1]  = NULL;
  g_idletcb.argv = g_idleargv;

  /* Then add the idle task's TCB to the head of the ready to run list */

  dq_addfirst((FAR dq_entry_t*)&g_idletcb, (FAR dq_queue_t*)&g_readytorun);

  /* Initialize the processor-specific portion of the TCB */

  up_initial_state(&g_idletcb.cmn);

  /* Initialize RTOS facilities *********************************************/
  /* Initialize the semaphore facility.  This has to be done very early
   * because many subsystems depend upon fully functional semaphores.
   */

  sem_initialize();

#if defined(MM_KERNEL_USRHEAP_INIT) || defined(CONFIG_MM_KERNEL_HEAP) || defined(CONFIG_MM_PGALLOC)
  /* Initialize the memory manager */

  {
    FAR void *heap_start;
    size_t heap_size;

#ifdef MM_KERNEL_USRHEAP_INIT
    /* Get the user-mode heap from the platform specific code and configure
     * the user-mode memory allocator.
     */

    up_allocate_heap(&heap_start, &heap_size);
    kumm_initialize(heap_start, heap_size);
#endif

#ifdef CONFIG_MM_KERNEL_HEAP
    /* Get the kernel-mode heap from the platform specific code and configure
     * the kernel-mode memory allocator.
     */

    up_allocate_kheap(&heap_start, &heap_size);
    kmm_initialize(heap_start, heap_size);
#endif

#ifdef CONFIG_MM_PGALLOC
    /* If there is a page allocator in the configuration, then get the page
     * heap information from the platform-specific code and configure the
     * page allocator.
     */

    up_allocate_pgheap(&heap_start, &heap_size);
    mm_pginitialize(heap_start, heap_size);
#endif
  }
#endif

#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS)
  /* Initialize tasking data structures */

#ifdef CONFIG_HAVE_WEAKFUNCTIONS
  if (task_initialize != NULL)
#endif
    {
      task_initialize();
    }
#endif

  /* Initialize the interrupt handling subsystem (if included) */

#ifdef CONFIG_HAVE_WEAKFUNCTIONS
  if (irq_initialize != NULL)
#endif
    {
      irq_initialize();
    }

  /* Initialize the watchdog facility (if included in the link) */

#ifdef CONFIG_HAVE_WEAKFUNCTIONS
  if (wd_initialize != NULL)
#endif
    {
      wd_initialize();
    }

  /* Initialize the POSIX timer facility (if included in the link) */

#ifdef CONFIG_HAVE_WEAKFUNCTIONS
  if (clock_initialize != NULL)
#endif
    {
      clock_initialize();
    }

#ifndef CONFIG_DISABLE_POSIX_TIMERS
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
  if (timer_initialize != NULL)
#endif
    {
      timer_initialize();
    }
#endif

#ifndef CONFIG_DISABLE_SIGNALS
  /* Initialize the signal facility (if in link) */

#ifdef CONFIG_HAVE_WEAKFUNCTIONS
  if (sig_initialize != NULL)
#endif
    {
      sig_initialize();
    }
#endif

#ifndef CONFIG_DISABLE_MQUEUE
  /* Initialize the named message queue facility (if in link) */

#ifdef CONFIG_HAVE_WEAKFUNCTIONS
  if (mq_initialize != NULL)
#endif
    {
      mq_initialize();
    }
#endif

#ifndef CONFIG_DISABLE_PTHREAD
  /* Initialize the thread-specific data facility (if in link) */

#ifdef CONFIG_HAVE_WEAKFUNCTIONS
  if (pthread_initialize != NULL)
#endif
    {
      pthread_initialize();
    }
#endif

#if CONFIG_NFILE_DESCRIPTORS > 0
  /* Initialize the file system (needed to support device drivers) */

  fs_initialize();
#endif

#ifdef CONFIG_NET
  /* Initialize the networking system.  Network initialization is
   * performed in two steps:  (1) net_setup() initializes static
   * configuration of the network support.  This must be done prior
   * to registering network drivers by up_initialize().  This step
   * cannot require upon any hardware-depending features such as
   * timers or interrupts.
   */

  net_setup();
#endif

  /* The processor specific details of running the operating system
   * will be handled here.  Such things as setting up interrupt
   * service routines and starting the clock are some of the things
   * that are different for each  processor and hardware platform.
   */

  up_initialize();

#ifdef CONFIG_NET
  /* Complete initialization the networking system now that interrupts
   * and timers have been configured by up_initialize().
   */

  net_initialize();
#endif

#ifdef CONFIG_MM_SHM
  /* Initialize shared memory support */

  shm_initialize();
#endif

  /* Initialize the C libraries.  This is done last because the libraries
   * may depend on the above.
   */

  lib_initialize();

  /* IDLE Group Initialization **********************************************/
#ifdef HAVE_TASK_GROUP
  /* Allocate the IDLE group */

  DEBUGVERIFY(group_allocate(&g_idletcb, g_idletcb.cmn.flags));
#endif

#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0
  /* Create stdout, stderr, stdin on the IDLE task.  These will be
   * inherited by all of the threads created by the IDLE task.
   */

  DEBUGVERIFY(group_setupidlefiles(&g_idletcb));
#endif

#ifdef HAVE_TASK_GROUP
  /* Complete initialization of the IDLE group.  Suppress retention
   * of child status in the IDLE group.
   */

  DEBUGVERIFY(group_initialize(&g_idletcb));
  g_idletcb.cmn.group->tg_flags = GROUP_FLAG_NOCLDWAIT;
#endif

  /* Bring Up the System ****************************************************/
  /* Create initial tasks and bring-up the system */

  DEBUGVERIFY(os_bringup());

  /* The IDLE Loop **********************************************************/
  /* When control is return to this point, the system is idle. */

  sdbg("Beginning Idle Loop\n");
  for (;;)
    {
      /* Perform garbage collection (if it is not being done by the worker
       * thread).  This cleans-up memory de-allocations that were queued
       * because they could not be freed in that execution context (for
       * example, if the memory was freed from an interrupt handler).
       */

#ifndef CONFIG_SCHED_WORKQUEUE
      /* We must have exclusive access to the memory manager to do this
       * BUT the idle task cannot wait on a semaphore.  So we only do
       * the cleanup now if we can get the semaphore -- this should be
       * possible because if the IDLE thread is running, no other task is!
       *
       * WARNING: This logic could have undesirable side-effects if priority
       * inheritance is enabled.  Imaginee the possible issues if the
       * priority of the IDLE thread were to get boosted!  Moral: If you
       * use priority inheritance, then you should also enable the work
       * queue so that is done in a safer context.
       */

      if (kmm_trysemaphore() == 0)
        {
          sched_garbagecollection();
          kmm_givesemaphore();
        }
#endif

      /* Perform any processor-specific idle state operations */

      up_idle();
    }
}
Exemplo n.º 11
0
Arquivo: kernel.c Projeto: Kloniks/muk
void kernel_main(unsigned long magic,
		 unsigned long addr)
{
  multiboot_info_t *mbi;

  if (magic != MULTIBOOT_BOOTLOADER_MAGIC)
    return;

  mbi = (multiboot_info_t*)addr;

  /* kernel init
   */
  serial_init(DEBUG_SERIAL_PORT,
	      DEBUG_SERIAL_SPEED,
	      UART_8BITS_WORD,
	      UART_NO_PARITY,
	      UART_1_STOP_BIT);
  cls();

  cpu_cli();
  printf("[x] interrupts disabled\n");

  gdt_initialize();
  printf("[x] gdt initialized\n");

  idt_initialize();
  printf("[x] idt initialized\n");

  breakpoint_initialize();

#if defined(USE_APIC)
  apic_initialize();
  serial_printl("[x] apic initialized\n");
#else
  pic_initialize();
  serial_printl("[x] pic initialized\n");
#endif /* USE_APIC */

  /* initialize the kernel
   */
  {
    kernel_init(mbi);
  }

  /* memory initialization
   */
  {
    phys_init(mbi);
    phys_debug();
/*     vm_init(); */
/*     unit_test_vm(); */
/*     cpu_hlt(); */
  }

#if defined(USE_PCI)
  pci_initialize();
  pci_list();
#endif

  cpu_sti();

#if defined(USE_TASK)
 {
   /* subsystems
    */
   event_initialize();
   sched_initialize();
   task_initialize();

   /* tasks
    */
   idle_initialize();
   muksh_initialize();
   net_initialize();

/*    task_test(); */

   /* start scheduling
    */
   sched_start();
 }
#endif

 /* endless loop
  */
 serial_printl("[?] kernel loop\n");
 while (1)
   {
     serial_printl("k");
     cpu_hlt();
   }
}
Exemplo n.º 12
0
Arquivo: main.c Projeto: CoiLock/uhub
int main_loop()
{
	struct hub_config configuration;
	struct acl_handle acl;
	struct hub_info* hub = 0;

	if (net_initialize() == -1)
		return -1;

	do
	{
		if (hub)
		{
			LOG_INFO("Reloading configuration files...");
			LOG_DEBUG("Hub status: %d", (int) hub->status);

			/* Reinitialize logs */
			hub_log_shutdown();
			hub_log_initialize(arg_log, arg_log_syslog);
			hub_set_log_verbosity(arg_verbose);
		}

		if (read_config(arg_config, &configuration, !arg_have_config) == -1)
			return -1;

		if (acl_initialize(&configuration, &acl) == -1)
			return -1;

		/*
		 * Don't restart networking when re-reading configuration.
		 * This might not be possible either, since we might have
		 * dropped our privileges to do so.
		 */
		if (!hub)
		{
			hub = hub_start_service(&configuration);
			if (!hub)
			{
				acl_shutdown(&acl);
				free_config(&configuration);
				net_destroy();
				hub_log_shutdown();
				return -1;
			}
#if !defined(WIN32)
			setup_signal_handlers(hub);
#ifdef SYSTEMD
                        /* Notify the service manager that this daemon has
                         * been successfully initalized and shall enter the
                         * main loop.
                         */
                        sd_notifyf(0, "READY=1\n"
                                      "MAINPID=%lu", (unsigned long) getpid());
#endif /* SYSTEMD */

#endif /* ! WIN32 */
		}

		hub_set_variables(hub, &acl);

		hub_event_loop(hub);

		hub_free_variables(hub);
		acl_shutdown(&acl);
		free_config(&configuration);

	} while (hub->status == hub_status_restart);

#if !defined(WIN32)
	shutdown_signal_handlers(hub);
#endif

	if (hub)
	{
		hub_shutdown_service(hub);
	}

	net_destroy();
	hub_log_shutdown();
	return 0;
}
Exemplo n.º 13
0
int main(int argc, char** argv) {
    WINDOW *lic = NULL;
    int x, y, mr;
    int opt = 0, cnt = 0;
    char remname[256];
    char *licpath = NULL;
    FILE *fout = NULL;
    char *version = NULL;
    if (am_bin_path(instance_path, sizeof (instance_path)) == -1) {
        return 0;
    } else {
        if (am_whitespace(instance_path) > 0) {
            fprintf(stderr, "Whitespace in path: %s \n", instance_path);
            return 0;
        }

        snprintf(log_path, sizeof (log_path), "%s/../logs/install_%s.log", instance_path, TIMESTAMPLONG);
        snprintf(lic_path, sizeof (lic_path), "%s/../legal-notices/license.txt", instance_path);

        fout = fopen(log_path, "a");
        if (fout != NULL) {
            fprintf(fout, "\n\n===================================================");
            print_version(fout, NULL);
            fprintf(fout, "\r\n");
            fclose(fout);
        }

        strcat(instance_path, "../instances");
        snprintf(int_conf_path, sizeof (int_conf_path), "%s/.agents", instance_path);
    }

    net_initialize();

    /* cli mode */
    if (argc > 1) {
        while ((opt = opts(argc, argv, "e:vlxr:o:a:i:p:c:")) != -1)
            switch (opt) {
                case 'e':
                {
                    char encryptpasswd[1024] = "";
                    char origpasswd[1024] = "";
                    char *keystr;
                    char bkeystr[1024] = "";
                    strcpy(origpasswd, oarg);
                    am_trim(origpasswd);
                    keystr = am_random_key();
                    memset(bkeystr, 0, 1024);
                    am_b64encode(keystr, bkeystr);
                    encrypt_base64(origpasswd, encryptpasswd, bkeystr);
                    fprintf(stderr, "\nEncrypted password:\n%s\n\nKey:\n%s\n\n", encryptpasswd, bkeystr);
                    net_shutdown();
                    return (EXIT_SUCCESS);
                }
                    break;
                case 'l':
                {
                    fprintf(stderr, "Agent instances:\n");
                    int n;
                    am_conf_p inst = NULL, temp;
                    if ((n = am_read_instances(instance_path, &inst)) > 0) {
                        temp = inst;
                        while (temp != NULL) {
                            fprintf(stderr, "%s\n", temp->name);
                            temp = temp->next;
                        }
                        am_free(inst);
                    } else
                        fprintf(stderr, "There are no agent instances registered.\n");
                    net_shutdown();
                    return (EXIT_SUCCESS);
                }
                    break;
                case 'v':
                {
                    print_version(stdout, NULL);
                    net_shutdown();
                    return (EXIT_SUCCESS);
                }
                    break;
                case 'r':
                {
                    fprintf(stderr, "Removing \"%s\" instance...\n", oarg);
                    if (remove_instance(oarg)) {
                        fprintf(stderr, "Instance \"%s\" removed.\n", oarg);
                    } else
                        fprintf(stderr, "Error removing \"%s\" instance.\n", oarg);
                    net_shutdown();
                    return (EXIT_SUCCESS);
                }
                    break;
                case 'o':
                    sprintf(openam_url, oarg);
                    cnt = 1;
                    break;
                case 'a':
                    sprintf(agent_url, oarg);
                    cnt = 1;
                    break;
                case 'i':
                    sprintf(agent_id, oarg);
                    cnt = 1;
                    break;
                case 'p':
                    sprintf(agent_pass_file, oarg);
                    cnt = 1;
                    break;
                case 'c':
                    sprintf(web_conf_path, oarg);
                    cnt = 1;
                    break;
                case 'x':
                {
                    asprintf(&licpath, "%s/.license", instance_path);
                    if (licpath) {
                        am_setup_conf(licpath, NULL);
                        free(licpath);
                        licpath = NULL;
                    }
                    net_shutdown();
                    return (EXIT_SUCCESS);
                }
                    break;
                case '?':
                    if (oopt == 'e' || oopt == 'r' || oopt == 'o' || oopt == 'a' || oopt == 'i' || oopt == 'p' || oopt == 'c')
                        fprintf(stderr, "\nError: option -%c requires an argument.\n", oopt);
                    else if (isprint(oopt))
                        fprintf(stderr, "\nError: unknown option `-%c'.\n", oopt);
                    else
                        fprintf(stderr, "\nnError: unknown option character `\\x%x'.\n", oopt);
                    opt = -1;
                default:
                    opt = -1;
            }

        if (cnt == 1) {
            asprintf(&licpath, "%s/.license", instance_path);
            if (licpath && am_file_exists(licpath) == 0) {
                am_free(licpath);
                fprintf(stderr, "\nYou have to accept ForgeRock Web Policy Agent license terms to continue.\n"
                        "Please run agentadmin with -x option or interactively to view and accept the license.\n\n");
                net_shutdown();
                return (EXIT_FAILURE);
            }
            am_free(licpath);
            licpath = NULL;
        }

        if (cnt == 1) {
            url_t u, ua;
            am_trim(openam_url);
            u = URL(openam_url);
            if (u.error == 0) {
                if (validate_am_host(&u) != 0) {
                    fprintf(stderr, "Error validating OpenAM URL\n");
                    net_shutdown();
                    return (EXIT_FAILURE);
                }
            } else {
                fprintf(stderr, "Invalid OpenAM URL value\n");
                net_shutdown();
                return (EXIT_FAILURE);
            }
            am_trim(agent_url);
            ua = URL(agent_url);
            if (ua.error != 0) {
                fprintf(stderr, "Invalid Agent URL value\n");
                net_shutdown();
                return (EXIT_FAILURE);
            } else {
                am_trim(agent_id);
                am_trim(agent_pass_file);
                if (am_read_password(agent_pass_file, agent_pass) == 0) {
                    fprintf(stderr, "Error reading password file\n");
                    net_shutdown();
                    return (EXIT_FAILURE);
                }
                if (validate_agent(&u, agent_id, agent_pass) != 0) {
                    fprintf(stderr, "%s\n", PROFILE_NOT_FOUND);
                    net_shutdown();
                    return (EXIT_FAILURE);
                }
            }
            am_trim(web_conf_path);
            if (web_conf_path == NULL || web_conf_path[0] == '\0') {
                fprintf(stderr, "Varnish vmod directory must not be empty\n");
                net_shutdown();
                return (EXIT_FAILURE);
            } else {
                char *t = NULL;
                asprintf(&t, "%s/libvmod_am.so", web_conf_path);
                if (am_whitespace(web_conf_path) > 0) {
                    fprintf(stderr, "Path to Varnish modules directory must not contain spaces\n");
                    am_free(t);
                    net_shutdown();
                    return (EXIT_FAILURE);
                } else if (am_file_writeable(web_conf_path) == 0) {
                    fprintf(stderr, "Error opening Varnish modules directory\n");
                    am_free(t);
                    net_shutdown();
                    return (EXIT_FAILURE);
                } else if (am_file_exists(t) == 1) {
                    fprintf(stderr, "This Varnish instance is already configured\n");
                    am_free(t);
                    net_shutdown();
                    return (EXIT_FAILURE);
                }
                am_free(t);
            }
            create_varnish_instance(ua);
            fprintf(stderr, "\nVarnish and agent configuration files are here:\n%s\nCheck installation log %s for any errors.\n\n", web_conf_path_out, log_path);
        } else {
            display_usage();
        }
        net_shutdown();
        return (EXIT_SUCCESS);
    }

    print_version(NULL, &version);
    if (version != NULL) {
        snprintf(vers, sizeof (vers), "Version: %s", version);
        free(version);
    }

    initscr();
    cbreak();
    noecho();
    keypad(stdscr, TRUE);
    start_color();
    init_pair(1, COLOR_RED, COLOR_BLACK);
    getmaxyx(stdscr, y, x);

    asprintf(&licpath, "%s/.license", instance_path);
    if (am_file_exists(licpath) == 0) {
        lic = license(y, x, &mr);
        wrefresh(lic);
        delwin(lic);
        lic = NULL;
        if (mr == KEY_F(4)) {
            goto all_done;
        } else {
            am_setup_conf(licpath, NULL);
        }
    }

ret_to_menu:

    refresh();

    mr = mainmenu(y, x);

    if (mr == 0) {
        int cr = configure_step(y, x);
        if (cr == KEY_F(4)) {
            goto ret_to_menu;
        }
    } else if (mr >= 2 && mr < menu_size - 1) {
        memset(remname, 0, sizeof (remname));
        if (sscanf(menu_values[mr], "Remove '%[^''']' instance", remname) == 1) {
            if (remove_step(remname, y, x) == KEY_F(4))
                goto ret_to_menu;
        }
        goto ret_to_menu;
    } else if (mr == 1) {
        encrypt_step(y, x);
        goto ret_to_menu;
    }

all_done:

    am_free(licpath);
    clean_main_menu();
    move(0, 0);
    clrtoeol();
    refresh();
    endwin();
    net_shutdown();
    return (EXIT_SUCCESS);
}