From: Auke Kok Date: Fri, 6 Aug 2010 23:13:35 +0000 (-0700) Subject: Add reason extraction, UID finding. X-Git-Tag: accepted/trunk/20130110.014835~153 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bf9f8fe503b80152275e8125a846daff3543fe16;p=platform%2Fupstream%2Fcorewatcher.git Add reason extraction, UID finding. --- diff --git a/coredump.c b/coredump.c index 01ee289..c491a6e 100644 --- a/coredump.c +++ b/coredump.c @@ -34,10 +34,14 @@ #include #include #include +#include #include "corewatcher.h" int do_unlink = 0; +int uid; +int sig; +char *corefile; #define MAX(A,B) ((A) > (B) ? (A) : (B)) @@ -128,6 +132,21 @@ void get_component_arch(char *package, char **component, char **arch) { return; } +char *signame(int sig) +{ + switch(sig) { + case SIGINT: return "INT"; + case SIGILL: return "ILL"; + case SIGABRT: return "ABRT"; + case SIGFPE: return "FPE"; + case SIGSEGV: return "SEGV"; + case SIGPIPE: return "PIPE"; + case SIGBUS: return "BUS"; + default: return strsignal(sig); + } + return NULL; +} + static char *get_kernel(void) { char *command = NULL, *line = NULL; FILE *file; @@ -168,25 +187,28 @@ char *build_core_header(char *appfile, char *corefile) { get_component_arch(package, &component, &arch); ret = asprintf(&result, - "executable: %s\n" + "analyzer: corewatcher-gdb\n" "architecture: %s\n" "component: %s\n" "coredump: %s\n" + "executable: %s\n" "kernel: %s\n" "package: %s\n" + "reason: Process %s was killed by signal %d (%s)\n" "release: %s\n" "time: %lu\n" "uid: %d\n" "\nbacktrace\n-----\n", - appfile, arch, component, corefile, + appfile, kernel, package, + appfile, sig, signame(sig), release, tv.tv_sec, - getuid()); + uid); free(kernel); free(package); @@ -201,7 +223,7 @@ char *build_core_header(char *appfile, char *corefile) { char *extract_core(char *corefile) { char *command = NULL, *c1 = NULL, *c2 = NULL, *line, *c3; - char *coredump; + char *coredump = NULL; char *appfile; FILE *file; @@ -292,7 +314,7 @@ int scan_dmesg(void __unused *unused) if (!dir) return 1; - fprintf(stderr, "+ scanning..\n"); + fprintf(stderr, "+ scanning...\n"); do { entry = readdir(dir); if (!entry) diff --git a/corewatcher.h b/corewatcher.h index 35d4078..2a3ebc6 100644 --- a/corewatcher.h +++ b/corewatcher.h @@ -48,8 +48,10 @@ extern char *submit_url; extern int testmode; extern int pinged; -extern char *find_executable(char *fragment); -extern char *find_coredump(char *corefile); +extern char *find_executable(char *); +extern char *find_coredump(char *); +extern int uid; +extern int sig; #endif diff --git a/find_file.c b/find_file.c index 8dd2ca9..dd0b122 100644 --- a/find_file.c +++ b/find_file.c @@ -59,9 +59,8 @@ char *find_coredump(char *corefile) size_t size = 0; FILE *file = NULL; char command[PATH_MAX*2]; - static char core[PATH_MAX]; + char *app = NULL; - memset(core, 0, sizeof(core)); sprintf(command, "eu-readelf -n %s", corefile); file = popen(command, "r"); if (!file) @@ -69,26 +68,39 @@ char *find_coredump(char *corefile) while (!feof(file)) { if (getline(&line, &size, file) < 0) - goto out;; - if (strstr(line, "fname:")) break; + + c = strstr(line,"psargs: "); + if (c) { + c += 8; + c2 = strchr(c, ' '); + if (c2) + *c2 = 0; + c2 = strchr(c, '\n'); + if (c2) + *c2 = 0; + app = strdup(c); + + fprintf(stderr,"+ causing app: %s\n", app); + } + + c = strstr(line, "EUID: "); + if (c) { + c += 6; + sscanf(c, "%i", &uid); + fprintf(stderr, "+ uid: %d\n", uid); + } + + c = strstr(line, "cursig: "); + if (c) { + c += 8; + sscanf(c, "%i", &sig); + fprintf(stderr, "+ sig: %d\n", sig); + } } - c = strstr(line,"psargs: "); - if (!c) - goto out; - c += 8; - c2 = strchr(c, ' '); - if (c2) - *c2 = 0; - c2 = strchr(c, '\n'); - if (c2) - *c2 = 0; - strcpy(core, c); - c2 = strchr(core, ' '); - if (c2) *c2 = 0; - fprintf(stderr,"+ causing app: %s\n", core); -out: + pclose(file); free(line); - return core; + + return app; }