#include "../lib/irc_string.h"
#include "../lib/splitline.h"
#include "../lib/strlfunc.h"
+#include "../lib/valgrind.h"
#include "config.h"
#include "error.h"
#include <stdio.h>
#define DEPFILE "modules.dep"
-#define MAXMODULES 100
+#define MAXMODULES 200
/* Module dependency stuff.
*
Error("core",ERR_ERROR,
"Too many modules in dependency file; rebuild with higher MAXMODULES. Module dependencies disabled.\n");
clearmoduledeps();
+ fclose(fp);
return;
}
Error("core",ERR_WARNING,"Couldn't find parent module %s of %s. Module dependencies disabled.",
largv[i+1],largv[0]);
clearmoduledeps();
+ fclose(fp);
return;
}
mdp->parents[i]->numchildren++; /* break the bad news */
}
}
+
+ fclose(fp);
/* Second pass */
for (i=0;i<knownmodules;i++) {
}
-int rmmod(char *modulename) {
+int rmmod(char *modulename, int close) {
int i,j;
module *mods;
struct module_dep *mdp;
if ((mdp=getmoduledep(modulebuf))) {
for (j=0;j<mdp->numchildren;j++) {
if (isloaded(mdp->children[j]->name->content)) {
- if (rmmod(mdp->children[j]->name->content)) {
+ if (rmmod(mdp->children[j]->name->content, close)) {
Error("core",ERR_WARNING,"Unable to remove child module %s (depends on %s)",
mdp->children[j]->name->content, modulebuf);
return 1;
mods=(module *)(modules.content);
+ if (!close
#ifdef BROKEN_DLCLOSE
- {
+ || 1
+#endif
+ ) {
void (*fini)();
fini = dlsym(mods[i].handle, "__fini");
if(!dlerror())
fini();
- }
-#endif
+ } else
+ dlclose(mods[i].handle);
- dlclose(mods[i].handle);
freesstring(mods[i].name);
array_delslot(&modules,i);
return;
preparereload(safereload_str->content);
- rmmod(safereload_str->content);
+ rmmod(safereload_str->content, 1);
insmod(safereload_str->content);
reloadmarked();
mods=(module *)(modules.content);
strlcpy(buf, mods[0].name->content, sizeof(buf));
- rmmod(buf);
+
+ /* Unload the module unless we're running on Valgrind -
+ * in which case unloading the module would invalidate
+ * stacktraces Valgrind has captured so far. */
+ rmmod(buf, !RUNNING_ON_VALGRIND);
}
clearmoduledeps();