first stab at resending coredumps that were unsent
authorWilliam Douglas <william.douglas@linux.intel.com>
Mon, 4 Apr 2011 23:52:15 +0000 (16:52 -0700)
committerWilliam Douglas <william.douglas@linux.intel.com>
Mon, 4 Apr 2011 23:52:15 +0000 (16:52 -0700)
Signed-off-by: William Douglas <william.douglas@linux.intel.com>
configfile.c
coredump.c
corewatcher.conf
corewatcher.h
submit.c

index 361f2f8..958a915 100644 (file)
@@ -38,6 +38,7 @@ int opted_in;
 int allow_distro_to_pass_on;
 char *submit_url[MAX_URLS];
 char *build_release;
+char *core_folder;
 int url_count = 0;
 extern int do_unlink;
 
@@ -100,6 +101,13 @@ void read_config_file(char *filename)
                        if (c)
                                build_release = strdup(c);
                }
+               c = strstr(line, "core-folder");
+               if (c) {
+                       c += 11;
+                       c = strstr(c, "/");
+                       if (c)
+                               core_folder = strdup(c);
+               }
                free(line);
        }
        fclose(file);
@@ -107,4 +115,6 @@ void read_config_file(char *filename)
                build_release = strdup("/etc/meego-release");
        if (!url_count)
                submit_url[url_count++] = strdup("http://crashdb.meego.com/submitbug.php");
+       if (!core_folder)
+               core_folder = strdup("/tmp/corewatcher/");
 }
index 6984474..c4fd8b8 100644 (file)
@@ -396,6 +396,7 @@ struct oops *extract_core(char *corefile)
        memset(oops, 0, sizeof(struct oops));
        oops->application = strdup(appfile);
        oops->text = c1;
+       oops->filename = strdup(corefile);
        return oops;
 }
 
@@ -408,7 +409,7 @@ void write_core_detail_file(char *filename, char *text)
        if (!(pid = strstr(filename, ".")))
                return;
 
-       snprintf(detail_filename, 8192, "/tmp/%s.txt", ++pid);
+       snprintf(detail_filename, 8192, "%s%s.txt", core_folder, ++pid);
        if ((fd = open(detail_filename, O_WRONLY | O_CREAT | O_TRUNC, 0)) != -1) {
                write(fd, text, strlen(text));
                fchmod(fd, 0644);
@@ -420,6 +421,7 @@ void process_corefile(char *filename)
 {
        struct oops *oops;
        char newfile[8192];
+
        oops = extract_core(filename);
 
        if (!oops) {
@@ -427,20 +429,25 @@ void process_corefile(char *filename)
                return;
        }
 
-       queue_backtrace(oops);
-       fprintf(stderr, "---[start of coredump]---\n%s\n---[end of coredump]---\n", oops->text);
+       /* if this oops hasn't been processed before need to write details out and rename */
+       if (!strstr(filename, ".processed")) {
 
-       /* try to write coredump text details to text file */
-       write_core_detail_file(filename, oops->text);
+               fprintf(stderr, "---[start of coredump]---\n%s\n---[end of coredump]---\n", oops->text);
 
-       sprintf(newfile,"%s.processed", filename);
-       if (do_unlink)
-               unlink(filename);
-       else
+               /* try to write coredump text details to text file */
+               write_core_detail_file(filename, oops->text);
+
+               sprintf(newfile,"%s%s.processed", core_folder, filename);
                rename(filename, newfile);
+               free(oops->filename);
+               oops->filename = strdup(newfile);
+       }
+
+       queue_backtrace(oops);
 
        free(oops->application);
        free(oops->text);
+       free(oops->filename);
        free(oops);
 }
 
@@ -455,7 +462,7 @@ int scan_dmesg(void __unused *unused)
        if (!dir)
                return 1;
 
-       fprintf(stderr, "+ scanning...\n");
+       fprintf(stderr, "+ scanning /tmp/...\n");
        do {
                entry = readdir(dir);
                if (!entry)
@@ -470,11 +477,28 @@ int scan_dmesg(void __unused *unused)
                fprintf(stderr, "+ Looking at %s\n", path);
                process_corefile(path);
        } while (entry);
+       closedir(dir);
+
+       dir = opendir(core_folder);
+       if (!dir)
+               return 1;
+
+       fprintf(stderr, "+ scanning %s...\n", core_folder);
+       do {
+               entry = readdir(dir);
+               if (!entry)
+                       break;
+               if (!strstr(entry->d_name, ".processed"))
+                       continue;
+               sprintf(path, "%s%s", core_folder, entry->d_name);
+               fprintf(stderr, "+ Looking at %s\n", path);
+               process_corefile(path);
+       } while(entry);
+       closedir(dir);
 
        if (opted_in >= 2)
                submit_queue();
        else if (opted_in >= 1)
                ask_permission();
-       closedir(dir);
        return 1;
 }
