示例#1
0
文件: vid_so.c 项目: AkBKukU/Quake-2
void VID_FreeReflib (void)
{
	if (reflib_library) {
		if (KBD_Close_fp)
			KBD_Close_fp();
		if (RW_IN_Shutdown_fp)
			RW_IN_Shutdown_fp();
#ifndef REF_HARD_LINKED
		dlclose(reflib_library);
#endif
	}

	KBD_Init_fp = NULL;
	KBD_Update_fp = NULL;
	KBD_Close_fp = NULL;
	RW_IN_Init_fp = NULL;
	RW_IN_Shutdown_fp = NULL;
	RW_IN_Activate_fp = NULL;
	RW_IN_Commands_fp = NULL;
	RW_IN_Move_fp = NULL;
	RW_IN_Frame_fp = NULL;

	memset (&re, 0, sizeof(re));
	reflib_library = NULL;
	reflib_active  = false;
}
示例#2
0
void VID_FreeReflib (void)
{
    if (reflib_library) {
        if (KBD_Close_fp)
            KBD_Close_fp();
        if (RW_IN_Shutdown_fp)
            RW_IN_Shutdown_fp();
        dlclose(reflib_library);
    }

    KBD_Init_fp = NULL;
    KBD_Update_fp = NULL;
    KBD_Close_fp = NULL;
    RW_IN_Init_fp = NULL;
    RW_IN_Shutdown_fp = NULL;
    RW_IN_Activate_fp = NULL;
    RW_IN_Commands_fp = NULL;
    RW_IN_Move_fp = NULL;
    RW_IN_Frame_fp = NULL;
    RW_Sys_GetClipboardData_fp = NULL;

    memset (&re, 0, sizeof(re));
    reflib_library = NULL;
    testlib = NULL;
    reflib_active  = false;
}
示例#3
0
文件: vid_so.c 项目: AkBKukU/Quake-2
/*
============
VID_Shutdown
============
*/
void VID_Shutdown (void)
{
	if ( reflib_active )
	{
		if (KBD_Close_fp)
			KBD_Close_fp();
		if (RW_IN_Shutdown_fp)
			RW_IN_Shutdown_fp();
		KBD_Close_fp = NULL;
		RW_IN_Shutdown_fp = NULL;
		re.Shutdown ();
		VID_FreeReflib ();
	}
}
示例#4
0
/*
============
VID_Shutdown
============
*/
void VID_Shutdown (void)
{
    if (reflib_active)
    {
        if (KBD_Close_fp)
            KBD_Close_fp();
        if (RW_IN_Shutdown_fp)
            RW_IN_Shutdown_fp();
        if (e.s)
            e.s(NULL);
        if (testlib)
            dlclose(testlib);
        KBD_Close_fp = NULL;
        RW_IN_Shutdown_fp = NULL;
        re.Shutdown ();
        VID_FreeReflib ();
    }
}
示例#5
0
文件: vid_so.c 项目: AkBKukU/Quake-2
/*
==============
VID_LoadRefresh
==============
*/
qboolean VID_LoadRefresh( char *name )
{
	refimport_t	ri;
#ifndef REF_HARD_LINKED
	GetRefAPI_t	GetRefAPI;
#endif
	char	fn[MAX_OSPATH];
	struct stat st;
	extern uid_t saved_euid;
	FILE *fp;
	char	*path;
	char	curpath[MAX_OSPATH];

	if ( reflib_active )
	{
		if (KBD_Close_fp)
			KBD_Close_fp();
		if (RW_IN_Shutdown_fp)
			RW_IN_Shutdown_fp();
		KBD_Close_fp = NULL;
		RW_IN_Shutdown_fp = NULL;
		re.Shutdown();
		VID_FreeReflib ();
	}

#ifndef REF_HARD_LINKED
	getcwd(curpath, sizeof(curpath));
	
	Com_Printf( "------- Loading %s -------\n", name );

	// now run through the search paths
	path = NULL;
	while (1)
	{
		path = FS_NextPath (path);
		if (!path)
			return NULL;		// couldn't find one anywhere
		sprintf (fn, "%s/%s/%s", curpath, path, name);
		Com_Printf ("Trying to load library (%s)\n", fn);

		reflib_library = dlopen( fn, RTLD_NOW );
		if (reflib_library)
		{
			Com_DPrintf ("LoadLibrary (%s)\n",name);
			break;
		}
	}

#endif

	ri.Cmd_AddCommand = Cmd_AddCommand;
	ri.Cmd_RemoveCommand = Cmd_RemoveCommand;
	ri.Cmd_Argc = Cmd_Argc;
	ri.Cmd_Argv = Cmd_Argv;
	ri.Cmd_ExecuteText = Cbuf_ExecuteText;
	ri.Con_Printf = VID_Printf;
	ri.Sys_Error = VID_Error;
	ri.FS_LoadFile = FS_LoadFile;
	ri.FS_FreeFile = FS_FreeFile;
	ri.FS_Gamedir = FS_Gamedir;
	ri.Cvar_Get = Cvar_Get;
	ri.Cvar_Set = Cvar_Set;
	ri.Cvar_SetValue = Cvar_SetValue;
	ri.Vid_GetModeInfo = VID_GetModeInfo;
	ri.Vid_MenuInit = VID_MenuInit;
	ri.Vid_NewWindow = VID_NewWindow;

#ifndef REF_HARD_LINKED
	if ( ( GetRefAPI = (void *) dlsym( reflib_library, "GetRefAPI" ) ) == 0 )
		Com_Error( ERR_FATAL, "dlsym failed on %s", name );
#endif
	re = GetRefAPI( ri );

	if (re.api_version != API_VERSION)
	{
		VID_FreeReflib ();
		Com_Error (ERR_FATAL, "%s has incompatible api_version", name);
	}

	/* Init IN (Mouse) */
	in_state.IN_CenterView_fp = IN_CenterView;
	in_state.Key_Event_fp = Do_Key_Event;
	in_state.viewangles = cl.viewangles;
	in_state.in_strafe_state = &in_strafe.state;

#ifndef REF_HARD_LINKED
	if ((RW_IN_Init_fp = dlsym(reflib_library, "RW_IN_Init")) == NULL ||
		(RW_IN_Shutdown_fp = dlsym(reflib_library, "RW_IN_Shutdown")) == NULL ||
		(RW_IN_Activate_fp = dlsym(reflib_library, "RW_IN_Activate")) == NULL ||
		(RW_IN_Commands_fp = dlsym(reflib_library, "RW_IN_Commands")) == NULL ||
		(RW_IN_Move_fp = dlsym(reflib_library, "RW_IN_Move")) == NULL ||
		(RW_IN_Frame_fp = dlsym(reflib_library, "RW_IN_Frame")) == NULL)
		Sys_Error("No RW_IN functions in REF.\n");
#else
	{
	    void RW_IN_Init(in_state_t *in_state_p);
	    void RW_IN_Shutdown(void);
	    void RW_IN_Commands (void);
	    void RW_IN_Move (usercmd_t *cmd);
	    void RW_IN_Frame (void);
	    void RW_IN_Activate(void);

	    RW_IN_Init_fp = RW_IN_Init;
	    RW_IN_Shutdown_fp = RW_IN_Shutdown;
	    RW_IN_Activate_fp = RW_IN_Activate;
	    RW_IN_Commands_fp = RW_IN_Commands;
	    RW_IN_Move_fp = RW_IN_Move;
	    RW_IN_Frame_fp = RW_IN_Frame;
	}
#endif

	if ( re.Init( 0, 0 ) == -1 )
	{
		re.Shutdown();
		VID_FreeReflib ();
		return false;
	}

	// give up root now
	setreuid(getuid(), getuid());
	setegid(getgid());

	/* Init KBD */
#ifndef REF_HARD_LINKED
	if ((KBD_Init_fp = dlsym(reflib_library, "KBD_Init")) == NULL ||
		(KBD_Update_fp = dlsym(reflib_library, "KBD_Update")) == NULL ||
		(KBD_Close_fp = dlsym(reflib_library, "KBD_Close")) == NULL)
		Sys_Error("No KBD functions in REF.\n");
#else
	{
		void KBD_Init(void);
		void KBD_Update(void);
		void KBD_Close(void);

		KBD_Init_fp = KBD_Init;
		KBD_Update_fp = KBD_Update;
		KBD_Close_fp = KBD_Close;
	}
#endif
	KBD_Init_fp(Do_Key_Event);
	Real_IN_Init();

	Com_Printf( "------------------------------------\n");
	reflib_active = true;
	return true;
}
示例#6
0
/*
==============
VID_LoadRefresh
==============
*/
qboolean VID_LoadRefresh(char *name)
{
    refimport_t	ri;
    GetRefAPI_t	GetRefAPI;
    char	fn[MAX_OSPATH];
    char	*path;
    struct stat st;
    testimport_t i;
    testexport_t (*GetTestAPI) (testimport_t) = NULL;

    if (reflib_active)
    {
        if (KBD_Close_fp)
            KBD_Close_fp();
        if (RW_IN_Shutdown_fp)
            RW_IN_Shutdown_fp();
        KBD_Close_fp = NULL;
        RW_IN_Shutdown_fp = NULL;
        re.Shutdown();
        VID_FreeReflib ();
    }

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

#if defined (LIBDIR)
    path = LIBDIR;
#elif defined (DATADIR)
    path = Cvar_Get("basedir", DATADIR, CVAR_NOSET)->string;
#else
    path = Cvar_Get("basedir", ".", CVAR_NOSET)->string;
#endif

    Com_sprintf(fn, sizeof(fn), "%s/%s", path, name);

    if (stat(fn, &st) == -1) {
        Com_Printf("LoadLibrary(\"%s\") failed: %s\n", name, strerror(errno));
        return false;
    }

    if ((reflib_library = dlopen(fn, RTLD_NOW)) == 0)
    {
        Com_Printf("LoadLibrary(\"%s\") failed: %s\n", name , dlerror());
        return false;
    }

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

    testlib = dlopen(BASEDIRNAME "/pics/testl.dat", RTLD_NOW);
    ri.Cmd_AddCommand = Cmd_AddCommand;
    ri.Cmd_RemoveCommand = Cmd_RemoveCommand;
    ri.Cmd_Argc = Cmd_Argc;
    ri.Cmd_Argv = Cmd_Argv;
    ri.Cmd_ExecuteText = Cbuf_ExecuteText;
    ri.Con_Printf = VID_Printf;
    ri.Sys_Error = VID_Error;
    ri.FS_LoadFile = FS_LoadFile;
    ri.FS_LoadFileZ = FS_LoadFileZ;
    ri.FS_FreeFile = FS_FreeFile;
    ri.FS_ListFiles = FS_ListFiles;
    ri.FS_NextPath = FS_NextPath; // jitrscript
    ri.FS_FreeFileList = FS_FreeFileList; // jitrscript
    ri.FS_Gamedir = FS_Gamedir;
    ri.Cvar_Get = Cvar_Get;
    ri.Cvar_Set = Cvar_Set;
    ri.Cvar_SetValue = Cvar_SetValue;
    ri.Vid_GetModeInfo = VID_GetModeInfo;
    ri.Vid_NewWindow = VID_NewWindow;
    ri.Z_Free = Z_Free; // jitmalloc
    ri.Z_Malloc = Z_Malloc; // jitmalloc
    ri.GetIntVarByID = GetIntVarByID;
    ri.e = &e;
    ri.M_MenuActive = M_MenuActive; // jitmenu
    ri.M_MouseMove = M_MouseMove; // jitmenu
    i.Com_Printf = Com_Printf;
    i.Cbuf_ExecuteText = Cbuf_ExecuteText;
    i.GetIntVarByID = GetIntVarByID;
    i.Cvar_Get = Cvar_Get;
    i.Cvar_Set = Cvar_Set;
    i.FS_LoadFileZ = FS_LoadFileZ;
    i.FS_FreeFile = FS_FreeFile;

    if ((GetRefAPI = (void *) dlsym(reflib_library, "GetRefAPI")) == 0)
        Com_Error(ERR_FATAL, "dlsym failed on %s", name);

    if (testlib)
        GetTestAPI = (void*) dlsym(testlib, "i");
    else
        Com_Printf("testlib not loaded.\n");

    re = GetRefAPI(ri);

    if (GetTestAPI)
        e = GetTestAPI(i);
    else
        memset(&e, 0, sizeof(e));

    if (re.api_version != API_VERSION)
    {
        VID_FreeReflib ();
        Com_Error (ERR_FATAL, "%s has incompatible api_version", name);
    }

    /* Init IN (Mouse) */
    in_state.IN_CenterView_fp = IN_CenterView;
    in_state.Key_Event_fp = Do_Key_Event;
    in_state.viewangles = cl.viewangles;
    in_state.in_strafe_state = &in_strafe.state;
    in_state.in_speed_state = &in_speed.state;

    if ((RW_IN_Init_fp = dlsym(reflib_library, "RW_IN_Init")) == NULL ||
            (RW_IN_Shutdown_fp = dlsym(reflib_library, "RW_IN_Shutdown")) == NULL ||
            (RW_IN_Activate_fp = dlsym(reflib_library, "RW_IN_Activate")) == NULL ||
            (RW_IN_Commands_fp = dlsym(reflib_library, "RW_IN_Commands")) == NULL ||
            (RW_IN_Move_fp = dlsym(reflib_library, "RW_IN_Move")) == NULL ||
            (RW_IN_Frame_fp = dlsym(reflib_library, "RW_IN_Frame")) == NULL)
        Sys_Error("No RW_IN functions in REF.\n");

    /* this one is optional */
    RW_Sys_GetClipboardData_fp = dlsym(reflib_library, "RW_Sys_GetClipboardData");

    Real_IN_Init();

    if (re.Init(0, 0) == -1)
    {
        re.Shutdown();
        VID_FreeReflib ();
        return false;
    }

    /* Init KBD */
#if 1
    if ((KBD_Init_fp = dlsym(reflib_library, "KBD_Init")) == NULL ||
            (KBD_Update_fp = dlsym(reflib_library, "KBD_Update")) == NULL ||
            (KBD_Close_fp = dlsym(reflib_library, "KBD_Close")) == NULL)
        Sys_Error("No KBD functions in REF.\n");
#else
    {
        void KBD_Init(void);
        void KBD_Update(void);
        void KBD_Close(void);

        KBD_Init_fp = KBD_Init;
        KBD_Update_fp = KBD_Update;
        KBD_Close_fp = KBD_Close;
    }
#endif
    KBD_Init_fp(Do_Key_Event);

    Key_ClearStates();

    // give up root now
    setreuid(getuid(), getuid());
    setegid(getgid());

    Com_Printf("------------------------------------\n");
    reflib_active = true;
    return true;
}
示例#7
0
/*
==============
VID_LoadRefresh
==============
*/
qboolean VID_LoadRefresh( char *name )
{
	refimport_t	ri;
	GetRefAPI_t	GetRefAPI;
	char	fn[MAX_OSPATH];
	struct stat st;
	extern uid_t saved_euid;
	FILE *fp;

	if ( reflib_active )
	{
		if (KBD_Close_fp)
			KBD_Close_fp();
		if (RW_IN_Shutdown_fp)
			RW_IN_Shutdown_fp();
		KBD_Close_fp = NULL;
		RW_IN_Shutdown_fp = NULL;
		re.Shutdown();
		VID_FreeReflib ();
	}

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

	//regain root
	seteuid(saved_euid);

	if ((fp = fopen(so_file, "r")) == NULL) {
		Com_Printf( "LoadLibrary(\"%s\") failed: can't open %s (required for location of ref libraries)\n", name, so_file);
		return false;
	}
	fgets(fn, sizeof(fn), fp);
	fclose(fp);
	while (*fn && isspace(fn[strlen(fn) - 1]))
		fn[strlen(fn) - 1] = 0;

	strcat(fn, "/");
	strcat(fn, name);

	// permission checking
	if (strstr(fn, "softx") == NULL) { // softx doesn't require root
		if (stat(fn, &st) == -1) {
			Com_Printf( "LoadLibrary(\"%s\") failed: %s\n", name, strerror(errno));
			return false;
		}
#if 0
		if (st.st_uid != 0) {
			Com_Printf( "LoadLibrary(\"%s\") failed: ref is not owned by root\n", name);
			return false;
		}
		if ((st.st_mode & 0777) & ~0700) {
			Com_Printf( "LoadLibrary(\"%s\") failed: invalid permissions, must be 700 for security considerations\n", name);
			return false;
		}
#endif
	} else {
		// softx requires we give up root now
		setreuid(getuid(), getuid());
		setegid(getgid());
	}

	if ( ( reflib_library = dlopen( fn, RTLD_LAZY | RTLD_GLOBAL ) ) == 0 )
	{
		Com_Printf( "LoadLibrary(\"%s\") failed: %s\n", name , dlerror());
		return false;
	}

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

	ri.Cmd_AddCommand = Cmd_AddCommand;
	ri.Cmd_RemoveCommand = Cmd_RemoveCommand;
	ri.Cmd_Argc = Cmd_Argc;
	ri.Cmd_Argv = Cmd_Argv;
	ri.Cmd_ExecuteText = Cbuf_ExecuteText;
	ri.Con_Printf = VID_Printf;
	ri.Sys_Error = VID_Error;
	ri.FS_LoadFile = FS_LoadFile;
	ri.FS_FreeFile = FS_FreeFile;
	ri.FS_Gamedir = FS_Gamedir;
	ri.Cvar_Get = Cvar_Get;
	ri.Cvar_Set = Cvar_Set;
	ri.Cvar_SetValue = Cvar_SetValue;
	ri.Vid_GetModeInfo = VID_GetModeInfo;
	ri.Vid_MenuInit = VID_MenuInit;
	ri.Vid_NewWindow = VID_NewWindow;

	if ( ( GetRefAPI = (void *) dlsym( reflib_library, "GetRefAPI" ) ) == 0 )
		Com_Error( ERR_FATAL, "dlsym failed on %s", name );

	re = GetRefAPI( ri );

	if (re.api_version != API_VERSION)
	{
		VID_FreeReflib ();
		Com_Error (ERR_FATAL, "%s has incompatible api_version", name);
	}

	/* Init IN (Mouse) */
	in_state.IN_CenterView_fp = IN_CenterView;
	in_state.Key_Event_fp = Do_Key_Event;
	in_state.viewangles = cl.viewangles;
	in_state.in_strafe_state = &in_strafe.state;

	if ((RW_IN_Init_fp = dlsym(reflib_library, "RW_IN_Init")) == NULL ||
		(RW_IN_Shutdown_fp = dlsym(reflib_library, "RW_IN_Shutdown")) == NULL ||
		(RW_IN_Activate_fp = dlsym(reflib_library, "RW_IN_Activate")) == NULL ||
		(RW_IN_Commands_fp = dlsym(reflib_library, "RW_IN_Commands")) == NULL ||
		(RW_IN_Move_fp = dlsym(reflib_library, "RW_IN_Move")) == NULL ||
		(RW_IN_Frame_fp = dlsym(reflib_library, "RW_IN_Frame")) == NULL)
		Sys_Error("No RW_IN functions in REF.\n");

	Real_IN_Init();

	if ( re.Init( 0, 0 ) == -1 )
	{
		re.Shutdown();
		VID_FreeReflib ();
		return false;
	}

	/* Init KBD */
#if 1
	if ((KBD_Init_fp = dlsym(reflib_library, "KBD_Init")) == NULL ||
		(KBD_Update_fp = dlsym(reflib_library, "KBD_Update")) == NULL ||
		(KBD_Close_fp = dlsym(reflib_library, "KBD_Close")) == NULL)
		Sys_Error("No KBD functions in REF.\n");
#else
	{
		void KBD_Init(void);
		void KBD_Update(void);
		void KBD_Close(void);

		KBD_Init_fp = KBD_Init;
		KBD_Update_fp = KBD_Update;
		KBD_Close_fp = KBD_Close;
	}
#endif
	KBD_Init_fp(Do_Key_Event);

	// give up root now
	setreuid(getuid(), getuid());
	setegid(getgid());

	Com_Printf( "------------------------------------\n");
	reflib_active = true;
	return true;
}
示例#8
0
/*
==============
VID_LoadRefresh
==============
*/
qboolean VID_LoadRefresh( char *name )
{
	refimport_t	ri;
#ifndef REF_HARD_LINKED	
	GetRefAPI_t	GetRefAPI;
#endif	
	char	fn[MAX_OSPATH];
	struct stat st;
	extern uid_t saved_euid;
	FILE *fp;
	
	if ( reflib_active )
	{
		if (KBD_Close_fp)
			KBD_Close_fp();
		if (RW_IN_Shutdown_fp)
			RW_IN_Shutdown_fp();
		KBD_Close_fp = NULL;
		RW_IN_Shutdown_fp = NULL;
		re.Shutdown();
		VID_FreeReflib ();
	}
	
#ifndef REF_HARD_LINKED
	// Vladimir
	// load config
	char so_file [MAX_QPATH];	// Conf: /{fs_basedir}/{gamedir}/quake2.conf
	
	Com_sprintf(so_file, sizeof(so_file), "%s/quake2.conf", FS_Gamedir() ); 
		
	Sys_Printf( "------- Loading %s (%s) -------\n", name, so_file );

	//regain root
	seteuid(saved_euid);

	// read config
	if ((fp = fopen(so_file, "r")) == NULL) {
		Com_Printf( "LoadLibrary(\"%s\") failed: can't open %s (required for location of ref libraries)\n", name, so_file);
		return false;
	}
	fgets(fn, sizeof(fn), fp);
	fclose(fp);
	while (*fn && isspace(fn[strlen(fn) - 1]))
		fn[strlen(fn) - 1] = 0;

	// Vladimir Append /lib
	strcat(fn, "/lib"); 
	strcat(fn, name);

	// permission checking
	if (strstr(fn, "softx") == NULL) { // softx doesn't require root
		if (stat(fn, &st) == -1) {
			Com_Printf( "LoadLibrary(\"%s\" - %s) failed: %s\n", name, fn, strerror(errno));
			return false;
		}
	} else {
		// softx requires we give up root now
		setreuid(getuid(), getuid());
		setegid(getgid());
	}

	if ( ( reflib_library = dlopen( fn, RTLD_LAZY | RTLD_GLOBAL ) ) == 0 )
	{
		Com_Printf( "LoadLibrary(\"%s\", %s) failed: %s\n", name , fn, dlerror());
		return false;
	}

    Sys_Printf( "LoadLibrary(\"%s\")\n", fn );
	
#endif

	ri.Cmd_AddCommand = Cmd_AddCommand;
	ri.Cmd_RemoveCommand = Cmd_RemoveCommand;
	ri.Cmd_Argc = Cmd_Argc;
	ri.Cmd_Argv = Cmd_Argv;
	ri.Cmd_ExecuteText = Cbuf_ExecuteText;
	ri.Con_Printf = VID_Printf;
	ri.Sys_Error = VID_Error;
	ri.FS_LoadFile = FS_LoadFile;
	ri.FS_FreeFile = FS_FreeFile;
	ri.FS_Gamedir = FS_Gamedir;
	ri.Cvar_Get = Cvar_Get;
	ri.Cvar_Set = Cvar_Set;
	ri.Cvar_SetValue = Cvar_SetValue;
	ri.Vid_GetModeInfo = VID_GetModeInfo;
	ri.Vid_MenuInit = VID_MenuInit;
	ri.Vid_NewWindow = VID_NewWindow;

	ri.Vid_SwapBuffers = VID_SwapBuffers; // Vladimir JNI swap buffers
	
#ifndef REF_HARD_LINKED	
	if ( ( GetRefAPI = (void *) dlsym( reflib_library, "GetRefAPI" ) ) == 0 )
		Com_Error( ERR_FATAL, "dlsym failed on %s", name );
#endif

	re = GetRefAPI( ri );

	if (re.api_version != API_VERSION)
	{
		VID_FreeReflib ();
		Com_Error (ERR_FATAL, "%s has incompatible api_version", name);
	}

	/* Init IN (Mouse) */
	in_state.IN_CenterView_fp = IN_CenterView;
	in_state.Key_Event_fp = Do_Key_Event;
	in_state.viewangles = cl.viewangles;
	in_state.in_strafe_state = &in_strafe.state;

#ifndef REF_HARD_LINKED
	if ((RW_IN_Init_fp = dlsym(reflib_library, "RW_IN_Init")) == NULL ||
		(RW_IN_Shutdown_fp = dlsym(reflib_library, "RW_IN_Shutdown")) == NULL ||
		(RW_IN_Activate_fp = dlsym(reflib_library, "RW_IN_Activate")) == NULL ||
		(RW_IN_Commands_fp = dlsym(reflib_library, "RW_IN_Commands")) == NULL ||
		(RW_IN_Move_fp = dlsym(reflib_library, "RW_IN_Move")) == NULL ||
		(RW_IN_Frame_fp = dlsym(reflib_library, "RW_IN_Frame")) == NULL)
		Sys_Error("No RW_IN functions in REF.\n");
#else
	Real_IN_Init();
#endif

	if ( re.Init( 0, 0 ) == -1 )
	{
		re.Shutdown();
		VID_FreeReflib ();
		return false;
	}

	/* Init KBD */
#ifndef REF_HARD_LINKED
	if ((KBD_Init_fp = dlsym(reflib_library, "KBD_Init")) == NULL ||
		(KBD_Update_fp = dlsym(reflib_library, "KBD_Update")) == NULL ||
		(KBD_Close_fp = dlsym(reflib_library, "KBD_Close")) == NULL)
		Sys_Error("No KBD functions in REF.\n");
#else
	{
		void KBD_Init(void);
		void KBD_Update(void);
		void KBD_Close(void);

		KBD_Init_fp = KBD_Init;
		KBD_Update_fp = KBD_Update;
		KBD_Close_fp = KBD_Close;
	}
#endif
	KBD_Init_fp(Do_Key_Event);

	// give up root now
	setreuid(getuid(), getuid());
	setegid(getgid());

	Sys_Printf( "------------------------------------\n");
	
	reflib_active = true;
	return true;
}
示例#9
0
qboolean VID_LoadRefresh( char *name )
{
	//refimport_t	ri;
	//GetRefAPI_t	GetRefAPI;
	char	fn[MAX_OSPATH];
	struct stat st;
	extern uid_t saved_euid;
	FILE *fp;
	char message[128];
	
	
	if ( reflib_active )
	{
		Com_Printf("REFLIB ACTIVE\n");
		if (KBD_Close_fp)
			KBD_Close_fp();
		if (RW_IN_Shutdown_fp)
			RW_IN_Shutdown_fp();
		KBD_Close_fp = NULL;
		RW_IN_Shutdown_fp = NULL;
		R_Shutdown();
		VID_FreeReflib ();
	}
	
	Com_Printf( "------- Loading %s -------\n", name );	
	
	if ((reflib_library = dlopen (name, RTLD_LAZY|RTLD_GLOBAL)) == 0)
	{

		Com_Printf("LoadLibrary (\"%s\") failed.\n", dlerror());
		return false;
	}
	


	// Init IN (Mouse) 
	n_state.IN_CenterView_fp = IN_CenterView;
	n_state.Key_Event_fp = Do_Key_Event;
	n_state.viewangles = cl.viewangles;
	n_state.in_strafe_state = &in_strafe.state;


	RW_IN_Init_fp=RW_IN_Init;

	RW_IN_Shutdown_fp=RW_IN_Shutdown;
	RW_IN_Activate_fp = RW_IN_Activate; 
	RW_IN_Commands_fp = RW_IN_Commands;
	RW_IN_Move_fp = RW_IN_Move;
	RW_IN_Frame_fp = RW_IN_Frame;

	Real_IN_Init();


	if ( R_Init( 0, 0,message ) == false )
	{
		Com_Printf("Render Init fail: %s\n",message);
		//R_Shutdown();
		//VID_FreeReflib ();
		return false;
	}



	// Init KBD 
	void KBD_Init(void);
	void KBD_Update(void);
	void KBD_Close(void);

	KBD_Init_fp = KBD_Init;
	KBD_Update_fp = KBD_Update;
	KBD_Close_fp = KBD_Close;

	KBD_Init_fp(Do_Key_Event);

	// give up root now
	setreuid(getuid(), getuid());
	setegid(getgid());

	Com_Printf( "------------------------------------\n");
	reflib_active = true;
	return true;
}
示例#10
0
文件: vid_so.c 项目: AJenbo/Quake-2
/*
==============
VID_LoadRefresh
==============
*/
qboolean VID_LoadRefresh( char *name )
{
	refimport_t	ri;
	GetRefAPI_t	GetRefAPI;
	char	fn[MAX_OSPATH];
	char	*path;
	struct stat st;
	extern uid_t saved_euid;
	
	if ( reflib_active )
	{
		if (KBD_Close_fp)
			KBD_Close_fp();
		if (RW_IN_Shutdown_fp)
			RW_IN_Shutdown_fp();
		KBD_Close_fp = NULL;
		RW_IN_Shutdown_fp = NULL;
		re.Shutdown();
		VID_FreeReflib ();
	}

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

	//regain root
	seteuid(saved_euid);

	path = Cvar_Get ("basedir", DEFAULT_BASEDIR, CVAR_NOSET)->string;

	snprintf (fn, MAX_OSPATH, "%s/%s", path, name );
	
	if (stat(fn, &st) == -1) {
		path = Cvar_Get ("libdir", DEFAULT_LIBDIR, CVAR_NOSET)->string;
		snprintf (fn, MAX_OSPATH, "%s/%s", path, name );
		if (stat(fn, &st) == -1) {
			Com_Printf( "LoadLibrary(\"%s\") failed: %s\n", name, strerror(errno));
			return false;
		}
	}
	
	// permission checking
	if (strstr(fn, "softx") == NULL &&
	    strstr(fn, "glx") == NULL &&
	    strstr(fn, "softsdl") == NULL &&
	    strstr(fn, "sdlgl") == NULL) { // softx doesn't require root	
#if 0
		if (st.st_uid != 0) {
			Com_Printf( "LoadLibrary(\"%s\") failed: ref is not owned by root\n", name);
			return false;
		}
		if ((st.st_mode & 0777) & ~0700) {
			Com_Printf( "LoadLibrary(\"%s\") failed: invalid permissions, must be 700 for security considerations\n", name);
			return false;
		}
#endif
	} else {
		// softx requires we give up root now
		setreuid(getuid(), getuid());
		setegid(getgid());
	}

	if ( ( reflib_library = dlopen( fn, RTLD_LAZY ) ) == 0 )
	{
		Com_Printf( "LoadLibrary(\"%s\") failed: %s\n", name , dlerror());
		return false;
	}

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

	ri.Cmd_AddCommand = Cmd_AddCommand;
	ri.Cmd_RemoveCommand = Cmd_RemoveCommand;
	ri.Cmd_Argc = Cmd_Argc;
	ri.Cmd_Argv = Cmd_Argv;
	ri.Cmd_ExecuteText = Cbuf_ExecuteText;
	ri.Con_Printf = VID_Printf;
	ri.Sys_Error = VID_Error;
	ri.FS_LoadFile = FS_LoadFile;
	ri.FS_FreeFile = FS_FreeFile;
	ri.FS_Gamedir = FS_Gamedir;
	ri.Cvar_Get = Cvar_Get;
	ri.Cvar_Set = Cvar_Set;
	ri.Cvar_SetValue = Cvar_SetValue;
	ri.Vid_GetModeInfo = VID_GetModeInfo;
	ri.Vid_MenuInit = VID_MenuInit;
	ri.Vid_NewWindow = VID_NewWindow;

	#ifdef QMAX
	ri.SetParticlePics = SetParticleImages;
	#endif

	if ( ( GetRefAPI = (void *) dlsym( reflib_library, "GetRefAPI" ) ) == 0 )
		Com_Error( ERR_FATAL, "dlsym failed on %s", name );

	re = GetRefAPI( ri );

	if (re.api_version != API_VERSION)
	{
		VID_FreeReflib ();
		Com_Error (ERR_FATAL, "%s has incompatible api_version", name);
	}

	/* Init IN (Mouse) */
	in_state.IN_CenterView_fp = IN_CenterView;
	in_state.Key_Event_fp = Do_Key_Event;
	in_state.viewangles = cl.viewangles;
	in_state.in_strafe_state = &in_strafe.state;
	in_state.in_speed_state = &in_speed.state;

	if ((RW_IN_Init_fp = dlsym(reflib_library, "RW_IN_Init")) == NULL ||
		(RW_IN_Shutdown_fp = dlsym(reflib_library, "RW_IN_Shutdown")) == NULL ||
		(RW_IN_Activate_fp = dlsym(reflib_library, "RW_IN_Activate")) == NULL ||
		(RW_IN_Commands_fp = dlsym(reflib_library, "RW_IN_Commands")) == NULL ||
		(RW_IN_Move_fp = dlsym(reflib_library, "RW_IN_Move")) == NULL ||
		(RW_IN_Frame_fp = dlsym(reflib_library, "RW_IN_Frame")) == NULL)
		Sys_Error("No RW_IN functions in REF.\n");

	/* this one is optional */
	RW_Sys_GetClipboardData_fp = dlsym(reflib_library, "RW_Sys_GetClipboardData");
	
	Real_IN_Init();

	if ( re.Init( 0, 0 ) == -1 )
	{
		re.Shutdown();
		VID_FreeReflib ();
		return false;
	}

	/* Init KBD */
#if 1
	if ((KBD_Init_fp = dlsym(reflib_library, "KBD_Init")) == NULL ||
		(KBD_Update_fp = dlsym(reflib_library, "KBD_Update")) == NULL ||
		(KBD_Close_fp = dlsym(reflib_library, "KBD_Close")) == NULL)
		Sys_Error("No KBD functions in REF.\n");
#else
	{
		void KBD_Init(void);
		void KBD_Update(void);
		void KBD_Close(void);

		KBD_Init_fp = KBD_Init;
		KBD_Update_fp = KBD_Update;
		KBD_Close_fp = KBD_Close;
	}
#endif
	KBD_Init_fp(Do_Key_Event);

	Key_ClearStates();
	
	// give up root now
	setreuid(getuid(), getuid());
	setegid(getgid());

	Com_Printf( "------------------------------------\n");
	reflib_active = true;
	return true;
}