servicemp3.cpp: more simple/flexible streaming detection
[enigma2.git] / lib / base / eerror.cpp
index 3fc38ade39af12b81c033934dc74194e9edaa2f3..35e46e05d4199d38190202573e48c601e7f509fa 100644 (file)
@@ -1,13 +1,13 @@
 #include <lib/base/eerror.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
+#include <lib/base/elock.h>
+#include <cstdarg>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
 #include <unistd.h>
 
 #include <string>
 
-// #include <lib/gui/emessage.h>
-
 #ifdef MEMLEAK_CHECK
 AllocList *allocList;
 pthread_mutex_t memLock =
@@ -21,14 +21,16 @@ void DumpUnfreed()
        if(!allocList)
                return;
 
+       FILE *f = fopen("/var/tmp/enigma2_mem.out", "w");
        size_t len = 1024;
        char *buffer = (char*)malloc(1024);
        for(i = allocList->begin(); i != allocList->end(); i++)
        {
                unsigned int tmp;
-               printf("%s\tLINE %d\tADDRESS %p\t%d unfreed\ttype %d (btcount %d)\n",
+               fprintf(f, "%s\tLINE %d\tADDRESS %p\t%d unfreed\ttype %d (btcount %d)\n",
                        i->second.file, i->second.line, (void*)i->second.address, i->second.size, i->second.type, i->second.btcount);
                totalSize += i->second.size;
+
                char **bt_string = backtrace_symbols( i->second.backtrace, i->second.btcount );
                for ( tmp=0; tmp < i->second.btcount; tmp++ )
                {
@@ -48,34 +50,36 @@ void DumpUnfreed()
                                                        int state;
                                                        abi::__cxa_demangle(tmp1.c_str(), buffer, &len, &state);
                                                        if (!state)
-                                                               printf("%d %s%s\n", tmp, buffer,tmp2.c_str());
+                                                               fprintf(f, "%d %s%s\n", tmp, buffer,tmp2.c_str());
                                                        else
-                                                               printf("%d %s\n", tmp, bt_string[tmp]);
+                                                               fprintf(f, "%d %s\n", tmp, bt_string[tmp]);
                                                }
                                        }
                                }
                                else
-                                       printf("%d %s\n", tmp, bt_string[tmp]);
+                                       fprintf(f, "%d %s\n", tmp, bt_string[tmp]);
                        }
                }
                free(bt_string);
-               printf("\n");
+               if (i->second.btcount)
+                       fprintf(f, "\n");
        }
        free(buffer);
 
-       printf("-----------------------------------------------------------\n");
-       printf("Total Unfreed: %d bytes\n", totalSize);
-       fflush(stdout);
+       fprintf(f, "-----------------------------------------------------------\n");
+       fprintf(f, "Total Unfreed: %d bytes\n", totalSize);
+       fflush(f);
 };
-#else
-       #include <lib/base/elock.h>
 #endif
 
-int infatal=0;
-
 Signal2<void, int, const std::string&> logOutput;
 int logOutputConsole=1;
 
+static pthread_mutex_t DebugLock =
+       PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP;
+
+extern void bsodFatal(const char *component);
+
 void eFatal(const char* fmt, ...)
 {
        char buf[1024];
@@ -83,19 +87,12 @@ void eFatal(const char* fmt, ...)
        va_start(ap, fmt);
        vsnprintf(buf, 1024, fmt, ap);
        va_end(ap);
-       logOutput(lvlFatal, buf);
-       fprintf(stderr, "FATAL: %s\n",buf );
-#if 0
-       if (!infatal)
        {
-               infatal=1;
-               eMessageBox msg(buf, "FATAL ERROR", eMessageBox::iconError|eMessageBox::btOK);
-               msg.show();
-               msg.exec();
+               singleLock s(DebugLock);
+               logOutput(lvlFatal, "FATAL: " + std::string(buf) + "\n");
+               fprintf(stderr, "FATAL: %s\n",buf );
        }
-#endif
-
-       _exit(0);
+       bsodFatal("enigma2");
 }
 
 #ifdef DEBUG
@@ -106,6 +103,7 @@ 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 (logOutputConsole)
                fprintf(stderr, "%s\n", buf);
@@ -118,6 +116,7 @@ void eDebugNoNewLine(const char* fmt, ...)
        va_start(ap, fmt);
        vsnprintf(buf, 1024, fmt, ap);
        va_end(ap);
+       singleLock s(DebugLock);
        logOutput(lvlDebug, buf);
        if (logOutputConsole)
                fprintf(stderr, "%s", buf);
@@ -130,6 +129,7 @@ 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 (logOutputConsole)
                fprintf(stderr, "%s\n", buf);
@@ -138,9 +138,12 @@ void eWarning(const char* fmt, ...)
 
 void ePythonOutput(const char *string)
 {
+#ifdef DEBUG
+       singleLock s(DebugLock);
        logOutput(lvlWarning, string);
        if (logOutputConsole)
                fwrite(string, 1, strlen(string), stderr);
+#endif
 }
 
 void eWriteCrashdump()