summaryrefslogtreecommitdiffstats
path: root/src/Daemon
diff options
context:
space:
mode:
Diffstat (limited to 'src/Daemon')
-rw-r--r--src/Daemon/CrashWatcher.cpp7
-rw-r--r--src/Daemon/Daemon.cpp80
-rw-r--r--src/Daemon/MiddleWare.cpp56
-rw-r--r--src/Daemon/MiddleWare.h8
4 files changed, 84 insertions, 67 deletions
diff --git a/src/Daemon/CrashWatcher.cpp b/src/Daemon/CrashWatcher.cpp
index f859515..b82823c 100644
--- a/src/Daemon/CrashWatcher.cpp
+++ b/src/Daemon/CrashWatcher.cpp
@@ -20,6 +20,7 @@
#include "abrtlib.h"
#include "Daemon.h"
#include "ABRTException.h"
+#include "DebugDump.h"
#include "CrashWatcher.h"
void CCrashWatcher::Status(const char *pMessage, const char* peer, uint64_t pJobID)
@@ -75,7 +76,7 @@ vector_crash_infos_t GetCrashInfos(const char *pUID)
error_msg("Can't open file in dump directory for UUID %s, deleting", uuid);
{
std::string debugDumpDir = DeleteCrashInfo(uuid, uid);
- DeleteDebugDumpDir(debugDumpDir.c_str());
+ delete_debug_dump_dir(debugDumpDir.c_str());
}
break;
default:
@@ -132,7 +133,7 @@ map_crash_report_t GetJobResult(const char* pUUID, const char* pUID, int force)
default:
error_msg("Corrupted crash with UUID %s, deleting", pUUID);
std::string debugDumpDir = DeleteCrashInfo(pUUID, pUID);
- DeleteDebugDumpDir(debugDumpDir.c_str());
+ delete_debug_dump_dir(debugDumpDir.c_str());
break;
}
return crashReport;
@@ -211,7 +212,7 @@ bool DeleteDebugDump(const char *pUUID, const char *pUID)
try
{
std::string debugDumpDir = DeleteCrashInfo(pUUID, pUID);
- DeleteDebugDumpDir(debugDumpDir.c_str());
+ delete_debug_dump_dir(debugDumpDir.c_str());
}
catch (CABRTException& e)
{
diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp
index 087d537..0e80c25 100644
--- a/src/Daemon/Daemon.cpp
+++ b/src/Daemon/Daemon.cpp
@@ -41,6 +41,7 @@
#include "abrtlib.h"
#include "ABRTException.h"
#include "CrashWatcher.h"
+#include "DebugDump.h"
#include "Daemon.h"
@@ -118,53 +119,6 @@ static bool s_exiting;
CCommLayerServer* g_pCommLayer;
-static double GetDirSize(const std::string &pPath, std::string *worst_dir = NULL, const char *excluded = NULL)
-{
- DIR *dp = opendir(pPath.c_str());
- if (dp == NULL)
- return 0;
-
- struct dirent *ep;
- struct stat stats;
- double size = 0;
- double maxsz = 0;
- while ((ep = readdir(dp)) != NULL)
- {
- if (dot_or_dotdot(ep->d_name))
- continue;
- std::string dname = pPath + "/" + ep->d_name;
- if (lstat(dname.c_str(), &stats) != 0)
- continue;
- if (S_ISDIR(stats.st_mode))
- {
- double sz = GetDirSize(dname);
- size += sz;
-
- if (worst_dir && strcmp(excluded, ep->d_name) != 0)
- {
- /* Calculate "weighted" size and age
- * w = sz_kbytes * age_mins */
- sz /= 1024;
- long age = (time(NULL) - stats.st_mtime) / 60;
- if (age > 0)
- sz *= age;
-
- if (sz > maxsz)
- {
- maxsz = sz;
- *worst_dir = ep->d_name;
- }
- }
- }
- else if (S_ISREG(stats.st_mode))
- {
- size += stats.st_size;
- }
- }
- closedir(dp);
- return size;
-}
-
static void cron_delete_callback_data_cb(gpointer data)
{
cron_callback_data_t* cronDeleteCallbackData = static_cast<cron_callback_data_t*>(data);
@@ -385,7 +339,7 @@ static void FindNewDumps(const char* pPath)
case MW_REPORTED:
case MW_OCCURED:
VERB1 log("Already saved crash %s, deleting", itt->c_str());
- DeleteDebugDumpDir(itt->c_str());
+ delete_debug_dump_dir(itt->c_str());
break;
case MW_BLACKLISTED:
case MW_CORRUPTED:
@@ -394,7 +348,7 @@ static void FindNewDumps(const char* pPath)
case MW_FILE_ERROR:
default:
log("Corrupted or bad crash %s (res:%d), deleting", itt->c_str(), (int)res);
- DeleteDebugDumpDir(itt->c_str());
+ delete_debug_dump_dir(itt->c_str());
break;
}
}
@@ -513,12 +467,12 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin
std::string worst_dir;
while (g_settings_nMaxCrashReportsSize > 0
- && GetDirSize(DEBUG_DUMPS_DIR, &worst_dir, name) / (1024*1024) >= g_settings_nMaxCrashReportsSize
+ && get_dirsize_find_largest_dir(DEBUG_DUMPS_DIR, &worst_dir, name) / (1024*1024) >= g_settings_nMaxCrashReportsSize
&& worst_dir != ""
) {
log("Size of '%s' >= %u MB, deleting '%s'", DEBUG_DUMPS_DIR, g_settings_nMaxCrashReportsSize, worst_dir.c_str());
g_pCommLayer->QuotaExceed(_("Report size exceeded the quota. Please check system's MaxCrashReportsSize value in abrt.conf."));
- DeleteDebugDumpDir(concat_path_file(DEBUG_DUMPS_DIR, worst_dir.c_str()).c_str());
+ delete_debug_dump_dir(concat_path_file(DEBUG_DUMPS_DIR, worst_dir.c_str()).c_str());
worst_dir = "";
}
@@ -540,6 +494,28 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin
log("Already saved crash, just sending dbus signal");
/* Send dbus signal */
{
+ // I don't see any usable usecase for other plugin to be able automatic report.
+ if (analyzer_has_AutoReportUIDs(/*crashinfo[CD_MWANALYZER][CD_CONTENT].c_str()*/"Kerneloops",crashinfo[CD_UID][CD_CONTENT].c_str()))
+ {
+ map_crash_report_t crash_report;
+ VERB3 log("Create autoreport for user with uid %s",crashinfo[CD_UID][CD_CONTENT].c_str());
+ mw_result_t crash_result = CreateCrashReport(crashinfo[CD_UUID][CD_CONTENT].c_str(), crashinfo[CD_UID][CD_CONTENT].c_str(), 0, crash_report);
+ if (crash_result == MW_OK)
+ {
+ map_analyzer_actions_and_reporters_t::const_iterator it = g_settings_mapAnalyzerActionsAndReporters.find("Kerneloops");
+ map_analyzer_actions_and_reporters_t::const_iterator end = g_settings_mapAnalyzerActionsAndReporters.end();
+ if (it != end)
+ {
+ vector_pair_string_string_t keys = it->second;
+
+ uint32_t size = keys.size();
+ for (uint32_t ii = 0; ii < size; ii++)
+ {
+ autoreport(keys[ii], crash_report);
+ }
+ }
+ }
+ }
const char *uid_str = analyzer_has_InformAllUsers(crashinfo[CD_MWANALYZER][CD_CONTENT].c_str())
? NULL
: crashinfo[CD_UID][CD_CONTENT].c_str();
@@ -554,7 +530,7 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin
case MW_FILE_ERROR:
default:
log("Corrupted or bad crash, deleting");
- DeleteDebugDumpDir(fullname.c_str());
+ delete_debug_dump_dir(fullname.c_str());
break;
}
}
diff --git a/src/Daemon/MiddleWare.cpp b/src/Daemon/MiddleWare.cpp
index f3c6bdf..69d36bf 100644
--- a/src/Daemon/MiddleWare.cpp
+++ b/src/Daemon/MiddleWare.cpp
@@ -520,13 +520,6 @@ report_status_t Report(const map_crash_report_t& pCrashReport,
return ret;
}
-void DeleteDebugDumpDir(const char *pDebugDumpDir)
-{
- CDebugDump dd;
- dd.Open(pDebugDumpDir);
- dd.Delete();
-}
-
std::string DeleteCrashInfo(const char *pUUID,
const char *pUID)
{
@@ -661,6 +654,55 @@ bool analyzer_has_InformAllUsers(const char *analyzer_name)
return string_to_bool(it->second.c_str());
}
+bool analyzer_has_AutoReportUIDs(const char *analyzer_name, const char* uid)
+{
+ CAnalyzer* analyzer = g_pPluginManager->GetAnalyzer(analyzer_name);
+ if (!analyzer)
+ {
+ VERB1 log("Strange, asked for analyzer %s but it doesn't exist?", analyzer_name);
+ return false;
+ }
+ map_plugin_settings_t settings = analyzer->GetSettings();
+ map_plugin_settings_t::const_iterator it = settings.find("AutoReportUIDs");
+ if (it == settings.end())
+ return false;
+
+ vector_string_t logins;
+ parse_args(it->second.c_str(), logins);
+
+ uint32_t size = logins.size();
+ if (size == 0)
+ return false;
+
+ if ((strcmp(analyzer_name, "Kerneloops") == 0) && (strcmp(uid, "-1") == 0))
+ return true;
+
+ uid_t id;
+ for (uint32_t ii = 0; ii < size; ii++)
+ {
+ if (!xgetpwnam(logins[ii].c_str(), &id))
+ continue;
+
+ if (strcmp(uid, to_string(id).c_str()) == 0)
+ return true;
+ }
+
+ return false;
+}
+
+void autoreport(const pair_string_string_t& reporter_options, const map_crash_report_t& crash_report)
+{
+ CReporter* reporter = g_pPluginManager->GetReporter(reporter_options.first.c_str());
+ if (!reporter)
+ {
+ VERB1 log("Strange, asked for reporter %s but it doesn't exist?", reporter_options.first.c_str());
+ return;
+ }
+
+ map_plugin_settings_t plugin_settings;
+ std::string res = reporter->Report(crash_report, plugin_settings, reporter_options.second);
+}
+
/**
* Execute all action plugins, which are associated to
* particular analyzer plugin.
diff --git a/src/Daemon/MiddleWare.h b/src/Daemon/MiddleWare.h
index ac042de..3de287b 100644
--- a/src/Daemon/MiddleWare.h
+++ b/src/Daemon/MiddleWare.h
@@ -105,11 +105,6 @@ report_status_t Report(const map_crash_report_t& pCrashReport,
std::string getDebugDumpDir( const char *pUUID,
const char *pUID);
/**
- * Deletes particular debugdump directory.
- * @param pDebugDumpDir A debugdump directory.
- */
-void DeleteDebugDumpDir(const char *pDebugDumpDir);
-/**
* Deletes a row from database. If a deleting is
* successfull, it returns a debugdump directort, which is not
* deleted. Otherwise, it returns empty string.
@@ -167,4 +162,7 @@ void AddActionOrReporter(const char *pActionOrReporter,
bool analyzer_has_InformAllUsers(const char *analyzer_name);
+bool analyzer_has_AutoReportUIDs(const char *analyzer_name, const char* uid);
+
+void autoreport(const pair_string_string_t& reporter_options, const map_crash_report_t& crash_report);
#endif /*MIDDLEWARE_H_*/