From 18536e201f26f20bde6379afa996153433404c65 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 10 Jan 2013 16:37:48 +0000 Subject: add a segfault handler that writes out the info log into a crash file alongside the blend file. --- source/blender/blenkernel/intern/report.c | 43 ++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 4 deletions(-) (limited to 'source/blender/blenkernel/intern/report.c') 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 +#include +#include +#include #include "MEM_guardedalloc.h" @@ -39,10 +43,6 @@ #include "BKE_report.h" #include "BKE_global.h" /* G.background only */ -#include -#include -#include - 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; +} -- cgit v1.2.3