From 8df9ef8b79464c7aa7c0d55bc38c9ae1610b4c3b Mon Sep 17 00:00:00 2001 From: William Douglas Date: Thu, 7 Apr 2011 02:03:50 +0300 Subject: [PATCH] Send message to dbus once core is processed and once core is submitted --- coredump.c | 8 ++++++-- corewatcher.c | 26 +++++++++++++++++++++----- corewatcher.h | 3 ++- submit.c | 2 +- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/coredump.c b/coredump.c index bd2d403..6652296 100644 --- a/coredump.c +++ b/coredump.c @@ -390,6 +390,7 @@ struct oops *extract_core(char *corefile) continue; free(c2); } else { + /* keep going even if asprintf has errors */ asprintf(&c1, "%s", line); } } @@ -453,6 +454,7 @@ void process_corefile(char *filename) c = strtok(NULL, delim); } fprintf(stderr, "---[start of coredump]---\n%s\n---[end of coredump]---\n", oops->text); + dbus_say_found(oops); /* try to write coredump text details to text file */ write_core_detail_file(filename, oops->text); @@ -463,10 +465,12 @@ void process_corefile(char *filename) free(dfile); free(oops->filename); oops->filename = strdup(newfile); + } else { + /* backtrace queued only if files have been processed + to avoid putting a new coredump in twice */ + queue_backtrace(oops); } - queue_backtrace(oops); - free(oops->application); free(oops->text); free(oops->filename); diff --git a/corewatcher.c b/corewatcher.c index 86c8bbc..82ce15d 100644 --- a/corewatcher.c +++ b/corewatcher.c @@ -149,11 +149,9 @@ void dbus_ask_permission(char * detail_file_name) } -void dbus_say_thanks(struct oops *oops, char *url) +void dbus_say_thanks(char *url) { DBusMessage *message; - unsigned int crash_id = 0; - char *dbus_msg_arg; if (!bus) return; @@ -165,13 +163,31 @@ void dbus_say_thanks(struct oops *oops, char *url) dbus_message_unref(message); syslog(LOG_WARNING, "corewatcher.org: oops is posted as %s", url); } +} + +void dbus_say_found(struct oops *oops) +{ + DBusMessage *message; + char detail_filename[8192]; + char *dbus_msg_arg; + char *pid; + + if (!bus || !oops) + return; + + if (!(pid = strstr(oops->filename, "."))) { + sprintf(detail_filename, "Unknown"); + } else { + snprintf(detail_filename, 8192, "%s%s.txt", core_folder, ++pid); + } message = dbus_message_new_signal("/org/corewatcher/submit/sent", "org.corewatcher.submit.sent", "sent"); - sscanf(url, "%*[^?]?number=%u", &crash_id); - asprintf(&dbus_msg_arg, "crash report #%u\n", crash_id); + if ((asprintf(&dbus_msg_arg, "crash report located at: %s\n", detail_filename)) <= 0) + return; dbus_message_append_args(message, DBUS_TYPE_STRING, &oops->application, DBUS_TYPE_STRING, &dbus_msg_arg, DBUS_TYPE_INVALID); + dbus_connection_send(bus, message, NULL); dbus_message_unref(message); free(dbus_msg_arg); diff --git a/corewatcher.h b/corewatcher.h index da73290..b714372 100644 --- a/corewatcher.h +++ b/corewatcher.h @@ -49,7 +49,8 @@ extern void read_config_file(char *filename); extern void ask_permission(void); extern void dbus_ask_permission(char * detail_file_name); -extern void dbus_say_thanks(struct oops *oops, char *url); +extern void dbus_say_thanks(char *url); +extern void dbus_say_found(struct oops *oops); extern int opted_in; extern int allow_distro_to_pass_on; diff --git a/submit.c b/submit.c index d03e8df..338f341 100644 --- a/submit.c +++ b/submit.c @@ -268,7 +268,7 @@ void submit_queue_with_url(struct oops *queue, char *wsubmit_url) rename(oops->filename, newfile); checksums[submitted++] = oops->checksum; - dbus_say_thanks(oops, result_url); + dbus_say_thanks(result_url); } count++; -- 2.7.4