#include <sys/time.h>
#include <dirent.h>
#include <signal.h>
+#include <errno.h>
#include "corewatcher.h"
#define MAX(A,B) ((A) > (B) ? (A) : (B))
+long int get_time(char *filename)
+{
+ struct stat st;
+ if (stat(filename, &st)) {
+ return 0;
+ }
+ return st.st_mtim.tv_sec;
+}
+
char *get_build(void) {
FILE *file;
char *line = NULL;
char *build = get_build();
char *release = get_release();
char *kernel = get_kernel();
- struct timeval tv;
+ long int time = get_time(corefile);
- gettimeofday(&tv, NULL);
get_package_info(appfile);
ret = asprintf(&result,
appfile, sig, signame(sig),
release,
build,
- tv.tv_sec,
+ time,
uid);
free(kernel);
/* if this oops hasn't been processed before need to write details out and rename */
if (!strstr(filename, ".processed")) {
+ char *dfile = NULL, *c = NULL, *d = NULL;
+ char delim[] = "/";
+ dfile = strdup(filename);
+ if (!dfile)
+ return;
+
+ c = strtok(dfile, delim);
+ while(c) {
+ d = c;
+ c = strtok(NULL, delim);
+ }
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, oops->text);
-
- sprintf(newfile,"%s%s.processed", core_folder, filename);
+ if (!mkdir(core_folder, S_IRWXU | S_IRWXG | S_IRWXO) && errno != EEXIST)
+ return;
+ sprintf(newfile,"%s%s.processed", core_folder, d);
rename(filename, newfile);
+ free(dfile);
free(oops->filename);
oops->filename = strdup(newfile);
}
sum = checksum(oops->text);
for (i = 0; i < submitted; i++) {
if (checksums[i] == sum) {
- printf("Match with oops %i (%x)\n", i, sum);
+ printf("Match with oops %i (%d)\n", i, sum);
+ unlink(oops->filename);
return;
}
}
- checksums[submitted++] = sum;
new = malloc(sizeof(struct oops));
memset(new, 0, sizeof(struct oops));
fprintf(stderr, "+ Submit text is:\n---[start of oops]---\n%s\n---[end of oops]---\n", oops->text);
next = oops->next;
+ free(oops->application);
free(oops->text);
+ free(oops->filename);
free(oops);
oops = next;
count++;
return size * nmemb;
}
-void submit_queue_with_url(char *wsubmit_url)
+void submit_queue_with_url(struct oops *queue, char *wsubmit_url)
{
int result;
struct oops *oops;
- struct oops *queue;
CURL *handle;
int count = 0;
handle = curl_easy_init();
curl_easy_setopt(handle, CURLOPT_URL, wsubmit_url);
- queue = queued_backtraces;
- queued_backtraces = NULL;
- barrier();
-
oops = queue;
while (oops) {
struct curl_httppost *post = NULL;
struct curl_httppost *last = NULL;
struct oops *next;
+ unsigned int sum;
+ int i;
+
+ sum = oops->checksum;
+ for (i = 0; i < submitted; i++) {
+ if (checksums[i] == sum) {
+ printf("Match with oops %i (%d)\n", i, sum);
+ unlink(oops->filename);
+ goto dup;
+ }
+ }
/* set up the POST data */
curl_formadd(&post, &last,
curl_formfree(post);
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;
oldfile[strlen(oldfile) - strlen(c)] = '\0';
}
- sprintf(newfile,"%s%s.submitted", core_folder, oldfile);
+ sprintf(newfile,"%s.submitted", oldfile);
+
if (do_unlink)
unlink(oops->filename);
else
rename(oops->filename, newfile);
+ checksums[submitted++] = oops->checksum;
dbus_say_thanks(oops, result_url);
}
+ count++;
+ dup:
next = oops->next;
+ free(oops->application);
free(oops->text);
+ free(oops->filename);
free(oops);
oops = next;
- count++;
}
curl_easy_cleanup(handle);
void submit_queue(void)
{
int i;
+ struct oops *queue;
CURL *handle;
memset(result_url, 0, 4096);
return;
}
+ queue = queued_backtraces;
+ queued_backtraces = NULL;
+ barrier();
+
handle = curl_easy_init();
curl_easy_setopt(handle, CURLOPT_NOBODY, 1);
curl_easy_setopt(handle, CURLOPT_TIMEOUT, 5);
for (i = 0; i < url_count; i++) {
curl_easy_setopt(handle, CURLOPT_URL, submit_url[i]);
if (!curl_easy_perform(handle)) {
- submit_queue_with_url(submit_url[i]);
+ submit_queue_with_url(queue, submit_url[i]);
break;
}
}
oops = queue;
while (oops) {
next = oops->next;
+ free(oops->application);
free(oops->text);
+ free(oops->filename);
free(oops);
oops = next;
}