From 131278451859defb85265ef26fcfe9073d55c20e Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 18 Apr 2019 16:54:23 -0700 Subject: [PATCH] ircd::mapi: Add a serial number to deal with removed modules which are still installed. --- include/ircd/mods/mapi.h | 15 ++++++++++++++- ircd/mods.cc | 10 ++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/include/ircd/mods/mapi.h b/include/ircd/mods/mapi.h index 75129bd2d..c28b5ea3d 100644 --- a/include/ircd/mods/mapi.h +++ b/include/ircd/mods/mapi.h @@ -30,7 +30,8 @@ namespace ircd::mapi struct header; struct metablock; using magic_t = uint32_t; - using version_t = uint32_t; + using version_t = uint16_t; + using serial_t = uint16_t; using meta_data = std::map>; using init_func = std::function; using fini_func = std::function; @@ -63,6 +64,17 @@ IRCD_MAPI_VERSION 4 }; +/// The serial number recorded by the module header. We increment this number +/// after removing a module from the project because that module will still +/// remain in the user's install directory. The removed module's serial nr +/// will not be incremented anymore; libircd can ignore modules with serial +/// numbers < this value. +constexpr const ircd::mapi::serial_t +IRCD_MAPI_SERIAL +{ + 1 +}; + /// Module Header /// /// A static instance of this class must be included in an IRCd module with @@ -74,6 +86,7 @@ struct ircd::mapi::header { const magic_t magic {IRCD_MAPI_MAGIC}; // The magic must match const version_t version {IRCD_MAPI_VERSION}; // Version indicator + const serial_t serial {IRCD_MAPI_SERIAL}; // Serial indicator const int64_t timestamp {RB_DATECODE}; // Module's compile epoch std::unique_ptr meta; // Non-standard-layout header data mods::mod *self {nullptr}; // Point to mod instance once loaded diff --git a/ircd/mods.cc b/ircd/mods.cc index 54d350ec8..369d31101 100644 --- a/ircd/mods.cc +++ b/ircd/mods.cc @@ -192,6 +192,16 @@ try "Unknown MAPI version [%u] expecting: [%u]", header->version, IRCD_MAPI_VERSION }; + if(header->serial < IRCD_MAPI_SERIAL) + throw error + { + "Module '%s' serial=%u is expired; expecting serial >= %u. This module was probably removed" + " from the project and you should delete it from the installation directory.", + name(), + header->serial, + IRCD_MAPI_SERIAL + }; + // Tell the module where to find us. header->self = this;