0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 10:12:39 +01:00

ircd::mapi: Add a serial number to deal with removed modules which are still installed.

This commit is contained in:
Jason Volk 2019-04-18 16:54:23 -07:00
parent 61e136f577
commit 1312784518
2 changed files with 24 additions and 1 deletions

View file

@ -30,7 +30,8 @@ namespace ircd::mapi
struct header; struct header;
struct metablock; struct metablock;
using magic_t = uint32_t; 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<string_view, string_view, std::less<>>; using meta_data = std::map<string_view, string_view, std::less<>>;
using init_func = std::function<void ()>; using init_func = std::function<void ()>;
using fini_func = std::function<void ()>; using fini_func = std::function<void ()>;
@ -63,6 +64,17 @@ IRCD_MAPI_VERSION
4 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 /// Module Header
/// ///
/// A static instance of this class must be included in an IRCd module with /// 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 magic_t magic {IRCD_MAPI_MAGIC}; // The magic must match
const version_t version {IRCD_MAPI_VERSION}; // Version indicator 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 const int64_t timestamp {RB_DATECODE}; // Module's compile epoch
std::unique_ptr<metablock> meta; // Non-standard-layout header data std::unique_ptr<metablock> meta; // Non-standard-layout header data
mods::mod *self {nullptr}; // Point to mod instance once loaded mods::mod *self {nullptr}; // Point to mod instance once loaded

View file

@ -192,6 +192,16 @@ try
"Unknown MAPI version [%u] expecting: [%u]", header->version, IRCD_MAPI_VERSION "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. // Tell the module where to find us.
header->self = this; header->self = this;