return line;
}
-char *set_wrapped_app(char *line)
+void set_wrapped_app(char *line)
{
- char *dline = NULL, *app = NULL, delim[] = " '";
+ char *dline = NULL, *app = NULL, *ret = NULL;
+ char delim[] = " '";
dline = strdup(line);
}
app = strtok(NULL, delim);
}
-
+ ret = find_executable(app);
free(dline);
/*
- * This may return NULL if app isn't on the path
- * but we aren't going to worry about that here.
+ * May have got NULL from find_executable if app
+ * isn't on the path but it doesn't matter as we
+ * don't change the filename in that case.
*/
- return find_executable(app);
}
void get_package_info(char *appfile) {
package = strdup("Unknown");
} else {
file = popen(command, "r");
+ free(command);
ret = getline(&line, &size, file);
if ((!size) || (ret < 0)) {
- free(line);
- line = strdup("Unknown");
+ package = strdup("Unknown");
+ } else {
+ c = strchr(line, '\n');
+ if (c) *c = 0;
+ package = strdup(line);
}
- c = strchr(line, '\n');
- if (c) *c = 0;
pclose(file);
- package = strdup(line);
}
- free(line);
- free(command);
if (asprintf(&command, "rpm -q --whatprovides %s --queryformat \"%%{NAME}\"", appfile) < 0) {
component = strdup("Unknown");
} else {
file = popen(command, "r");
+ free(command);
ret = getline(&line, &size, file);
if ((!size) || (ret < 0)) {
- free(line);
- line = strdup("Unknown");
+ component = strdup("Unknown");
+ } else {
+ c = strchr(line, '\n');
+ if (c) *c = 0;
+ component = strdup(line);
}
- c = strchr(line, '\n');
- if (c) *c = 0;
pclose(file);
- component = strdup(line);
}
- free(line);
- free(command);
if (asprintf(&command, "rpm -q --whatprovides %s --queryformat \"%%{ARCH}\"", appfile) < 0) {
arch = strdup("Unknown");
} else {
file = popen(command, "r");
+ free(command);
ret = getline(&line, &size, file);
if ((!size) || (ret < 0)) {
- free(line);
- line = strdup("Unknown");
+ arch = strdup("Unknown");
+ } else {
+ c = strchr(line, '\n');
+ if (c) *c = 0;
+ arch = strdup(line);
}
- c = strchr(line, '\n');
- if (c) *c = 0;
pclose(file);
- arch = strdup(line);
}
free(line);
- free(command);
}
char *signame(int sig)
return result;
}
-char *extract_core(char *corefile)
+/*
+ * Scan core dump in case a wrapper was used
+ * to run the process and get the actual binary name
+ */
+void wrapper_scan(char *command)
{
- char *command = NULL, *c1 = NULL, *c2 = NULL, *line;
- char *coredump = NULL;
- char *appfile;
+ char *line = NULL;
FILE *file;
- coredump = find_coredump(corefile);
- 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) {
- free(command);
- return NULL;
- }
-
- /*
- * Scan core dump in case meego-tablet-wrapper was used
- * to run the process and get the actual app name
- */
file = popen(command, "r");
while (!feof(file)) {
size_t size = 0;
int ret;
-
- line = NULL;
+ free(line);
ret = getline(&line, &size, file);
if (!size)
break;
if (strstr(line, "Core was generated by") &&
strstr(line, "--app")) {
/* attempt to update appfile */
- appfile = set_wrapped_app(line);
+ set_wrapped_app(line);
break;
}
}
free(line);
pclose(file);
+}
+
+char *extract_core(char *corefile)
+{
+ char *command = NULL, *c1 = NULL, *c2 = NULL, *line;
+ char *coredump = NULL;
+ char *appfile;
+ FILE *file;
+ coredump = find_coredump(corefile);
+ if (!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) {
+ free(command);
+ return NULL;
+ }
+
+ wrapper_scan(command);
c1 = build_core_header(appfile, corefile);
file = popen(command, "r");
int ret;
c2 = c1;
+ free(line);
ret = getline(&line, &size, file);
if (!size)
break;
continue;
free(c2);
} else {
- free(c1);
- c1 = NULL;
- if (asprintf(&c1, "%s", line) < 0)
- continue;
+ asprintf(&c1, "%s", line);
}
}
free(line);