#include <sys/stat.h>
#include <sys/time.h>
#include <dirent.h>
+#include <signal.h>
#include "corewatcher.h"
int do_unlink = 0;
+int uid;
+int sig;
+char *corefile;
#define MAX(A,B) ((A) > (B) ? (A) : (B))
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;
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);
char *extract_core(char *corefile)
{
char *command = NULL, *c1 = NULL, *c2 = NULL, *line, *c3;
- char *coredump;
+ char *coredump = NULL;
char *appfile;
FILE *file;
if (!dir)
return 1;
- fprintf(stderr, "+ scanning..\n");
+ fprintf(stderr, "+ scanning...\n");
do {
entry = readdir(dir);
if (!entry)
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
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)
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;
}