diff options
| author | Zdenek Prikryl <zprikryl@redhat.com> | 2009-09-08 17:08:16 +0200 |
|---|---|---|
| committer | Zdenek Prikryl <zprikryl@redhat.com> | 2009-09-08 17:08:16 +0200 |
| commit | f02e1d87d46aa6161d0cab5444e0abfa9624b78d (patch) | |
| tree | cc1148c8ef544818a7995074e679a987ba325a44 /src/Daemon | |
| parent | 58d9dfde6ce788c5ffdfe5160d19aaeb8ac7b3a2 (diff) | |
| parent | ff2627e7c597e50025ca4d91ff8168eec80f9054 (diff) | |
| download | abrt-f02e1d87d46aa6161d0cab5444e0abfa9624b78d.tar.gz abrt-f02e1d87d46aa6161d0cab5444e0abfa9624b78d.tar.xz abrt-f02e1d87d46aa6161d0cab5444e0abfa9624b78d.zip | |
Merge branch 'master' of git://git.fedorahosted.org/abrt
Diffstat (limited to 'src/Daemon')
| -rw-r--r-- | src/Daemon/CommLayerServer.h | 13 | ||||
| -rw-r--r-- | src/Daemon/CommLayerServerDBus.cpp | 134 | ||||
| -rw-r--r-- | src/Daemon/CommLayerServerDBus.h | 14 | ||||
| -rw-r--r-- | src/Daemon/CommLayerServerSocket.cpp | 11 | ||||
| -rw-r--r-- | src/Daemon/CommLayerServerSocket.h | 6 | ||||
| -rw-r--r-- | src/Daemon/CrashWatcher.cpp | 138 | ||||
| -rw-r--r-- | src/Daemon/CrashWatcher.h | 8 | ||||
| -rw-r--r-- | src/Daemon/Daemon.cpp | 34 | ||||
| -rw-r--r-- | src/Daemon/Daemon.h | 3 | ||||
| -rw-r--r-- | src/Daemon/MiddleWare.cpp | 22 |
10 files changed, 202 insertions, 181 deletions
diff --git a/src/Daemon/CommLayerServer.h b/src/Daemon/CommLayerServer.h index 7e6f8d7..0b1027a 100644 --- a/src/Daemon/CommLayerServer.h +++ b/src/Daemon/CommLayerServer.h @@ -14,13 +14,12 @@ class CCommLayerServer { /* just stubs to be called when not implemented in specific comm layer */ virtual void Crash(const std::string& progname, const std::string& uid) {} - virtual void AnalyzeComplete(const map_crash_report_t& arg1) {} - virtual void Error(const std::string& arg1) {} - virtual void Update(const std::string& pMessage, uint64_t pJobID) {}; - virtual void Warning(const std::string& pMessage) {}; - virtual void JobDone(const char* pDest, uint64_t pJobID) = 0; - virtual void JobStarted(const char* pDest, uint64_t pJobID) {}; - virtual void Warning(const std::string& pMessage, uint64_t pJobID) {}; + virtual void JobDone(const char* pDest, const char* pUUID) = 0; + virtual void JobStarted(const char* pDest) {}; + + virtual void Error(const std::string& pMessage, const char* peer) {} + virtual void Update(const std::string& pMessage, const char* peer, uint64_t pJobID) {}; + virtual void Warning(const std::string& pMessage, const char* peer, uint64_t pJobID) {}; }; #endif diff --git a/src/Daemon/CommLayerServerDBus.cpp b/src/Daemon/CommLayerServerDBus.cpp index c3cef3b..c6908f5 100644 --- a/src/Daemon/CommLayerServerDBus.cpp +++ b/src/Daemon/CommLayerServerDBus.cpp @@ -336,12 +336,15 @@ static inline int load_val(DBusMessageIter* iter, std::map<K,V>& val) { return */ /* helpers */ -static DBusMessage* new_signal_msg(const char* member) +static DBusMessage* new_signal_msg(const char* member, const char* peer = NULL) { /* path, interface, member name */ DBusMessage* msg = dbus_message_new_signal(CC_DBUS_PATH, CC_DBUS_IFACE, member); if (!msg) die_out_of_memory(); + /* Send unicast dbus signal if peer is known */ + if (peer && !dbus_message_set_destination(msg, peer)) + die_out_of_memory(); return msg; } static void send_flush_and_unref(DBusMessage* msg) @@ -363,79 +366,61 @@ void CCommLayerServerDBus::Crash(const std::string& progname, const std::string& DBUS_TYPE_STRING, &c_progname, DBUS_TYPE_STRING, &c_uid, DBUS_TYPE_INVALID); + VERB2 log("Sending signal Crash('%s','%s')", c_progname, c_uid); send_flush_and_unref(msg); } -/* Notify the clients that creating a report has finished */ -void CCommLayerServerDBus::AnalyzeComplete(const map_crash_report_t& arg1) +void CCommLayerServerDBus::JobStarted(const char* peer) { - DBusMessage* msg = new_signal_msg("AnalyzeComplete"); - DBusMessageIter out_iter; - dbus_message_iter_init_append(msg, &out_iter); - store_val(&out_iter, arg1); - send_flush_and_unref(msg); -} - -void CCommLayerServerDBus::JobDone(const char* pDest, uint64_t job_id) -{ - DBusMessage* msg = new_signal_msg("JobDone"); - /* TODO: if (!dbus_message_set_destination(msg, pDest) die_out_of_memory(); */ + DBusMessage* msg = new_signal_msg("JobStarted", peer); + uint64_t nJobID = uint64_t(pthread_self()); dbus_message_append_args(msg, - DBUS_TYPE_STRING, &pDest, /* TODO: redundant parameter, remove from API */ - DBUS_TYPE_UINT64, &job_id, + DBUS_TYPE_STRING, &peer, /* TODO: redundant parameter, remove from API */ + DBUS_TYPE_UINT64, &nJobID, /* TODO: redundant parameter, remove from API */ DBUS_TYPE_INVALID); + VERB2 log("Sending signal JobStarted('%s',%llx)", peer, (unsigned long long)nJobID); send_flush_and_unref(msg); } -void CCommLayerServerDBus::JobStarted(const char* pDest, uint64_t job_id) +void CCommLayerServerDBus::JobDone(const char* peer, const char* pUUID) { - DBusMessage* msg = new_signal_msg("JobStarted"); - /* TODO: if (!dbus_message_set_destination(msg, pDest) die_out_of_memory(); */ + DBusMessage* msg = new_signal_msg("JobDone", peer); dbus_message_append_args(msg, - DBUS_TYPE_STRING, &pDest, /* TODO: redundant parameter, remove from API */ - DBUS_TYPE_UINT64, &job_id, + DBUS_TYPE_STRING, &peer, /* TODO: redundant parameter, remove from API */ + DBUS_TYPE_STRING, &pUUID, /* TODO: redundant parameter, remove from API */ DBUS_TYPE_INVALID); + VERB2 log("Sending signal JobDone('%s','%s')", peer, pUUID); send_flush_and_unref(msg); } -void CCommLayerServerDBus::Error(const std::string& arg1) +void CCommLayerServerDBus::Error(const std::string& pMessage, const char* peer) { - DBusMessage* msg = new_signal_msg("Error"); - const char* c_arg1 = arg1.c_str(); - dbus_message_append_args(msg, - DBUS_TYPE_STRING, &c_arg1, - DBUS_TYPE_INVALID); - send_flush_and_unref(msg); -} - -void CCommLayerServerDBus::Update(const std::string& pMessage, uint64_t job_id) -{ - DBusMessage* msg = new_signal_msg("Update"); + DBusMessage* msg = new_signal_msg("Error", peer); const char* c_message = pMessage.c_str(); dbus_message_append_args(msg, DBUS_TYPE_STRING, &c_message, - DBUS_TYPE_UINT64, &job_id, DBUS_TYPE_INVALID); send_flush_and_unref(msg); } -void CCommLayerServerDBus::Warning(const std::string& pMessage) +void CCommLayerServerDBus::Update(const std::string& pMessage, const char* peer, uint64_t job_id) { - DBusMessage* msg = new_signal_msg("Warning"); + DBusMessage* msg = new_signal_msg("Update", peer); const char* c_message = pMessage.c_str(); dbus_message_append_args(msg, DBUS_TYPE_STRING, &c_message, + DBUS_TYPE_UINT64, &job_id, /* TODO: redundant parameter, remove from API */ DBUS_TYPE_INVALID); send_flush_and_unref(msg); } -void CCommLayerServerDBus::Warning(const std::string& pMessage, uint64_t job_id) +void CCommLayerServerDBus::Warning(const std::string& pMessage, const char* peer, uint64_t job_id) { - DBusMessage* msg = new_signal_msg("Warning"); + DBusMessage* msg = new_signal_msg("Warning", peer); const char* c_message = pMessage.c_str(); dbus_message_append_args(msg, DBUS_TYPE_STRING, &c_message, - DBUS_TYPE_UINT64, &job_id, + DBUS_TYPE_UINT64, &job_id, /* TODO: redundant parameter, remove from API */ DBUS_TYPE_INVALID); send_flush_and_unref(msg); } @@ -456,7 +441,7 @@ static long get_remote_uid(DBusMessage* call, const char** ppSender = NULL) if (dbus_error_is_set(&err)) { dbus_error_free(&err); - error_msg("can't determine remore uid, assuming 0"); + error_msg("Can't determine remote uid, assuming 0"); return 0; } return uid; @@ -495,17 +480,47 @@ static int handle_CreateReport(DBusMessage* call, DBusMessage* reply) const char* sender; long unix_uid = get_remote_uid(call, &sender); - VERB1 log("got %s('%s') call from uid %ld", "CreateReport", pUUID, unix_uid); - uint64_t argout1 = CreateReport_t(pUUID, to_string(unix_uid).c_str(), sender); + VERB1 log("got %s('%s') call from sender '%s' uid %ld", "CreateReport", pUUID, sender, unix_uid); + if (CreateReportThread(pUUID, to_string(unix_uid).c_str(), sender) != 0) + return -1; /* can't create thread (err msg is already logged) */ dbus_message_append_args(reply, - DBUS_TYPE_UINT64, &argout1, + DBUS_TYPE_STRING, &pUUID, /* redundant, eliminate from API */ DBUS_TYPE_INVALID); send_flush_and_unref(reply); return 0; } +static int handle_GetJobResult(DBusMessage* call, DBusMessage* reply) +{ + const char* pUUID; + DBusMessageIter in_iter; + if (!dbus_message_iter_init(call, &in_iter)) + { + error_msg("dbus call %s: no parameters", "GetJobResult"); + return -1; + } + int r = load_val(&in_iter, pUUID); + if (r != LAST_FIELD) + { + if (r == MORE_FIELDS) + error_msg("dbus call %s: extra parameters", "GetJobResult"); + return -1; + } + + long unix_uid = get_remote_uid(call); + VERB1 log("got %s('%s') call from uid %ld", "GetJobResult", pUUID, unix_uid); + map_crash_report_t report = GetJobResult(pUUID, to_string(unix_uid).c_str()); + + DBusMessageIter out_iter; + dbus_message_iter_init_append(reply, &out_iter); + store_val(&out_iter, report); + + send_flush_and_unref(reply); + return 0; +} + static int handle_Report(DBusMessage* call, DBusMessage* reply) { map_crash_report_t argin1; @@ -577,35 +592,6 @@ static int handle_DeleteDebugDump(DBusMessage* call, DBusMessage* reply) return 0; } -static int handle_GetJobResult(DBusMessage* call, DBusMessage* reply) -{ - uint64_t job_id; - DBusMessageIter in_iter; - if (!dbus_message_iter_init(call, &in_iter)) - { - error_msg("dbus call %s: no parameters", "GetJobResult"); - return -1; - } - int r = load_val(&in_iter, job_id); - if (r != LAST_FIELD) - { - if (r == MORE_FIELDS) - error_msg("dbus call %s: extra parameters", "GetJobResult"); - return -1; - } - - long unix_uid = get_remote_uid(call); - VERB1 log("got %s(%llx) call from uid %ld", "GetJobResult", (long long)job_id, unix_uid); - map_crash_report_t report = GetJobResult(job_id, to_string(unix_uid)); - - DBusMessageIter out_iter; - dbus_message_iter_init_append(reply, &out_iter); - store_val(&out_iter, report); - - send_flush_and_unref(reply); - return 0; -} - static int handle_GetPluginsInfo(DBusMessage* call, DBusMessage* reply) { vector_map_string_t plugins_info = g_pPluginManager->GetPluginsInfo(); @@ -885,6 +871,8 @@ static DBusHandlerResult message_received(DBusConnection *conn, DBusMessage *msg const char* member = dbus_message_get_member(msg); log("%s(method:'%s')", __func__, member); + set_client_name(dbus_message_get_sender(msg)); + DBusMessage* reply = dbus_message_new_method_return(msg); int r = -1; if (strcmp(member, "GetCrashInfos") == 0) @@ -931,6 +919,8 @@ static DBusHandlerResult message_received(DBusConnection *conn, DBusMessage *msg } } + set_client_name(NULL); + return DBUS_HANDLER_RESULT_HANDLED; } /* Callback: "DBusObjectPathVTable is unregistered (or its connection is freed)" */ diff --git a/src/Daemon/CommLayerServerDBus.h b/src/Daemon/CommLayerServerDBus.h index 6ac702d..3a8822d 100644 --- a/src/Daemon/CommLayerServerDBus.h +++ b/src/Daemon/CommLayerServerDBus.h @@ -12,14 +12,12 @@ class CCommLayerServerDBus /* DBus signal senders */ virtual void Crash(const std::string& progname, const std::string& uid); - virtual void AnalyzeComplete(const map_crash_report_t& arg1); - virtual void Error(const std::string& arg1); - virtual void Update(const std::string& pMessage, uint64_t pJobID); - //the job id should be enough in jobdone - virtual void JobDone(const char* pDest, uint64_t pJobID); - virtual void JobStarted(const char* pDest, uint64_t pJobID); - virtual void Warning(const std::string& pMessage); - virtual void Warning(const std::string& pMessage, uint64_t pJobID); + virtual void JobStarted(const char* pDest); + virtual void JobDone(const char* pDest, const char* pUUID); + + virtual void Error(const std::string& pMessage, const char* peer); + virtual void Update(const std::string& pMessage, const char* peer, uint64_t pJobID); + virtual void Warning(const std::string& pMessage, const char* peer, uint64_t pJobID); }; #endif diff --git a/src/Daemon/CommLayerServerSocket.cpp b/src/Daemon/CommLayerServerSocket.cpp index c88e0f3..8f1fd4f 100644 --- a/src/Daemon/CommLayerServerSocket.cpp +++ b/src/Daemon/CommLayerServerSocket.cpp @@ -148,7 +148,7 @@ void CCommLayerServerSocket::ProcessMessage(const std::string& pMessage, GIOChan { // std::string UUID = pMessage.substr(sizeof(MESSAGE_CREATE_REPORT) - 1); // map_crash_report_t crashReport = CreateReport(UUID, UID); -//use CreateReport_t instead of CreateReport? +//use CreateReportThread instead of CreateReport? // std::string message = MESSAGE_CREATE_REPORT + crash_report_to_string(crashReport); // Send(message, pSource); } @@ -220,7 +220,7 @@ vector_crash_infos_t CCommLayerServerSocket::GetCrashInfos(const std::string &pS return crashInfos; } -//reimplement as CreateReport_t(...)? +//reimplement as CreateReportThread(...)? //map_crash_report_t CCommLayerServerSocket::CreateReport(const std::string &pUUID,const std::string &pSender) //{ // map_crash_report_t crashReport; @@ -246,12 +246,7 @@ void CCommLayerServerSocket::Crash(const std::string& arg1) //Send("(CRASH)New Crash Detected: " + arg1); } -void CCommLayerServerSocket::AnalyzeComplete(const map_crash_report_t& arg1) -{ - //Send("(ANALYZE_COMPLETE)Analyze Complete."); -} - -void CCommLayerServerSocket::Error(const std::string& arg1) +void CCommLayerServerSocket::Error(const std::string& arg1, const char* peer) { //Send("(ERROR)Error: " + arg1); } diff --git a/src/Daemon/CommLayerServerSocket.h b/src/Daemon/CommLayerServerSocket.h index bf5b2ff..0ee4701 100644 --- a/src/Daemon/CommLayerServerSocket.h +++ b/src/Daemon/CommLayerServerSocket.h @@ -31,7 +31,7 @@ class CCommLayerServerSocket : public CCommLayerServer virtual bool DeleteDebugDump(const std::string& pUUID, const std::string& pSender); virtual void Crash(const std::string& arg1); - virtual void AnalyzeComplete(const map_crash_report_t& arg1); - virtual void Error(const std::string& arg1); - virtual void JobStarted(const char* pDest, uint64_t pJobID) {}; + virtual void JobStarted(const char* pDest) {}; + + virtual void Error(const std::string& arg1, const char* peer); }; diff --git a/src/Daemon/CrashWatcher.cpp b/src/Daemon/CrashWatcher.cpp index 06afabd..6c4d654 100644 --- a/src/Daemon/CrashWatcher.cpp +++ b/src/Daemon/CrashWatcher.cpp @@ -24,19 +24,18 @@ #include "ABRTException.h" #include "CrashWatcher.h" -void CCrashWatcher::Status(const std::string& pMessage, uint64_t pJobID) +void CCrashWatcher::Status(const std::string& pMessage, const char* peer, uint64_t pJobID) { - log("Update: %s", pMessage.c_str()); - //FIXME: send updates only to job owner + VERB1 log("Update('%s'): %s", peer, pMessage.c_str()); if (g_pCommLayer != NULL) - g_pCommLayer->Update(pMessage, pJobID); + g_pCommLayer->Update(pMessage, peer, pJobID); } -void CCrashWatcher::Warning(const std::string& pMessage, uint64_t pJobID) +void CCrashWatcher::Warning(const std::string& pMessage, const char* peer, uint64_t pJobID) { - log("Warning: %s", pMessage.c_str()); + VERB1 log("Warning('%s'): %s", peer, pMessage.c_str()); if (g_pCommLayer != NULL) - g_pCommLayer->Warning(pMessage, pJobID); + g_pCommLayer->Warning(pMessage, peer, pJobID); } CCrashWatcher::CCrashWatcher() @@ -102,97 +101,129 @@ vector_crash_infos_t GetCrashInfos(const std::string &pUID) return retval; } +/* + * "GetJobResult" is a bit of a misnomer. + * It actually _creates_ a_ report_ and returns the result. + * It is called in two cases: + * (1) by CreateReport dbus call -> CreateReportThread(), in the thread + * (2) by GetJobResult dbus call + * In the second case, it finishes quickly, because previous + * CreateReport dbus call already did all the processing, and we just retrieve + * the result from dump directory, which is fast. + */ +map_crash_report_t GetJobResult(const char* pUUID, const char* pUID) +{ + map_crash_info_t crashReport; + + /* FIXME: starting from here, any shared data must be protected with a mutex. + * For example, CreateCrashReport does: + * g_pPluginManager->GetDatabase(g_settings_sDatabase); + * which is unsafe wrt concurrent updates to g_pPluginManager state. + */ + mw_result_t res = CreateCrashReport(pUUID, pUID, crashReport); + switch (res) + { + case MW_OK: + break; + case MW_IN_DB_ERROR: + warn_client(std::string("Did not find crash with UUID ") + pUUID + " in database"); + break; + case MW_PLUGIN_ERROR: + warn_client("Particular analyzer plugin isn't loaded or there is an error within plugin(s)"); + break; + case MW_CORRUPTED: + case MW_FILE_ERROR: + default: + warn_client(std::string("Corrupted crash with UUID ") + pUUID + ", deleting"); + std::string debugDumpDir = DeleteCrashInfo(pUUID, pUID); + DeleteDebugDumpDir(debugDumpDir); + break; + } + return crashReport; +} + typedef struct thread_data_t { pthread_t thread_id; char* UUID; char* UID; - char* dest; + char* peer; } thread_data_t; -static void *create_report(void *arg) +static void* create_report(void* arg) { thread_data_t *thread_data = (thread_data_t *) arg; - map_crash_info_t crashReport; - g_pCommLayer->JobStarted(thread_data->dest, uint64_t(thread_data->thread_id)); + g_pCommLayer->JobStarted(thread_data->peer); + + /* Client name is per-thread, need to set it */ + set_client_name(thread_data->peer); - log("Creating report..."); try { - mw_result_t res; - res = CreateCrashReport(thread_data->UUID, thread_data->UID, crashReport); - switch (res) - { - case MW_OK: - break; - case MW_IN_DB_ERROR: - warn_client(std::string("Did not find crash with UUID ") + thread_data->UUID + " in database"); - break; - case MW_PLUGIN_ERROR: - warn_client(std::string("Particular analyzer plugin isn't loaded or there is an error within plugin(s)")); - break; - case MW_CORRUPTED: - case MW_FILE_ERROR: - default: - warn_client(std::string("Corrupted crash with UUID ") + thread_data->UUID + ", deleting"); - std::string debugDumpDir = DeleteCrashInfo(thread_data->UUID, thread_data->UID); - DeleteDebugDumpDir(debugDumpDir); - break; - } - /* only one thread can write */ - pthread_mutex_lock(&g_pJobsMutex); - g_pending_jobs[std::string(thread_data->UID)][uint64_t(thread_data->thread_id)] = crashReport; - pthread_mutex_unlock(&g_pJobsMutex); - g_pCommLayer->JobDone(thread_data->dest, uint64_t(thread_data->thread_id)); + /* "GetJobResult" is a bit of a misnomer */ + log("Creating report..."); + map_crash_info_t crashReport = GetJobResult(thread_data->UUID, thread_data->UID); + g_pCommLayer->JobDone(thread_data->peer, thread_data->UUID); } catch (CABRTException& e) { if (e.type() == EXCEP_FATAL) { + set_client_name(NULL); /* free strduped strings */ free(thread_data->UUID); free(thread_data->UID); - free(thread_data->dest); + free(thread_data->peer); free(thread_data); throw e; } warn_client(e.what()); } + set_client_name(NULL); + /* free strduped strings */ free(thread_data->UUID); free(thread_data->UID); - free(thread_data->dest); + free(thread_data->peer); free(thread_data); /* Bogus value. pthreads require us to return void* */ return NULL; } -uint64_t CreateReport_t(const char* pUUID, const char* pUID, const char* pSender) +int CreateReportThread(const char* pUUID, const char* pUID, const char* pSender) { thread_data_t *thread_data = (thread_data_t *)xzalloc(sizeof(thread_data_t)); thread_data->UUID = xstrdup(pUUID); thread_data->UID = xstrdup(pUID); - thread_data->dest = xstrdup(pSender); - if (pthread_create(&thread_data->thread_id, NULL, create_report, (void *)thread_data) != 0) + thread_data->peer = xstrdup(pSender); +//TODO: do we need this? +//pthread_attr_t attr; +//pthread_attr_init(&attr); +//pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + int r = pthread_create(&thread_data->thread_id, NULL, create_report, thread_data); + if (r != 0) { free(thread_data->UUID); free(thread_data->UID); - free(thread_data->dest); + free(thread_data->peer); free(thread_data); /* The only reason this may happen is system-wide resource starvation, - * or ulimit is exceeded (someoune floods us with CreateReport() dbus calls?) + * or ulimit is exceeded (someone floods us with CreateReport() dbus calls?) */ - error_msg("cannot create thread"); - return 0; + error_msg("Can't create thread"); + } + else + { + VERB3 log("Thread %llx created", (unsigned long long)thread_data->thread_id); } - return uint64_t(thread_data->thread_id); +//pthread_attr_destroy(&attr); + return r; } bool DeleteDebugDump(const std::string& pUUID, const std::string& pUID) { try { - std::string debugDumpDir; - debugDumpDir = DeleteCrashInfo(pUUID, pUID); + std::string debugDumpDir = DeleteCrashInfo(pUUID, pUID); DeleteDebugDumpDir(debugDumpDir); } catch (CABRTException& e) @@ -207,12 +238,3 @@ bool DeleteDebugDump(const std::string& pUUID, const std::string& pUID) } return true; } - -map_crash_report_t GetJobResult(uint64_t pJobID, const std::string& pSender) -{ - /* FIXME: once we return the result, we should remove it from map to free memory - - use some TTL to clean the memory even if client won't get it - - if we don't find it in the cache we should try to ask MW to get it again?? - */ - return g_pending_jobs[pSender][pJobID]; -} diff --git a/src/Daemon/CrashWatcher.h b/src/Daemon/CrashWatcher.h index f35e100..00bb4d5 100644 --- a/src/Daemon/CrashWatcher.h +++ b/src/Daemon/CrashWatcher.h @@ -44,13 +44,13 @@ class CCrashWatcher public: /* Observer methods */ - virtual void Status(const std::string& pMessage, uint64_t pJobID=0); - virtual void Warning(const std::string& pMessage, uint64_t pJobID=0); + virtual void Status(const std::string& pMessage, const char* peer, uint64_t pJobID); + virtual void Warning(const std::string& pMessage, const char* peer, uint64_t pJobID); }; vector_crash_infos_t GetCrashInfos(const std::string &pUID); -uint64_t CreateReport_t(const char* pUUID, const char* pUID, const char* pSender); +int CreateReportThread(const char* pUUID, const char* pUID, const char* pSender); +map_crash_report_t GetJobResult(const char* pUUID, const char* pUID); bool DeleteDebugDump(const std::string& pUUID, const std::string& pUID); -map_crash_report_t GetJobResult(uint64_t pJobID, const std::string& pSender); #endif /*CRASHWATCHER_H_*/ diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index fc28e8b..a7c9737 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -51,9 +51,12 @@ * - GetCrashInfos(): returns a vector_crash_infos_t (vector_map_vector_string_t) * of crashes for given uid * v[N]["executable"/"uid"/"kernel"/"backtrace"][N] = "contents" - * - CreateReport(UUID): starts creating a report for /var/cache/abrt/DIR with this UUID - * Returns job id (uint64) - * - GetJobResult(job_id): returns map_crash_report_t (map_vector_string_t) + * - CreateReport(UUID): starts creating a report for /var/cache/abrt/DIR with this UUID. + * Returns job id (uint64). + * Emits JobStarted(client_dbus_ID,job_id) dbus signal. + * After it returns, when report creation thread has finished, + * JobDone(client_dbus_ID,UUID) dbus signal is emitted. + * - GetJobResult(UUID): returns map_crash_report_t (map_vector_string_t) * - Report(map_crash_report_t (map_vector_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 @@ -67,7 +70,20 @@ * - SetSettings(map_abrt_settings_t): returns void * * DBus signals we emit: - * - ... + * - Crash(progname,uid) - a new crash occurred (new /var/cache/abrt/DIR is found) + * - JobStarted(client_dbus_ID,job_id) - see CreateReport above. + * Sent as unicast to the client which did CreateReport. + * - JobDone(client_dbus_ID,UUID) - see CreateReport above. + * Sent as unicast to the client which did CreateReport. + * - Error(msg) + * - Warning(msg[,job_id]) + * - Update(msg,job_id) + * + * TODO: + * - Error/Warning/Update dbus signals must be unicast too + * - API does not really need JobStarted dbus signal at all, and JobDone signal + * does not need to pass any parameters - out clients never sent multiple + * CreateReport's. */ @@ -98,12 +114,7 @@ static GMainLoop* g_pMainloop; int g_verbose; CCommLayerServer* g_pCommLayer; -/* - * Map to cache the results from CreateReport_t - * <UID, <job_id, result>> - */ -std::map<const std::string, std::map<uint64_t, map_crash_report_t> > g_pending_jobs; -/* mutex to protect g_pending_jobs */ + pthread_mutex_t g_pJobsMutex; @@ -503,7 +514,8 @@ static gboolean handle_event_cb(GIOChannel *gio, GIOCondition condition, gpointe /* ignore lock files and such */ if (!(event->mask & IN_ISDIR)) { - VERB3 log("File '%s' creation detected, ignoring", name); + // Happens all the time during normal run + //VERB3 log("File '%s' creation detected, ignoring", name); continue; } diff --git a/src/Daemon/Daemon.h b/src/Daemon/Daemon.h index 8fcce71..e03d983 100644 --- a/src/Daemon/Daemon.h +++ b/src/Daemon/Daemon.h @@ -49,9 +49,6 @@ extern CPluginManager* g_pPluginManager; */ extern set_string_t g_setBlackList; -/* Map <UID, <job_id, result>> to cache the results from CreateReport_t() */ -extern std::map<const std::string, std::map<uint64_t, map_crash_report_t> > g_pending_jobs; -/* Mutex to protect g_pending_jobs */ extern pthread_mutex_t g_pJobsMutex; #endif diff --git a/src/Daemon/MiddleWare.cpp b/src/Daemon/MiddleWare.cpp index e6c9187..4f499d6 100644 --- a/src/Daemon/MiddleWare.cpp +++ b/src/Daemon/MiddleWare.cpp @@ -173,33 +173,42 @@ mw_result_t CreateCrashReport(const std::string& pUUID, const std::string& pUID, map_crash_report_t& pCrashReport) { - CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase); - database_row_t row; - database->Connect(); - row = database->GetUUIDData(pUUID, pUID); - database->DisConnect(); - CDebugDump dd; + VERB2 log("CreateCrashReport('%s','%',result)", pUUID.c_str(), pUID.c_str()); + database_row_t row; + if (pUUID != "") + { + CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase); + database->Connect(); + row = database->GetUUIDData(pUUID, pUID); + database->DisConnect(); + } if (pUUID == "" || row.m_sUUID != pUUID) { warn_client("CreateCrashReport(): UUID '"+pUUID+"' is not in database."); return MW_IN_DB_ERROR; } + CDebugDump dd; try { std::string analyzer; std::string gUUID; + VERB3 log(" LoadText(FILENAME_ANALYZER,'%s')", row.m_sDebugDumpDir.c_str()); dd.Open(row.m_sDebugDumpDir); dd.LoadText(FILENAME_ANALYZER, analyzer); dd.Close(); + VERB3 log(" CreateReport('%s')", analyzer.c_str()); CreateReport(analyzer, row.m_sDebugDumpDir); gUUID = GetGlobalUUID(analyzer, row.m_sDebugDumpDir); + VERB3 log(" GetGlobalUUID:'%s'", gUUID.c_str()); + VERB3 log(" RunAnalyzerActions"); RunAnalyzerActions(analyzer, row.m_sDebugDumpDir); + VERB3 log(" DebugDumpToCrashReport"); DebugDumpToCrashReport(row.m_sDebugDumpDir, pCrashReport); add_crash_data_to_crash_report(pCrashReport, CD_UUID, CD_TXT, CD_ISNOTEDITABLE, gUUID); @@ -245,7 +254,6 @@ void RunAction(const std::string& pActionDir, warn_client("RunAction(): " + e.what()); update_client("Execution of '"+pPluginName+"' was not successful: " + e.what()); } - } void RunActionsAndReporters(const std::string& pDebugDumpDir) |
