diff options
| author | Denys Vlasenko <dvlasenk@redhat.com> | 2010-11-10 00:10:22 +0100 |
|---|---|---|
| committer | Denys Vlasenko <dvlasenk@redhat.com> | 2010-11-10 00:10:22 +0100 |
| commit | 9d2cb4518c3a8a72ccc714ddbc131aaa84506092 (patch) | |
| tree | e21efa47e3ed2e2f911c87fad8d0d992f236124a | |
| parent | d1c6a4329284a1daba12a7e0fbd743a90cb0d884 (diff) | |
| download | abrt-9d2cb4518c3a8a72ccc714ddbc131aaa84506092.tar.gz abrt-9d2cb4518c3a8a72ccc714ddbc131aaa84506092.tar.xz abrt-9d2cb4518c3a8a72ccc714ddbc131aaa84506092.zip | |
Decouple settings handling from old-style plugins
The breakage was discovered when i removed Logger class.
it turned out the fix is somewhat involved.
This change implements it as discussed with the rest of the team.
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
| -rw-r--r-- | abrt.spec | 1 | ||||
| -rw-r--r-- | inc/abrtlib.h | 2 | ||||
| -rw-r--r-- | inc/plugin.h | 3 | ||||
| -rw-r--r-- | lib/plugins/Bugzilla.conf | 2 | ||||
| -rw-r--r-- | lib/plugins/CCpp.h | 2 | ||||
| -rw-r--r-- | lib/plugins/FileTransfer.h | 2 | ||||
| -rw-r--r-- | lib/plugins/Logger.conf | 8 | ||||
| -rw-r--r-- | lib/plugins/Mailx.conf | 2 | ||||
| -rw-r--r-- | lib/plugins/Makefile.am | 4 | ||||
| -rw-r--r-- | lib/plugins/RHTSupport.conf | 2 | ||||
| -rw-r--r-- | lib/plugins/ReportUploader.conf | 2 | ||||
| -rw-r--r-- | lib/utils/Makefile.am | 1 | ||||
| -rw-r--r-- | lib/utils/Plugin.cpp | 15 | ||||
| -rw-r--r-- | lib/utils/overlapping_strcpy.c | 22 | ||||
| -rw-r--r-- | src/daemon/CommLayerServerDBus.cpp | 8 | ||||
| -rw-r--r-- | src/daemon/Daemon.cpp | 4 | ||||
| -rw-r--r-- | src/daemon/MiddleWare.cpp | 83 | ||||
| -rw-r--r-- | src/daemon/MiddleWare.h | 5 | ||||
| -rw-r--r-- | src/daemon/PluginManager.cpp | 31 | ||||
| -rw-r--r-- | src/daemon/PluginManager.h | 14 | ||||
| -rw-r--r-- | src/daemon/abrt-action-print.cpp | 11 |
21 files changed, 134 insertions, 90 deletions
@@ -417,6 +417,7 @@ fi %files plugin-logger %defattr(-,root,root,-) +%config(noreplace) %{_sysconfdir}/%{name}/plugins/Logger.conf %{_libdir}/%{name}/Logger.glade %{_mandir}/man7/abrt-Logger.7.gz %{_bindir}/abrt-action-print diff --git a/inc/abrtlib.h b/inc/abrtlib.h index a665b10f..4d565644 100644 --- a/inc/abrtlib.h +++ b/inc/abrtlib.h @@ -93,6 +93,8 @@ char *concat_path_file(const char *path, const char *filename); char *append_to_malloced_string(char *mstr, const char *append); char* skip_whitespace(const char *s); char* skip_non_whitespace(const char *s); +/* Like strcpy but can copy overlapping strings. */ +void overlapping_strcpy(char *dst, const char *src); /* A-la fgets, but malloced and of unlimited size */ char *xmalloc_fgets(FILE *file); diff --git a/inc/plugin.h b/inc/plugin.h index a22d0f67..e0f45b6c 100644 --- a/inc/plugin.h +++ b/inc/plugin.h @@ -63,7 +63,8 @@ class CPlugin * A method, which return current settings. It is not mandatory method. * @return Plugin's settings */ - virtual const map_plugin_settings_t& GetSettings(); +/// +// virtual const map_plugin_settings_t& GetSettings(); }; /** diff --git a/lib/plugins/Bugzilla.conf b/lib/plugins/Bugzilla.conf index 4eebd994..76e0d1d8 100644 --- a/lib/plugins/Bugzilla.conf +++ b/lib/plugins/Bugzilla.conf @@ -1,3 +1,5 @@ +# Description: Reports bugs to bugzilla + Enabled = yes # Bugzilla URL diff --git a/lib/plugins/CCpp.h b/lib/plugins/CCpp.h index db372b01..e95b4d09 100644 --- a/lib/plugins/CCpp.h +++ b/lib/plugins/CCpp.h @@ -44,8 +44,6 @@ class CAnalyzerCCpp : public CAnalyzer virtual void Init(); virtual void DeInit(); virtual void SetSettings(const map_plugin_settings_t& pSettings); -//ok to delete? -// virtual const map_plugin_settings_t& GetSettings(); }; #endif /* CCPP */ diff --git a/lib/plugins/FileTransfer.h b/lib/plugins/FileTransfer.h index 5e9f4938..17bebf3d 100644 --- a/lib/plugins/FileTransfer.h +++ b/lib/plugins/FileTransfer.h @@ -40,8 +40,6 @@ class CFileTransfer : public CAction public: CFileTransfer(); virtual void SetSettings(const map_plugin_settings_t& pSettings); -//ok to delete? -// virtual const map_plugin_settings_t& GetSettings(); virtual void Run(const char *pActionDir, const char *pArgs, int force); }; diff --git a/lib/plugins/Logger.conf b/lib/plugins/Logger.conf new file mode 100644 index 00000000..aadd3515 --- /dev/null +++ b/lib/plugins/Logger.conf @@ -0,0 +1,8 @@ +# Description: Writes report to a file + +# Configuration for Logger plugin +Enabled = yes + +LogPath = /var/log/abrt.log + +AppendLogs = yes diff --git a/lib/plugins/Mailx.conf b/lib/plugins/Mailx.conf index ccd14292..1d946427 100644 --- a/lib/plugins/Mailx.conf +++ b/lib/plugins/Mailx.conf @@ -1,3 +1,5 @@ +# Description: Sends an email with a report (using mailx command) + # Configuration to Email reporter plugin Enabled = yes diff --git a/lib/plugins/Makefile.am b/lib/plugins/Makefile.am index 2f1e7966..caf5ea27 100644 --- a/lib/plugins/Makefile.am +++ b/lib/plugins/Makefile.am @@ -27,6 +27,7 @@ dist_pluginsconf_DATA = \ CCpp.conf \ Mailx.conf \ SQLite3.conf \ + Logger.conf \ Kerneloops.conf \ Bugzilla.conf \ RHTSupport.conf \ @@ -53,7 +54,8 @@ $(DESTDIR)/$(DEBUG_INFO_DIR): install-data-hook: $(DESTDIR)/$(DEBUG_INFO_DIR) sed 's: = /var/: = $(localstatedir)/:g' -i \ - $(DESTDIR)$(sysconfdir)/abrt/plugins/SQLite3.conf + $(DESTDIR)$(sysconfdir)/abrt/plugins/SQLite3.conf \ + $(DESTDIR)$(sysconfdir)/abrt/plugins/Logger.conf INC_PATH=$(srcdir)/../../inc UTILS_PATH=$(srcdir)/../utils diff --git a/lib/plugins/RHTSupport.conf b/lib/plugins/RHTSupport.conf index ed2c3a85..ecd5992a 100644 --- a/lib/plugins/RHTSupport.conf +++ b/lib/plugins/RHTSupport.conf @@ -1,3 +1,5 @@ +# Description: Reports crashes to Red Hat support + Enabled = yes URL = https://api.access.redhat.com/rs diff --git a/lib/plugins/ReportUploader.conf b/lib/plugins/ReportUploader.conf index 57692531..7a7b9133 100644 --- a/lib/plugins/ReportUploader.conf +++ b/lib/plugins/ReportUploader.conf @@ -1,3 +1,5 @@ +# Description: Packs crash data into .tar.gz file, optionally uploads it via FTP/SCP/etc + Enabled = yes # Customer = "Example Inc." diff --git a/lib/utils/Makefile.am b/lib/utils/Makefile.am index 129feeb5..37508ee7 100644 --- a/lib/utils/Makefile.am +++ b/lib/utils/Makefile.am @@ -16,6 +16,7 @@ libABRTUtils_la_SOURCES = \ xfuncs.c \ concat_path_file.c \ append_to_malloced_string.c \ + overlapping_strcpy.c \ encbase64.c \ stdio_helpers.c \ hash_md5.c hash_md5.h \ diff --git a/lib/utils/Plugin.cpp b/lib/utils/Plugin.cpp index 8c00e609..bf237959 100644 --- a/lib/utils/Plugin.cpp +++ b/lib/utils/Plugin.cpp @@ -40,21 +40,6 @@ void CPlugin::SetSettings(const map_plugin_settings_t& pSettings) } } -const map_plugin_settings_t& CPlugin::GetSettings() -{ - VERB3 - { - log("GetSettings:"); - 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++; - } - } - return m_pSettings; -} - bool LoadPluginSettings(const char *pPath, map_plugin_settings_t& pSettings, bool skipKeysWithoutValue /*= true*/) { diff --git a/lib/utils/overlapping_strcpy.c b/lib/utils/overlapping_strcpy.c new file mode 100644 index 00000000..41c1c1a1 --- /dev/null +++ b/lib/utils/overlapping_strcpy.c @@ -0,0 +1,22 @@ +/* + * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> + * + * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. + */ +#include "abrtlib.h" + +/* Like strcpy but can copy overlapping strings. */ +void overlapping_strcpy(char *dst, const char *src) +{ + /* Cheap optimization for dst == src case - + * better to have it here than in many callers. + */ + if (dst != src) + { + while ((*dst = *src) != '\0') + { + dst++; + src++; + } + } +} diff --git a/src/daemon/CommLayerServerDBus.cpp b/src/daemon/CommLayerServerDBus.cpp index 5ce8e474..3e98ab80 100644 --- a/src/daemon/CommLayerServerDBus.cpp +++ b/src/daemon/CommLayerServerDBus.cpp @@ -337,7 +337,10 @@ static int handle_GetPluginsInfo(DBusMessage* call, DBusMessage* reply) { DBusMessageIter out_iter; dbus_message_iter_init_append(reply, &out_iter); - store_val(&out_iter, g_pPluginManager->GetPluginsInfo()); + + map_map_string_t map_of_plugin_info; + GetPluginsInfo(map_of_plugin_info); + store_val(&out_iter, map_of_plugin_info); send_flush_and_unref(reply); return 0; @@ -358,7 +361,8 @@ static int handle_GetPluginSettings(DBusMessage* call, DBusMessage* reply) //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()); + map_plugin_settings_t plugin_settings; + GetPluginSettings(PluginName, plugin_settings); DBusMessageIter out_iter; dbus_message_iter_init_append(reply, &out_iter); diff --git a/src/daemon/Daemon.cpp b/src/daemon/Daemon.cpp index 0aa04a30..a30b2d97 100644 --- a/src/daemon/Daemon.cpp +++ b/src/daemon/Daemon.cpp @@ -666,8 +666,8 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin const char *uid_str = get_crash_data_item_content(crashinfo, CD_UID).c_str(); /* Send dbus signal */ - if (analyzer_has_InformAllUsers(analyzer)) - uid_str = NULL; + //if (analyzer_has_InformAllUsers(analyzer)) + // uid_str = NULL; char *crash_id = xasprintf("%s:%s", get_crash_data_item_content(crashinfo, CD_UID).c_str(), get_crash_data_item_content(crashinfo, CD_UUID).c_str() diff --git a/src/daemon/MiddleWare.cpp b/src/daemon/MiddleWare.cpp index 0349514c..bc807d4b 100644 --- a/src/daemon/MiddleWare.cpp +++ b/src/daemon/MiddleWare.cpp @@ -401,20 +401,6 @@ static bool is_debug_dump_saved(const char *debug_dump_dir) return row != NULL; } -bool analyzer_has_InformAllUsers(const char *analyzer_name) -{ - CAnalyzer* analyzer = g_pPluginManager->GetAnalyzer(analyzer_name); - if (!analyzer) - { - return false; - } - map_plugin_settings_t settings = analyzer->GetSettings(); - map_plugin_settings_t::const_iterator it = settings.find("InformAllUsers"); - if (it == settings.end()) - return false; - return string_to_bool(it->second.c_str()); -} - /** * Save a debugdump into database. If saving is * successful, then crash info is filled. Otherwise the crash info is @@ -567,7 +553,7 @@ mw_result_t SaveDebugDump(const char *dump_dir_name, * else: an error code */ res = SaveDebugDumpToDatabase(state.crash_id, - analyzer_has_InformAllUsers(analyzer), + true, /*analyzer_has_InformAllUsers(analyzer),*/ time, dump_dir_name, pCrashData); @@ -844,3 +830,70 @@ void DeleteDebugDump_by_dir(const char *dump_dir) error_msg("%s", e.what()); } } + +void GetPluginsInfo(map_map_string_t &map_of_plugin_info) +{ + DIR *dir = opendir(PLUGINS_CONF_DIR); + if (!dir) + return; + + struct dirent *dent; + while ((dent = readdir(dir)) != NULL) + { + if (!is_regular_file(dent, PLUGINS_CONF_DIR)) + continue; + char *ext = strrchr(dent->d_name, '.'); + if (!ext || strcmp(ext + 1, PLUGINS_CONF_EXTENSION) != 0) + continue; + VERB3 log("Found %s", dent->d_name); + *ext = '\0'; + + char *glade_file = xasprintf(PLUGINS_LIB_DIR"/%s.glade", dent->d_name); + if (access(glade_file, F_OK) == 0) + { + *ext = '.'; + char *conf_file = concat_path_file(PLUGINS_CONF_DIR, dent->d_name); + *ext = '\0'; + FILE *fp = fopen(conf_file, "r"); + free(conf_file); + + char *descr = NULL; + if (fp) + { + descr = xmalloc_fgetline(fp); + fclose(fp); + if (descr && strncmp("# Description:", descr, strlen("# Description:")) == 0) + overlapping_strcpy(descr, skip_whitespace(descr + strlen("# Description:"))); + else + { + free(descr); + descr = NULL; + } + } + map_string_t plugin_info; + plugin_info["Name"] = dent->d_name; + plugin_info["Enabled"] = "yes"; + plugin_info["Type"] = "Reporter"; //was: plugin_type_str[module->GetType()]; field to be removed + plugin_info["Version"] = VERSION; //was: module->GetVersion(); field to be removed? + plugin_info["Description"] = descr ? descr : ""; //was: module->GetDescription(); + plugin_info["Email"] = ""; //was: module->GetEmail(); field to be removed + plugin_info["WWW"] = ""; //was: module->GetWWW(); field to be removed + plugin_info["GTKBuilder"] = glade_file; //was: module->GetGTKBuilder(); + free(descr); + map_of_plugin_info[dent->d_name] = plugin_info; + } + free(glade_file); + + } + closedir(dir); +} + +void GetPluginSettings(const char *plugin_name, map_plugin_settings_t &plugin_settings) +{ + char *conf_file = xasprintf(PLUGINS_CONF_DIR"/%s.conf", plugin_name); + LoadPluginSettings(conf_file, plugin_settings); + free(conf_file); + /* If settings are empty, most likely .conf file does not exist. + * Don't mislead the user: */ + VERB3 if (!plugin_settings.empty()) log("Loaded %s.conf", plugin_name); +} diff --git a/src/daemon/MiddleWare.h b/src/daemon/MiddleWare.h index 100a0720..cb0db9eb 100644 --- a/src/daemon/MiddleWare.h +++ b/src/daemon/MiddleWare.h @@ -130,7 +130,7 @@ void AddAnalyzerActionOrReporter(const char *pAnalyzer, const char *pActionOrReporter, const char *pArgs); -bool analyzer_has_InformAllUsers(const char *analyzer_name); +//bool analyzer_has_InformAllUsers(const char *analyzer_name); vector_map_crash_data_t GetCrashInfos(long caller_uid); int CreateReportThread(const char* crash_id, long caller_uid, int force, const char* pSender); @@ -138,4 +138,7 @@ void CreateReport(const char* crash_id, long caller_uid, int force, map_crash_da int DeleteDebugDump(const char *crash_id, long caller_uid); void DeleteDebugDump_by_dir(const char *dump_dir); +void GetPluginsInfo(map_map_string_t &map_of_plugin_info); +void GetPluginSettings(const char *plugin_name, map_plugin_settings_t &plugin_settings); + #endif /*MIDDLEWARE_H_*/ diff --git a/src/daemon/PluginManager.cpp b/src/daemon/PluginManager.cpp index ecc574d9..583b665e 100644 --- a/src/daemon/PluginManager.cpp +++ b/src/daemon/PluginManager.cpp @@ -154,7 +154,6 @@ CPlugin* CPluginManager::LoadPlugin(const char *pName, bool enabled_only) 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 */ } @@ -208,7 +207,6 @@ CPlugin* CPluginManager::LoadPlugin(const char *pName, bool enabled_only) 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); @@ -407,32 +405,3 @@ void CPluginManager::SetPluginSettings(const char *pName, */ #endif } - -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(); - 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 a00fd3e4..c372aa7f 100644 --- a/src/daemon/PluginManager.h +++ b/src/daemon/PluginManager.h @@ -53,7 +53,6 @@ class CPluginManager /** * 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: @@ -130,13 +129,6 @@ class CPluginManager */ plugin_type_t GetPluginType(const char *pName); /** - * A method, which gets all plugins info (even those plugins which are - * disabled). It can be sent via DBus to GUI and displayed to an user. - * Then user can fill all needed informations like URLs etc. - * @return A vector of maps <key, value> - */ - 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. * @param pName A plugin name. @@ -146,12 +138,6 @@ class CPluginManager void SetPluginSettings(const char *pName, const char *pUID, const map_plugin_settings_t& pSettings); - /** - * A method, which returns plugin's settings according to user. - * @param pName A plugin name. - * @return Plugin's settings. - */ - map_plugin_settings_t GetPluginSettings(const char *pName); }; #endif /*PLUGINMANAGER_H_*/ diff --git a/src/daemon/abrt-action-print.cpp b/src/daemon/abrt-action-print.cpp index 437387e1..a4db373a 100644 --- a/src/daemon/abrt-action-print.cpp +++ b/src/daemon/abrt-action-print.cpp @@ -53,18 +53,21 @@ int main(int argc, char **argv) OPT_END() }; + /*unsigned opts =*/ parse_opts(argc, argv, program_options, program_usage); + + putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); + //msg_prefix = PROGNAME; + char *env = getenv("Logger_LogPath"); + VERB3 log("output_file:'%s' Logger_LogPath env:'%s'", output_file, env); if (env) output_file = env; env = getenv("Logger_AppendLogs"); + VERB3 log("Logger_AppendLogs env:'%s'", env); if (env && string_to_bool(env)) open_mode = "a"; - /*unsigned opts =*/ parse_opts(argc, argv, program_options, program_usage); - - putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); - if (output_file) { if (!freopen(output_file, open_mode, stdout)) |
