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/BKE_report.h | 5 ++- source/blender/blenkernel/intern/report.c | 43 ++++++++++++++++++++-- source/blender/blenloader/intern/runtime.c | 5 ++- source/blender/editors/space_file/file_ops.c | 5 +-- source/blender/render/intern/source/pipeline.c | 20 +++++----- .../blender/render/intern/source/render_result.c | 10 ++--- 6 files changed, 63 insertions(+), 25 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/BKE_report.h b/source/blender/blenkernel/BKE_report.h index 4d69a013101..84cc4b6db83 100644 --- a/source/blender/blenkernel/BKE_report.h +++ b/source/blender/blenkernel/BKE_report.h @@ -72,7 +72,10 @@ void BKE_reports_print(ReportList *reports, ReportType level); Report *BKE_reports_last_displayable(ReportList *reports); int BKE_reports_contain(ReportList *reports, ReportType level); - + +// int BKE_report_write_file_fp(struct FILE *fp, ReportList *reports, const char *header); +bool BKE_report_write_file(const char *filepath, ReportList *reports, const char *header); + #ifdef __cplusplus } #endif 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; +} diff --git a/source/blender/blenloader/intern/runtime.c b/source/blender/blenloader/intern/runtime.c index 5d8a865eea8..cbbaf713e84 100644 --- a/source/blender/blenloader/intern/runtime.c +++ b/source/blender/blenloader/intern/runtime.c @@ -48,11 +48,12 @@ #include "BLO_readfile.h" #include "BLO_runtime.h" +#include "BLI_blenlib.h" +#include "BLI_utildefines.h" + #include "BKE_blender.h" #include "BKE_report.h" -#include "BLI_blenlib.h" - /* Runtime reading */ static int handle_read_msb_int(int handle) diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 763b18788de..9349abb4d8b 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -28,6 +28,8 @@ * \ingroup spfile */ +#include "BLI_blenlib.h" +#include "BLI_utildefines.h" #include "BKE_context.h" #include "BKE_screen.h" @@ -35,9 +37,6 @@ #include "BKE_report.h" #include "BKE_main.h" -#include "BLI_blenlib.h" -#include "BLI_utildefines.h" - #ifdef WIN32 # include "BLI_winstuff.h" #endif diff --git a/source/blender/render/intern/source/pipeline.c b/source/blender/render/intern/source/pipeline.c index 755c8f40ba1..dec11f0da91 100644 --- a/source/blender/render/intern/source/pipeline.c +++ b/source/blender/render/intern/source/pipeline.c @@ -45,6 +45,16 @@ #include "MEM_guardedalloc.h" +#include "BLI_math.h" +#include "BLI_rect.h" +#include "BLI_listbase.h" +#include "BLI_string.h" +#include "BLI_path_util.h" +#include "BLI_fileops.h" +#include "BLI_threads.h" +#include "BLI_rand.h" +#include "BLI_callbacks.h" + #include "BKE_animsys.h" /* <------ should this be here?, needed for sequencer update */ #include "BKE_camera.h" #include "BKE_global.h" @@ -57,16 +67,6 @@ #include "BKE_sequencer.h" #include "BKE_writeavi.h" /* <------ should be replaced once with generic movie module */ -#include "BLI_math.h" -#include "BLI_rect.h" -#include "BLI_listbase.h" -#include "BLI_string.h" -#include "BLI_path_util.h" -#include "BLI_fileops.h" -#include "BLI_threads.h" -#include "BLI_rand.h" -#include "BLI_callbacks.h" - #include "PIL_time.h" #include "IMB_colormanagement.h" #include "IMB_imbuf.h" diff --git a/source/blender/render/intern/source/render_result.c b/source/blender/render/intern/source/render_result.c index 6de5830df27..35b06385ae6 100644 --- a/source/blender/render/intern/source/render_result.c +++ b/source/blender/render/intern/source/render_result.c @@ -35,11 +35,6 @@ #include "MEM_guardedalloc.h" -#include "BKE_image.h" -#include "BKE_global.h" -#include "BKE_main.h" -#include "BKE_report.h" - #include "BLI_fileops.h" #include "BLI_listbase.h" #include "BLI_path_util.h" @@ -48,6 +43,11 @@ #include "BLI_threads.h" #include "BLI_utildefines.h" +#include "BKE_image.h" +#include "BKE_global.h" +#include "BKE_main.h" +#include "BKE_report.h" + #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" #include "IMB_colormanagement.h" -- cgit v1.2.3