Example #1
0
/* Loads the game dll */
void *Sys_GetGameAPI(void *parms){
	gameapi_t * GetGameAPI;
	FILE * fp;
	char name[MAX_OSPATH];
	char * path;
	
	setreuid(getuid(), getuid());
	setegid(getgid());
	
	if(game_library)
		Com_Error(ERR_FATAL, "Sys_GetGameAPI without Sys_UnloadGame");
		
	Com_Printf("------- Loading game.so -------\n");
	
	/* now run through the search paths */
	path = NULL;
	while(1){
		path = FS_NextPath(path);
		if(!path)
			return NULL;
		snprintf(name, MAX_OSPATH, "%s/game.so", path);
		
		/* skip it if it doesn't exist */
		fp = fopen(name, "rb");
		if(fp == NULL)
			continue;
		fclose(fp);
		
		game_library = dlopen(name, RTLD_NOW);
		if(game_library){
			Com_MDPrintf("LoadLibrary(%s)\n", name);
			break;
		} else {
			Com_MDPrintf("LoadLibrary(%s)\n", name);
			Com_MDPrintf("%s\n", dlerror());
		}
	}
	
	GetGameAPI =(gameapi_t *) dlsym(game_library, "GetGameAPI");
	
	if(!GetGameAPI){
		Sys_UnloadGame();
		return NULL;
	}
	
	return GetGameAPI(parms);
}
Example #2
0
/*
=================
Sys_GetGameAPI

Loads the game dll
=================
*/
void *Sys_GetGameAPI (void *parms)
{
	void	*(*GetGameAPI) (void *);
	
	FILE	*fp;
	char	name[MAX_OSPATH];
	char	*path;
	char	*str_p;
#if defined __i386__
	const char *gamename = "gamei386.so";
#elif defined __x86_64__
	const char *gamename = "gamex86_64.so";
#elif defined __alpha__
	const char *gamename = "gameaxp.so";
#elif defined __powerpc__
	const char *gamename = "gameppc.so";
#elif defined __sparc__
	const char *gamename = "gamesparc.so";
#elif defined __arm__
	const char *gamename = "gamearm.so";
#else
#error Unknown arch
#endif

	setreuid(getuid(), getuid());
	setegid(getgid());

	if (game_library)
		Com_Error (ERR_FATAL, "Sys_GetGameAPI without Sys_UnloadingGame");

	Com_Printf("------- Loading %s -------\n", gamename);

	// now run through the search paths
	path = NULL;
	while (1)
	{
		path = FS_NextPath (path);
		if (!path)
			return NULL;		// couldn't find one anywhere
		snprintf (name, MAX_OSPATH, "%s/%s", path, gamename);
		
		/* skip it if it just doesn't exist */
		fp = fopen(name, "rb");
		if (fp == NULL)
			continue;
		fclose(fp);
		
		game_library = dlopen (name, RTLD_NOW);
		if (game_library)
		{
			Com_MDPrintf ("LoadLibrary (%s)\n",name);
			break;
		} 
		else 
		{
			Com_Printf ("LoadLibrary (%s):", name);
			
			path = dlerror();
			str_p = strchr(path, ':'); // skip the path (already shown)
			if (str_p == NULL)
				str_p = path;
			else
				str_p++;
				
			Com_Printf ("%s\n", str_p);
			
			return NULL; 
		}
	}

	GetGameAPI = (void *)dlsym (game_library, "GetGameAPI");

	if (!GetGameAPI)
	{
		Sys_UnloadGame ();		
		return NULL;
	}

	return GetGameAPI (parms);
}
Example #3
0
/*
 * Loads the game dll
 */
void *
Sys_GetGameAPI(void *parms)
{
	void *(*GetGameAPI)(void *);

	FILE *fp;
	char name[MAX_OSPATH];
	char *path;
	char *str_p;
    #ifdef __APPLE__
        const char *gamename = "game.dylib";
    #else
        const char *gamename = "game.so";
    #endif

	setreuid(getuid(), getuid());
	setegid(getgid());

	if (game_library)
	{
		Com_Error(ERR_FATAL, "Sys_GetGameAPI without Sys_UnloadingGame");
	}

	Com_Printf("LoadLibrary(\"%s\")\n", gamename);

	/* now run through the search paths */
	path = NULL;

	while (1)
	{
		path = FS_NextPath(path);

		if (!path)
		{
			return NULL;     /* couldn't find one anywhere */
		}

		snprintf(name, MAX_OSPATH, "%s/%s", path, gamename);

		/* skip it if it just doesn't exist */
		fp = fopen(name, "rb");

		if (fp == NULL)
		{
			continue;
		}

		fclose(fp);

		game_library = dlopen(name, RTLD_NOW);

		if (game_library)
		{
			Com_MDPrintf("LoadLibrary (%s)\n", name);
			break;
		}
		else
		{
			Com_Printf("LoadLibrary (%s):", name);

			path = (char *)dlerror();
			str_p = strchr(path, ':');   /* skip the path (already shown) */

			if (str_p == NULL)
			{
				str_p = path;
			}
			else
			{
				str_p++;
			}

			Com_Printf("%s\n", str_p);

			return NULL;
		}
	}

	GetGameAPI = (void *)dlsym(game_library, "GetGameAPI");

	if (!GetGameAPI)
	{
		Sys_UnloadGame();
		return NULL;
	}

	return GetGameAPI(parms);
}