There are some up-front checks in DaemonServer
but it shouldn't assume that its checks are
necessarily going to match the choices about
how ActivePyModules composes its ::modules member,
so let's have some extra checks to avoid
risk of crashing mgr on commands sent to
unhealthy/unloaded modules.
Signed-off-by: John Spray <john.spray@redhat.com>
assert(ss != nullptr);
assert(ds != nullptr);
+ if (pClassInstance == nullptr) {
+ // Not the friendliest error string, but we could only
+ // hit this in quite niche cases, if at all.
+ *ss << "Module not instantiated";
+ return -EINVAL;
+ }
+
Gil gil(py_module->pMyThreadState, true);
PyFormatter f;
std::stringstream *ss)
{
lock.Lock();
- auto mod = modules.at(module_name).get();
+ auto mod_iter = modules.find(module_name);
+ if (mod_iter == modules.end()) {
+ *ss << "Module '" << module_name << "' is not available";
+ return -ENOENT;
+ }
+
lock.Unlock();
- return mod->handle_command(cmdmap, ds, ss);
+ return mod_iter->second->handle_command(cmdmap, ds, ss);
}
void ActivePyModules::get_health_checks(health_check_map_t *checks)