fix libsigc++ crash
[vuplus_dvbapp] / lib / base / eerror.cpp
index 1e4d348..e294970 100644 (file)
@@ -1,8 +1,9 @@
 #include <lib/base/eerror.h>
 #include <lib/base/elock.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
+#include <cstdarg>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
 #include <unistd.h>
 
 #include <string>
@@ -71,13 +72,14 @@ void DumpUnfreed()
 };
 #endif
 
+SigC::Connection logConnection;
 Signal2<void, int, const std::string&> logOutput;
 int logOutputConsole=1;
 
 static pthread_mutex_t DebugLock =
        PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP;
 
-extern void bsodFatal();
+extern void bsodFatal(const char *component);
 
 void eFatal(const char* fmt, ...)
 {
@@ -86,10 +88,12 @@ void eFatal(const char* fmt, ...)
        va_start(ap, fmt);
        vsnprintf(buf, 1024, fmt, ap);
        va_end(ap);
-       singleLock s(DebugLock);
-       logOutput(lvlFatal, "FATAL: " + std::string(buf) + "\n");
-       fprintf(stderr, "FATAL: %s\n",buf );
-       bsodFatal();
+       {
+               singleLock s(DebugLock);
+               logOutput(lvlFatal, "FATAL: " + std::string(buf) + "\n");
+               fprintf(stderr, "FATAL: %s\n",buf );
+       }
+       bsodFatal("enigma2");
 }
 
 #ifdef DEBUG
@@ -100,8 +104,10 @@ void eDebug(const char* fmt, ...)
        va_start(ap, fmt);
        vsnprintf(buf, 1024, fmt, ap);
        va_end(ap);
-       singleLock s(DebugLock);
-       logOutput(lvlDebug, std::string(buf) + "\n");
+       if (logConnection.connected()) {
+               singleLock s(DebugLock);
+               logOutput(lvlDebug, std::string(buf) + "\n");
+       }
        if (logOutputConsole)
                fprintf(stderr, "%s\n", buf);
 }
@@ -113,8 +119,10 @@ void eDebugNoNewLine(const char* fmt, ...)
        va_start(ap, fmt);
        vsnprintf(buf, 1024, fmt, ap);
        va_end(ap);
-       singleLock s(DebugLock);
-       logOutput(lvlDebug, buf);
+       if (logConnection.connected()) {
+               singleLock s(DebugLock);
+               logOutput(lvlDebug, buf);
+       }
        if (logOutputConsole)
                fprintf(stderr, "%s", buf);
 }
@@ -126,8 +134,10 @@ void eWarning(const char* fmt, ...)
        va_start(ap, fmt);
        vsnprintf(buf, 1024, fmt, ap);
        va_end(ap);
-       singleLock s(DebugLock);
-       logOutput(lvlWarning, std::string(buf) + "\n");
+       if (logConnection.connected()) {
+               singleLock s(DebugLock);
+               logOutput(lvlWarning, std::string(buf) + "\n");
+       }
        if (logOutputConsole)
                fprintf(stderr, "%s\n", buf);
 }
@@ -136,8 +146,10 @@ void eWarning(const char* fmt, ...)
 void ePythonOutput(const char *string)
 {
 #ifdef DEBUG
-       singleLock s(DebugLock);
-       logOutput(lvlWarning, string);
+       if (logConnection.connected()) {
+               singleLock s(DebugLock);
+               logOutput(lvlWarning, string);
+       }
        if (logOutputConsole)
                fwrite(string, 1, strlen(string), stderr);
 #endif