From 47728cc3c70c2b6d3a645e5760b39b20bd946e39 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 6 Dec 2010 16:56:50 +0100 Subject: This patch changes crash data to use C structures. The smallest data element is: struct crash_item { char *content; unsigned flags; }; where content is, eh, content, and flags is a bit flag field. crash_data_t is a map of crash_item's, implemented as a pointer to heap-allocated GHashTable. vector_of_crash_data_t is a vector of crash_data_t's, implemented as a pointer to heap-allocated GPtrArray. Most operations have light wrappers around them to hide the nature of the containers. For example, to free vector_of_crash_data, you need to use free_vector_of_crash_data(ptr) instead of open-coding g_ptr_array_free. The wrapper is thin. The goal is not so much to hide the implementation, but more to make it easier to use the correct function. dbus (un)marshalling functions convert crash_item to three-element array of strings, in order to keep compatibility with abrt-gui (python). This can be changed later to use native representation. crash_data_t and vector_of_crash_data_t are represented in "natural" way, no funny stuff there. Signed-off-by: Denys Vlasenko --- src/daemon/Daemon.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'src/daemon/Daemon.cpp') diff --git a/src/daemon/Daemon.cpp b/src/daemon/Daemon.cpp index 609b0b26..62bcdc68 100644 --- a/src/daemon/Daemon.cpp +++ b/src/daemon/Daemon.cpp @@ -55,15 +55,15 @@ using namespace std; * - signal: we got SIGTERM or SIGINT * * DBus methods we have: - * - GetCrashInfos(): returns a vector_map_crash_data_t (vector_map_vector_string_t) + * - GetCrashInfos(): returns a vector_of_crash_data * of crashes for given uid * v[N]["executable"/"uid"/"kernel"/"backtrace"][N] = "contents" * - StartJob(crash_id,force): starts creating a report for /var/spool/abrt/DIR with this UID:UUID. * Returns job id (uint64). * After thread returns, when report creation thread has finished, * JobDone() dbus signal is emitted. - * - CreateReport(crash_id): returns map_crash_data_t (map_vector_string_t) - * - Report(map_crash_data_t (map_vector_string_t[, map_map_string_t])): + * - CreateReport(crash_id): returns crash data (hash table of struct crash_item) + * - Report(crash_data[, map_map_string_t]): * "Please report this crash": calls Report() of all registered reporter plugins. * Returns report_status_t (map_vector_string_t) - the status of each call. * 2nd parameter is the contents of user's abrt.conf. @@ -542,11 +542,11 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin } char *fullname = NULL; + crash_data_t *crash_data = NULL; try { fullname = concat_path_file(DEBUG_DUMPS_DIR, name); - map_crash_data_t crashinfo; - mw_result_t res = LoadDebugDump(fullname, crashinfo); + mw_result_t res = LoadDebugDump(fullname, &crash_data); switch (res) { case MW_OK: @@ -557,24 +557,24 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin { if (res != MW_OK) { - const char *first = get_crash_data_item_content_or_NULL(crashinfo, CD_DUMPDIR); + const char *first = get_crash_item_content_or_NULL(crash_data, CD_DUMPDIR); log("Deleting crash %s (dup of %s), sending dbus signal", strrchr(fullname, '/') + 1, strrchr(first, '/') + 1); delete_crash_dump_dir(fullname); } - const char *uid_str = get_crash_data_item_content_or_NULL(crashinfo, FILENAME_UID); - const char *inform_all = get_crash_data_item_content_or_NULL(crashinfo, FILENAME_INFORMALL); + const char *uid_str = get_crash_item_content_or_NULL(crash_data, FILENAME_UID); + const char *inform_all = get_crash_item_content_or_NULL(crash_data, FILENAME_INFORMALL); if (inform_all && string_to_bool(inform_all)) uid_str = NULL; char *crash_id = xasprintf("%s:%s", - get_crash_data_item_content_or_NULL(crashinfo, FILENAME_UID), - get_crash_data_item_content_or_NULL(crashinfo, FILENAME_UUID) + get_crash_item_content_or_NULL(crash_data, FILENAME_UID), + get_crash_item_content_or_NULL(crash_data, FILENAME_UUID) ); /* Send dbus signal */ - g_pCommLayer->Crash(get_crash_data_item_content_or_NULL(crashinfo, FILENAME_PACKAGE), + g_pCommLayer->Crash(get_crash_item_content_or_NULL(crash_data, FILENAME_PACKAGE), crash_id, //TODO: stop passing this param, it is unused fullname, uid_str @@ -598,9 +598,11 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin { free(fullname); free(buf); + free_crash_data(crash_data); throw; } free(fullname); + free_crash_data(crash_data); } /* while */ free(buf); -- cgit From 816f3e001271ed8ab7fdadb6d90aeb2c61362dac Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 8 Dec 2010 14:51:47 +0100 Subject: removal of C++isms from libabrt, part 1 This patch converts libabrt usage of C++ map to a glib-based container, GHashTable. It is typedef-ed to map_string_h. We can't typedef it to map_string_t, since other parts of ABRT (daemon, cli) still use that name for C++ container. Also, exceptions are removed everywhere. Signed-off-by: Denys Vlasenko --- src/daemon/Daemon.cpp | 106 +++++++++++++++++++------------------------------- 1 file changed, 40 insertions(+), 66 deletions(-) (limited to 'src/daemon/Daemon.cpp') diff --git a/src/daemon/Daemon.cpp b/src/daemon/Daemon.cpp index 62bcdc68..f98d8741 100644 --- a/src/daemon/Daemon.cpp +++ b/src/daemon/Daemon.cpp @@ -27,7 +27,6 @@ #include /* ioctl(FIONREAD) */ #include #include "abrtlib.h" -#include "abrt_exception.h" #include "comm_layer_inner.h" #include "Settings.h" #include "CommLayerServerDBus.h" @@ -543,63 +542,49 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin char *fullname = NULL; crash_data_t *crash_data = NULL; - try + fullname = concat_path_file(DEBUG_DUMPS_DIR, name); + mw_result_t res = LoadDebugDump(fullname, &crash_data); + switch (res) { - fullname = concat_path_file(DEBUG_DUMPS_DIR, name); - mw_result_t res = LoadDebugDump(fullname, &crash_data); - switch (res) - { - case MW_OK: - log("New crash %s, processing", fullname); - /* Fall through */ + case MW_OK: + log("New crash %s, processing", fullname); + /* Fall through */ - case MW_OCCURRED: /* dup */ + case MW_OCCURRED: /* dup */ + { + if (res != MW_OK) { - if (res != MW_OK) - { - const char *first = get_crash_item_content_or_NULL(crash_data, CD_DUMPDIR); - log("Deleting crash %s (dup of %s), sending dbus signal", - strrchr(fullname, '/') + 1, - strrchr(first, '/') + 1); - delete_crash_dump_dir(fullname); - } - - const char *uid_str = get_crash_item_content_or_NULL(crash_data, FILENAME_UID); - const char *inform_all = get_crash_item_content_or_NULL(crash_data, FILENAME_INFORMALL); - - if (inform_all && string_to_bool(inform_all)) - uid_str = NULL; - char *crash_id = xasprintf("%s:%s", - get_crash_item_content_or_NULL(crash_data, FILENAME_UID), - get_crash_item_content_or_NULL(crash_data, FILENAME_UUID) - ); - /* Send dbus signal */ - g_pCommLayer->Crash(get_crash_item_content_or_NULL(crash_data, FILENAME_PACKAGE), - crash_id, //TODO: stop passing this param, it is unused - fullname, - uid_str - ); - free(crash_id); - break; - } - case MW_CORRUPTED: - case MW_GPG_ERROR: - default: - log("Corrupted or bad crash %s (res:%d), deleting", fullname, (int)res); + const char *first = get_crash_item_content_or_NULL(crash_data, CD_DUMPDIR); + log("Deleting crash %s (dup of %s), sending dbus signal", + strrchr(fullname, '/') + 1, + strrchr(first, '/') + 1); delete_crash_dump_dir(fullname); - break; + } + + const char *uid_str = get_crash_item_content_or_NULL(crash_data, FILENAME_UID); + const char *inform_all = get_crash_item_content_or_NULL(crash_data, FILENAME_INFORMALL); + + if (inform_all && string_to_bool(inform_all)) + uid_str = NULL; + char *crash_id = xasprintf("%s:%s", + get_crash_item_content_or_NULL(crash_data, FILENAME_UID), + get_crash_item_content_or_NULL(crash_data, FILENAME_UUID) + ); + /* Send dbus signal */ + g_pCommLayer->Crash(get_crash_item_content_or_NULL(crash_data, FILENAME_PACKAGE), + crash_id, //TODO: stop passing this param, it is unused + fullname, + uid_str + ); + free(crash_id); + break; } - } - catch (CABRTException& e) - { - error_msg("%s", e.what()); - } - catch (...) - { - free(fullname); - free(buf); - free_crash_data(crash_data); - throw; + case MW_CORRUPTED: + case MW_GPG_ERROR: + default: + log("Corrupted or bad crash %s (res:%d), deleting", fullname, (int)res); + delete_crash_dump_dir(fullname); + break; } free(fullname); free_crash_data(crash_data); @@ -899,19 +884,8 @@ int main(int argc, char** argv) s_signal_pipe_write = s_signal_pipe[1]; /* Enter the event loop */ - try - { - log("Init complete, entering main loop"); - run_main_loop(pMainloop); - } - catch (CABRTException& e) - { - error_msg("Error: %s", e.what()); - } - catch (std::exception& e) - { - error_msg("Error: %s", e.what()); - } + log("Init complete, entering main loop"); + run_main_loop(pMainloop); cleanup: /* Error or INT/TERM. Clean up, in reverse order. -- cgit From 6a2b728d7525214402eff838bb37be175ddce6c3 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 15 Dec 2010 18:44:55 +0100 Subject: Rename foo_crash_dump_dir -> foo_dump_dir To be exact, these three functions are renamed: load_crash_data_from_crash_dump_dir create_crash_dump_dir delete_crash_dump_dir Rationale: data structure is called "struct dump_dir", not "struct crash_dump_dir" Signed-off-by: Denys Vlasenko --- src/daemon/Daemon.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/daemon/Daemon.cpp') diff --git a/src/daemon/Daemon.cpp b/src/daemon/Daemon.cpp index f98d8741..a181da15 100644 --- a/src/daemon/Daemon.cpp +++ b/src/daemon/Daemon.cpp @@ -535,7 +535,7 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin char *d = concat_path_file(DEBUG_DUMPS_DIR, worst_dir); free(worst_dir); worst_dir = NULL; - delete_crash_dump_dir(d); + delete_dump_dir(d); free(d); } } @@ -558,7 +558,7 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin log("Deleting crash %s (dup of %s), sending dbus signal", strrchr(fullname, '/') + 1, strrchr(first, '/') + 1); - delete_crash_dump_dir(fullname); + delete_dump_dir(fullname); } const char *uid_str = get_crash_item_content_or_NULL(crash_data, FILENAME_UID); @@ -583,7 +583,7 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin case MW_GPG_ERROR: default: log("Corrupted or bad crash %s (res:%d), deleting", fullname, (int)res); - delete_crash_dump_dir(fullname); + delete_dump_dir(fullname); break; } free(fullname); -- cgit From c4bdeaeb27855878c6caadaa6b85fa566bc09677 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 11 Jan 2011 14:40:48 +0100 Subject: move abrt-action-FOO from /usr/libexec to /usr/bin Signed-off-by: Denys Vlasenko --- src/daemon/Daemon.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src/daemon/Daemon.cpp') diff --git a/src/daemon/Daemon.cpp b/src/daemon/Daemon.cpp index a181da15..c01ea75a 100644 --- a/src/daemon/Daemon.cpp +++ b/src/daemon/Daemon.cpp @@ -726,13 +726,9 @@ int main(int argc, char** argv) * (I saw it set only DBUS_STARTER_ADDRESS and DBUS_STARTER_BUS_TYPE). * In this case, set something sane: */ - /* Need to add LIBEXEC_DIR to PATH, because otherwise abrt-action-* - * are not found by exec() - */ const char *env_path = getenv("PATH"); if (!env_path || !env_path[0]) - env_path = "/usr/sbin:/usr/bin:/sbin:/bin"; - putenv(xasprintf("PATH=%s:%s", LIBEXEC_DIR, env_path)); + putenv((char*)"PATH=/usr/sbin:/usr/bin:/sbin:/bin"); putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); -- cgit From e796e95a4efbfeb04223f61c600c7712da7b500f Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 17 Jan 2011 16:39:11 +0100 Subject: replace KerneloopsScanner plugin and dumpoops with abrt-dump-oops, use it in abrtd Patch adds new tool: $ abrt-dump-oops Usage: abrt-dump-oops [-vsrdow] FILE Extract oops from syslog/dmesg file -v, --verbose Be verbose -s Log to syslog -r Parse kernel's message buffer before parsing FILE -d Create ABRT dump for every oops found -o Print found oopses on standard output -w Do not exit, watch the file for new oopses It extends dumpoops. Extensions: * it can watch the syslog using -w option (uses inotify) * it can scan dmesg buffer too In this way, it also becomes a replacement for KerneloopsScanner plugin: oops-detecting logic is taken verbatim from KerneloopsScanner source. abrtd is changed to start it if it sees this directive in abrt.conf: [ LogScanners ] abrt-dump-oops = abrt-dump-oops -drw /var/log/messages Default abrt.conf is changed to have such line. Patch doesn't remove KerneloopsScanner plugin and dumpoops binary yet, I will do it in a separate trivial patch. Signed-off-by: Denys Vlasenko --- src/daemon/Daemon.cpp | 57 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 11 deletions(-) (limited to 'src/daemon/Daemon.cpp') diff --git a/src/daemon/Daemon.cpp b/src/daemon/Daemon.cpp index c01ea75a..e864c466 100644 --- a/src/daemon/Daemon.cpp +++ b/src/daemon/Daemon.cpp @@ -90,6 +90,7 @@ static volatile sig_atomic_t s_sig_caught; static int s_signal_pipe[2]; static int s_signal_pipe_write = -1; static int s_upload_watch = -1; +static pid_t log_scanner_pid = -1; static unsigned s_timeout; static bool s_exiting; @@ -432,12 +433,22 @@ static gboolean handle_signal_cb(GIOChannel *gio, GIOCondition condition, gpoint s_exiting = 1; else { - if (socket_client_count) - socket_client_count--; - if (!socket_channel_cb_id) + pid_t pid; + while ((pid = waitpid(-1, NULL, WNOHANG)) > 0) { - log("Accepting connections on '%s'", SOCKET_FILE); - socket_channel_cb_id = add_watch_or_die(socket_channel, G_IO_IN | G_IO_PRI, server_socket_cb); + if (pid == log_scanner_pid) + { + log("log scanner exited"); + log_scanner_pid = -1; + continue; + } + if (socket_client_count) + socket_client_count--; + if (!socket_channel_cb_id) + { + log("Accepting connections on '%s'", SOCKET_FILE); + socket_channel_cb_id = add_watch_or_die(socket_channel, G_IO_IN | G_IO_PRI, server_socket_cb); + } } } return TRUE; @@ -648,6 +659,7 @@ static void start_syslog_logging() xdup2(STDIN_FILENO, STDERR_FILENO); openlog("abrtd", 0, LOG_DAEMON); logmode = LOGMODE_SYSLOG; + putenv((char*)"ABRT_SYSLOG=1"); } static void ensure_writable_dir(const char *dir, mode_t mode, const char *user) @@ -719,9 +731,10 @@ int main(int argc, char** argv) unsigned opts = parse_opts(argc, argv, abrtd_options, abrtd_usage); - if (opts & OPT_s) - start_syslog_logging(); + msg_prefix = "abrtd"; /* for log(), error_msg() and such */ + unsetenv("ABRT_SYSLOG"); + putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); /* When dbus daemon starts us, it doesn't set PATH * (I saw it set only DBUS_STARTER_ADDRESS and DBUS_STARTER_BUS_TYPE). * In this case, set something sane: @@ -730,9 +743,8 @@ int main(int argc, char** argv) if (!env_path || !env_path[0]) putenv((char*)"PATH=/usr/sbin:/usr/bin:/sbin:/bin"); - putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); - - msg_prefix = "abrtd"; /* for log(), error_msg() and such */ + if (opts & OPT_s) + start_syslog_logging(); xpipe(s_signal_pipe); close_on_exec_on(s_signal_pipe[0]); @@ -879,6 +891,22 @@ int main(int argc, char** argv) /* Only now we want signal pipe to work */ s_signal_pipe_write = s_signal_pipe[1]; + if (g_settings_sLogScanners) + { + const char *scanner_argv[] = { + "/bin/sh", "-c", + g_settings_sLogScanners, + NULL + }; + log_scanner_pid = fork_execv_on_steroids(EXECFLG_INPUT_NUL, + (char**)scanner_argv, + /*pipefds:*/ NULL, + /*unsetenv_vec:*/ NULL, + /*dir:*/ NULL, + /*uid:*/ 0); + VERB1 log("Started log scanner, pid:%d", (int)log_scanner_pid); + } + /* Enter the event loop */ log("Init complete, entering main loop"); run_main_loop(pMainloop); @@ -913,10 +941,17 @@ int main(int argc, char** argv) g_main_loop_unref(pMainloop); settings_free(); + + if (log_scanner_pid > 0) + { + VERB2 log("Sending SIGTERM to %d", log_scanner_pid); + kill(log_scanner_pid, SIGTERM); + } + /* Exiting */ if (s_sig_caught && s_sig_caught != SIGALRM && s_sig_caught != SIGCHLD) { - error_msg_and_die("Got signal %d, exiting", s_sig_caught); + error_msg("Got signal %d, exiting", s_sig_caught); signal(s_sig_caught, SIG_DFL); raise(s_sig_caught); } -- cgit From b3330ba6dccd65f4d0bef843e092f4c0f2c56c7f Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 17 Jan 2011 17:41:59 +0100 Subject: remove [ Cron ] handling Signed-off-by: Denys Vlasenko --- src/daemon/Daemon.cpp | 160 -------------------------------------------------- 1 file changed, 160 deletions(-) (limited to 'src/daemon/Daemon.cpp') diff --git a/src/daemon/Daemon.cpp b/src/daemon/Daemon.cpp index e864c466..1516f159 100644 --- a/src/daemon/Daemon.cpp +++ b/src/daemon/Daemon.cpp @@ -203,163 +203,6 @@ static void dumpsocket_shutdown() } } - -/* Cron handling */ - -typedef struct cron_callback_data_t -{ - std::string m_sPluginName; - std::string m_sPluginArgs; - unsigned int m_nTimeout; - - cron_callback_data_t( - const std::string& pPluginName, - const std::string& pPluginArgs, - const unsigned int& pTimeout) : - m_sPluginName(pPluginName), - m_sPluginArgs(pPluginArgs), - m_nTimeout(pTimeout) - {} -} cron_callback_data_t; - -static void cron_delete_callback_data_cb(gpointer data) -{ - cron_callback_data_t* cronDeleteCallbackData = static_cast(data); - delete cronDeleteCallbackData; -} - -static gboolean cron_activation_periodic_cb(gpointer data) -{ - cron_callback_data_t* cronPeriodicCallbackData = static_cast(data); - VERB1 log("Activating plugin: %s", cronPeriodicCallbackData->m_sPluginName.c_str()); - RunAction(DEBUG_DUMPS_DIR, - cronPeriodicCallbackData->m_sPluginName.c_str(), - cronPeriodicCallbackData->m_sPluginArgs.c_str() - ); - return TRUE; -} -static gboolean cron_activation_one_cb(gpointer data) -{ - cron_callback_data_t* cronOneCallbackData = static_cast(data); - VERB1 log("Activating plugin: %s", cronOneCallbackData->m_sPluginName.c_str()); - RunAction(DEBUG_DUMPS_DIR, - cronOneCallbackData->m_sPluginName.c_str(), - cronOneCallbackData->m_sPluginArgs.c_str() - ); - return FALSE; -} -static gboolean cron_activation_reshedule_cb(gpointer data) -{ - cron_callback_data_t* cronResheduleCallbackData = static_cast(data); - VERB1 log("Rescheduling plugin: %s", cronResheduleCallbackData->m_sPluginName.c_str()); - cron_callback_data_t* cronPeriodicCallbackData = new cron_callback_data_t(cronResheduleCallbackData->m_sPluginName, - cronResheduleCallbackData->m_sPluginArgs, - cronResheduleCallbackData->m_nTimeout); - g_timeout_add_seconds_full(G_PRIORITY_DEFAULT, - cronPeriodicCallbackData->m_nTimeout, - cron_activation_periodic_cb, - static_cast(cronPeriodicCallbackData), - cron_delete_callback_data_cb - ); - return FALSE; -} - -static int SetUpCron() -{ - map_cron_t::iterator it_c = g_settings_mapCron.begin(); - for (; it_c != g_settings_mapCron.end(); it_c++) - { - std::string::size_type pos = it_c->first.find(":"); - int timeout = 0; - int nH = -1; - int nM = -1; - int nS = -1; - -//TODO: rewrite using good old sscanf? - - if (pos != std::string::npos) - { - std::string sH; - std::string sM; - - sH = it_c->first.substr(0, pos); - nH = xatou(sH.c_str()); - nH = nH > 23 ? 23 : nH; - nH = nH < 0 ? 0 : nH; - timeout += nH * 60 * 60; - sM = it_c->first.substr(pos + 1); - nM = xatou(sM.c_str()); - nM = nM > 59 ? 59 : nM; - nM = nM < 0 ? 0 : nM; - timeout += nM * 60; - } - else - { - std::string sS; - - sS = it_c->first; - nS = xatou(sS.c_str()); - nS = nS <= 0 ? 1 : nS; - timeout = nS; - } - - if (nS != -1) - { - vector_pair_string_string_t::iterator it_ar = it_c->second.begin(); - for (; it_ar != it_c->second.end(); it_ar++) - { - cron_callback_data_t* cronPeriodicCallbackData = new cron_callback_data_t(it_ar->first, it_ar->second, timeout); - g_timeout_add_seconds_full(G_PRIORITY_DEFAULT, - timeout, - cron_activation_periodic_cb, - static_cast(cronPeriodicCallbackData), - cron_delete_callback_data_cb); - } - } - else - { - time_t actTime = time(NULL); - struct tm locTime; - localtime_r(&actTime, &locTime); - locTime.tm_hour = nH; - locTime.tm_min = nM; - locTime.tm_sec = 0; - time_t nextTime = mktime(&locTime); - if (nextTime == ((time_t)-1)) - { - /* paranoia */ - perror_msg("Can't set up cron time"); - return -1; - } - if (actTime > nextTime) - { - timeout = 24*60*60 + (nextTime - actTime); - } - else - { - timeout = nextTime - actTime; - } - vector_pair_string_string_t::iterator it_ar = it_c->second.begin(); - for (; it_ar != it_c->second.end(); it_ar++) - { - cron_callback_data_t* cronOneCallbackData = new cron_callback_data_t(it_ar->first, it_ar->second, timeout); - g_timeout_add_seconds_full(G_PRIORITY_DEFAULT, - timeout, - cron_activation_one_cb, - static_cast(cronOneCallbackData), - cron_delete_callback_data_cb); - cron_callback_data_t* cronResheduleCallbackData = new cron_callback_data_t(it_ar->first, it_ar->second, 24 * 60 * 60); - g_timeout_add_seconds_full(G_PRIORITY_DEFAULT, - timeout, - cron_activation_reshedule_cb, - static_cast(cronResheduleCallbackData), - cron_delete_callback_data_cb); - } - } - } - return 0; -} - static int CreatePidFile() { int fd; @@ -837,9 +680,6 @@ int main(int argc, char** argv) g_pPluginManager = new CPluginManager(); g_pPluginManager->LoadPlugins(); - if (SetUpCron() != 0) - throw 1; - /* Add an event source which waits for INT/TERM signal */ VERB1 log("Adding signal pipe watch to glib main loop"); channel_signal = g_io_channel_unix_new(s_signal_pipe[0]); -- cgit From e001c3c0c7d8dc9576f1630551a73cc01f19769b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 19 Jan 2011 17:12:53 +0100 Subject: move (de)installation of abrt-hook-ccpp into abrt-ccpp service. Init script is packaged and installed with abrt-addon-ccpp package. In order to not install the hook twice, "old" plugin loading in abrtd is disabled (pending deletion of entire "old" plugin machinery). Signed-off-by: Denys Vlasenko --- src/daemon/Daemon.cpp | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'src/daemon/Daemon.cpp') diff --git a/src/daemon/Daemon.cpp b/src/daemon/Daemon.cpp index 1516f159..6d9bd87f 100644 --- a/src/daemon/Daemon.cpp +++ b/src/daemon/Daemon.cpp @@ -676,10 +676,6 @@ int main(int argc, char** argv) handle_inotify_cb, NULL); - VERB1 log("Loading plugins from "PLUGINS_LIB_DIR); - g_pPluginManager = new CPluginManager(); - g_pPluginManager->LoadPlugins(); - /* Add an event source which waits for INT/TERM signal */ VERB1 log("Adding signal pipe watch to glib main loop"); channel_signal = g_io_channel_unix_new(s_signal_pipe[0]); @@ -771,12 +767,7 @@ int main(int argc, char** argv) g_io_channel_unref(channel_inotify); delete g_pCommLayer; - if (g_pPluginManager) - { - /* This restores /proc/sys/kernel/core_pattern, among other things: */ - g_pPluginManager->UnLoadPlugins(); - delete g_pPluginManager; - } + if (pMainloop) g_main_loop_unref(pMainloop); -- cgit From 72805b810ddd46e63c316ee477bc6f025eaf7f14 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 19 Jan 2011 17:49:14 +0100 Subject: abrtd: merge pid and lock files into one Signed-off-by: Denys Vlasenko --- src/daemon/Daemon.cpp | 68 +++++++++++++++++++++------------------------------ 1 file changed, 28 insertions(+), 40 deletions(-) (limited to 'src/daemon/Daemon.cpp') diff --git a/src/daemon/Daemon.cpp b/src/daemon/Daemon.cpp index 6d9bd87f..eddcd766 100644 --- a/src/daemon/Daemon.cpp +++ b/src/daemon/Daemon.cpp @@ -38,7 +38,6 @@ using namespace std; -#define VAR_RUN_LOCK_FILE VAR_RUN"/abrt/abrtd.lock" #define VAR_RUN_PIDFILE VAR_RUN"/abrtd.pid" #define SOCKET_FILE VAR_RUN"/abrt/abrt.socket" @@ -203,48 +202,36 @@ static void dumpsocket_shutdown() } } -static int CreatePidFile() +static int create_pidfile() { - int fd; - - /* JIC */ - unlink(VAR_RUN_PIDFILE); - - /* open the pidfile */ - fd = open(VAR_RUN_PIDFILE, O_WRONLY|O_CREAT|O_EXCL, 0644); + /* Note: + * No O_EXCL: we would happily overwrite stale pidfile from previous boot. + * No O_TRUNC: we must first try to lock the file, and if lock fails, + * there is another live abrtd. O_TRUNCing the file in this case + * would be wrong - it'll erase the pid to empty string! + */ + int fd = open(VAR_RUN_PIDFILE, O_WRONLY|O_CREAT, 0644); if (fd >= 0) { + if (lockf(fd, F_TLOCK, 0) < 0) + { + perror_msg("Can't lock file '%s'", VAR_RUN_PIDFILE); + return -1; + } + close_on_exec_on(fd); /* write our pid to it */ char buf[sizeof(long)*3 + 2]; int len = sprintf(buf, "%lu\n", (long)getpid()); write(fd, buf, len); - close(fd); + ftruncate(fd, len); + /* we leak opened+locked fd intentionally */ return 0; } - /* something went wrong */ perror_msg("Can't open '%s'", VAR_RUN_PIDFILE); return -1; } -static int Lock() -{ - int lfd = open(VAR_RUN_LOCK_FILE, O_RDWR|O_CREAT, 0640); - if (lfd < 0) - { - perror_msg("Can't open '%s'", VAR_RUN_LOCK_FILE); - return -1; - } - if (lockf(lfd, F_TLOCK, 0) < 0) - { - perror_msg("Can't lock file '%s'", VAR_RUN_LOCK_FILE); - return -1; - } - close_on_exec_on(lfd); - return 0; - /* we leak opened lfd intentionally */ -} - static void handle_signal(int signo) { int save_errno = errno; @@ -637,7 +624,6 @@ int main(int argc, char** argv) guint channel_inotify_event_id = 0; GIOChannel* channel_signal = NULL; guint channel_signal_event_id = 0; - bool lockfile_created = false; bool pidfile_created = false; CCrashWatcher watcher; @@ -650,24 +636,32 @@ int main(int argc, char** argv) if (LoadSettings() != 0) throw 1; + sanitize_dump_dir_rights(); + VERB1 log("Creating glib main loop"); pMainloop = g_main_loop_new(NULL, FALSE); VERB1 log("Initializing inotify"); - sanitize_dump_dir_rights(); errno = 0; int inotify_fd = inotify_init(); if (inotify_fd == -1) perror_msg_and_die("inotify_init failed"); close_on_exec_on(inotify_fd); + /* 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); + { + perror_msg("inotify_add_watch failed on '%s'", DEBUG_DUMPS_DIR); + throw 1; + } if (g_settings_sWatchCrashdumpArchiveDir) { 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); + { + perror_msg("inotify_add_watch failed on '%s'", g_settings_sWatchCrashdumpArchiveDir); + throw 1; + } } VERB1 log("Adding inotify watch to glib main loop"); channel_inotify = g_io_channel_unix_new(inotify_fd); @@ -685,12 +679,8 @@ int main(int argc, char** argv) NULL); /* Mark the territory */ - VERB1 log("Creating lock file"); - if (Lock() != 0) - throw 1; - lockfile_created = true; VERB1 log("Creating pid file"); - if (CreatePidFile() != 0) + if (create_pidfile() != 0) throw 1; pidfile_created = true; @@ -754,8 +744,6 @@ int main(int argc, char** argv) dumpsocket_shutdown(); if (pidfile_created) unlink(VAR_RUN_PIDFILE); - if (lockfile_created) - unlink(VAR_RUN_LOCK_FILE); if (channel_signal_event_id > 0) g_source_remove(channel_signal_event_id); -- cgit From d7d62ea5ee19f5cad52dcfb2f2a49d8d36fa1228 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 20 Jan 2011 18:34:08 +0100 Subject: introduce and use new helper function list_free_with_free Signed-off-by: Denys Vlasenko --- src/daemon/Daemon.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/daemon/Daemon.cpp') diff --git a/src/daemon/Daemon.cpp b/src/daemon/Daemon.cpp index eddcd766..8d972a9a 100644 --- a/src/daemon/Daemon.cpp +++ b/src/daemon/Daemon.cpp @@ -25,7 +25,6 @@ #include #include #include /* ioctl(FIONREAD) */ -#include #include "abrtlib.h" #include "comm_layer_inner.h" #include "Settings.h" @@ -633,7 +632,7 @@ int main(int argc, char** argv) init_daemon_logging(&watcher); VERB1 log("Loading settings"); - if (LoadSettings() != 0) + if (load_settings() != 0) throw 1; sanitize_dump_dir_rights(); @@ -759,7 +758,7 @@ int main(int argc, char** argv) if (pMainloop) g_main_loop_unref(pMainloop); - settings_free(); + free_settings(); if (log_scanner_pid > 0) { -- cgit From e3d48ee0458f1d0078da65bad99804d2ba58aaf0 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 20 Jan 2011 20:33:34 +0100 Subject: make option handling more regular across all tools Signed-off-by: Denys Vlasenko --- src/daemon/Daemon.cpp | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'src/daemon/Daemon.cpp') diff --git a/src/daemon/Daemon.cpp b/src/daemon/Daemon.cpp index 8d972a9a..7c063d9d 100644 --- a/src/daemon/Daemon.cpp +++ b/src/daemon/Daemon.cpp @@ -34,6 +34,8 @@ #include "Daemon.h" #include "parse_options.h" +#define PROGNAME "abrtd" + using namespace std; @@ -463,10 +465,10 @@ static void run_main_loop(GMainLoop* loop) fds = (GPollFD *)xrealloc(fds, fds_size * sizeof(fds[0])); } - if (s_timeout) + if (s_timeout != 0) alarm(s_timeout); g_poll(fds, nfds, timeout); - if (s_timeout) + if (s_timeout != 0) alarm(0); some_ready = g_main_context_check(context, max_priority, fds, nfds); @@ -486,7 +488,7 @@ static void start_syslog_logging() * Otherwise fprintf(stderr) dumps messages into random fds, etc. */ xdup2(STDIN_FILENO, STDOUT_FILENO); xdup2(STDIN_FILENO, STDERR_FILENO); - openlog("abrtd", 0, LOG_DAEMON); + openlog(PROGNAME, 0, LOG_DAEMON); logmode = LOGMODE_SYSLOG; putenv((char*)"ABRT_SYSLOG=1"); } @@ -523,23 +525,6 @@ static void sanitize_dump_dir_rights() ensure_writable_dir(VAR_RUN"/abrt", 0755, "root"); } -static char *timeout_opt; -static const char* abrtd_usage = _("abrtd [options]"); -enum { - OPT_v = 1 << 0, - OPT_d = 1 << 1, - OPT_s = 1 << 2, - OPT_t = 1 << 3, -}; -/* Keep enum above and order of options below in sync! */ -static struct options abrtd_options[] = { - OPT__VERBOSE(&g_verbose), - OPT_BOOL( 'd' , 0, NULL, _("Do not daemonize")), - OPT_BOOL( 's' , 0, NULL, _("Log to syslog even with -d")), - OPT_INTEGER( 't' , 0, &timeout_opt, _("Exit after SEC seconds of inactivity")), - OPT_END() -}; - int main(int argc, char** argv) { int parent_pid = getpid(); @@ -558,9 +543,24 @@ int main(int argc, char** argv) if (env_verbose) g_verbose = atoi(env_verbose); - unsigned opts = parse_opts(argc, argv, abrtd_options, abrtd_usage); - - msg_prefix = "abrtd"; /* for log(), error_msg() and such */ + const char *program_usage_string = _( + PROGNAME" [options]" + ); + enum { + OPT_v = 1 << 0, + OPT_d = 1 << 1, + OPT_s = 1 << 2, + OPT_t = 1 << 3, + }; + /* Keep enum above and order of options below in sync! */ + struct options program_options[] = { + OPT__VERBOSE(&g_verbose), + OPT_BOOL( 'd', NULL, NULL , _("Do not daemonize")), + OPT_BOOL( 's', NULL, NULL , _("Log to syslog even with -d")), + OPT_INTEGER('t', NULL, &s_timeout, _("Exit after SEC seconds of inactivity")), + OPT_END() + }; + unsigned opts = parse_opts(argc, argv, program_options, program_usage_string); unsetenv("ABRT_SYSLOG"); putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); @@ -571,7 +571,7 @@ int main(int argc, char** argv) const char *env_path = getenv("PATH"); if (!env_path || !env_path[0]) putenv((char*)"PATH=/usr/sbin:/usr/bin:/sbin:/bin"); - + msg_prefix = PROGNAME; /* for log(), error_msg() and such */ if (opts & OPT_s) start_syslog_logging(); @@ -581,7 +581,7 @@ int main(int argc, char** argv) signal(SIGTERM, handle_signal); signal(SIGINT, handle_signal); signal(SIGCHLD, handle_signal); - if (s_timeout) + if (s_timeout != 0) signal(SIGALRM, handle_signal); /* Daemonize unless -d */ -- cgit From a387e6c91cd45ffc35c03e42bde7ba926231de4b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 21 Jan 2011 00:44:39 +0100 Subject: Remove CCrashWatcher and CObserver classes; merge libabrt_daemon into abrtd Signed-off-by: Denys Vlasenko --- src/daemon/Daemon.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/daemon/Daemon.cpp') diff --git a/src/daemon/Daemon.cpp b/src/daemon/Daemon.cpp index 7c063d9d..78ebafea 100644 --- a/src/daemon/Daemon.cpp +++ b/src/daemon/Daemon.cpp @@ -29,7 +29,6 @@ #include "comm_layer_inner.h" #include "Settings.h" #include "CommLayerServerDBus.h" -#include "CrashWatcher.h" #include "MiddleWare.h" #include "Daemon.h" #include "parse_options.h" @@ -624,12 +623,11 @@ int main(int argc, char** argv) GIOChannel* channel_signal = NULL; guint channel_signal_event_id = 0; bool pidfile_created = false; - CCrashWatcher watcher; /* Initialization */ try { - init_daemon_logging(&watcher); + init_daemon_logging(); VERB1 log("Loading settings"); if (load_settings() != 0) -- cgit From 28a25818179cbc6f5b2721c0da009c3729673d96 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 21 Jan 2011 17:33:43 +0100 Subject: s/QuotaExceed/QuotaExceeded/g Signed-off-by: Denys Vlasenko --- src/daemon/Daemon.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/daemon/Daemon.cpp') diff --git a/src/daemon/Daemon.cpp b/src/daemon/Daemon.cpp index 78ebafea..25b2bbdf 100644 --- a/src/daemon/Daemon.cpp +++ b/src/daemon/Daemon.cpp @@ -371,7 +371,7 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin && worst_dir ) { log("Size of '%s' >= %u MB, deleting '%s'", DEBUG_DUMPS_DIR, g_settings_nMaxCrashReportsSize, worst_dir); - g_pCommLayer->QuotaExceed(_("The size of the report exceeded the quota. Please check system's MaxCrashReportsSize value in abrt.conf.")); + g_pCommLayer->QuotaExceeded(_("The size of the report exceeded the quota. Please check system's MaxCrashReportsSize value in abrt.conf.")); /* deletes both directory and DB record */ char *d = concat_path_file(DEBUG_DUMPS_DIR, worst_dir); free(worst_dir); -- cgit From 5d3a66f0b6cc2e9fd6a5dc5815d65d6708050ccc Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 21 Jan 2011 17:34:29 +0100 Subject: remove CCommLayerServer[DBus] classes Signed-off-by: Denys Vlasenko --- src/daemon/Daemon.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'src/daemon/Daemon.cpp') diff --git a/src/daemon/Daemon.cpp b/src/daemon/Daemon.cpp index 25b2bbdf..ca9cf0c5 100644 --- a/src/daemon/Daemon.cpp +++ b/src/daemon/Daemon.cpp @@ -30,7 +30,6 @@ #include "Settings.h" #include "CommLayerServerDBus.h" #include "MiddleWare.h" -#include "Daemon.h" #include "parse_options.h" #define PROGNAME "abrtd" @@ -83,8 +82,6 @@ using namespace std; * Both are sent as unicast to last client set by set_client_name(name). * If set_client_name(NULL) was done, they are not sent. */ -CCommLayerServer* g_pCommLayer; - static volatile sig_atomic_t s_sig_caught; static int s_signal_pipe[2]; static int s_signal_pipe_write = -1; @@ -371,7 +368,7 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin && worst_dir ) { log("Size of '%s' >= %u MB, deleting '%s'", DEBUG_DUMPS_DIR, g_settings_nMaxCrashReportsSize, worst_dir); - g_pCommLayer->QuotaExceeded(_("The size of the report exceeded the quota. Please check system's MaxCrashReportsSize value in abrt.conf.")); + send_dbus_sig_QuotaExceeded(_("The size of the report exceeded the quota. Please check system's MaxCrashReportsSize value in abrt.conf.")); /* deletes both directory and DB record */ char *d = concat_path_file(DEBUG_DUMPS_DIR, worst_dir); free(worst_dir); @@ -411,8 +408,7 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin get_crash_item_content_or_NULL(crash_data, FILENAME_UID), get_crash_item_content_or_NULL(crash_data, FILENAME_UUID) ); - /* Send dbus signal */ - g_pCommLayer->Crash(get_crash_item_content_or_NULL(crash_data, FILENAME_PACKAGE), + send_dbus_sig_Crash(get_crash_item_content_or_NULL(crash_data, FILENAME_PACKAGE), crash_id, //TODO: stop passing this param, it is unused fullname, uid_str @@ -688,8 +684,7 @@ int main(int argc, char** argv) * therefore it should be the last thing to initialize. */ VERB1 log("Initializing dbus"); - g_pCommLayer = new CCommLayerServerDBus(); - if (g_pCommLayer->m_init_error) + if (init_dbus() != 0) throw 1; } catch (...) @@ -751,7 +746,7 @@ int main(int argc, char** argv) if (channel_inotify) g_io_channel_unref(channel_inotify); - delete g_pCommLayer; + deinit_dbus(); if (pMainloop) g_main_loop_unref(pMainloop); -- cgit From 292fb47cb67837bc203c3038f75968a978440be7 Mon Sep 17 00:00:00 2001 From: Jiri Moskovcak Date: Mon, 21 Feb 2011 18:39:48 +0100 Subject: run abrt-action-install-debuginfo.py using trivial sgid wrapper Signed-off-by: Jiri Moskovcak Signed-off-by: Denys Vlasenko --- src/daemon/Daemon.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/daemon/Daemon.cpp') diff --git a/src/daemon/Daemon.cpp b/src/daemon/Daemon.cpp index ca9cf0c5..f791fb38 100644 --- a/src/daemon/Daemon.cpp +++ b/src/daemon/Daemon.cpp @@ -515,7 +515,7 @@ static void sanitize_dump_dir_rights() /* 00777 bits are usual "rwxrwxrwx" access rights */ ensure_writable_dir(DEBUG_DUMPS_DIR, 0755, "abrt"); /* debuginfo cache */ - ensure_writable_dir(DEBUG_INFO_DIR, 0755, "root"); + ensure_writable_dir(DEBUG_INFO_DIR, 0775, "abrt"); /* temp dir */ ensure_writable_dir(VAR_RUN"/abrt", 0755, "root"); } -- cgit