From 1ecea715fef0a261dca8541a3c22a7ae7ad4e6f5 Mon Sep 17 00:00:00 2001 From: brain Date: Sun, 8 Jan 2006 19:56:50 +0000 Subject: 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 --- src/dynamic.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'src') 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 +#include +#include 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 } -- cgit v1.2.3