Пример #1
0
/**
 * @brief   The main entry point to the program
 */
int main()
{   
    // Construct the EventManager Controller
    EventManager::EventManager();
    
    // Construct visual log and GUI, and input Keyboard views
    Log *logView = new Log();
    GUI *guiView = new GUI(0.5);
    Keyboard *keyView = new Keyboard();
    
    // Announce Hello Message
    stringstream hello;
    hello << "Welcome to " << PROJECT_DESC;
    announce_message(hello.str());
    
    // Decalre game model
    Game *gameModel = nullptr;
    // Network is required to create type of Model
    Network *networkView = nullptr;
    
    /*
        Network determines host/client, which determines
        who is cat/mouse. Both gameModel and networkView
        get their own setup network function.
        Setup the network connection and game together
        by passing in the network view and game model
        by reference
     */
    setup_network(&networkView, &gameModel);

    // If there was a timeout (i..e networkView did not connect?)
    if (! networkView->is_connected()) { return 0; }
    
    // Process game loop while not window closed
    do
    {
        keyView    ->process_keyboard();
        guiView    ->process_screen();
        
        // Only process network where still connected
        if ( !networkView->is_connected() ) break;
        networkView->process_messages();
    }
    while ( ! window_close_requested() );
    
    // Relinquish all views and model
    delete guiView;
    delete keyView;
    delete networkView;
    delete gameModel;
    
    // Log is the last to go
    delete logView;
    
    return 0;
}
Пример #2
0
void kmain(struct multiboot* b, uint32_t magic)
{
	hide_cursor();
	cls();
	setup_gdt();
	setup_idt();
	if(b->mods_count == 1)
	{
		uint32_t mods_start_addr=*(uint32_t*)(b->mods_addr);
		uint32_t mods_end_addr=*(uint32_t*)(b->mods_addr + 4);
		if(((uint32_t)&__kernel_end - KERNEL_VMA) < mods_end_addr) kernel_end_addr=(mods_end_addr & 0xFFFFF000) + 0x1000;
	}
	setup_bitmap();
	setup_vmm();
	setup_pic();
	setup_tasking();
	setup_process_tree();
	set_timer_freq(100);

	pci_init();
	setup_network();

	b=(struct multiboot*)((uint8_t*)b+KERNEL_VMA);
	uint32_t mods_addr=*(uint32_t*)(b->mods_addr + KERNEL_VMA) + KERNEL_VMA;
	root_fs=ext2_fs_init((uint8_t*)mods_addr);
	struct inode *devfs=devfs_init();
	struct inode *devfs_root=vfs_search((struct inode*)root_fs, "/dev");
	if(devfs_root)
	{
		vfs_mount(devfs, devfs_root);
		register_tty_driver();
		register_kbd_driver();
		register_rtl8139_driver();
	}
	else kprintf("Could not mount /dev, no such directory\n");

	kprintf("\n%@Welcome to tapiOS!%@\n\n", 0x05, 0x07, b->mods_count, 0x03);

	struct inode *node=vfs_search((struct inode*)root_fs, "/bin/init");
	if(node)
	{
		struct file *init=vfs_open(node, NULL, O_RDONLY);
		uint8_t *init_mem=kmalloc(node->size);
		int read=vfs_read(init, init_mem, node->size);
		vaddr_t entrypoint=init_elf_get_entry_point(init_mem);
		setup_initial_process(entrypoint);
	}
	else kprintf("Init not found\n");
	__asm__ volatile("hltloop: hlt; jmp hltloop");

	PANIC();
}
Пример #3
0
int main()
{
  std::cout << "Enet Server" << std::endl;

  setup_network();
  setup_as_server();

  while(true)
  {
    poll_events();
  }

  destroy_network();

  return 0;
}
Пример #4
0
int init_proc(void *arg)
{
    container_spec_t *cspec = (container_spec_t*)arg;

    // Build the path that will contain the filesystem pivot and
    // ensure it exists on disk
    char *pivot = "/.pivot";
    char *pivot_abs = calloc(strlen(cspec->root) + strlen(pivot) + 1, 1);
    if (pivot_abs == NULL)
    {
        return 1;
    }
    strcat(pivot_abs, cspec->root);
    strcat(pivot_abs, pivot);

    if (mkdir(pivot_abs, S_IRWXU | S_IRWXG) < 0)
    {
        if (errno != EEXIST)
        {
            printf("init_proc(): mkdir(): %d\n", errno);
            return 1;
        }
    }

    // Create and enter new namespaces
    if (unshare(unshare_flags) < 0)
    {
        printf("init_proc(): unshare(): %d\n", errno);
        return 1;
    }

    if (setup_network("sub") < 0)
    {
        printf("init_proc(): setup_network() failed\n");
        return 1;
    }

    if (setup_filesystem(cspec->root, pivot, pivot_abs) < 0)
    {
        printf("init_proc(): setup_filesystem() failed\n");
        return 1;
    }

    return run_entry_point(cspec->entry_point, cspec->entry_point_argv);
}
Пример #5
0
int main( int argc, char ** argv )
{
	setvbuf( stdin, NULL, _IONBF, 0 );

	if(parse_command_line( argc, argv ))
		return 1;

	if(setup_network())
		return 1;

	while( 1 )
	{
		check_input();
		network_pump( handle_packet, NULL );
		network_flush();
		usleep(1000*100); // 100ms, 0.1s
	}

	return 0;
}
Пример #6
0
// Entry point
// Use the program as: ./mouliserver <port> <sqlitefile> <configfile>
int	main(int argc, char **argv)
{
  t_mouli mouli;

  if (argc != 4)
    {
      fprintf(stderr, "Usage: %s port sqlitefile configfile\n", *argv);
      return (1);
    }

  // Init config and database
  mouli_init(&mouli);
  if (load_config(&mouli, argv[3]))
    return (1);
  if (database_init(argv[2]))
    {
      mouli_delete(&mouli);
      fprintf(stderr, "%s\n", database_geterror());
      return (1);
    }

  // Init network and set main loop
  if (setup_network(&mouli, argv[1]) || mouli_run(&mouli))
    {
      curl_global_cleanup();
      if (database_close())
	fprintf(stderr, "Warning: failed to close database properly\n");
      mouli_delete(&mouli);
      return (1);
    }

  // Global cleanup
  mouli_delete(&mouli);
  curl_global_cleanup();
  if (database_close())
    fprintf(stderr, "Warning: failed to close database properly\n");
  return (0);
}
Пример #7
0
Файл: tincd.c Проект: Rumko/tinc
int main2(int argc, char **argv) {
	InitializeCriticalSection(&mutex);
	EnterCriticalSection(&mutex);
#endif

	if(!detach())
		return 1;

#ifdef HAVE_MLOCKALL
	/* Lock all pages into memory if requested.
	 * This has to be done after daemon()/fork() so it works for child.
	 * No need to do that in parent as it's very short-lived. */
	if(do_mlock && mlockall(MCL_CURRENT | MCL_FUTURE) != 0) {
		logger(LOG_ERR, "System call `%s' failed: %s", "mlockall",
		   strerror(errno));
		return 1;
	}
#endif

	/* Setup sockets and open device. */

	if(!setup_network())
		goto end;

	/* Initiate all outgoing connections. */

	try_outgoing_connections();

	/* Change process priority */

        char *priority = 0;

        if(get_config_string(lookup_config(config_tree, "ProcessPriority"), &priority)) {
                if(!strcasecmp(priority, "Normal")) {
                        if (setpriority(NORMAL_PRIORITY_CLASS) != 0) {
                                logger(LOG_ERR, "System call `%s' failed: %s",
                                       "setpriority", strerror(errno));
                                goto end;
                        }
                } else if(!strcasecmp(priority, "Low")) {
                        if (setpriority(BELOW_NORMAL_PRIORITY_CLASS) != 0) {
                                       logger(LOG_ERR, "System call `%s' failed: %s",
                                       "setpriority", strerror(errno));
                                goto end;
                        }
                } else if(!strcasecmp(priority, "High")) {
                        if (setpriority(HIGH_PRIORITY_CLASS) != 0) {
                                logger(LOG_ERR, "System call `%s' failed: %s",
                                       "setpriority", strerror(errno));
                                goto end;
                        }
                } else {
                        logger(LOG_ERR, "Invalid priority `%s`!", priority);
                        goto end;
                }
        }

	/* drop privileges */
	if (!drop_privs())
		goto end;

	/* Start main loop. It only exits when tinc is killed. */

	status = main_loop();

	/* Shutdown properly. */

	ifdebug(CONNECTIONS)
		dump_device_stats();

	close_network_connections();

end:
	logger(LOG_NOTICE, "Terminating");

#ifndef HAVE_MINGW
	remove_pid(pidfilename);
#endif

	EVP_cleanup();
	ENGINE_cleanup();
	CRYPTO_cleanup_all_ex_data();
	ERR_remove_state(0);
	ERR_free_strings();

	exit_configuration(&config_tree);
	free_names();

	return status;
}
Пример #8
0
void setup_state(struct State *S)
{
        setup_network(&S->ntw);
        setup_simulation(&S->sim);
}
Пример #9
0
int main(int argc, char **argv)
{
    krb5_error_code	retval;
    krb5_context	kcontext;
    int errout = 0;

    krb5_boolean log_stderr_set;

    (void) setlocale(LC_ALL, "");

#if !defined(TEXT_DOMAIN)		/* Should be defined by cc -D */
#define	TEXT_DOMAIN	"KRB5KDC_TEST"	/* Use this only if it weren't */
#endif

    (void) textdomain(TEXT_DOMAIN);

    if (strrchr(argv[0], '/'))
	argv[0] = strrchr(argv[0], '/')+1;

    if (!(kdc_realmlist = (kdc_realm_t **) malloc(sizeof(kdc_realm_t *) * 
						  KRB5_KDC_MAX_REALMS))) {
	fprintf(stderr, gettext("%s: cannot get memory for realm list\n"), argv[0]);
	exit(1);
    }
    memset((char *) kdc_realmlist, 0,
	   (size_t) (sizeof(kdc_realm_t *) * KRB5_KDC_MAX_REALMS));

    /*
     * A note about Kerberos contexts: This context, "kcontext", is used
     * for the KDC operations, i.e. setup, network connection and error
     * reporting.  The per-realm operations use the "realm_context"
     * associated with each realm.
     */
    retval = krb5int_init_context_kdc(&kcontext);
    if (retval) {
	    com_err(argv[0], retval, gettext("while initializing krb5"));
	    exit(1);
    }
    krb5_klog_init(kcontext, "kdc", argv[0], 1);

    /*
     * Solaris Kerberos:
     * In the early stages of krb5kdc it is desirable to log error messages
     * to stderr as well as any other logging locations specified in config
     * files.
     */
     log_stderr_set = krb5_klog_logging_to_stderr();
     if (log_stderr_set != TRUE) {
     	krb5_klog_add_stderr();
     }

    /* initialize_kdc5_error_table();  SUNWresync121 XXX */

    /*
     * Scan through the argument list
     */
    initialize_realms(kcontext, argc, argv);

    setup_signal_handlers();

    load_preauth_plugins(kcontext);

    retval = setup_sam();
    if (retval) {
	com_err(argv[0], retval, gettext("while initializing SAM"));
	finish_realms(argv[0]);
	return 1;
    }

    if ((retval = setup_network(argv[0]))) {
	com_err(argv[0], retval, gettext("while initializing network"));
	finish_realms(argv[0]);
	return 1;
    }

    /* Solaris Kerberos: Remove the extra stderr logging */
    if (log_stderr_set != TRUE)
	krb5_klog_remove_stderr();

    /*
     * Solaris Kerberos:
     * List the logs (FILE, STDERR, etc) which are currently being
     * logged to and print that to stderr. Useful when trying to
     * track down a failure via SMF.
     */
    if (retval = krb5_klog_list_logs(argv[0])) {
	com_err(argv[0], retval, gettext("while listing logs"));
	if (log_stderr_set != TRUE) {
		fprintf(stderr, gettext("%s: %s while listing logs\n"),
		    argv[0], error_message(retval));
	}
    }

    if (!nofork && daemon(0, 0)) {
	com_err(argv[0], errno, gettext("while detaching from tty"));
	if (log_stderr_set != TRUE) {
		fprintf(stderr, gettext("%s: %s while detaching from tty\n"),
		  argv[0], strerror(errno));
	}
	finish_realms(argv[0]);
	return 1;
    }
    if (retval = krb5_klog_syslog(LOG_INFO, "commencing operation")) {
	com_err(argv[0], retval, gettext("while logging message"));
	errout++;
	};

    if ((retval = listen_and_process(argv[0]))) {
	com_err(argv[0], retval, gettext("while processing network requests"));
	errout++;
    }
    if ((retval = closedown_network(argv[0]))) {
	com_err(argv[0], retval, gettext("while shutting down network"));
	errout++;
    }
    krb5_klog_syslog(LOG_INFO, "shutting down");
    unload_preauth_plugins(kcontext);
    krb5_klog_close(kdc_context);
    finish_realms(argv[0]);
    if (kdc_realmlist) 
      free(kdc_realmlist);
#ifdef USE_RCACHE
    (void) krb5_rc_close(kcontext, kdc_rcache);
#endif
#ifndef NOCACHE
    kdc_free_lookaside(kcontext);
#endif
    krb5_free_context(kcontext);
    return errout;
}
Пример #10
0
void init(char* hostUDPport, char* hostname){
	setup_network(hostUDPport, hostname);
	tcp_handshake();
	start_machine(); // set Start state
	sequencenumber = 1;
}
Пример #11
0
int main2(int argc, char **argv) {
#endif
    char *priority = NULL;

    if(!detach())
        return 1;

#ifdef HAVE_MLOCKALL
    /* Lock all pages into memory if requested.
     * This has to be done after daemon()/fork() so it works for child.
     * No need to do that in parent as it's very short-lived. */
    if(do_mlock && mlockall(MCL_CURRENT | MCL_FUTURE) != 0) {
        logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "mlockall",
               strerror(errno));
        return 1;
    }
