#include <stdio.h>
#include <string.h>
#include <assert.h>
+#include <fcntl.h>
#include <asm/unistd.h>
#include <sys/types.h>
int do_unlink = 0;
int uid;
int sig;
-char *corefile;
char *package;
char *component;
char *arch;
return line;
}
-void set_wrapped_app(char *line)
+char *set_wrapped_app(char *line)
{
char *dline = NULL, *app = NULL, delim[] = " '";
app = strtok(NULL, delim);
}
- if (app != NULL)
- /*
- * This may return NULL if app isn't on the path
- * but we aren't going to worry about that here.
- */
- app = find_executable(app);
free(dline);
-
- return;
+ /*
+ * This may return NULL if app isn't on the path
+ * but we aren't going to worry about that here.
+ */
+ return find_executable(app);
}
void get_package_info(char *appfile) {
size_t size = 0;
if (asprintf(&command, "rpm -q --whatprovides %s --queryformat \"%%{NAME}-%%{VERSION}-%%{RELEASE}-%%{ARCH}\"", appfile) < 0) {
- line = strdup("Unknown");
+ package = strdup("Unknown");
} else {
file = popen(command, "r");
-
ret = getline(&line, &size, file);
- if ((!size) || (ret < 0))
+ if ((!size) || (ret < 0)) {
+ free(line);
line = strdup("Unknown");
+ }
c = strchr(line, '\n');
if (c) *c = 0;
pclose(file);
+ package = strdup(line);
}
- package = strdup(line);
+ free(line);
+ free(command);
if (asprintf(&command, "rpm -q --whatprovides %s --queryformat \"%%{NAME}\"", appfile) < 0) {
- line = strdup("Unknown");
+ component = strdup("Unknown");
} else {
file = popen(command, "r");
ret = getline(&line, &size, file);
- if ((!size) || (ret < 0))
+ if ((!size) || (ret < 0)) {
+ free(line);
line = strdup("Unknown");
+ }
c = strchr(line, '\n');
if (c) *c = 0;
pclose(file);
+ component = strdup(line);
}
- component = strdup(line);
+ free(line);
+ free(command);
if (asprintf(&command, "rpm -q --whatprovides %s --queryformat \"%%{ARCH}\"", appfile) < 0) {
- line = strdup("Unknown");
+ arch = strdup("Unknown");
} else {
file = popen(command, "r");
ret = getline(&line, &size, file);
- if ((!size) || (ret < 0))
+ if ((!size) || (ret < 0)) {
+ free(line);
line = strdup("Unknown");
+ }
c = strchr(line, '\n');
if (c) *c = 0;
pclose(file);
+ arch = strdup(line);
}
- arch = strdup(line);
+ free(line);
+ free(command);
}
char *signame(int sig)
if (asprintf(&command, "uname -r") < 0) {
line = strdup("Unknown");
+ free(command);
return line;
}
file = popen(command, "r");
+ free(command);
ret = getline(&line, &size, file);
if ((!size) || (ret < 0)) {
free(kernel);
free(package);
free(release);
+ free(component);
+ free(arch);
if (ret < 0)
result = strdup("Unknown");
FILE *file;
coredump = find_coredump(corefile);
- if (!coredump)
+ if (!coredump) {
+ free(coredump);
return NULL;
+ }
appfile = find_executable(coredump);
+ /* coredump no longer used, so free it as it was strdup'd */
+ free(coredump);
if (!appfile)
return NULL;
- if (asprintf(&command, "LANG=C gdb --batch -f %s %s -x /var/lib/corewatcher/gdb.command 2> /dev/null", appfile, corefile) < 0)
+ if (asprintf(&command, "LANG=C gdb --batch -f %s %s -x /var/lib/corewatcher/gdb.command 2> /dev/null", appfile, corefile) < 0) {
+ free(command);
return NULL;
+ }
/*
* Scan core dump in case meego-tablet-wrapper was used
if (ret < 0)
break;
- if (strstr(line, "Core was generated by `")) {
+ if (strstr(line, "Core was generated by") &&
+ strstr(line, "--app")) {
/* attempt to update appfile */
- set_wrapped_app(line);
+ appfile = set_wrapped_app(line);
break;
}
}
+ free(line);
+ pclose(file);
c1 = build_core_header(appfile, corefile);
int ret;
c2 = c1;
- line = NULL;
ret = getline(&line, &size, file);
if (!size)
break;
break;
if (strstr(line, "no debugging symbols found")) {
- free(line);
continue;
}
if (strstr(line, "reason: ")) {
- free(line);
continue;
}
continue;
free(c2);
} else {
+ free(c1);
c1 = NULL;
if (asprintf(&c1, "%s", line) < 0)
continue;
}
- free(line);
}
+ free(line);
pclose(file);
free(command);
return c1;
}
+void write_core_detail_file(char *filename, char *text)
+{
+ int fd;
+ char *pid;
+ char detail_filename[8192];
+
+ if (!(pid = strstr(filename, ".")))
+ return;
+
+ snprintf(detail_filename, 8192, "/tmp/%s.txt", ++pid);
+ if ((fd = open(detail_filename, O_WRONLY | O_CREAT | O_TRUNC, 0)) != -1) {
+ write(fd, text, strlen(text));
+ fchmod(fd, 0644);
+ close(fd);
+ }
+}
+
void process_corefile(char *filename)
{
char *ptr;
if (!ptr) {
unlink(filename);
+ free(ptr);
return;
}
queue_backtrace(ptr);
fprintf(stderr, "---[start of coredump]---\n%s\n---[end of coredump]---\n", ptr);
+
+ /* try to write coredump text details to text file */
+ write_core_detail_file(filename, ptr);
+
sprintf(newfile,"%s.processed", filename);
if (do_unlink)
unlink(filename);
submit_queue();
else if (opted_in >= 1)
ask_permission();
+ closedir(dir);
return 1;
}
}
-static void write_logfile(int count)
+static void write_logfile(int count, char *wsubmit_url)
{
openlog("corewatcher", 0, LOG_KERN);
- syslog(LOG_WARNING, "Submitted %i coredump signatures to %s", count, submit_url);
+ syslog(LOG_WARNING, "Submitted %i coredump signatures to %s", count, wsubmit_url);
closelog();
}
if (c2) *c2 = 0;
strncpy(result_url, c1, 4095);
}
+ free(c);
return size * nmemb;
}
-void submit_queue(void)
+void submit_queue_with_url(char *wsubmit_url)
{
int result;
struct oops *oops;
CURL *handle;
int count = 0;
- memset(result_url, 0, 4096);
-
- if (testmode) {
- print_queue();
- return;
- }
-
handle = curl_easy_init();
- curl_easy_setopt(handle, CURLOPT_URL, submit_url);
+ curl_easy_setopt(handle, CURLOPT_URL, wsubmit_url);
queue = queued_backtraces;
queued_backtraces = NULL;
curl_easy_cleanup(handle);
if (count && !testmode)
- write_logfile(count);
+ write_logfile(count, wsubmit_url);
if (count)
dbus_say_thanks(result_url);
}
}
+void submit_queue(void)
+{
+ int i;
+ CURL *handle;
+
+ memset(result_url, 0, 4096);
+
+ if (testmode) {
+ print_queue();
+ return;
+ }
+
+ 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]);
+ break;
+ }
+ }
+
+ curl_easy_cleanup(handle);
+}
+
void clear_queue(void)
{
struct oops *oops, *next;
free(oops);
oops = next;
}
- write_logfile(0);
+ write_logfile(0, "Unknown");
}
void ask_permission(void)