--- a/src/irc_log.c Wed Apr 01 19:31:11 2009 +0300
+++ b/src/irc_log.c Thu Apr 02 02:25:35 2009 +0300
@@ -27,6 +27,9 @@
/** Are we currently unloading ourself (via irc_log_unload) ? */
bool unloading;
+
+ /** The `struct module` passed to us once we unload() */
+ struct module *module;
};
/**
@@ -53,22 +56,13 @@
/**
* The irc_log_ctx has completed stopping all the channels, and should now destroy itself
- *
*/
static void irc_log_stopped (struct irc_log_ctx *ctx)
{
- log_debug("destroying the irc_log_ctx");
-
- // schedule an evsql_destroy
- if (evsql_destroy_next(ctx->db))
- log_fatal("evsql_destroy_next failed");
+ log_debug("module unload() completed");
- // hands-off on the db
- ctx->db = NULL;
-
- // free ourself
- // XXX: wrong, we need to implement a irc_log_destroy that's called by module?
- free(ctx);
+ // notify
+ module_unloaded(ctx->module);
}
/**
@@ -478,13 +472,14 @@
/**
* Deinitialize, logging CLOSE events for all channels, and removing any hooks we've added
*/
-static err_t irc_log_unload (void *_ctx)
+static err_t irc_log_unload (void *_ctx, struct module *module)
{
struct irc_log_ctx *ctx = _ctx;
struct irc_log_chan *chan_ctx;
// update our state to mark ourselves as unloading
ctx->unloading = true;
+ ctx->module = module;
// stop logging each channel
TAILQ_FOREACH(chan_ctx, &ctx->channels, ctx_channels) {
@@ -496,11 +491,28 @@
}
/**
+ * We can safely destroy the evsql instance from here, since we're outside of any callbacks from this module
+ */
+static void irc_log_destroy (void *_ctx)
+{
+ struct irc_log_ctx *ctx = _ctx;
+
+ log_debug("destroying the irc_log_ctx");
+
+ // destroy the evsql instance
+ evsql_destroy(ctx->db);
+
+ // ...no more
+ free(ctx);
+}
+
+/**
* The module function table
*/
struct module_desc irc_log_module = {
.init = &irc_log_init,
.config_options = irc_log_config_options,
.unload = &irc_log_unload,
+ .destroy = &irc_log_destroy
};