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;
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)
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)
else
rename(filename, newfile);
- free(ptr);
+ free(oops->application);
+ free(oops->text);
+ free(oops);
}
#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);
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
return temp;
}
-void queue_backtrace(char *oops)
+void queue_backtrace(struct oops *oops)
{
int i;
unsigned int sum;
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);
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;
}