From 2d89b583e95aa528a990f012b5b6dbc58c2e703e Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 25 Oct 2016 23:16:33 -0700 Subject: [PATCH] ircd::mods: Throw filesystem_error when requesting symbols on bad path. --- ircd/modules.cc | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/ircd/modules.cc b/ircd/modules.cc index 4db90305f..9ada5740e 100644 --- a/ircd/modules.cc +++ b/ircd/modules.cc @@ -81,6 +81,7 @@ filesystem::path prefix_if_relative(const filesystem::path &path); filesystem::path postfixed(const filesystem::path &path); std::string postfixed(const std::string &name); +template R info(const filesystem::path &, F&& closure); std::vector sections(const filesystem::path &path); std::vector symbols(const filesystem::path &path); std::vector symbols(const filesystem::path &path, const std::string §ion); @@ -537,23 +538,50 @@ ircd::mods::symbols(const std::string &fullpath, std::vector ircd::mods::sections(const filesystem::path &path) { - boost::dll::library_info info(path); - return info.sections(); + return info>(path, [] + (boost::dll::library_info &info) + { + return info.sections(); + }); } std::vector ircd::mods::symbols(const filesystem::path &path) { - boost::dll::library_info info(path); - return info.symbols(); + return info>(path, [] + (boost::dll::library_info &info) + { + return info.symbols(); + }); } std::vector ircd::mods::symbols(const filesystem::path &path, const std::string §ion) { + return info>(path, [§ion] + (boost::dll::library_info &info) + { + return info.symbols(section); + }); +} + +template +R +ircd::mods::info(const filesystem::path &path, + F&& closure) +{ + if(!exists(path)) + throw filesystem_error("`%s' does not exist", + path.string().c_str()); + + if(!is_regular_file(path)) + throw filesystem_error("`%s' is not a file", + path.string().c_str()); + boost::dll::library_info info(path); - return info.symbols(section); + return closure(info); } void