From 6d4e17a77c196f6b5ec361d0823d0f09bedf4399 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 25 Jul 2019 21:09:43 -0700 Subject: [PATCH] modules/media: Hold a reference to magick module. --- ircd/m.cc | 2 +- modules/media/media.cc | 69 ++++++++++++++++++++++++-------------- modules/media/media.h | 6 ++++ modules/media/thumbnail.cc | 4 +-- 4 files changed, 52 insertions(+), 29 deletions(-) diff --git a/ircd/m.cc b/ircd/m.cc index 24bd08a7e..34566edc1 100644 --- a/ircd/m.cc +++ b/ircd/m.cc @@ -323,7 +323,7 @@ ircd::m::module_names decltype(ircd::m::module_names_optional) ircd::m::module_names_optional { - "media_magick", + }; /////////////////////////////////////////////////////////////////////////////// diff --git a/modules/media/media.cc b/modules/media/media.cc index bdddee9c0..caac4c1e4 100644 --- a/modules/media/media.cc +++ b/modules/media/media.cc @@ -10,35 +10,52 @@ #include "media.h" -mapi::header +ircd::mapi::header IRCD_MODULE { "11.7 :Content respository", - [] // init - { - static const std::string dbopts; - media = std::make_shared("media", dbopts, media_description); - blocks = db::column{*media, "blocks"}; - - // The conf setter callbacks must be manually executed after - // the database was just loaded to set the cache size. - conf::reset("ircd.media.blocks.cache.size"); - conf::reset("ircd.media.blocks.cache_comp.size"); - - magick_support.reset(new module{"magick"}); - }, - [] // fini - { - magick_support.reset(); - - // The database close contains pthread_join()'s within RocksDB which - // deadlock under certain conditions when called during a dlclose() - // (i.e static destruction of this module). Therefor we must manually - // close the db here first. - media = std::shared_ptr{}; - } + ircd::m::media::init, + ircd::m::media::fini }; +void +ircd::m::media::init() +{ + static const std::string dbopts; + ::media = std::make_shared("media", dbopts, media_description); + ::blocks = db::column{*::media, "blocks"}; + + // The conf setter callbacks must be manually executed after + // the database was just loaded to set the cache size. + conf::reset("ircd.media.blocks.cache.size"); + conf::reset("ircd.media.blocks.cache_comp.size"); + + try + { + ::magick_support.reset(new module{"magick"}); + } + catch(std::exception &e) + { + log::warning + { + media_log, "Failed to load GraphicsMagick support :%s", + e.what() + }; + } +} + +void +ircd::m::media::fini() +{ + ::magick_support.reset(); + + // The database close contains pthread_join()'s within RocksDB which + // deadlock under certain conditions when called during a dlclose() + // (i.e static destruction of this module). Therefor we must manually + // close the db here first. + ::media = std::shared_ptr{}; +} + decltype(media_log) media_log { @@ -149,8 +166,8 @@ media; decltype(blocks) blocks; -decltype(magick) -magick; +decltype(magick_support) +magick_support; std::set downloading; diff --git a/modules/media/media.h b/modules/media/media.h index 7a0163442..ac0771bfb 100644 --- a/modules/media/media.h +++ b/modules/media/media.h @@ -8,6 +8,12 @@ // copyright notice and this permission notice is present in all copies. The // full license for this software is available in the LICENSE file. +namespace ircd::m::media +{ + void init(); + void fini(); +} + using namespace ircd; extern mapi::header IRCD_MODULE; diff --git a/modules/media/thumbnail.cc b/modules/media/thumbnail.cc index bdcf52b1a..89c601f12 100644 --- a/modules/media/thumbnail.cc +++ b/modules/media/thumbnail.cc @@ -252,9 +252,9 @@ get__thumbnail_local(client &client, copied }; - static const bool available + const bool available { - mods::loaded("media_magick") + magick_support }; const auto mime_type