index dd8b775..00e726d 100644 (file)
@@ -47,4 +47,10 @@ submit-url = http://crashdb.meego.com/submitbug.php
 # Location for the MeeGo build release file
 #
 
-release-info = /etc/meego-release
\ No newline at end of file
+release-info = /etc/meego-release
+
+#
+# Location to store meego coredumps after they are processed
+#
+
+core-folder = /tmp/corewatcher/
\ No newline at end of file
index 3cefe34..da73290 100644 (file)
@@ -36,6 +36,7 @@ struct oops {
        struct oops *next;
        char *application;
        char *text;
+       char *filename;
        unsigned int checksum;
 };
 
@@ -55,6 +56,7 @@ extern int allow_distro_to_pass_on;
 extern char *submit_url[MAX_URLS];
 extern int url_count;
 extern char *build_release;
+extern char *core_folder;
 
 extern int testmode;
 extern int pinged;
index ac639ec..89bde7b 100644 (file)
--- a/submit.c
+++ b/submit.c
@@ -59,6 +59,7 @@ static int submitted;
  */
 static struct oops *queued_backtraces;
 static int newoops;
+static int unsubmittedoops;
 
 /* For communicating details to the applet, we write the
  * details in a file, and provide the filename to the applet
@@ -102,8 +103,9 @@ void queue_backtrace(struct oops *oops)
        new->checksum = sum;
        new->application = strdup(oops->application);
        new->text = strdup(oops->text);
+       new->filename = strdup(oops->filename);
        queued_backtraces = new;
-       newoops = 1;
+       unsubmittedoops = 1;
 }
 
 
@@ -233,9 +235,41 @@ void submit_queue_with_url(char *wsubmit_url)
                curl_easy_setopt(handle, CURLOPT_HTTPPOST, post);
                curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, writefunction);
                result = curl_easy_perform(handle);
-
                curl_formfree(post);
-               dbus_say_thanks(oops, result_url);
+
+               if (!result) {
+                       struct oops *new;
+                       new = malloc(sizeof(struct oops));
+                       memset(new, 0, sizeof(struct oops));
+                       new->next = queued_backtraces;
+                       new->checksum = oops->checksum;
+                       new->application = strdup(oops->application);
+                       new->text = strdup(oops->text);
+                       queued_backtraces = new;
+                       newoops = 1;
+               } else {
+                       char newfile[8192];
+                       char oldfile[8192];
+                       char *c;
+
+                       memset(newfile, 0, sizeof(newfile));
+                       memset(oldfile, 0, sizeof(oldfile));
+
+                       strncpy(oldfile, oops->filename, 8192);
+                       oldfile[8191] = '\0';
+                       c = strstr(oldfile, ".processed");
+                       if (c) {
+                               oldfile[strlen(oldfile) - strlen(c)] = '\0';
+                       }
+
+                       sprintf(newfile,"%s%s.submitted",  core_folder, oldfile);
+                       if (do_unlink)
+                               unlink(oops->filename);
+                       else
+                               rename(oops->filename, newfile);
+
+                       dbus_say_thanks(oops, result_url);
+               }
 
                next = oops->next;
                free(oops->text);
@@ -306,10 +340,11 @@ void clear_queue(void)
 
 void ask_permission(void)
 {
-       if (!newoops && !pinged)
+       if (!newoops && !pinged && !unsubmittedoops)
                return;
        pinged = 0;
        newoops = 0;
+       unsubmittedoops = 0;
        if (queued_backtraces) {
                write_detail_file();
                dbus_ask_permission(detail_filename);