diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-01-10 20:37:48 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-01-10 20:37:48 +0400 |
commit | 18536e201f26f20bde6379afa996153433404c65 (patch) | |
tree | 092fee45425217006de6d36ba26c110831c0cabe /source/blender/blenkernel/intern/report.c | |
parent | f6f33515ac62fb603ceba0eeaf79047b4451f754 (diff) |
add a segfault handler that writes out the info log into a crash file alongside the blend file.
Diffstat (limited to 'source/blender/blenkernel/intern/report.c')
-rw-r--r-- | source/blender/blenkernel/intern/report.c | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/source/blender/blenkernel/intern/report.c b/source/blender/blenkernel/intern/report.c index 185aeac5452..3acb35260cb 100644 --- a/source/blender/blenkernel/intern/report.c +++ b/source/blender/blenkernel/intern/report.c @@ -27,6 +27,10 @@ * \ingroup bke */ +#include <stdarg.h> +#include <stdio.h> +#include <string.h> +#include <errno.h> #include "MEM_guardedalloc.h" @@ -39,10 +43,6 @@ #include "BKE_report.h" #include "BKE_global.h" /* G.background only */ -#include <stdarg.h> -#include <stdio.h> -#include <string.h> - static const char *report_type_str(int type) { switch (type) { @@ -302,3 +302,38 @@ int BKE_reports_contain(ReportList *reports, ReportType level) return FALSE; } +static bool BKE_report_write_file_fp(FILE *fp, ReportList *reports, const char *header) +{ + Report *report; + + if (header) { + fputs(header, fp); + } + + for (report = reports->list.first; report; report = report->next) { + fprintf((FILE *)fp, "%s # %s\n", report->message, report->typestr); + } + + return true; +} + +bool BKE_report_write_file(const char *filepath, ReportList *reports, const char *header) +{ + FILE *fp; + + /* first try create the file, if it exists call without 'O_CREAT', + * to avoid writing to a symlink - use 'O_EXCL' (CVE-2008-1103) */ + errno = 0; + fp = BLI_fopen(filepath, "wb"); + if (fp == NULL) { + fprintf(stderr, "Unable to save '%s': %s\n", + filepath, errno ? strerror(errno) : "Unknown error opening file"); + return false; + } + + BKE_report_write_file_fp(fp, reports, header); + + fclose(fp); + + return true; +} |