pass oops struct instead of just a text blob, just to keep application name useable
authorChris Leech <christopher.leech@linux.intel.com>
Fri, 1 Apr 2011 23:54:26 +0000 (16:54 -0700)
committerChris Leech <christopher.leech@linux.intel.com>
Fri, 1 Apr 2011 23:54:26 +0000 (16:54 -0700)
Signed-off-by: Chris Leech <christopher.leech@linux.intel.com>
coredump.c
corewatcher.h
submit.c

index ba78971..f587e3e 100644 (file)
@@ -325,8 +325,9 @@ void wrapper_scan(char *command)
        pclose(file);
 }
 
-char *extract_core(char *corefile)
+struct oops *extract_core(char *corefile)
 {
+       struct oops *oops;
        char *command = NULL, *c1 = NULL, *c2 = NULL, *line = NULL;
        char *coredump = NULL;
        char *appfile;
@@ -383,7 +384,15 @@ char *extract_core(char *corefile)
                free(line);
        pclose(file);
        free(command);
-       return c1;
+       oops = malloc(sizeof(struct oops));
+       if (!oops) {
+               free(c1);
+               return NULL;
+       }
+       memset(oops, 0, sizeof(struct oops));
+       oops->application = strdup(appfile);
+       oops->text = c1;
+       return oops;
 }
 
 void write_core_detail_file(char *filename, char *text)
@@ -405,21 +414,20 @@ void write_core_detail_file(char *filename, char *text)
 
 void process_corefile(char *filename)
 {
-       char *ptr;
+       struct oops *oops;
        char newfile[8192];
-       ptr = extract_core(filename);
+       oops = extract_core(filename);
 
-       if (!ptr) {
+       if (!oops) {
                unlink(filename);
-               free(ptr);
                return;
        }
 
-       queue_backtrace(ptr);
-       fprintf(stderr, "---[start of coredump]---\n%s\n---[end of coredump]---\n", ptr);
+       queue_backtrace(oops);
+       fprintf(stderr, "---[start of coredump]---\n%s\n---[end of coredump]---\n", oops->text);
 
        /* try to write coredump text details to text file */
-       write_core_detail_file(filename, ptr);
+       write_core_detail_file(filename, oops->text);
 
        sprintf(newfile,"%s.processed", filename);
        if (do_unlink)
@@ -427,7 +435,9 @@ void process_corefile(char *filename)
        else
                rename(filename, newfile);
 
-       free(ptr);
+       free(oops->application);
+       free(oops->text);
+       free(oops);
 }
 
 
index 1c3d905..0ffac0a 100644 (file)
 
 #define MAX_URLS 9
 
-extern void queue_backtrace(char *oops);
+struct oops {
+       struct oops *next;
+       char *application;
+       char *text;
+       unsigned int checksum;
+};
+
+extern void queue_backtrace(struct oops *oops);
 extern void submit_queue(void);
 extern void clear_queue(void);
 
index c90fb1c..300f2b0 100644 (file)
--- a/submit.c
+++ b/submit.c
@@ -52,14 +52,6 @@ extern int do_unlink;
 static unsigned int checksums[MAX_CHECKSUMS];
 static int submitted;
 
-struct oops;
-
-struct oops {
-       struct oops *next;
-       char *text;
-       unsigned int checksum;
-};
-
 /* we queue up oopses, and then submit in a batch.
  * This is useful to be able to cancel all submissions, in case
  * we later find our marker indicating we submitted everything so far already
@@ -86,7 +78,7 @@ static unsigned int checksum(char *ptr)
        return temp;
 }
 
-void queue_backtrace(char *oops)
+void queue_backtrace(struct oops *oops)
 {
        int i;
        unsigned int sum;
@@ -95,7 +87,7 @@ void queue_backtrace(char *oops)
        if (submitted >= MAX_CHECKSUMS-1)
                return;
        /* first, check if we haven't already submitted the oops */
-       sum = checksum(oops);
+       sum = checksum(oops->text);
        for (i = 0; i < submitted; i++) {
                if (checksums[i] == sum) {
                        printf("Match with oops %i (%x)\n", i, sum);
@@ -108,7 +100,8 @@ void queue_backtrace(char *oops)
        memset(new, 0, sizeof(struct oops));
        new->next = queued_backtraces;
        new->checksum = sum;
-       new->text = strdup(oops);
+       new->application = strdup(oops->application);
+       new->text = strdup(oops->text);
        queued_backtraces = new;
        newoops = 1;
 }