made messagelog handle messages with newlines

Fri, 18 Oct 2013 22:07:26 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Fri, 18 Oct 2013 22:07:26 +0300
changeset 514
d78fea0f664c
parent 513
29eb671b34f6
child 515
a0ad72800b96

made messagelog handle messages with newlines

src/crashcatcher.cpp file | annotate | diff | comparison | revisions
src/download.cpp file | annotate | diff | comparison | revisions
src/messagelog.cpp file | annotate | diff | comparison | revisions
--- a/src/crashcatcher.cpp	Fri Oct 18 21:52:09 2013 +0300
+++ b/src/crashcatcher.cpp	Fri Oct 18 22:07:26 2013 +0300
@@ -27,58 +27,54 @@
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-static void handleSignal (int sig)
-{	printf ("caught signal %d\n", sig);
+static void handleCrash (int sig)
+{	printf ("%s: crashed with signal %d, launching gdb\n", __func__, sig);
 
 	if (g_crashCatcherActive)
 	{	printf ("caught signal while crash catcher is active!\n");
 		return;
 	}
 
-	if (g_signalsToCatch.indexOf (sig) != -1)
-	{	const pid_t pid = getpid();
-		QProcess proc;
-		QTemporaryFile commandsFile;
+	const pid_t pid = getpid();
+	QProcess proc;
+	QTemporaryFile commandsFile;
 
-		g_crashCatcherActive = true;
-		printf ("%s: crashed with signal %d, launching gdb\n", __func__, sig);
+	g_crashCatcherActive = true;
 
-		if (commandsFile.open())
-		{	commandsFile.write (fmt ("attach %1\n", pid).toLocal8Bit());
-			commandsFile.write (str ("backtrace full\n").toLocal8Bit());
-			commandsFile.write (str ("detach\n").toLocal8Bit());
-			commandsFile.write (str ("quit").toLocal8Bit());
-			commandsFile.flush();
-			commandsFile.close();
-		}
+	if (commandsFile.open())
+	{	commandsFile.write (fmt ("attach %1\n", pid).toLocal8Bit());
+		commandsFile.write (str ("backtrace full\n").toLocal8Bit());
+		commandsFile.write (str ("detach\n").toLocal8Bit());
+		commandsFile.write (str ("quit").toLocal8Bit());
+		commandsFile.flush();
+		commandsFile.close();
+	}
 
-		QStringList args ({"-x", commandsFile.fileName()});
+	QStringList args ({"-x", commandsFile.fileName()});
 
-		proc.start ("gdb", args);
+	proc.start ("gdb", args);
 
-		// Linux doesn't allow ptrace to be used on anything but direct child processes
-		// so we need to use prctl to register an exception to this to allow GDB attach to us.
-		// We need to do this now and no earlier because only now we actually know GDB's PID.
-		prctl (PR_SET_PTRACER, proc.pid(), 0, 0, 0);
+	// Linux doesn't allow ptrace to be used on anything but direct child processes
+	// so we need to use prctl to register an exception to this to allow GDB attach to us.
+	// We need to do this now and no earlier because only now we actually know GDB's PID.
+	prctl (PR_SET_PTRACER, proc.pid(), 0, 0, 0);
 
-		proc.waitForFinished (5000);
-		str output = QString (proc.readAllStandardOutput());
-		str err = QString (proc.readAllStandardError());
+	proc.waitForFinished (1000);
+	str output = QString (proc.readAllStandardOutput());
+	str err = QString (proc.readAllStandardError());
 
-		bombBox (fmt ("<h3>Program crashed with signal %1</h3>\n\n"
-			"%2"
-			"<p><b>GDB <tt>stdout</tt>:</b></p><pre>%3</pre>\n"
-			"<p><b>GDB <tt>stderr</tt>:</b></p><pre>%4</pre>",
-			sig, (!g_assertionFailure.isEmpty()) ? g_assertionFailure : "", output, err));
-		exit (137);
-	}
+	bombBox (fmt ("<h3>Program crashed with signal %1</h3>\n\n"
+		"%2"
+		"<p><b>GDB <tt>stdout</tt>:</b></p><pre>%3</pre>\n"
+		"<p><b>GDB <tt>stderr</tt>:</b></p><pre>%4</pre>",
+		sig, (!g_assertionFailure.isEmpty()) ? g_assertionFailure : "", output, err));
 }
 
 // =============================================================================
 // -----------------------------------------------------------------------------
 void initCrashCatcher()
 {	struct sigaction sighandler;
-	sighandler.sa_handler = &handleSignal;
+	sighandler.sa_handler = &handleCrash;
 	sighandler.sa_flags = 0;
 	sigemptyset (&sighandler.sa_mask);
 
--- a/src/download.cpp	Fri Oct 18 21:52:09 2013 +0300
+++ b/src/download.cpp	Fri Oct 18 22:07:26 2013 +0300
@@ -41,7 +41,6 @@
 // -----------------------------------------------------------------------------
 void PartDownloader::k_download()
 {	str path = getDownloadPath();
-	assert (false);
 
 	if (path == "" || QDir (path).exists() == false)
 	{	critical (PartDownloader::tr ("You need to specify a valid path for "
--- a/src/messagelog.cpp	Fri Oct 18 21:52:09 2013 +0300
+++ b/src/messagelog.cpp	Fri Oct 18 22:07:26 2013 +0300
@@ -119,9 +119,11 @@
 void DoLog (std::initializer_list<StringFormatArg> args)
 {	const str msg = DoFormat (args);
 
-	if (g_win)
-		g_win->addMessage (msg);
+	for (str& a : msg.split ("\n", QString::SkipEmptyParts))
+	{	if (g_win)
+			g_win->addMessage (a);
 
-	// Also print it to stdout
-	fprint (stdout, "%1", msg);
+		// Also print it to stdout
+		fprint (stdout, "%1\n", a);
+	}
 }

mercurial