# HG changeset patch # User Santeri Piippo # Date 1382123246 -10800 # Node ID d78fea0f664c62fb1035d0658534e82ee7d36cec # Parent 29eb671b34f6ff0fc09e3e30505adb885bafea34 made messagelog handle messages with newlines diff -r 29eb671b34f6 -r d78fea0f664c src/crashcatcher.cpp --- 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 ("

Program crashed with signal %1

\n\n" - "%2" - "

GDB stdout:

%3
\n" - "

GDB stderr:

%4
", - sig, (!g_assertionFailure.isEmpty()) ? g_assertionFailure : "", output, err)); - exit (137); - } + bombBox (fmt ("

Program crashed with signal %1

\n\n" + "%2" + "

GDB stdout:

%3
\n" + "

GDB stderr:

%4
", + 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); diff -r 29eb671b34f6 -r d78fea0f664c src/download.cpp --- 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 " diff -r 29eb671b34f6 -r d78fea0f664c src/messagelog.cpp --- 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 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); + } }