diff options
author | Denys Vlasenko <dvlasenk@redhat.com> | 2011-01-19 17:14:05 +0100 |
---|---|---|
committer | Denys Vlasenko <dvlasenk@redhat.com> | 2011-01-19 17:14:05 +0100 |
commit | 480cac7647d567c3c3cb148c5a4750091b651934 (patch) | |
tree | 2ca255952e55660af4374aa889fdba7c14d2d6da /src | |
parent | e001c3c0c7d8dc9576f1630551a73cc01f19769b (diff) | |
download | abrt-480cac7647d567c3c3cb148c5a4750091b651934.tar.gz abrt-480cac7647d567c3c3cb148c5a4750091b651934.tar.xz abrt-480cac7647d567c3c3cb148c5a4750091b651934.zip |
remove old plugin machinery. -10k and -1 library dependence in abrtd
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/daemon/Daemon.h | 4 | ||||
-rw-r--r-- | src/daemon/Makefile.am | 1 | ||||
-rw-r--r-- | src/daemon/MiddleWare.cpp | 22 | ||||
-rw-r--r-- | src/daemon/MiddleWare.h | 10 | ||||
-rw-r--r-- | src/daemon/PluginManager.cpp | 264 | ||||
-rw-r--r-- | src/daemon/PluginManager.h | 95 | ||||
-rw-r--r-- | src/include/Makefile.am | 2 | ||||
-rw-r--r-- | src/include/action.h | 44 | ||||
-rw-r--r-- | src/include/analyzer.h | 34 | ||||
-rw-r--r-- | src/include/plugin.h | 84 | ||||
-rw-r--r-- | src/lib/Makefile.am | 6 | ||||
-rw-r--r-- | src/lib/Plugin.cpp | 41 | ||||
-rw-r--r-- | src/plugins/CCpp.cpp | 301 | ||||
-rw-r--r-- | src/plugins/CCpp.h | 49 | ||||
-rw-r--r-- | src/plugins/Makefile.am | 19 |
15 files changed, 3 insertions, 973 deletions
diff --git a/src/daemon/Daemon.h b/src/daemon/Daemon.h index 0c3db566..eb691262 100644 --- a/src/daemon/Daemon.h +++ b/src/daemon/Daemon.h @@ -25,12 +25,8 @@ class CCrashWatcher; class CCommLayerServer; -class CPluginManager; /* Used for sending dbus signals */ extern CCommLayerServer *g_pCommLayer; -/* Collection of loaded plugins */ -extern CPluginManager* g_pPluginManager; - #endif diff --git a/src/daemon/Makefile.am b/src/daemon/Makefile.am index 584b4e3e..bef380bf 100644 --- a/src/daemon/Makefile.am +++ b/src/daemon/Makefile.am @@ -10,7 +10,6 @@ sbin_PROGRAMS = \ abrt-server abrtd_SOURCES = \ - PluginManager.h PluginManager.cpp \ MiddleWare.h MiddleWare.cpp \ CrashWatcher.h CrashWatcher.cpp \ CommLayerServer.h CommLayerServer.cpp \ diff --git a/src/daemon/MiddleWare.cpp b/src/daemon/MiddleWare.cpp index 1379e4fb..4da4db19 100644 --- a/src/daemon/MiddleWare.cpp +++ b/src/daemon/MiddleWare.cpp @@ -19,6 +19,7 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "abrtlib.h" +#include "plugin.h" #include "Daemon.h" #include "Settings.h" #include "comm_layer_inner.h" @@ -28,14 +29,6 @@ using namespace std; /** - * An instance of CPluginManager. When MiddleWare wants to do something - * with plugins, it calls the plugin manager. - * @see PluginManager.h - */ -CPluginManager* g_pPluginManager; - - -/** * Get one crash info. If getting is successful, * then crash info is filled. * @param dump_dir_name A dump dir containing all necessary data. @@ -179,19 +172,6 @@ static mw_result_t CreateCrashReport(const char *dump_dir_name, return r; } -void RunAction(const char *pActionDir, - const char *pPluginName, - const char *pPluginArgs) -{ - CAction* action = g_pPluginManager->GetAction(pPluginName); - if (!action) - { - /* GetAction() already complained */ - return; - } - action->Run(pActionDir, pPluginArgs, /*force:*/ 0); -} - struct logging_state { char *last_line; }; diff --git a/src/daemon/MiddleWare.h b/src/daemon/MiddleWare.h index 4826d79d..2cbf4eb5 100644 --- a/src/daemon/MiddleWare.h +++ b/src/daemon/MiddleWare.h @@ -23,7 +23,6 @@ #define MIDDLEWARE_H_ #include "abrt_types.h" -#include "PluginManager.h" /** * An enum contains all return codes. @@ -46,15 +45,6 @@ typedef enum { /** - * Activates particular action plugin. - * @param pActionDir A directory, which is passed as working to a action plugin. - * @param pPluginName An action plugin name. - * @param pPluginArgs Action plugin's arguments. - */ -void RunAction(const char *pActionDir, - const char *pPluginName, - const char *pPluginArgs); -/** * Reports a crash report to particular receiver. It * takes an user uid, tries to find user config file and load it. If it * fails, then default config is used. If pUID is emply string, default diff --git a/src/daemon/PluginManager.cpp b/src/daemon/PluginManager.cpp deleted file mode 100644 index e6059583..00000000 --- a/src/daemon/PluginManager.cpp +++ /dev/null @@ -1,264 +0,0 @@ -/* - PluginManager.cpp - - Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com) - Copyright (C) 2009 RedHat inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include <dlfcn.h> -#include "abrtlib.h" -#include "PluginManager.h" - -using namespace std; - - -/** - * CLoadedModule class. A class which contains a loaded plugin. - */ -class CLoadedModule -{ - private: - /* dlopen'ed library */ - void *m_pHandle; - const plugin_info_t *m_pPluginInfo; - CPlugin* (*m_pFnPluginNew)(); - - public: - CLoadedModule(void *handle, const char *mod_name); - ~CLoadedModule() { dlclose(m_pHandle); } - int GetMagicNumber() { return m_pPluginInfo->m_nMagicNumber; } - const char *GetVersion() { return m_pPluginInfo->m_sVersion; } - const char *GetName() { return m_pPluginInfo->m_sName; } - const char *GetDescription() { return m_pPluginInfo->m_sDescription; } - const char *GetEmail() { return m_pPluginInfo->m_sEmail; } - const char *GetWWW() { return m_pPluginInfo->m_sWWW; } - const char *GetGTKBuilder() { return m_pPluginInfo->m_sGTKBuilder; } - plugin_type_t GetType() { return m_pPluginInfo->m_Type; } - CPlugin *PluginNew() { return m_pFnPluginNew(); } -}; -CLoadedModule::CLoadedModule(void *handle, const char *mod_name) -{ - m_pHandle = handle; - /* All errors are fatal */ -#define LOADSYM(fp, handle, name) \ - do { \ - fp = (typeof(fp)) (dlsym(handle, name)); \ - if (!fp) \ - error_msg_and_die("'%s' has no %s entry", mod_name, name); \ - } while (0) - - LOADSYM(m_pPluginInfo, handle, "plugin_info"); - LOADSYM(m_pFnPluginNew, handle, "plugin_new"); -#undef LOADSYM -} - - -/** - * Text representation of plugin types. - */ -static const char *const plugin_type_str[] = { - "Analyzer", - "Action", - "Reporter", - "Database" -}; - - -CPluginManager::CPluginManager() -{} - -CPluginManager::~CPluginManager() -{} - -void CPluginManager::LoadPlugins() -{ - DIR *dir = opendir(PLUGINS_LIB_DIR); - if (dir != NULL) - { - struct dirent *dent; - while ((dent = readdir(dir)) != NULL) - { - if (!is_regular_file(dent, PLUGINS_LIB_DIR)) - continue; - char *ext = strrchr(dent->d_name, '.'); - if (!ext || strcmp(ext + 1, PLUGINS_LIB_EXTENSION) != 0) - continue; - *ext = '\0'; - 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); - } -} - -void CPluginManager::UnLoadPlugins() -{ - map_loaded_module_t::iterator it_module; - while ((it_module = m_mapLoadedModules.begin()) != m_mapLoadedModules.end()) - { - UnLoadPlugin(it_module->first.c_str()); - } -} - -CPlugin* CPluginManager::LoadPlugin(const char *pName, bool enabled_only) -{ - map_plugin_t::iterator it_plugin = m_mapPlugins.find(pName); - if (it_plugin != m_mapPlugins.end()) - { - return it_plugin->second; /* ok */ - } - - map_string_t plugin_info; - plugin_info["Name"] = pName; - - const char *conf_name = pName; - if (strncmp(pName, "Kerneloops", sizeof("Kerneloops")-1) == 0) - { - /* Kerneloops{,Scanner,Reporter} share the same .conf file */ - conf_name = "Kerneloops"; - } - char *conf_fullname = xasprintf(PLUGINS_CONF_DIR"/%s."PLUGINS_CONF_EXTENSION, conf_name); - map_string_h *pluginSettings = new_map_string(); - if (load_conf_file(conf_fullname, pluginSettings, /*skip key w/o values:*/ true)) - VERB3 log("Loaded %s.conf", conf_name); - free(conf_fullname); - - if (enabled_only) - { - if (!string_to_bool(get_map_string_item_or_empty(pluginSettings, "Enabled"))) - { - 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; - VERB3 log("Plugin %s: 'Enabled' is not set, not loading it (yet)", pName); - free_map_string(pluginSettings); - return NULL; /* error */ - } - } - - char *libPath = xasprintf(PLUGINS_LIB_DIR"/"PLUGINS_LIB_PREFIX"%s."PLUGINS_LIB_EXTENSION, pName); - void *handle = dlopen(libPath, RTLD_NOW); - if (!handle) - { - error_msg("Can't load '%s': %s", libPath, dlerror()); - free(libPath); - free_map_string(pluginSettings); - return NULL; /* error */ - } - free(libPath); - CLoadedModule *module = new CLoadedModule(handle, pName); - if (module->GetMagicNumber() != PLUGINS_MAGIC_NUMBER - || module->GetType() < 0 - || module->GetType() > MAX_PLUGIN_TYPE - ) { - error_msg("Can't load non-compatible plugin %s: magic %d != %d or type %d is not in [0,%d]", - pName, - module->GetMagicNumber(), PLUGINS_MAGIC_NUMBER, - module->GetType(), MAX_PLUGIN_TYPE); - delete module; - free_map_string(pluginSettings); - return NULL; /* error */ - } - VERB3 log("Loaded plugin %s v.%s", pName, module->GetVersion()); - - CPlugin *plugin = NULL; - plugin = module->PluginNew(); - plugin->Init(); - /* Need to convert pluginSettings from map_string_h container - * to map_string_t, since plugin->SetSettings() needs that type. - * To be removed when remaining uses of map_string_t - * are globally converted to map_string_h. - */ - { - map_string_t pluginSettings2; - GHashTableIter iter; - char *name; - char *value; - g_hash_table_iter_init(&iter, pluginSettings); - while (g_hash_table_iter_next(&iter, (void**)&name, (void**)&value)) - { - pluginSettings2[name] = value; - } - plugin->SetSettings(pluginSettings2); - } - free_map_string(pluginSettings); - - 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_mapLoadedModules[pName] = module; - m_mapPlugins[pName] = plugin; - log("Registered %s plugin '%s'", plugin_type_str[module->GetType()], pName); - return plugin; /* ok */ -} - -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()) /* always true */ - { - it_plugin->second->DeInit(); - delete it_plugin->second; - m_mapPlugins.erase(it_plugin); - } - log("UnRegistered %s plugin %s", plugin_type_str[it_module->second->GetType()], pName); - delete it_module->second; - m_mapLoadedModules.erase(it_module); - } -} - -CAction* CPluginManager::GetAction(const char *pName, bool silent) -{ - CPlugin *plugin = LoadPlugin(pName); - if (!plugin) - { - error_msg("Plugin '%s' is not registered", pName); - return NULL; - } - if (m_mapLoadedModules[pName]->GetType() != ACTION) - { - if (!silent) - error_msg("Plugin '%s' is not an action plugin", pName); - return NULL; - } - return (CAction*)plugin; -} - -plugin_type_t CPluginManager::GetPluginType(const char *pName) -{ - CPlugin *plugin = LoadPlugin(pName); - if (!plugin) - { - return INVALID_PLUGIN_TYPE; - } - map_loaded_module_t::iterator it_module = m_mapLoadedModules.find(pName); - return it_module->second->GetType(); -} diff --git a/src/daemon/PluginManager.h b/src/daemon/PluginManager.h deleted file mode 100644 index 1108b985..00000000 --- a/src/daemon/PluginManager.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - PluginManager.h - header file for plugin manager. it takes care about - (un)loading plugins - - Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com) - Copyright (C) 2009 RedHat inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#ifndef PLUGINMANAGER_H_ -#define PLUGINMANAGER_H_ - -#include "abrt_types.h" -#include "plugin.h" -#include "analyzer.h" -#include "action.h" - -class CLoadedModule; /* opaque */ - -/** - * A class. It takes care of loading, registering and manipulating with - * plugins. When a plugin is loaded, its library is opened, but no plugin - * instance is created. It is possible after plugin registration. - */ -class CPluginManager -{ - private: - typedef std::map<std::string, CLoadedModule*> map_loaded_module_t; - typedef std::map<std::string, CPlugin*> map_plugin_t; - - /** - * Loaded plugins. A key is a plugin name. - */ - map_loaded_module_t m_mapLoadedModules; - /** - * Registered plugins. A key is a plugin name. - */ - map_plugin_t m_mapPlugins; - - public: - /** - * A constructor. - * @param pPluginsConfDir A plugins configuration directory. - * @param pPluginsLibDir A plugins library directory. - */ - CPluginManager(); - /** - * A destructor. - */ - ~CPluginManager(); - /** - * A method, which loads all plugins in plugins library direcotry. - */ - void LoadPlugins(); - /** - * A method, which unregister and unload all loaded plugins. - */ - void UnLoadPlugins(); - /** - * A method, which loads particular plugin. - * @param pName A plugin name. - */ - 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); - /** - * A method, which returns instance of particular action plugin. - * @param pName A plugin name. - * @return An action plugin. - */ - CAction* GetAction(const char *pName, bool silent = false); - /** - * A method, which returns type of particular plugin. - * @param pName A plugin name. - * @return A plugin type. - */ - plugin_type_t GetPluginType(const char *pName); -}; - -#endif /*PLUGINMANAGER_H_*/ diff --git a/src/include/Makefile.am b/src/include/Makefile.am index b5d604ef..cf524f7e 100644 --- a/src/include/Makefile.am +++ b/src/include/Makefile.am @@ -13,6 +13,4 @@ libabrt_include_HEADERS = \ dbus_common.h \ observer.h \ plugin.h \ - action.h \ - analyzer.h \ xfuncs.h diff --git a/src/include/action.h b/src/include/action.h deleted file mode 100644 index 21183366..00000000 --- a/src/include/action.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - Action.h - header file for action plugin - - Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com) - Copyright (C) 2009 RedHat inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#ifndef ACTION_H_ -#define ACTION_H_ - -#include "plugin.h" - -/** - * An abstract class. The class defines an action plugin interface. - */ -class CAction : public CPlugin -{ - public: - /** - * A Method which performs particular action. As the first parameter it - * takes an action directory. It could be either a directory of actual - * crash or it could be a directory contains all crashes. It depends on - * who call the plugin. The plugin can takes arguments, but the plugin - * has to parse them by itself. - * @param pActionDir An actual directory. - * @param pArgs Plugin's arguments. - */ - virtual void Run(const char *pActionDir, const char *pArgs, int force) = 0; -}; - -#endif diff --git a/src/include/analyzer.h b/src/include/analyzer.h deleted file mode 100644 index 1d78d576..00000000 --- a/src/include/analyzer.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - Analyzer.h - header file for analyzer plugin - - Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com) - Copyright (C) 2009 RedHat inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#ifndef ANALYZER_H_ -#define ANALYZER_H_ - -#include <string> -#include "plugin.h" - -/** - * An abstract class. The class defines an analyzer plugin interface. - */ -class CAnalyzer : public CPlugin -{ -}; - -#endif /*ANALYZER_H_*/ diff --git a/src/include/plugin.h b/src/include/plugin.h index e3f1f81f..5af5753c 100644 --- a/src/include/plugin.h +++ b/src/include/plugin.h @@ -25,90 +25,6 @@ #include "abrt_types.h" #include "abrt_crash_data.h" -#define PLUGINS_MAGIC_NUMBER 6 - #define PLUGINS_CONF_EXTENSION "conf" -#define PLUGINS_LIB_EXTENSION "so" -#define PLUGINS_LIB_PREFIX "lib" - -/** - * An abstract class. The class defines a common plugin interface. If a plugin - * has some settings, then a *Settings(*) method has to be written. - */ -class CPlugin -{ - protected: - map_plugin_settings_t m_pSettings; - - public: - CPlugin(); - /** - * A destructor. - */ - virtual ~CPlugin(); - /** - * A method, which initializes a plugin. It is not mandatory method. - */ - virtual void Init(); - /** - * A method, which deinitializes a plugin. It is not mandatory method. - */ - virtual void DeInit(); - /** - * A method, which takes a settings and apply them. It is not a mandatory method. - * @param pSettings Plugin's settings - */ - virtual void SetSettings(const map_plugin_settings_t& pSettings); - /** - * A method, which return current settings. It is not mandatory method. - * @return Plugin's settings - */ -/// -// virtual const map_plugin_settings_t& GetSettings(); -}; - -/** - * An enum of plugin types. - */ -typedef enum { - ANALYZER, /**< An analyzer plugin*/ - ACTION, /**< An action plugin*/ - REPORTER, /**< A reporter plugin*/ - DATABASE, /**< A database plugin*/ - MAX_PLUGIN_TYPE = DATABASE, - INVALID_PLUGIN_TYPE -} plugin_type_t; - -/** - * A struct contains all needed data about particular plugin. - */ -typedef struct SPluginInfo -{ - const plugin_type_t m_Type; /**< Plugin type.*/ - const char *const m_sName; /**< Plugin name.*/ - const char *const m_sVersion; /**< Plugin version.*/ - const char *const m_sDescription; /**< Plugin description.*/ - const char *const m_sEmail; /**< Plugin author's email.*/ - const char *const m_sWWW; /**< Plugin's home page.*/ - const char *const m_sGTKBuilder; /**< Plugin's gui description.*/ - const int m_nMagicNumber; /**< Plugin magical number.*/ -} plugin_info_t; - -#define PLUGIN_INFO(type, plugin_class, name, version, description, email, www, gtk_builder)\ - extern "C" CPlugin* plugin_new()\ - {\ - return new plugin_class();\ - }\ - extern "C" const plugin_info_t plugin_info =\ - {\ - type,\ - name,\ - version,\ - description,\ - email,\ - www,\ - gtk_builder,\ - PLUGINS_MAGIC_NUMBER,\ - }; #endif diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 6d6c22bb..20fbd4ed 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -78,8 +78,7 @@ libabrt_dbus_la_LIBADD = \ $(DBUS_LIBS) libabrt_daemon_la_SOURCES = \ - CommLayerInner.cpp \ - Plugin.cpp + CommLayerInner.cpp libabrt_daemon_la_CPPFLAGS = \ -I$(srcdir)/../include/report -I$(srcdir)/../include \ -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \ @@ -93,8 +92,7 @@ libabrt_daemon_la_CPPFLAGS = \ -D_GNU_SOURCE libabrt_daemon_la_LDFLAGS = \ -version-info 0:1:0 -libabrt_daemon_la_LIBADD = \ - -ldl +libabrt_daemon_la_LIBADD = libabrt_web_la_SOURCES = \ abrt_curl.h abrt_curl.c \ diff --git a/src/lib/Plugin.cpp b/src/lib/Plugin.cpp deleted file mode 100644 index 0c2137f5..00000000 --- a/src/lib/Plugin.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com) - Copyright (C) 2009 RedHat inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include "plugin.h" -#include "abrtlib.h" - -CPlugin::CPlugin() {} - -/* class CPlugin's virtuals */ -CPlugin::~CPlugin() {} -void CPlugin::Init() {} -void CPlugin::DeInit() {} -void CPlugin::SetSettings(const map_plugin_settings_t& pSettings) -{ - m_pSettings = pSettings; - VERB3 - { - log("SetSettings:"); - map_plugin_settings_t::const_iterator it = m_pSettings.begin(); - while (it != m_pSettings.end()) - { - log(" settings[%s]='%s'", it->first.c_str(), it->second.c_str()); - it++; - } - } -} diff --git a/src/plugins/CCpp.cpp b/src/plugins/CCpp.cpp deleted file mode 100644 index df2c4482..00000000 --- a/src/plugins/CCpp.cpp +++ /dev/null @@ -1,301 +0,0 @@ -/* - CCpp.cpp - - Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com) - Copyright (C) 2009 RedHat inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#include <set> -#include "abrtlib.h" -#include "CCpp.h" -#include "comm_layer_inner.h" - -using namespace std; - -#define CORE_PATTERN_IFACE "/proc/sys/kernel/core_pattern" -/* - * %s - signal number - * %c - ulimit -c value - * %p - pid - * %u - uid - * %g - gid - * %t - UNIX time of dump - * %h - hostname - * %e - executable filename - * %% - output one "%" - */ -#define CORE_PATTERN "|"CCPP_HOOK_PATH" "DEBUG_DUMPS_DIR" %s %c %p %u %g %t %h %e" - -#define CORE_PIPE_LIMIT_IFACE "/proc/sys/kernel/core_pipe_limit" -/* core_pipe_limit specifies how many dump_helpers might run at the same time - * 0 - means unlimited, but it's not guaranteed that /proc/<pid> of crashing - * process will be available for dump_helper. - * 4 - means that 4 dump_helpers can run at the same time (the rest will also - * run, but they will fail to read /proc/<pid>). - * This should be enough for ABRT, we can miss some crashes, but what are - * the odds that more processes crash at the same time? - * The value of 4 has been recommended by nhorman. - */ -#define CORE_PIPE_LIMIT "4" - -#define DEBUGINFO_CACHE_DIR LOCALSTATEDIR"/cache/abrt-di" - -CAnalyzerCCpp::CAnalyzerCCpp() : - m_bBacktrace(true), - m_bBacktraceRemotes(false), - m_bMemoryMap(false), - m_bInstallDebugInfo(true), - m_nDebugInfoCacheMB(4000), - m_nGdbTimeoutSec(60) -{} - -/* - this is just a workaround until kernel changes it's behavior - when handling pipes in core_pattern -*/ -#ifdef HOSTILE_KERNEL -#define CORE_SIZE_PATTERN "Max core file size=1:unlimited" -static int isdigit_str(char *str) -{ - do { - if (*str < '0' || *str > '9') - return 0; - } while (*++str); - return 1; -} - -static int set_limits() -{ - DIR *dir = opendir("/proc"); - if (!dir) { - /* this shouldn't fail, but to be safe.. */ - return 1; - } - - struct dirent *ent; - while ((ent = readdir(dir)) != NULL) { - if (!isdigit_str(ent->d_name)) - continue; - - char limits_name[sizeof("/proc/%s/limits") + sizeof(long)*3]; - snprintf(limits_name, sizeof(limits_name), "/proc/%s/limits", ent->d_name); - FILE *limits_fp = fopen(limits_name, "r"); - if (!limits_fp) { - break; - } - - char line[128]; - char *ulimit_c = NULL; - while (1) { - if (fgets(line, sizeof(line)-1, limits_fp) == NULL) - break; - if (strncmp(line, "Max core file size", sizeof("Max core file size")-1) == 0) { - ulimit_c = skip_whitespace(line + sizeof("Max core file size")-1); - skip_non_whitespace(ulimit_c)[0] = '\0'; - break; - } - } - fclose(limits_fp); - if (!ulimit_c || ulimit_c[0] != '0' || ulimit_c[1] != '\0') { - /*process has nonzero ulimit -c, so need to modify it*/ - continue; - } - /* echo -n 'Max core file size=1:unlimited' >/proc/PID/limits */ - int fd = open(limits_name, O_WRONLY); - if (fd >= 0) { - errno = 0; - /*full_*/ - ssize_t n = write(fd, CORE_SIZE_PATTERN, sizeof(CORE_SIZE_PATTERN)-1); - if (n < sizeof(CORE_SIZE_PATTERN)-1) - log("warning: can't write core_size limit to: %s", limits_name); - close(fd); - } - else - { - log("warning: can't open %s for writing", limits_name); - } - } - closedir(dir); - return 0; -} -#endif /* HOSTILE_KERNEL */ - -void CAnalyzerCCpp::Init() -{ - FILE *fp = fopen(CORE_PATTERN_IFACE, "r"); - if (fp) - { - char line[PATH_MAX]; - if (fgets(line, sizeof(line), fp)) - m_sOldCorePattern = line; - fclose(fp); - } - if (m_sOldCorePattern[0] == '|') - { - if (strncmp(m_sOldCorePattern.c_str(), CORE_PATTERN, strlen(CORE_PATTERN)) == 0) - { - log("warning: %s already contains %s, " - "did abrt daemon crash recently?", - CORE_PATTERN_IFACE, CORE_PATTERN); - /* There is no point in "restoring" CORE_PATTERN_IFACE - * to CORE_PATTERN on exit. Will restore to a default value: - */ - m_sOldCorePattern = "core"; - } else { - log("warning: %s was already set to run a crash analyser (%s), " - "abrt may interfere with it", - CORE_PATTERN_IFACE, CORE_PATTERN); - } - } -#ifdef HOSTILE_KERNEL - if (set_limits() != 0) - log("warning: failed to set core_size limit, ABRT won't detect crashes in" - "compiled apps"); -#endif - - fp = fopen(CORE_PATTERN_IFACE, "w"); - if (fp) - { - if (m_sOldCorePattern[0] != '|') - { - const char *old = m_sOldCorePattern.c_str(); - unsigned len = strchrnul(old, '\n') - old; - char *hex_old = (char*)xmalloc(len * 2 + 1); - bin2hex(hex_old, old, len)[0] = '\0'; - /* Trailing 00 is a sentinel. Decoder in the hook will check it. - * If it won't see it, then kernel has truncated the argument: - */ - char *pattern = xasprintf("%s %s00", CORE_PATTERN, hex_old); - //log("old:'%s'->'%s'", old, hex_old); - //log("pattern:'%s'", pattern); - - fputs(pattern, fp); - - free(pattern); - free(hex_old); - } - else - { - fputs(CORE_PATTERN, fp); - } - fclose(fp); - } - - /* read the core_pipe_limit and change it if it's == 0 - * otherwise the abrt-hook-ccpp won't be able to read /proc/<pid> - * of the crashing process - */ - fp = fopen(CORE_PIPE_LIMIT_IFACE, "r"); - if (fp) - { - /* we care only about the first char, if it's - * not '0' then we don't have to change it, - * because it means that it's already != 0 - */ - char pipe_limit[2]; - if (!fgets(pipe_limit, sizeof(pipe_limit), fp)) - pipe_limit[0] = '1'; /* not 0 */ - fclose(fp); - if (pipe_limit[0] == '0') - { - fp = fopen(CORE_PIPE_LIMIT_IFACE, "w"); - if (fp) - { - fputs(CORE_PIPE_LIMIT, fp); - fclose(fp); - } - else - { - log("warning: failed to set core_pipe_limit, ABRT won't detect" - "crashes in compiled apps if kernel > 2.6.31"); - } - } - } -} - -void CAnalyzerCCpp::DeInit() -{ - /* no need to restore the core_pipe_limit, because it's only used - when there is s pipe in core_pattern - */ - FILE *fp = fopen(CORE_PATTERN_IFACE, "w"); - if (fp) - { - fputs(m_sOldCorePattern.c_str(), fp); - fclose(fp); - } -} - -void CAnalyzerCCpp::SetSettings(const map_plugin_settings_t& pSettings) -{ - m_pSettings = pSettings; - - map_plugin_settings_t::const_iterator end = pSettings.end(); - map_plugin_settings_t::const_iterator it; - it = pSettings.find("Backtrace"); - if (it != end) - { - m_bBacktrace = string_to_bool(it->second.c_str()); - } - it = pSettings.find("BacktraceRemotes"); - if (it != end) - { - m_bBacktraceRemotes = string_to_bool(it->second.c_str()); - } - it = pSettings.find("MemoryMap"); - if (it != end) - { - m_bMemoryMap = string_to_bool(it->second.c_str()); - } - it = pSettings.find("DebugInfo"); - if (it != end) - { - m_sDebugInfo = it->second; - } - it = pSettings.find("DebugInfoCacheMB"); - if (it != end) - { - m_nDebugInfoCacheMB = xatou(it->second.c_str()); - } - it = pSettings.find("GdbTimeoutSec"); - if (it != end) - { - m_nGdbTimeoutSec = xatoi_positive(it->second.c_str()); - } - it = pSettings.find("InstallDebugInfo"); - if (it == end) //compat, remove after 0.0.11 - it = pSettings.find("InstallDebuginfo"); - if (it != end) - { - m_bInstallDebugInfo = string_to_bool(it->second.c_str()); - } - m_sDebugInfoDirs = DEBUGINFO_CACHE_DIR; - it = pSettings.find("ReadonlyLocalDebugInfoDirs"); - if (it != end) - { - m_sDebugInfoDirs += ':'; - m_sDebugInfoDirs += it->second; - } -} - -PLUGIN_INFO(ANALYZER, - CAnalyzerCCpp, - "CCpp", - "0.0.1", - _("Analyzes crashes in C/C++ programs"), - "zprikryl@redhat.com", - "https://fedorahosted.org/abrt/wiki", - ""); diff --git a/src/plugins/CCpp.h b/src/plugins/CCpp.h deleted file mode 100644 index e95b4d09..00000000 --- a/src/plugins/CCpp.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - CCpp.h - header file for C/C++ analyzer plugin - - it can get UUID and memory maps from core files - - Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com) - Copyright (C) 2009 RedHat inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -#ifndef CCPP_H_ -#define CCPP_H_ - -#include <string> -#include "plugin.h" -#include "analyzer.h" - -class CAnalyzerCCpp : public CAnalyzer -{ - private: - bool m_bBacktrace; - bool m_bBacktraceRemotes; - bool m_bMemoryMap; - bool m_bInstallDebugInfo; - unsigned m_nDebugInfoCacheMB; - unsigned m_nGdbTimeoutSec; - std::string m_sOldCorePattern; - std::string m_sDebugInfo; - std::string m_sDebugInfoDirs; - - public: - CAnalyzerCCpp(); - virtual void Init(); - virtual void DeInit(); - virtual void SetSettings(const map_plugin_settings_t& pSettings); -}; - -#endif /* CCPP */ diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index f70198be..3ba454e2 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am @@ -16,9 +16,6 @@ bin_PROGRAMS = \ abrt-action-mailx \ abrt-action-print -pluginslib_LTLIBRARIES = \ - libCCpp.la - dist_pluginslib_DATA = \ Logger.glade \ Mailx.glade \ @@ -58,22 +55,6 @@ install-data-hook: $(DESTDIR)/$(DEBUG_INFO_DIR) sed 's: = /var/: = $(localstatedir)/:g' -i \ $(DESTDIR)$(sysconfdir)/abrt/plugins/Logger.conf -# CCpp -libCCpp_la_SOURCES = \ - CCpp.cpp CCpp.h -libCCpp_la_CPPFLAGS = \ - -I$(srcdir)/../include/report -I$(srcdir)/../include \ - -I$(srcdir)/../lib \ - -DCCPP_HOOK_PATH=\"${libexecdir}/abrt-hook-ccpp\" \ - -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \ - -DLOCALSTATEDIR='"$(localstatedir)"' \ - $(GLIB_CFLAGS) \ - -D_GNU_SOURCE \ - -Wall -Werror -# -DHOSTILE_KERNEL -libCCpp_la_LDFLAGS = \ - -avoid-version - abrt_dump_oops_SOURCES = \ abrt-dump-oops.c abrt_dump_oops_CPPFLAGS = \ |