From 090981fded1bc758119066d5374ab11cc002d462 Mon Sep 17 00:00:00 2001 From: William Douglas Date: Thu, 10 Feb 2011 14:44:06 -0800 Subject: [PATCH] Have the process reported be the actual process run by meego-tablet-wrapper --- coredump.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++-- find_file.c | 13 ++++++++++--- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/coredump.c b/coredump.c index 3532a95..ad166ca 100644 --- a/coredump.c +++ b/coredump.c @@ -82,6 +82,32 @@ static char *get_release(void) { return line; } +void set_wrapped_app(char *line) +{ + char *dline = NULL, *app = NULL, delim[] = " '"; + + dline = strdup(line); + + app = strtok(dline, delim); + while(app) { + if (strcmp(app, "--app") == 0) { + app = strtok(NULL, delim); + break; + } + 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; +} + void get_package_info(char *appfile) { char *command = NULL, *line = NULL; char *c; @@ -229,11 +255,34 @@ char *extract_core(char *corefile) if (!appfile) return NULL; - c1 = build_core_header(appfile, corefile); - if (asprintf(&command, "LANG=C gdb --batch -f %s %s -x /var/lib/corewatcher/gdb.command 2> /dev/null", appfile, corefile) < 0) 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; + ret = getline(&line, &size, file); + if (!size) + break; + if (ret < 0) + break; + + if (strstr(line, "Core was generated by `")) { + /* attempt to update appfile */ + set_wrapped_app(line); + break; + } + } + + c1 = build_core_header(appfile, corefile); + file = popen(command, "r"); while (!feof(file)) { size_t size = 0; diff --git a/find_file.c b/find_file.c index dd0b122..6d9de80 100644 --- a/find_file.c +++ b/find_file.c @@ -22,6 +22,12 @@ char *find_executable(char *fragment) { + /* + * Added path_filename to avoid writing over + * filename if this function is called twice. + * (When meego-tablet-wrapper is used) + */ + char path_filename[PATH_MAX*2]; char *path, *c1, *c2; static char filename[PATH_MAX*2]; @@ -42,9 +48,10 @@ char *find_executable(char *fragment) while (c1 && strlen(c1)>0) { c2 = strchr(c1, ':'); if (c2) *c2=0; - sprintf(filename, "%s/%s", c1, fragment); - if (!access(filename, X_OK)) { - printf("Found %s\n", filename); + sprintf(path_filename, "%s/%s", c1, fragment); + if (!access(path_filename, X_OK)) { + printf("Found %s\n", path_filename); + strcpy(filename, path_filename); return filename; } c1 = c2; -- 2.7.4