diff options
Diffstat (limited to 'src/Daemon')
| -rw-r--r-- | src/Daemon/CommLayerServerDBus.cpp | 14 | ||||
| -rw-r--r-- | src/Daemon/CrashWatcher.cpp | 12 | ||||
| -rw-r--r-- | src/Daemon/Daemon.cpp | 36 | ||||
| -rw-r--r-- | src/Daemon/MiddleWare.cpp | 45 | ||||
| -rw-r--r-- | src/Daemon/PluginManager.cpp | 282 | ||||
| -rw-r--r-- | src/Daemon/PluginManager.h | 31 | ||||
| -rw-r--r-- | src/Daemon/RPM.cpp | 4 | ||||
| -rw-r--r-- | src/Daemon/Settings.cpp | 7 | ||||
| -rw-r--r-- | src/Daemon/Settings.h | 1 | ||||
| -rwxr-xr-x | src/Daemon/abrt-debuginfo-install | 6 | ||||
| -rw-r--r-- | src/Daemon/abrt.conf | 6 | ||||
| -rw-r--r-- | src/Daemon/abrt.conf.5 | 4 |
12 files changed, 225 insertions, 223 deletions
diff --git a/src/Daemon/CommLayerServerDBus.cpp b/src/Daemon/CommLayerServerDBus.cpp index 9222c59..db0d2f5 100644 --- a/src/Daemon/CommLayerServerDBus.cpp +++ b/src/Daemon/CommLayerServerDBus.cpp @@ -325,11 +325,9 @@ static int handle_DeleteDebugDump(DBusMessage* call, DBusMessage* reply) static int handle_GetPluginsInfo(DBusMessage* call, DBusMessage* reply) { - vector_map_string_t plugins_info = g_pPluginManager->GetPluginsInfo(); - DBusMessageIter out_iter; dbus_message_iter_init_append(reply, &out_iter); - store_val(&out_iter, plugins_info); + store_val(&out_iter, g_pPluginManager->GetPluginsInfo()); send_flush_and_unref(reply); return 0; @@ -348,9 +346,9 @@ static int handle_GetPluginSettings(DBusMessage* call, DBusMessage* reply) return -1; } - long unix_uid = get_remote_uid(call); - VERB1 log("got %s('%s') call from uid %ld", "GetPluginSettings", PluginName, unix_uid); - map_plugin_settings_t plugin_settings = g_pPluginManager->GetPluginSettings(PluginName, to_string(unix_uid).c_str()); + //long unix_uid = get_remote_uid(call); + //VERB1 log("got %s('%s') call from uid %ld", "GetPluginSettings", PluginName, unix_uid); + map_plugin_settings_t plugin_settings = g_pPluginManager->GetPluginSettings(PluginName); //, to_string(unix_uid).c_str()); DBusMessageIter out_iter; dbus_message_iter_init_append(reply, &out_iter); @@ -393,6 +391,7 @@ static int handle_SetPluginSettings(DBusMessage* call, DBusMessage* reply) return 0; } +#ifdef PLUGIN_DYNAMIC_LOAD_UNLOAD static int handle_RegisterPlugin(DBusMessage* call, DBusMessage* reply) { int r; @@ -432,6 +431,7 @@ static int handle_UnRegisterPlugin(DBusMessage* call, DBusMessage* reply) send_flush_and_unref(reply); return 0; } +#endif static int handle_GetSettings(DBusMessage* call, DBusMessage* reply) { @@ -496,10 +496,12 @@ static DBusHandlerResult message_received(DBusConnection* conn, DBusMessage* msg r = handle_GetPluginSettings(msg, reply); else if (strcmp(member, "SetPluginSettings") == 0) r = handle_SetPluginSettings(msg, reply); +#ifdef PLUGIN_DYNAMIC_LOAD_UNLOAD else if (strcmp(member, "RegisterPlugin") == 0) r = handle_RegisterPlugin(msg, reply); else if (strcmp(member, "UnRegisterPlugin") == 0) r = handle_UnRegisterPlugin(msg, reply); +#endif else if (strcmp(member, "GetSettings") == 0) r = handle_GetSettings(msg, reply); else if (strcmp(member, "SetSettings") == 0) diff --git a/src/Daemon/CrashWatcher.cpp b/src/Daemon/CrashWatcher.cpp index 88c058b..59f9e65 100644 --- a/src/Daemon/CrashWatcher.cpp +++ b/src/Daemon/CrashWatcher.cpp @@ -168,12 +168,11 @@ int CreateReportThread(const char* pUUID, const char* pUID, int force, const cha thread_data->force = force; thread_data->peer = xstrdup(pSender); -//TODO: do we need this? -//pthread_attr_t attr; -//pthread_attr_init(&attr); -//pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - - int r = pthread_create(&thread_data->thread_id, NULL, create_report, thread_data); + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + int r = pthread_create(&thread_data->thread_id, &attr, create_report, thread_data); + pthread_attr_destroy(&attr); if (r != 0) { free(thread_data->UUID); @@ -187,7 +186,6 @@ int CreateReportThread(const char* pUUID, const char* pUID, int force, const cha return r; } VERB3 log("Thread %llx created", (unsigned long long)thread_data->thread_id); -//pthread_attr_destroy(&attr); return r; } diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index 1a6cadf..a2970af 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -65,7 +65,8 @@ * Returns report_status_t (map_vector_string_t) - the status of each call. * 2nd parameter is the contents of user's abrt.conf. * - DeleteDebugDump(UUID): delete it from DB and delete corresponding /var/cache/abrt/DIR - * - GetPluginsInfo(): returns vector_map_string_t + * - GetPluginsInfo(): returns map_map_string_t + * map["plugin"] = { "Name": "plugin", "Enabled": "yes" ... } * - GetPluginSettings(PluginName): returns map_plugin_settings_t (map_string_t) * - SetPluginSettings(PluginName, map_plugin_settings_t): returns void * - RegisterPlugin(PluginName): returns void @@ -173,13 +174,6 @@ static int SetUpMW() { g_setBlackList.insert(*it_b); } - VERB1 log("Registering plugins"); - set_string_t::iterator it_p = g_settings_setEnabledPlugins.begin(); - for (; it_p != g_settings_setEnabledPlugins.end(); it_p++) - { - if (g_pPluginManager->RegisterPlugin(it_p->c_str()) != 0) - return -1; - } VERB1 log("Adding actions or reporters"); vector_pair_string_string_t::iterator it_ar = g_settings_vectorActionsAndReporters.begin(); for (; it_ar != g_settings_vectorActionsAndReporters.end(); it_ar++) @@ -210,10 +204,12 @@ static int SetUpCron() int nM = -1; int nS = -1; +//TODO: rewrite using good old sscanf? + if (pos != std::string::npos) { - std::string sH = ""; - std::string sM = ""; + std::string sH; + std::string sM; sH = it_c->first.substr(0, pos); nH = xatou(sH.c_str()); @@ -228,7 +224,7 @@ static int SetUpCron() } else { - std::string sS = ""; + std::string sS; sS = it_c->first; nS = xatou(sS.c_str()); @@ -368,8 +364,8 @@ static int CreatePidFile() if (fd >= 0) { /* write our pid to it */ - char buf[sizeof(int)*3 + 2]; - int len = sprintf(buf, "%u\n", (unsigned)getpid()); + char buf[sizeof(long)*3 + 2]; + int len = sprintf(buf, "%lu\n", (long)getpid()); write(fd, buf, len); close(fd); return 0; @@ -637,7 +633,7 @@ static void start_syslog_logging() logmode = LOGMODE_SYSLOG; } -static void ensure_writable_dir(const char *dir, mode_t mode, const char *group) +static void ensure_writable_dir(const char *dir, mode_t mode, const char *user) { struct stat sb; @@ -646,12 +642,12 @@ static void ensure_writable_dir(const char *dir, mode_t mode, const char *group) if (stat(dir, &sb) != 0 || !S_ISDIR(sb.st_mode)) error_msg_and_die("'%s' is not a directory", dir); - struct group *gr = getgrnam(group); - if (!gr) - perror_msg_and_die("Can't find group '%s'", group); + struct passwd *pw = getpwnam(user); + if (!pw) + perror_msg_and_die("Can't find user '%s'", user); - if ((sb.st_uid != 0 || sb.st_gid != gr->gr_gid) && chown(dir, 0, gr->gr_gid) != 0) - perror_msg_and_die("Can't set owner 0:%u on '%s'", (unsigned int)gr->gr_gid, dir); + if ((sb.st_uid != pw->pw_uid || sb.st_gid != pw->pw_gid) && chown(dir, pw->pw_uid, pw->pw_gid) != 0) + perror_msg_and_die("Can't set owner %u:%u on '%s'", (unsigned int)pw->pw_uid, (unsigned int)pw->pw_gid, dir); if ((sb.st_mode & 07777) != mode && chmod(dir, mode) != 0) perror_msg_and_die("Can't set mode %o on '%s'", mode, dir); } @@ -662,7 +658,7 @@ static void sanitize_dump_dir_rights() * us with thousands of bogus or malicious dumps */ /* 07000 bits are setuid, setgit, and sticky, and they must be unset */ /* 00777 bits are usual "rwxrwxrwx" access rights */ - ensure_writable_dir(DEBUG_DUMPS_DIR, 0775, "abrt"); + ensure_writable_dir(DEBUG_DUMPS_DIR, 0755, "abrt"); /* debuginfo cache */ ensure_writable_dir(DEBUG_DUMPS_DIR"-di", 0755, "root"); /* temp dir */ diff --git a/src/Daemon/MiddleWare.cpp b/src/Daemon/MiddleWare.cpp index 25fe253..70527eb 100644 --- a/src/Daemon/MiddleWare.cpp +++ b/src/Daemon/MiddleWare.cpp @@ -204,7 +204,11 @@ static void DebugDumpToCrashReport(const char *pDebugDumpDir, map_crash_report_t static std::string GetLocalUUID(const char *pAnalyzer, const char *pDebugDumpDir) { CAnalyzer* analyzer = g_pPluginManager->GetAnalyzer(pAnalyzer); - return analyzer->GetLocalUUID(pDebugDumpDir); + if (analyzer) + { + return analyzer->GetLocalUUID(pDebugDumpDir); + } + throw CABRTException(EXCEP_PLUGIN, "Error running '%s'", pAnalyzer); } /** @@ -217,7 +221,11 @@ static std::string GetGlobalUUID(const char *pAnalyzer, const char *pDebugDumpDir) { CAnalyzer* analyzer = g_pPluginManager->GetAnalyzer(pAnalyzer); - return analyzer->GetGlobalUUID(pDebugDumpDir); + if (analyzer) + { + return analyzer->GetGlobalUUID(pDebugDumpDir); + } + throw CABRTException(EXCEP_PLUGIN, "Error running '%s'", pAnalyzer); } /** @@ -232,7 +240,11 @@ static void CreateReport(const char *pAnalyzer, int force) { CAnalyzer* analyzer = g_pPluginManager->GetAnalyzer(pAnalyzer); - analyzer->CreateReport(pDebugDumpDir, force); + if (analyzer) + { + analyzer->CreateReport(pDebugDumpDir, force); + } + /* else: GetAnalyzer() already complained, no need to handle it here */ } mw_result_t CreateCrashReport(const char *pUUID, @@ -320,9 +332,14 @@ void RunAction(const char *pActionDir, const char *pPluginName, const char *pPluginArgs) { + CAction* action = g_pPluginManager->GetAction(pPluginName); + if (!action) + { + /* GetAction() already complained */ + return; + } try { - CAction* action = g_pPluginManager->GetAction(pPluginName); action->Run(pActionDir, pPluginArgs); } catch (CABRTException& e) @@ -500,7 +517,9 @@ report_status_t Report(const map_crash_report_t& pCrashReport, #endif ret[plugin_name].push_back("1"); // REPORT_STATUS_IDX_FLAG ret[plugin_name].push_back(res); // REPORT_STATUS_IDX_MSG - message += res + "\n"; + if (message != "") + message += "; "; + message += res; } } catch (CABRTException& e) @@ -531,6 +550,8 @@ report_status_t Report(const map_crash_report_t& pCrashReport, static bool IsDebugDumpSaved(const char *pUID, const char *pDebugDumpDir) { + /* TODO: use database query instead of dumping all rows and searching in them */ + CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase.c_str()); database->Connect(); vector_database_rows_t rows = database->GetUIDData(pUID); @@ -770,13 +791,17 @@ static void RunAnalyzerActions(const char *pAnalyzer, const char *pDebugDumpDir) for (; it_a != analyzer->second.end(); it_a++) { const char *plugin_name = it_a->first.c_str(); + CAction* action = g_pPluginManager->GetAction(plugin_name, /*silent:*/ true); + if (!action) + { + /* GetAction() already complained if no such plugin. + * If plugin exists but isn't an Action, it's not an error. + */ + continue; + } try { - if (g_pPluginManager->GetPluginType(plugin_name) == ACTION) - { - CAction* action = g_pPluginManager->GetAction(plugin_name); - action->Run(pDebugDumpDir, it_a->second.c_str()); - } + action->Run(pDebugDumpDir, it_a->second.c_str()); } catch (CABRTException& e) { diff --git a/src/Daemon/PluginManager.cpp b/src/Daemon/PluginManager.cpp index 663228b..c552880 100644 --- a/src/Daemon/PluginManager.cpp +++ b/src/Daemon/PluginManager.cpp @@ -27,6 +27,8 @@ #include "Polkit.h" #include "PluginManager.h" +using namespace std; + /** * Text representation of plugin types. */ @@ -40,12 +42,12 @@ static const char *const plugin_type_str[] = { bool LoadPluginSettings(const char *pPath, map_plugin_settings_t& pSettings) { - std::ifstream fIn; + ifstream fIn; fIn.open(pPath); if (!fIn.is_open()) return false; - std::string line; + string line; while (!fIn.eof()) { getline(fIn, line); @@ -54,8 +56,8 @@ bool LoadPluginSettings(const char *pPath, map_plugin_settings_t& pSettings) bool is_value = false; bool valid = false; bool in_quote = false; - std::string key; - std::string value; + string key; + string value; for (ii = 0; ii < line.length(); ii++) { if (line[ii] == '"') @@ -138,7 +140,9 @@ void CPluginManager::LoadPlugins() if (!ext || strcmp(ext + 1, PLUGINS_LIB_EXTENSION) != 0) continue; *ext = '\0'; - LoadPlugin(dent->d_name + sizeof(PLUGINS_LIB_PREFIX)-1); + if (strncmp(dent->d_name, PLUGINS_LIB_PREFIX, sizeof(PLUGINS_LIB_PREFIX)-1) != 0) + continue; + LoadPlugin(dent->d_name + sizeof(PLUGINS_LIB_PREFIX)-1, /*enabled_only:*/ true); } closedir(dir); } @@ -153,16 +157,51 @@ void CPluginManager::UnLoadPlugins() } } -void CPluginManager::LoadPlugin(const char *pName) +CPlugin* CPluginManager::LoadPlugin(const char *pName, bool enabled_only) { - if (m_mapLoadedModules.find(pName) != m_mapLoadedModules.end()) + map_string_t plugin_info; + + plugin_info["Name"] = pName; + + map_plugin_t::iterator it_plugin = m_mapPlugins.find(pName); + if (it_plugin != m_mapPlugins.end()) { - return; + return it_plugin->second; /* ok */ } - std::string libPath = ssprintf(PLUGINS_LIB_DIR"/"PLUGINS_LIB_PREFIX"%s."PLUGINS_LIB_EXTENSION, pName); - CLoadedModule* module = new CLoadedModule(libPath.c_str()); + const char *conf_name = pName; + if (strncmp(pName, "Kerneloops", sizeof("Kerneloops")-1) == 0) + { + /* Kerneloops{,Scanner,Reporter} share the same .conf file */ + conf_name = "Kerneloops"; + } + map_plugin_settings_t pluginSettings; + string conf_fullname = ssprintf(PLUGINS_CONF_DIR"/%s."PLUGINS_CONF_EXTENSION, conf_name); + LoadPluginSettings(conf_fullname.c_str(), pluginSettings); + m_map_plugin_settings[pName] = pluginSettings; + VERB3 log("Loaded %s.conf", conf_name); + if (enabled_only) + { + map_plugin_settings_t::iterator it = pluginSettings.find("Enabled"); + if (it == pluginSettings.end() || !string_to_bool(it->second.c_str())) + { + plugin_info["Enabled"] = "no"; + string empty; + plugin_info["Type"] = empty; + plugin_info["Version"] = empty; + plugin_info["Description"] = empty; + plugin_info["Email"] = empty; + plugin_info["WWW"] = empty; + plugin_info["GTKBuilder"] = empty; + m_map_plugin_info[pName] = plugin_info; + VERB3 log("Plugin %s: 'Enabled' is not set, not loading it (yet)", pName); + return NULL; /* error */ + } + } + + string libPath = ssprintf(PLUGINS_LIB_DIR"/"PLUGINS_LIB_PREFIX"%s."PLUGINS_LIB_EXTENSION, pName); + CLoadedModule* module = new CLoadedModule(libPath.c_str()); if (module->GetMagicNumber() != PLUGINS_MAGIC_NUMBER || module->GetType() < 0 || module->GetType() > MAX_PLUGIN_TYPE @@ -172,95 +211,74 @@ void CPluginManager::LoadPlugin(const char *pName) module->GetMagicNumber(), PLUGINS_MAGIC_NUMBER, module->GetType(), MAX_PLUGIN_TYPE); delete module; - return; + return NULL; /* error */ } + VERB3 log("Loaded plugin %s v.%s", pName, module->GetVersion()); - log("Plugin %s (%s) succesfully loaded", pName, module->GetVersion()); - m_mapLoadedModules[pName] = module; -} - -void CPluginManager::UnLoadPlugin(const char *pName) -{ - map_loaded_module_t::iterator it_module = m_mapLoadedModules.find(pName); - if (it_module != m_mapLoadedModules.end()) - { - UnRegisterPlugin(pName); - delete it_module->second; - m_mapLoadedModules.erase(it_module); - log("Plugin %s successfully unloaded", pName); - } -} - -int CPluginManager::RegisterPlugin(const char *pName) -{ - map_loaded_module_t::iterator it_module = m_mapLoadedModules.find(pName); - if (it_module == m_mapLoadedModules.end()) - { - error_msg("Can't initialize plugin %s: no such plugin installed", pName); - return -1; /* failure */ - } - if (m_mapPlugins.find(pName) != m_mapPlugins.end()) - { - return 0; /* already registered, success */ - } - - /* Loaded, but not registered yet */ - CPlugin* plugin = it_module->second->PluginNew(); - map_plugin_settings_t pluginSettings; - - const char *conf_name = pName; - if (strncmp(pName, "Kerneloops", sizeof("Kerneloops")-1) == 0) { - /* Kerneloops{,Scanner,Reporter} share the same .conf file */ - conf_name = "Kerneloops"; - } - LoadPluginSettings(ssprintf(PLUGINS_CONF_DIR"/%s."PLUGINS_CONF_EXTENSION, conf_name).c_str(), pluginSettings); - VERB3 log("Loaded %s.conf", conf_name); + CPlugin* plugin = NULL; try { + plugin = module->PluginNew(); plugin->Init(); plugin->SetSettings(pluginSettings); } catch (CABRTException& e) { - error_msg("Can't initialize plugin %s(%s): %s", + error_msg("Can't initialize plugin %s: %s", pName, - plugin_type_str[it_module->second->GetType()], e.what() ); - UnLoadPlugin(pName); - return -1; /* failure */ + delete plugin; + delete module; + return NULL; /* error */ } - m_mapPlugins[pName] = plugin; - log("Registered plugin %s(%s)", pName, plugin_type_str[it_module->second->GetType()]); - return 0; /* success */ -} -void CPluginManager::RegisterPluginDBUS(const char *pName, const char *pDBUSSender) -{ - int polkit_result = polkit_check_authorization(pDBUSSender, - "org.fedoraproject.abrt.change-daemon-settings"); - if (polkit_result == PolkitYes) - { - RegisterPlugin(pName); - } else - { - log("User %s not authorized, returned %d", pDBUSSender, polkit_result); - } + plugin_info["Enabled"] = "yes"; + plugin_info["Type"] = plugin_type_str[module->GetType()]; + //plugin_info["Name"] = module->GetName(); + plugin_info["Version"] = module->GetVersion(); + plugin_info["Description"] = module->GetDescription(); + plugin_info["Email"] = module->GetEmail(); + plugin_info["WWW"] = module->GetWWW(); + plugin_info["GTKBuilder"] = module->GetGTKBuilder(); + + m_map_plugin_info[pName] = plugin_info; + m_mapLoadedModules[pName] = module; + m_mapPlugins[pName] = plugin; + log("Registered %s plugin '%s'", plugin_type_str[module->GetType()], pName); + return plugin; /* ok */ } -void CPluginManager::UnRegisterPlugin(const char *pName) +void CPluginManager::UnLoadPlugin(const char *pName) { map_loaded_module_t::iterator it_module = m_mapLoadedModules.find(pName); if (it_module != m_mapLoadedModules.end()) { map_plugin_t::iterator it_plugin = m_mapPlugins.find(pName); - if (it_plugin != m_mapPlugins.end()) + if (it_plugin != m_mapPlugins.end()) /* always true */ { it_plugin->second->DeInit(); delete it_plugin->second; m_mapPlugins.erase(it_plugin); - log("UnRegistered plugin %s(%s)", pName, plugin_type_str[it_module->second->GetType()]); } + log("UnRegistered %s plugin %s", plugin_type_str[it_module->second->GetType()], pName); + m_mapLoadedModules.erase(it_module); + delete it_module->second; + } +} + +#ifdef PLUGIN_DYNAMIC_LOAD_UNLOAD +void CPluginManager::RegisterPluginDBUS(const char *pName, const char *pDBUSSender) +{ + int polkit_result = polkit_check_authorization(pDBUSSender, + "org.fedoraproject.abrt.change-daemon-settings"); + if (polkit_result == PolkitYes) + { +//TODO: report success/failure + LoadPlugin(pName); + } else + { + log("User %s not authorized, returned %d", pDBUSSender, polkit_result); } } @@ -270,60 +288,67 @@ void CPluginManager::UnRegisterPluginDBUS(const char *pName, const char *pDBUSSe "org.fedoraproject.abrt.change-daemon-settings"); if (polkit_result == PolkitYes) { - UnRegisterPlugin(pName); + UnLoadPlugin(pName); } else { log("user %s not authorized, returned %d", pDBUSSender, polkit_result); } } - +#endif CAnalyzer* CPluginManager::GetAnalyzer(const char *pName) { - map_plugin_t::iterator it_plugin = m_mapPlugins.find(pName); - if (it_plugin == m_mapPlugins.end()) + CPlugin* plugin = LoadPlugin(pName); + if (!plugin) { - throw CABRTException(EXCEP_PLUGIN, "Plugin '%s' is not registered", pName); + error_msg("Plugin '%s' is not registered", pName); + return NULL; } if (m_mapLoadedModules[pName]->GetType() != ANALYZER) { - throw CABRTException(EXCEP_PLUGIN, "Plugin '%s' is not an analyzer plugin", pName); + error_msg("Plugin '%s' is not an analyzer plugin", pName); + return NULL; } - return (CAnalyzer*)(it_plugin->second); + return (CAnalyzer*)plugin; } CReporter* CPluginManager::GetReporter(const char *pName) { - map_plugin_t::iterator it_plugin = m_mapPlugins.find(pName); - if (it_plugin == m_mapPlugins.end()) + CPlugin* plugin = LoadPlugin(pName); + if (!plugin) { - throw CABRTException(EXCEP_PLUGIN, "Plugin '%s' is not registered", pName); + error_msg("Plugin '%s' is not registered", pName); + return NULL; } if (m_mapLoadedModules[pName]->GetType() != REPORTER) { - throw CABRTException(EXCEP_PLUGIN, "Plugin '%s' is not a reporter plugin", pName); + error_msg("Plugin '%s' is not a reporter plugin", pName); + return NULL; } - return (CReporter*)(it_plugin->second); + return (CReporter*)plugin; } -CAction* CPluginManager::GetAction(const char *pName) +CAction* CPluginManager::GetAction(const char *pName, bool silent) { - map_plugin_t::iterator it_plugin = m_mapPlugins.find(pName); - if (it_plugin == m_mapPlugins.end()) + CPlugin* plugin = LoadPlugin(pName); + if (!plugin) { - throw CABRTException(EXCEP_PLUGIN, "Plugin '%s' is not registered", pName); + error_msg("Plugin '%s' is not registered", pName); + return NULL; } if (m_mapLoadedModules[pName]->GetType() != ACTION) { - throw CABRTException(EXCEP_PLUGIN, "Plugin '%s' is not an action plugin", pName); + if (!silent) + error_msg("Plugin '%s' is not an action plugin", pName); + return NULL; } - return (CAction*)(it_plugin->second); + return (CAction*)plugin; } CDatabase* CPluginManager::GetDatabase(const char *pName) { - map_plugin_t::iterator it_plugin = m_mapPlugins.find(pName); - if (it_plugin == m_mapPlugins.end()) + CPlugin* plugin = LoadPlugin(pName); + if (!plugin) { throw CABRTException(EXCEP_PLUGIN, "Plugin '%s' is not registered", pName); } @@ -331,39 +356,18 @@ CDatabase* CPluginManager::GetDatabase(const char *pName) { throw CABRTException(EXCEP_PLUGIN, "Plugin '%s' is not a database plugin", pName); } - return (CDatabase*)(it_plugin->second); + return (CDatabase*)plugin; } plugin_type_t CPluginManager::GetPluginType(const char *pName) { - map_plugin_t::iterator it_plugin = m_mapPlugins.find(pName); - if (it_plugin == m_mapPlugins.end()) + CPlugin* plugin = LoadPlugin(pName); + if (!plugin) { throw CABRTException(EXCEP_PLUGIN, "Plugin '%s' is not registered", pName); } - return m_mapLoadedModules[pName]->GetType(); -} - -vector_map_string_t CPluginManager::GetPluginsInfo() -{ - vector_map_string_t ret; - map_loaded_module_t::iterator it_module = m_mapLoadedModules.begin(); - for (; it_module != m_mapLoadedModules.end(); it_module++) - { - map_string_t plugin_info; - - plugin_info["Enabled"] = (m_mapPlugins.find(it_module->second->GetName()) != m_mapPlugins.end()) ? - "yes" : "no"; - plugin_info["Type"] = plugin_type_str[it_module->second->GetType()]; - plugin_info["Name"] = it_module->second->GetName(); - plugin_info["Version"] = it_module->second->GetVersion(); - plugin_info["Description"] = it_module->second->GetDescription(); - plugin_info["Email"] = it_module->second->GetEmail(); - plugin_info["WWW"] = it_module->second->GetWWW(); - plugin_info["GTKBuilder"] = it_module->second->GetGTKBuilder(); - ret.push_back(plugin_info); - } - return ret; + map_loaded_module_t::iterator it_module = m_mapLoadedModules.find(pName); + return it_module->second->GetType(); } void CPluginManager::SetPluginSettings(const char *pName, @@ -388,14 +392,14 @@ void CPluginManager::SetPluginSettings(const char *pName, return; } - std::string home = get_home_dir(xatoi_u(pUID.c_str())); + string home = get_home_dir(xatoi_u(pUID.c_str())); if (home == "") { return; } - std::string confDir = home + "/.abrt"; - std::string confPath = confDir + "/" + pName + "."PLUGINS_CONF_EXTENSION; + string confDir = home + "/.abrt"; + string confPath = confDir + "/" + pName + "."PLUGINS_CONF_EXTENSION; uid_t uid = xatoi_u(pUID.c_str()); struct passwd* pw = getpwuid(uid); gid_t gid = pw ? pw->pw_gid : uid; @@ -415,7 +419,7 @@ void CPluginManager::SetPluginSettings(const char *pName, } if (chown(confDir.c_str(), uid, gid) == -1) { - perror_msg("Can't change '%s' ownership to %u:%u", confPath.c_str(), (int)uid, (int)gid); + perror_msg("Can't change '%s' ownership to %lu:%lu", confPath.c_str(), (long)uid, (long)gid); return; } } @@ -433,40 +437,38 @@ void CPluginManager::SetPluginSettings(const char *pName, SavePluginSettings(confPath, pSettings); if (chown(confPath.c_str(), uid, gid) == -1) { - perror_msg("Can't change '%s' ownership to %u:%u", confPath.c_str(), (int)uid, (int)gid); + perror_msg("Can't change '%s' ownership to %lu:%lu", confPath.c_str(), (long)uid, (long)gid); return; } */ #endif } -map_plugin_settings_t CPluginManager::GetPluginSettings(const char *pName, - const char *pUID) +map_plugin_settings_t CPluginManager::GetPluginSettings(const char *pName) { map_plugin_settings_t ret; + map_loaded_module_t::iterator it_module = m_mapLoadedModules.find(pName); if (it_module != m_mapLoadedModules.end()) { map_plugin_t::iterator it_plugin = m_mapPlugins.find(pName); if (it_plugin != m_mapPlugins.end()) { + VERB3 log("Returning settings for loaded plugin %s", pName); ret = it_plugin->second->GetSettings(); - /** we don't want to load it from daemon if it's running under root - but wi might get back to this once we make the daemon to not run - with root privileges - */ - /* - if (it_module->second->GetType() == REPORTER) - { - std::string home = get_home_dir(xatoi_u(pUID.c_str())); - if (home != "") - { - LoadPluginSettings(home + "/.abrt/" + pName + "."PLUGINS_CONF_EXTENSION, ret); - } - } - */ return ret; } } + /* else: module is not loaded */ + map_map_string_t::iterator it_settings = m_map_plugin_settings.find(pName); + if (it_settings != m_map_plugin_settings.end()) + { + /* but it exists, its settings are available nevertheless */ + VERB3 log("Returning settings for non-loaded plugin %s", pName); + ret = it_settings->second; + return ret; + } + + VERB3 log("Request for settings of unknown plugin %s, returning null result", pName); return ret; } diff --git a/src/Daemon/PluginManager.h b/src/Daemon/PluginManager.h index 2d649c5..22cc387 100644 --- a/src/Daemon/PluginManager.h +++ b/src/Daemon/PluginManager.h @@ -50,6 +50,11 @@ class CPluginManager * Registered plugins. A key is a plugin name. */ map_plugin_t m_mapPlugins; + /** + * List of all possible plugins (loaded or not), with some attributes. + */ + map_map_string_t m_map_plugin_info; + map_map_string_t m_map_plugin_settings; public: /** @@ -74,28 +79,17 @@ class CPluginManager * A method, which loads particular plugin. * @param pName A plugin name. */ - void LoadPlugin(const char *pName); + CPlugin* LoadPlugin(const char *pName, bool enabled_only = false); /** * A method, which unloads particular plugin. * @param pName A plugin name. */ void UnLoadPlugin(const char *pName); +#ifdef PLUGIN_DYNAMIC_LOAD_UNLOAD /** * A method, which registers particular plugin. * @param pName A plugin name. */ - int RegisterPlugin(const char *pName); - /** - * A method, which unregister particular plugin. - * @param pName A plugin name. - */ - void UnRegisterPlugin(const char *pName); - /** - * A method, which registers particular plugin, - * called via DBUS - * @param pName A plugin name. - * @param pDBUSSender DBUS user identification - */ void RegisterPluginDBUS(const char *pName, const char *pDBUSSender); /** * A method, which unregister particular plugin, @@ -104,6 +98,7 @@ class CPluginManager * @param pDBUSSender DBUS user identification */ void UnRegisterPluginDBUS(const char *pName, const char *pDBUSSender); +#endif /** * A method, which returns instance of particular analyzer plugin. * @param pName A plugin name. @@ -121,7 +116,7 @@ class CPluginManager * @param pName A plugin name. * @return An action plugin. */ - CAction* GetAction(const char *pName); + CAction* GetAction(const char *pName, bool silent = false); /** * A method, which returns instance of particular database plugin. * @param pName A plugin name. @@ -140,7 +135,7 @@ class CPluginManager * Then user can fill all needed informations like URLs etc. * @return A vector of maps <key, value> */ - vector_map_string_t GetPluginsInfo(); + const map_map_string_t& GetPluginsInfo() { return m_map_plugin_info; } /** * A method, which sets up a plugin. The settings are also saved in home * directory of an user. @@ -154,11 +149,9 @@ class CPluginManager /** * A method, which returns plugin's settings according to user. * @param pName A plugin name. - * @param pUID An uid of user. - * @return Plugin's settings accorting to user. + * @return Plugin's settings. */ - map_plugin_settings_t GetPluginSettings(const char *pName, - const char *pUID); + map_plugin_settings_t GetPluginSettings(const char *pName); }; /** diff --git a/src/Daemon/RPM.cpp b/src/Daemon/RPM.cpp index 6f05c0b..6cc0ba6 100644 --- a/src/Daemon/RPM.cpp +++ b/src/Daemon/RPM.cpp @@ -4,8 +4,8 @@ CRPM::CRPM() { - char *argv[] = { (char*)"" }; - m_poptContext = rpmcliInit(0, argv, NULL); + static const char *const argv[] = { "", NULL }; + m_poptContext = rpmcliInit(1, (char**)argv, NULL); } CRPM::~CRPM() diff --git a/src/Daemon/Settings.cpp b/src/Daemon/Settings.cpp index d89bebf..48658e2 100644 --- a/src/Daemon/Settings.cpp +++ b/src/Daemon/Settings.cpp @@ -37,7 +37,6 @@ bool g_settings_bOpenGPGCheck = false; /* one line: "OpenGPGPublicKeys = value1,value2" */ set_string_t g_settings_setOpenGPGPublicKeys; set_string_t g_settings_mapBlackList; -set_string_t g_settings_setEnabledPlugins; std::string g_settings_sDatabase; unsigned int g_settings_nMaxCrashReportsSize = 1000; /* one line: "ActionsAndReporters = aa_first,bb_first(bb_second),cc_first" */ @@ -168,11 +167,6 @@ static void ParseCommon() { g_settings_sDatabase = it->second; } - it = s_mapSectionCommon.find("EnabledPlugins"); - if (it != end) - { - g_settings_setEnabledPlugins = ParseList(it->second.c_str()); - } it = s_mapSectionCommon.find("MaxCrashReportsSize"); if (it != end) { @@ -434,7 +428,6 @@ void SaveSettings() SaveBool("OpenGPGCheck", g_settings_bOpenGPGCheck, fOut); SaveSetString("OpenGPGPublicKeys", g_settings_setOpenGPGPublicKeys, fOut); SaveSetString("BlackList", g_settings_mapBlackList, fOut); - SaveSetString("EnabledPlugins", g_settings_setEnabledPlugins, fOut); fprintf(fOut, "Database = %s\n", g_settings_sDatabase.c_str()); fprintf(fOut, "MaxCrashReportsSize = %u\n", g_settings_nMaxCrashReportsSize); SaveVectorPairStrings("ActionsAndReporters", g_settings_vectorActionsAndReporters, fOut); diff --git a/src/Daemon/Settings.h b/src/Daemon/Settings.h index 9ee9370..3fdb8b9 100644 --- a/src/Daemon/Settings.h +++ b/src/Daemon/Settings.h @@ -9,7 +9,6 @@ typedef map_map_string_t map_abrt_settings_t; extern set_string_t g_settings_setOpenGPGPublicKeys; extern set_string_t g_settings_mapBlackList; -extern set_string_t g_settings_setEnabledPlugins; extern unsigned int g_settings_nMaxCrashReportsSize; extern bool g_settings_bOpenGPGCheck; extern std::string g_settings_sDatabase; diff --git a/src/Daemon/abrt-debuginfo-install b/src/Daemon/abrt-debuginfo-install index cfae49a..35f4d6a 100755 --- a/src/Daemon/abrt-debuginfo-install +++ b/src/Daemon/abrt-debuginfo-install @@ -145,9 +145,11 @@ print_package_names() { fi # when we look for debuginfo we need only -debuginfo* repos, so we can disable the rest and thus make it faster # also we want only fedora repositories, because abrt won't work for other packages anyway - local cmd="yum $yumopts --disablerepo=* --enablerepo=fedora-debuginfo* --enablerepo=updates-debuginfo* --quiet provides $missing_debuginfo_files" + local cmd="yum $yumopts '--disablerepo=*' '--enablerepo=fedora-debuginfo*' '--enablerepo=updates-debuginfo*' --quiet provides $missing_debuginfo_files" echo "$cmd" >"yum_provides.$1.OUT" - local yum_provides_OUT="`$cmd 2>&1`" + # eval is needed to strip away ''s; cant remove them above and just use + # $cmd, that would perform globbing on '*' + local yum_provides_OUT="`eval $cmd 2>&1`" local err=$? printf "%s\nyum exitcode:%s\n" "$yum_provides_OUT" $err >>"yum_provides.$1.OUT" test $err = 0 || error_msg_and_die "yum provides... exited with $err: diff --git a/src/Daemon/abrt.conf b/src/Daemon/abrt.conf index 276bf25..acf8566 100644 --- a/src/Daemon/abrt.conf +++ b/src/Daemon/abrt.conf @@ -9,11 +9,7 @@ OpenGPGCheck = no OpenGPGPublicKeys = /etc/pki/rpm-gpg/RPM-GPG-KEY-fedora # Blacklisted packages BlackList = nspluginwrapper -# Enabled plugins. -# You can disable handling e.g. Python crashes by not listing Python here. -# There has to be exactly one database plugin enabled. -EnabledPlugins = SQLite3, CCpp, Logger, Kerneloops, KerneloopsScanner, KerneloopsReporter, Bugzilla, Python, RunApp -# Database +# Which database plugin to use Database = SQLite3 # Max size for crash storage [MiB] MaxCrashReportsSize = 1000 diff --git a/src/Daemon/abrt.conf.5 b/src/Daemon/abrt.conf.5 index 3b172bc..7114f5c 100644 --- a/src/Daemon/abrt.conf.5 +++ b/src/Daemon/abrt.conf.5 @@ -30,10 +30,6 @@ to report them if "EnableOpenGPG = yes". .I abrt will ignore packages in this list and will not handle their crashes. .TP -.B EnabledPlugins = \fIplugin\fP, \fIplugin\fP ... -.I abrt -will only load plugins in this list. -.TP .B Database = \fIdatabasePlugin\fP This specifies which database plugin .I abrt |
