Example #1
0
int	launch_game(t_lemipc *lemipc)
{
  signal(SIGINT, catch_signal);
  srand(time(NULL));
  lock_sem(lemipc->game->sem_id);
  init_player(lemipc);
  unlock_sem(lemipc->game->sem_id);
  player_loop(lemipc);
  lemipc->game->map[lemipc->player.pos.y][lemipc->player.pos.x] = 0;
  if (count_players(lemipc) == 0)
    {
      printf("Winner is team %d\n", lemipc->player.team);
      free_ipcs(lemipc);
    }
  return (0);
}
Example #2
0
void shm_exit_ns(struct ipc_namespace *ns)
{
	free_ipcs(ns, &shm_ids(ns), do_shm_rmid);
	idr_destroy(&ns->ids[IPC_SHM_IDS].ipcs_idr);
}
Example #3
0
void msg_exit_ns(struct ipc_namespace *ns)
{
	free_ipcs(ns, &msg_ids(ns), freeque);
	idr_destroy(&ns->ids[IPC_MSG_IDS].ipcs_idr);
}
Example #4
0
void sem_exit_ns(struct ipc_namespace *ns)
{
	free_ipcs(ns, &sem_ids(ns), freeary);
	idr_destroy(&ns->ids[IPC_SEM_IDS].ipcs_idr);
}
Example #5
0
void sem_exit_ns(struct ipc_namespace *ns)
{
    free_ipcs(ns, &sem_ids(ns), freeary);
}
Example #6
0
void msg_exit_ns(struct ipc_namespace *ns)
{
	free_ipcs(ns, &msg_ids(ns), freeque);
}
Example #7
0
void shm_exit_ns(struct ipc_namespace *ns)
{
	free_ipcs(ns, &shm_ids(ns), do_shm_rmid);
}
Example #8
0
/* server_main()
 * -> sb_run_* APIs are enabled
 * -> all registries are enabled
 * -> all configs are enabled. config should follow and overwrite registry.
 */
int server_main()
{
	module *mod=NULL;

  /***********************************************************************
   * first-pass config 
   */

	set_proc_desc(NULL, "softbotd: master - loading static modules");
	/* load_static_modules()
	 *  -> hooking APIs. we cannot call sb_run_* APIs before this
	 */
	load_static_modules();

    /* FIXME why should i load kbo module?? */
	//load_kbo_module();

	if (read_config(mConfigFile, NULL) != SUCCESS) {
		crit("failed to read config file");
		exit(1);
	}
	/* 1. load dynamic modules -> make linked list of whole modules
	 * 2. setup each modules's configuration -> call each config function
	 */

	open_error_log(gErrorLogFile, gQueryLogFile);
#ifdef USE_TIMELOG
    if(sb_tstat_log_init(mTimeLogFile) != SUCCESS) {
        exit(1);
    }
#endif

	save_pid(mPidFile);

	load_dynamic_modules();
  /***********************************************************************
   * all the modules has been loaded.
   */

	sb_sort_hook();

	load_each_registry();
	/* 1. register each module to registry
	 * 2. do the shared memory related stuff...
	 * 3. XXX registry module does not guarantee shared memory locking...
	 */

	restore_registry_file(gRegistryFile);

	/* TODO second-pass config */

  /***********************************************************************
   * runtime configuration is done.
   */
	init_all_scoreboards();

	/* method 3 of doc/README.init */
	set_proc_desc(NULL, "softbotd: master - init each module");
	if ( init_core_modules(first_module) != SUCCESS ) goto STOP;
	if ( init_standard_modules(first_module) != SUCCESS ) goto STOP;

	if (clc_listen_port >= 2) { /* show using ports */
		show_portinfo();
		goto STOP;
	}
	set_proc_desc(NULL, "softbotd: master - spawning child");
	/* check debug_module */
	if ( strlen(debug_module) > 0 ) {
		mod = find_module(debug_module);
		if ( mod == NULL ) {
			error("no such module [%s]", debug_module);
			return FAIL;
		}
		else {
			info("debugging module [%s]", debug_module);
			// XXX: in debugging mode, isn't it better not to fork? is it?
			if (mod->main) 
				sb_run_spawn_process_for_module(scoreboard, mod);
			else {
				error("module[%s] has no main",debug_module);
				exit(1);
			}
		}
	}
	else if (unittest) {
		crit("unittesting started");
		do_unittest();
		crit("unittesting ended");
		goto STOP;
	}
	else
		sb_run_spawn_processes_for_each_module(scoreboard, first_module);

	CRIT("*** master monitoring loop ***");
	setproctitle("softbotd: master - monitoring");
	set_proc_desc(NULL, "softbotd: master - monitoring");
	scoreboard->period = CHILD_MONITORING_PERIOD;
	sb_run_monitor_processes_for_modules(scoreboard, first_module);

  /***********************************************************************
   * stopping state.
   */
STOP:	
	if ( save_registry_file(gRegistryFile) != SUCCESS )
		error("save_registry_file(%s) failed: %s",
			gRegistryFile, strerror(errno));
	free_ipcs(); /* release shared memory and semaphore */
	close_error_log(); /* close error_log file and semaphore */

#ifdef USE_TIMELOG
    sb_tstat_log_destroy();
#endif

	return SUCCESS;
}