diff options
author | Nikola Pajkovsky <npajkovs@redhat.com> | 2010-10-05 14:57:07 +0200 |
---|---|---|
committer | Nikola Pajkovsky <npajkovs@redhat.com> | 2010-10-05 14:57:07 +0200 |
commit | 818b3ef9e19c0d516b26cafa35777ae5319eb9e3 (patch) | |
tree | 869e44160d9404684d9043acdde580dc07783fe7 | |
parent | 1726bc056f6743170ca5c8cceb272f90deeb27e4 (diff) | |
parent | e7aaba4e7b10e0412f4377a9f2f9ebf48aef8441 (diff) | |
download | abrt-818b3ef9e19c0d516b26cafa35777ae5319eb9e3.tar.gz abrt-818b3ef9e19c0d516b26cafa35777ae5319eb9e3.tar.xz abrt-818b3ef9e19c0d516b26cafa35777ae5319eb9e3.zip |
Merge branch 'settings'
* settings:
g_settings_sWatchCrashdumpArchiveDir uses char*
g_settings_sDatabase uses char*
g_settings_setBlackListedPaths uses GList
g_settings_setBlackListedPkgs uses GList
g_settings_setOpenGPGPublicKeys uses GList
-rw-r--r-- | src/daemon/CrashWatcher.cpp | 6 | ||||
-rw-r--r-- | src/daemon/Daemon.cpp | 9 | ||||
-rw-r--r-- | src/daemon/MiddleWare.cpp | 15 | ||||
-rw-r--r-- | src/daemon/Settings.cpp | 79 | ||||
-rw-r--r-- | src/daemon/Settings.h | 13 | ||||
-rw-r--r-- | src/daemon/abrt-action-save-package-data.cpp | 23 |
6 files changed, 87 insertions, 58 deletions
diff --git a/src/daemon/CrashWatcher.cpp b/src/daemon/CrashWatcher.cpp index 416d5f41..95899265 100644 --- a/src/daemon/CrashWatcher.cpp +++ b/src/daemon/CrashWatcher.cpp @@ -94,7 +94,7 @@ void CreateReport(const char* crash_id, long caller_uid, int force, map_crash_da { /* FIXME: starting from here, any shared data must be protected with a mutex. * For example, CreateCrashReport does: - * g_pPluginManager->GetDatabase(g_settings_sDatabase.c_str()); + * g_pPluginManager->GetDatabase(g_settings_sDatabase); * which is unsafe wrt concurrent updates to g_pPluginManager state. */ mw_result_t res = CreateCrashReport(crash_id, caller_uid, force, crashReport); @@ -186,7 +186,7 @@ int DeleteDebugDump(const char *crash_id, long caller_uid) { try { - CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase.c_str()); + CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase); database->Connect(); struct db_row *row = database->GetRow(crash_id); if (!row) @@ -227,7 +227,7 @@ void DeleteDebugDump_by_dir(const char *dump_dir) { try { - CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase.c_str()); + CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase); database->Connect(); database->DeleteRows_by_dir(dump_dir); database->DisConnect(); diff --git a/src/daemon/Daemon.cpp b/src/daemon/Daemon.cpp index 719bc758..7f36b318 100644 --- a/src/daemon/Daemon.cpp +++ b/src/daemon/Daemon.cpp @@ -597,7 +597,7 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin if (ext && strcmp(ext + 1, "working") == 0) continue; - const char *dir = g_settings_sWatchCrashdumpArchiveDir.c_str(); + const char *dir = g_settings_sWatchCrashdumpArchiveDir; log("Detected creation of file '%s' in upload directory '%s'", name, dir); if (fork() == 0) { @@ -996,11 +996,11 @@ int main(int argc, char** argv) /* Watching DEBUG_DUMPS_DIR for new files... */ if (inotify_add_watch(inotify_fd, DEBUG_DUMPS_DIR, IN_CREATE | IN_MOVED_TO) < 0) perror_msg_and_die("inotify_add_watch failed on '%s'", DEBUG_DUMPS_DIR); - if (!g_settings_sWatchCrashdumpArchiveDir.empty()) + if (g_settings_sWatchCrashdumpArchiveDir) { - s_upload_watch = inotify_add_watch(inotify_fd, g_settings_sWatchCrashdumpArchiveDir.c_str(), IN_CLOSE_WRITE|IN_MOVED_TO); + s_upload_watch = inotify_add_watch(inotify_fd, g_settings_sWatchCrashdumpArchiveDir, IN_CLOSE_WRITE|IN_MOVED_TO); if (s_upload_watch < 0) - perror_msg_and_die("inotify_add_watch failed on '%s'", g_settings_sWatchCrashdumpArchiveDir.c_str()); + perror_msg_and_die("inotify_add_watch failed on '%s'", g_settings_sWatchCrashdumpArchiveDir); } VERB1 log("Adding inotify watch to glib main loop"); channel_inotify = g_io_channel_unix_new(inotify_fd); @@ -1116,6 +1116,7 @@ int main(int argc, char** argv) if (pMainloop) g_main_loop_unref(pMainloop); + settings_free(); /* Exiting */ if (s_sig_caught && s_sig_caught != SIGALRM && s_sig_caught != SIGCHLD) { diff --git a/src/daemon/MiddleWare.cpp b/src/daemon/MiddleWare.cpp index 4ff83570..ae25180f 100644 --- a/src/daemon/MiddleWare.cpp +++ b/src/daemon/MiddleWare.cpp @@ -274,7 +274,7 @@ mw_result_t CreateCrashReport(const char *crash_id, { VERB2 log("CreateCrashReport('%s',%ld,result)", crash_id, caller_uid); - CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase.c_str()); + CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase); database->Connect(); struct db_row *row = database->GetRow(crash_id); @@ -573,7 +573,7 @@ report_status_t Report(const map_crash_data_t& client_report, if (at_least_one_reporter_succeeded) { - CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase.c_str()); + CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase); database->Connect(); report_status_t::iterator ret_it = ret.begin(); while (ret_it != ret.end()) @@ -609,10 +609,7 @@ report_status_t Report(const map_crash_data_t& client_report, */ static bool is_debug_dump_saved(long uid, const char *debug_dump_dir) { - if (g_settings_sDatabase.empty()) - error_msg_and_die(_("Database plugin not specified. Please check abrtd settings.")); - - CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase.c_str()); + CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase); database->Connect(); GList *table = database->GetUIDData(uid); database->DisConnect(); @@ -792,7 +789,7 @@ static mw_result_t SaveDebugDumpToDatabase(const char *crash_id, const char *pDebugDumpDir, map_crash_data_t& pCrashData) { - CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase.c_str()); + CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase); database->Connect(); /* note: if [UUID,UID] record exists, pDebugDumpDir is not updated in the record */ database->Insert_or_Update(crash_id, inform_all_users, pDebugDumpDir, pTime); @@ -888,7 +885,7 @@ error: mw_result_t FillCrashInfo(const char *crash_id, map_crash_data_t& pCrashData) { - CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase.c_str()); + CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase); database->Connect(); struct db_row *row = database->GetRow(crash_id); database->DisConnect(); @@ -922,7 +919,7 @@ mw_result_t FillCrashInfo(const char *crash_id, void GetUUIDsOfCrash(long caller_uid, vector_string_t &result) { - CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase.c_str()); + CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase); database->Connect(); GList *rows = database->GetUIDData(caller_uid); database->DisConnect(); diff --git a/src/daemon/Settings.cpp b/src/daemon/Settings.cpp index a77e482b..f7b7d2ef 100644 --- a/src/daemon/Settings.cpp +++ b/src/daemon/Settings.cpp @@ -51,11 +51,11 @@ static map_string_t s_mapSectionCron; /* one line: "OpenGPGCheck = value" */ bool g_settings_bOpenGPGCheck = false; /* one line: "OpenGPGPublicKeys = value1,value2" */ -set_string_t g_settings_setOpenGPGPublicKeys; -set_string_t g_settings_setBlackListedPkgs; -set_string_t g_settings_setBlackListedPaths; -std::string g_settings_sDatabase; -std::string g_settings_sWatchCrashdumpArchiveDir; +GList *g_settings_setOpenGPGPublicKeys = NULL; +GList *g_settings_setBlackListedPkgs = NULL; +GList *g_settings_setBlackListedPaths = NULL; +char *g_settings_sDatabase = NULL; +char *g_settings_sWatchCrashdumpArchiveDir = NULL; unsigned int g_settings_nMaxCrashReportsSize = 1000; bool g_settings_bProcessUnpackaged = false; @@ -73,28 +73,27 @@ map_cron_t g_settings_mapCron; * Loading */ -static set_string_t ParseList(const char* pList) +static GList *parse_list(const char* list) { - unsigned ii; - std::string item; - set_string_t set; - for (ii = 0; pList[ii]; ii++) + struct strbuf *item = strbuf_new(); + GList *l = NULL; + + for (unsigned ii = 0; list[ii]; ii++) { - if (pList[ii] == ',') + if (list[ii] == ',') { - set.insert(item); - item = ""; + l = g_list_append(l, xstrdup(item->buf)); + strbuf_clear(item); } else - { - item += pList[ii]; - } + strbuf_append_char(item, list[ii]); } - if (item != "") - { - set.insert(item); - } - return set; + + if (item->len > 0) + l = g_list_append(l, xstrdup(item->buf)); + + strbuf_free(item); + return l; } /* Format: name, name(param),name("param with spaces \"and quotes\"") */ @@ -203,22 +202,28 @@ static int ParseCommon() it = s_mapSectionCommon.find("BlackList"); if (it != end) { - g_settings_setBlackListedPkgs = ParseList(it->second.c_str()); + g_settings_setBlackListedPkgs = parse_list(it->second.c_str()); } it = s_mapSectionCommon.find("BlackListedPaths"); if (it != end) { - g_settings_setBlackListedPaths = ParseList(it->second.c_str()); + g_settings_setBlackListedPaths = parse_list(it->second.c_str()); } it = s_mapSectionCommon.find("Database"); if (it != end) { - g_settings_sDatabase = it->second; + if (it->second.empty()) + error_msg_and_die(_("Database plugin not specified. Please check abrtd settings.")); + + g_settings_sDatabase = xstrdup(it->second.c_str()); } + else + error_msg_and_die(_("Database plugin not specified. Please check abrtd settings.")); + it = s_mapSectionCommon.find("WatchCrashdumpArchiveDir"); if (it != end) { - g_settings_sWatchCrashdumpArchiveDir = it->second; + g_settings_sWatchCrashdumpArchiveDir = xstrdup(it->second.c_str()); } it = s_mapSectionCommon.find("MaxCrashReportsSize"); if (it != end) @@ -348,7 +353,7 @@ static void LoadGPGKeys() if (line[0] == '/') // probably the begining of path, so let's handle it as a key { strchrnul(line, '\n')[0] = '\0'; - g_settings_setOpenGPGPublicKeys.insert(line); + g_settings_setOpenGPGPublicKeys = g_list_append(g_settings_setOpenGPGPublicKeys, xstrdup(line)); } } fclose(fp); @@ -559,3 +564,25 @@ void SetSettings(const map_abrt_settings_t& pSettings, const char *dbus_sender) ParseCron(); } } + +void settings_free() +{ + for (GList *li = g_settings_setOpenGPGPublicKeys; li != NULL; li = g_list_next(li)) + free((char*)li->data); + + g_list_free(g_settings_setOpenGPGPublicKeys); + + for (GList *li = g_settings_setBlackListedPkgs; li != NULL; li = g_list_next(li)) + free((char*)li->data); + + g_list_free(g_settings_setBlackListedPkgs); + + for (GList *li = g_settings_setBlackListedPaths; li != NULL; li = g_list_next(li)) + free((char*)li->data); + + g_list_free(g_settings_setBlackListedPaths); + + free(g_settings_sDatabase); + + free(g_settings_sWatchCrashdumpArchiveDir); +} diff --git a/src/daemon/Settings.h b/src/daemon/Settings.h index 3103dbd5..5ee365f6 100644 --- a/src/daemon/Settings.h +++ b/src/daemon/Settings.h @@ -20,19 +20,20 @@ #define SETTINGS_H_ #include "abrt_types.h" +#include <glib.h> typedef map_vector_pair_string_string_t map_analyzer_actions_and_reporters_t; typedef map_vector_pair_string_string_t map_cron_t; typedef map_map_string_t map_abrt_settings_t; -extern set_string_t g_settings_setOpenGPGPublicKeys; -extern set_string_t g_settings_setBlackListedPkgs; -extern set_string_t g_settings_setBlackListedPaths; +extern GList *g_settings_setOpenGPGPublicKeys; +extern GList *g_settings_setBlackListedPkgs; +extern GList *g_settings_setBlackListedPaths; extern unsigned int g_settings_nMaxCrashReportsSize; extern bool g_settings_bOpenGPGCheck; extern bool g_settings_bProcessUnpackaged; -extern std::string g_settings_sDatabase; -extern std::string g_settings_sWatchCrashdumpArchiveDir; +extern char *g_settings_sDatabase; +extern char *g_settings_sWatchCrashdumpArchiveDir; extern map_cron_t g_settings_mapCron; extern vector_pair_string_string_t g_settings_vectorActionsAndReporters; extern map_analyzer_actions_and_reporters_t g_settings_mapAnalyzerActionsAndReporters; @@ -42,4 +43,6 @@ void SaveSettings(); void SetSettings(const map_abrt_settings_t& pSettings, const char * dbus_sender); map_abrt_settings_t GetSettings(); +void settings_free(); + #endif diff --git a/src/daemon/abrt-action-save-package-data.cpp b/src/daemon/abrt-action-save-package-data.cpp index bd18bc86..9a5a1748 100644 --- a/src/daemon/abrt-action-save-package-data.cpp +++ b/src/daemon/abrt-action-save-package-data.cpp @@ -64,14 +64,12 @@ static char *get_argv1_if_full_path(const char* cmdline) static bool is_path_blacklisted(const char *path) { - set_string_t::iterator it = g_settings_setBlackListedPaths.begin(); - while (it != g_settings_setBlackListedPaths.end()) + for (GList *li = g_settings_setBlackListedPaths; li != NULL; li = g_list_next(li)) { - if (fnmatch(it->c_str(), path, /*flags:*/ 0) == 0) + if (fnmatch((char*)li->data, path, /*flags:*/ 0) == 0) { return true; } - it++; } return false; } @@ -197,11 +195,15 @@ static int SavePackageDescriptionToDebugDump(const char *dump_dir_name) package_short_name = get_package_name_from_NVR_or_NULL(package_full_name); VERB2 log("Package:'%s' short:'%s'", package_full_name, package_short_name); - if (g_settings_setBlackListedPkgs.find(package_short_name) != g_settings_setBlackListedPkgs.end()) + for (GList *li = g_settings_setBlackListedPkgs; li != NULL; li = g_list_next(li)) { - log("Blacklisted package '%s'", package_short_name); - goto ret; /* return 1 (failure) */ + if (strcmp((char*)li->data, package_short_name) == 0) + { + log("Blacklisted package '%s'", package_short_name); + goto ret; /* return 1 (failure) */ + } } + if (g_settings_bOpenGPGCheck && !remote) { if (rpm_chk_fingerprint(package_short_name)) @@ -320,11 +322,10 @@ int main(int argc, char **argv) VERB1 log("Initializing rpm library"); rpm_init(); - set_string_t::iterator it_k = g_settings_setOpenGPGPublicKeys.begin(); - for (; it_k != g_settings_setOpenGPGPublicKeys.end(); it_k++) + for (GList *li = g_settings_setOpenGPGPublicKeys; li != NULL; li = g_list_next(li)) { - VERB1 log("Loading GPG key '%s'", it_k->c_str()); - rpm_load_gpgkey(it_k->c_str()); + VERB1 log("Loading GPG key '%s'", (char*)li->data); + rpm_load_gpgkey((char*)li->data); } return SavePackageDescriptionToDebugDump(dump_dir_name); |