#endif

    /* Setup sockets and open device. */

    if(!setup_network())
        goto end;

    /* Change process priority */

    if(get_config_string(lookup_config(config_tree, "ProcessPriority"), &priority)) {
        if(!strcasecmp(priority, "Normal")) {
            if (setpriority(NORMAL_PRIORITY_CLASS) != 0) {
                logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "setpriority", strerror(errno));
                goto end;
            }
        } else if(!strcasecmp(priority, "Low")) {
            if (setpriority(BELOW_NORMAL_PRIORITY_CLASS) != 0) {
                logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "setpriority", strerror(errno));
                goto end;
            }
        } else if(!strcasecmp(priority, "High")) {
            if (setpriority(HIGH_PRIORITY_CLASS) != 0) {
                logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "setpriority", strerror(errno));
                goto end;
            }
        } else {
            logger(DEBUG_ALWAYS, LOG_ERR, "Invalid priority `%s`!", priority);
            goto end;
        }
    }

    /* drop privileges */
    if (!drop_privs())
        goto end;

    /* Start main loop. It only exits when tinc is killed. */

    logger(DEBUG_ALWAYS, LOG_NOTICE, "Ready");

    if(umbilical) { // snip!
        write(umbilical, "", 1);
        close(umbilical);
        umbilical = 0;
    }

    try_outgoing_connections();

    status = main_loop();

    /* Shutdown properly. */

end:
    close_network_connections();

    logger(DEBUG_ALWAYS, LOG_NOTICE, "Terminating");

    free(priority);

    crypto_exit();

    exit_configuration(&config_tree);
    free(cmdline_conf);
    free_names();

    return status;
}