diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-01-08 19:56:50 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-01-08 19:56:50 +0000 |
commit | 1ecea715fef0a261dca8541a3c22a7ae7ad4e6f5 (patch) | |
tree | 9ce88c042ac607de498b7bcead1dee61305fe8a8 /src | |
parent | d2c3c6f91c8738c3a0e2aefff7491b007842bab8 (diff) |
Used mkstemp trick similar to anope and unreal which copies the .so's to temp names under /tmp before loading them, using the current process's PID.
This allows for module developers to *safely* rebuild a module (NOT the core) without a segfault while the ircd is up.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2740 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r-- | src/dynamic.cpp | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/dynamic.cpp b/src/dynamic.cpp index 1def9b582..e1471a40a 100644 --- a/src/dynamic.cpp +++ b/src/dynamic.cpp @@ -28,6 +28,9 @@ using namespace std; #include "inspstring.h" #include "helperfuncs.h" +#include <unistd.h> +#include <sys/types.h> +#include <stdio.h> DLLManager::DLLManager(char *fname) { @@ -47,10 +50,27 @@ DLLManager::DLLManager(char *fname) } err = "Module is not statically compiled into the ircd"; #else - // Try to open the library now and get any error message. + // 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 + // segfaults. + FILE* x = fopen(fname,"rb"); + char tmpfile_template[255]; + char buffer[65536]; + snprintf(tmpfile_template, 255, "/tmp/inspircd_file.so.%d.XXXXXXXXXX",getpid()); + int fd = mkstemp(tmpfile_template); + while (!feof(x)) + { + int n = fread(buffer, 1, 65535, x); + if (n) + write(fd,buffer,n); + } + + // Try to open the library now and get any error message. - h = dlopen( fname, RTLD_NOW ); + h = dlopen(tmpfile_template, RTLD_NOW ); err = (char*)dlerror(); + close(fd); #endif } |