aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar brain2006-08-07 16:58:27 +0000
committerGravatar brain2006-08-07 16:58:27 +0000
commit6fa35bdb1814ef4eab42d050e283d05910dbf3d2 (patch)
tree439a3320a16da15085593fa7b254835bef8c88a3
parentExtra debug all over the place, which maybe we should keep (diff)
Better checks for running out of disk space, inability to write to tmp dir, etc
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4768 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/dynamic.h2
-rw-r--r--src/dynamic.cpp32
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()