diff options
-rw-r--r-- | include/dynamic.h | 2 | ||||
-rw-r--r-- | src/dynamic.cpp | 32 |
2 files changed, 19 insertions, 15 deletions
diff --git a/include/dynamic.h b/include/dynamic.h index 10b87b40c..ee43d1712 100644 --- a/include/dynamic.h +++ b/include/dynamic.h @@ -35,7 +35,7 @@ class DLLManager bool GetSymbol( void **, char *sym_name ); #endif - char *LastError() + char* LastError() { return err; } diff --git a/src/dynamic.cpp b/src/dynamic.cpp index d9ace43e0..0e207dbd9 100644 --- a/src/dynamic.cpp +++ b/src/dynamic.cpp @@ -37,6 +37,8 @@ extern ServerConfig* Config; DLLManager::DLLManager(char *fname) { + err = NULL; + if (!strstr(fname,".so")) { err = "This doesn't look like a module file to me..."; @@ -58,17 +60,6 @@ DLLManager::DLLManager(char *fname) } err = "Module is not statically compiled into the ircd"; #else -#ifdef IS_CYGWIN - // Cygwin behaviour is handled slightly differently - // With the advent of dynamic modules. Because Windows - // wont let you overwrite a file which is currently in - // Use, we can safely attempt to load the module from its - // Current location :) - - h = dlopen(fname, RTLD_NOW ); - err = (char*)dlerror(); - -#else // Copy the library to a temp location, this makes recompiles // a little safer if the ircd is running at the time as the // shared libraries are mmap()ed and not doing this causes @@ -83,23 +74,36 @@ DLLManager::DLLManager(char *fname) char buffer[65536]; snprintf(tmpfile_template, 255, "%s/inspircd_file.so.%d.XXXXXXXXXX",Config->TempDir,getpid()); int fd = mkstemp(tmpfile_template); + if (fd == -1) + { + fclose(x); + err = strerror(errno); + return; + } while (!feof(x)) { int n = fread(buffer, 1, 65535, x); if (n) - write(fd,buffer,n); + { + int written = write(fd,buffer,n); + if (written != n) + { + fclose(x); + err = strerror(errno); + return; + } + } } - // Try to open the library now and get any error message. h = dlopen(tmpfile_template, RTLD_NOW ); err = (char*)dlerror(); close(fd); + fclose(x); // We can delete the tempfile once it's loaded, leaving just the inode. if (!Config->debugging) unlink(tmpfile_template); #endif -#endif } DLLManager::~DLLManager() |