summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Nazarov <skuller@skuller.net>2012-11-12 18:21:01 +0400
committerAndrey Nazarov <skuller@skuller.net>2012-11-12 18:21:01 +0400
commit9062683d6483ecfc33b0ba8082fd52b1dca6d1a3 (patch)
treef27ca70ee9321a31e0ea24adb74f20f84c92dbc5
parent681f6dc2a30d7d24d7f9c40e5b4a6e2cd5b97c78 (diff)
Be more verbose about game library loading.
Print complete error message if Sys_LoadLibrary fails. Also print where the server attempts to load game library from.
-rw-r--r--src/server/game.c34
-rw-r--r--src/unix/system.c8
-rw-r--r--src/windows/system.c16
3 files changed, 34 insertions, 24 deletions
diff --git a/src/server/game.c b/src/server/game.c
index 017c61f..17430fa 100644
--- a/src/server/game.c
+++ b/src/server/game.c
@@ -780,6 +780,19 @@ void SV_ShutdownGameProgs(void)
Cvar_Set("g_features", "0");
}
+static void *_SV_LoadGameLibrary(const char *path)
+{
+ void *entry;
+
+ entry = Sys_LoadLibrary(path, "GetGameAPI", &game_library);
+ if (!entry)
+ Com_EPrintf("Failed to load game library: %s\n", Com_GetLastError());
+ else
+ Com_Printf("Loaded game library from %s\n", path);
+
+ return entry;
+}
+
static void *SV_LoadGameLibrary(const char *game, const char *prefix)
{
char path[MAX_OSPATH];
@@ -788,11 +801,18 @@ static void *SV_LoadGameLibrary(const char *game, const char *prefix)
len = Q_concat(path, sizeof(path), sys_libdir->string,
PATH_SEP_STRING, game, PATH_SEP_STRING,
prefix, "game" CPUSTRING LIBSUFFIX, NULL);
- if (len < sizeof(path))
- return Sys_LoadLibrary(path, "GetGameAPI", &game_library);
+ if (len >= sizeof(path)) {
+ Com_EPrintf("Game library path length exceeded\n");
+ return NULL;
+ }
+
+ if (os_access(path, F_OK)) {
+ if (!*prefix)
+ Com_Printf("Can't access %s: %s\n", path, strerror(errno));
+ return NULL;
+ }
- Com_WPrintf("Game library path length exceeded\n");
- return NULL;
+ return _SV_LoadGameLibrary(path);
}
/*
@@ -811,10 +831,8 @@ void SV_InitGameProgs(void)
SV_ShutdownGameProgs();
// for debugging or `proxy' mods
- if (sys_forcegamelib->string[0]) {
- entry = Sys_LoadLibrary(sys_forcegamelib->string,
- "GetGameAPI", &game_library);
- }
+ if (sys_forcegamelib->string[0])
+ entry = _SV_LoadGameLibrary(sys_forcegamelib->string);
// try game first
if (!entry && fs_game->string[0]) {
diff --git a/src/unix/system.c b/src/unix/system.c
index 574ac0f..77601cb 100644
--- a/src/unix/system.c
+++ b/src/unix/system.c
@@ -278,14 +278,15 @@ void *Sys_LoadLibrary(const char *path, const char *sym, void **handle)
module = dlopen(path, RTLD_LAZY);
if (!module) {
- Com_DPrintf("%s failed: %s\n", __func__, dlerror());
+ Com_SetLastError(dlerror());
return NULL;
}
if (sym) {
+ dlerror();
entry = dlsym(module, sym);
if (!entry) {
- Com_DPrintf("%s failed: %s\n", __func__, dlerror());
+ Com_SetLastError(dlerror());
dlclose(module);
return NULL;
}
@@ -293,10 +294,7 @@ void *Sys_LoadLibrary(const char *path, const char *sym, void **handle)
entry = NULL;
}
- Com_DPrintf("%s succeeded: %s\n", __func__, path);
-
*handle = module;
-
return entry;
}
diff --git a/src/windows/system.c b/src/windows/system.c
index ca3ada7..fa8a158 100644
--- a/src/windows/system.c
+++ b/src/windows/system.c
@@ -746,10 +746,7 @@ DLL LOADING
void Sys_FreeLibrary(void *handle)
{
- if (!handle) {
- return;
- }
- if (!FreeLibrary(handle)) {
+ if (handle && !FreeLibrary(handle)) {
Com_Error(ERR_FATAL, "FreeLibrary failed on %p", handle);
}
}
@@ -763,16 +760,16 @@ void *Sys_LoadLibrary(const char *path, const char *sym, void **handle)
module = LoadLibraryA(path);
if (!module) {
- Com_DPrintf("%s failed: LoadLibrary returned %lu on %s\n",
- __func__, GetLastError(), path);
+ Com_SetLastError(va("%s: LoadLibrary failed with error %lu\n",
+ path, GetLastError()));
return NULL;
}
if (sym) {
entry = GetProcAddress(module, sym);
if (!entry) {
- Com_DPrintf("%s failed: GetProcAddress returned %lu on %s\n",
- __func__, GetLastError(), path);
+ Com_SetLastError(va("%s: GetProcAddress failed with error %lu\n",
+ path, GetLastError()));
FreeLibrary(module);
return NULL;
}
@@ -781,9 +778,6 @@ void *Sys_LoadLibrary(const char *path, const char *sym, void **handle)
}
*handle = module;
-
- Com_DPrintf("%s succeeded: %s\n", __func__, path);
-
return entry;
}