[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53710] trunk/blender/source: add a segfault handler that writes out the info log into a crash file alongside the blend file .

Campbell Barton ideasman42 at gmail.com
Thu Jan 10 17:37:49 CET 2013


Revision: 53710
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53710
Author:   campbellbarton
Date:     2013-01-10 16:37:48 +0000 (Thu, 10 Jan 2013)
Log Message:
-----------
add a segfault handler that writes out the info log into a crash file alongside the blend file.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_report.h
    trunk/blender/source/blender/blenkernel/intern/report.c
    trunk/blender/source/blender/blenloader/intern/runtime.c
    trunk/blender/source/blender/editors/space_file/file_ops.c
    trunk/blender/source/blender/render/intern/source/pipeline.c
    trunk/blender/source/blender/render/intern/source/render_result.c
    trunk/blender/source/creator/creator.c

Modified: trunk/blender/source/blender/blenkernel/BKE_report.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_report.h	2013-01-10 16:11:12 UTC (rev 53709)
+++ trunk/blender/source/blender/blenkernel/BKE_report.h	2013-01-10 16:37:48 UTC (rev 53710)
@@ -72,7 +72,10 @@
 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

Modified: trunk/blender/source/blender/blenkernel/intern/report.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/report.c	2013-01-10 16:11:12 UTC (rev 53709)
+++ trunk/blender/source/blender/blenkernel/intern/report.c	2013-01-10 16:37:48 UTC (rev 53710)
@@ -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 @@
 	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;
+}

Modified: trunk/blender/source/blender/blenloader/intern/runtime.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/runtime.c	2013-01-10 16:11:12 UTC (rev 53709)
+++ trunk/blender/source/blender/blenloader/intern/runtime.c	2013-01-10 16:37:48 UTC (rev 53710)
@@ -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)

Modified: trunk/blender/source/blender/editors/space_file/file_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_file/file_ops.c	2013-01-10 16:11:12 UTC (rev 53709)
+++ trunk/blender/source/blender/editors/space_file/file_ops.c	2013-01-10 16:37:48 UTC (rev 53710)
@@ -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

Modified: trunk/blender/source/blender/render/intern/source/pipeline.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/pipeline.c	2013-01-10 16:11:12 UTC (rev 53709)
+++ trunk/blender/source/blender/render/intern/source/pipeline.c	2013-01-10 16:37:48 UTC (rev 53710)
@@ -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"

Modified: trunk/blender/source/blender/render/intern/source/render_result.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/render_result.c	2013-01-10 16:11:12 UTC (rev 53709)
+++ trunk/blender/source/blender/render/intern/source/render_result.c	2013-01-10 16:37:48 UTC (rev 53710)
@@ -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"

Modified: trunk/blender/source/creator/creator.c
===================================================================
--- trunk/blender/source/creator/creator.c	2013-01-10 16:11:12 UTC (rev 53709)
+++ trunk/blender/source/creator/creator.c	2013-01-10 16:37:48 UTC (rev 53710)
@@ -41,6 +41,12 @@
 #endif
 
 #ifdef WIN32
+#  include <process.h> /* getpid */
+#else
+#  include <unistd.h> /* getpid */
+#endif
+
+#ifdef WIN32
 #  include <Windows.h>
 #  include "utfconv.h"
 #endif
@@ -157,6 +163,8 @@
 /* Initialize callbacks for the modules that need them */
 static void setCallbacks(void); 
 
+static bool use_crash_handler = true;
+
 #ifndef WITH_PYTHON_MODULE
 
 /* set breakpoints here when running in debug mode, useful to catch floating point errors */
@@ -246,6 +254,7 @@
 	printf("Misc Options:\n");
 	BLI_argsPrintArgDoc(ba, "--debug");
 	BLI_argsPrintArgDoc(ba, "--debug-fpe");
+	BLI_argsPrintArgDoc(ba, "--disable-crash-handler");
 
 #ifdef WITH_FFMPEG
 	BLI_argsPrintArgDoc(ba, "--debug-ffmpeg");
@@ -350,6 +359,12 @@
 	return 0;
 }
 
+static int disable_crash_handler(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
+{
+	use_crash_handler = false;
+	return 0;
+}
+
 static int background_mode(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
 {
 	G.background = 1;
@@ -423,6 +438,56 @@
 	return 0;
 }
 
+static void blender_crash_handler(int signum)
+{
+
+#if 0
+	{
+		char fname[FILE_MAX];
+
+		if (!G.main->name[0]) {
+			BLI_make_file_string("/", fname, BLI_temporary_dir(), "crash.blend");
+		}
+		else {
+			BLI_strncpy(fname, G.main->name, sizeof(fname));
+			BLI_replace_extension(fname, sizeof(fname), ".crash.blend");
+		}
+
+		printf("Writing: %s\n", fname);
+		fflush(stdout);
+
+		BKE_undo_save_file(fname);
+	}
+#endif
+
+	{
+		char header[512];
+		wmWindowManager *wm = G.main->wm.first;
+
+		char fname[FILE_MAX];
+
+		if (!G.main->name[0]) {
+			BLI_make_file_string("/", fname, BLI_temporary_dir(), "blender.crash.txt");
+		}
+		else {
+			BLI_strncpy(fname, G.main->name, sizeof(fname));
+			BLI_replace_extension(fname, sizeof(fname), ".crash.txt");
+		}
+
+		printf("Writing: %s\n", fname);
+		fflush(stdout);
+
+		BLI_snprintf(header, sizeof(header), "# " BLEND_VERSION_STRING_FMT);
+
+		BKE_report_write_file(fname, &wm->reports, header);
+	}
+
+	/* really crash */
+	signal(signum, SIG_DFL);
+	kill(getpid(), signum);
+}
+
+
 static int set_factory_startup(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
 {
 	G.factory_startup = 1;
@@ -1122,6 +1187,8 @@
 	BLI_argsAdd(ba, 1, "-y", "--enable-autoexec", "\n\tEnable automatic python script execution" PY_ENABLE_AUTO, enable_python, NULL);
 	BLI_argsAdd(ba, 1, "-Y", "--disable-autoexec", "\n\tDisable automatic python script execution (pydrivers & startup scripts)" PY_DISABLE_AUTO, disable_python, NULL);
 
+	BLI_argsAdd(ba, 1, NULL, "--disable-crash-handler", "\n\tDisable the crash handler", disable_crash_handler, NULL);
+
 #undef PY_ENABLE_AUTO
 #undef PY_DISABLE_AUTO
 	
@@ -1301,6 +1368,10 @@
 	BLI_argsParse(ba, 1, NULL, NULL);
 #endif
 
+	if (use_crash_handler) {
+		/* after parsing args */
+		signal(SIGSEGV, blender_crash_handler);
+	}
 
 	/* after level 1 args, this is so playanim skips RNA init */
 	RNA_init();




More information about the Bf-blender-cvs mailing list