3 #include <asm/ptrace.h>
5 #include <lib/base/eerror.h>
6 #include <lib/base/smartptr.h>
7 #include <lib/base/nconfig.h>
8 #include <lib/gdi/grc.h>
9 #include <lib/gdi/gfbdc.h>
11 #include <lib/gdi/sdl.h>
16 /************************************************/
18 #define CRASH_EMAILADDR "crashlog@dream-multimedia-tv.de"
19 #define STDBUFFER_SIZE 512
20 #define RINGBUFFER_SIZE 16384
21 static char ringbuffer[RINGBUFFER_SIZE];
22 static int ringbuffer_head;
24 static void addToLogbuffer(const char *data, int len)
28 int remaining = RINGBUFFER_SIZE - ringbuffer_head;
33 memcpy(ringbuffer + ringbuffer_head, data, remaining);
36 ringbuffer_head += remaining;
37 if (ringbuffer_head >= RINGBUFFER_SIZE)
42 static std::string getLogBuffer()
44 int begin = ringbuffer_head;
45 while (ringbuffer[begin] == 0)
48 if (begin == RINGBUFFER_SIZE)
50 if (begin == ringbuffer_head)
53 if (begin < ringbuffer_head)
54 return std::string(ringbuffer + begin, ringbuffer_head - begin);
57 return std::string(ringbuffer + begin, RINGBUFFER_SIZE - begin) + std::string(ringbuffer, ringbuffer_head);
61 static void addToLogbuffer(int level, const std::string &log)
63 addToLogbuffer(log.c_str(), log.size());
66 static std::string getConfigFileValue(const char *entry)
68 std::string configfile = "/etc/enigma2/settings";
69 std::string configvalue;
72 ePythonConfigQuery::getConfigValue(entry, configvalue);
73 if (configvalue != "") //we get at least the default value if python is still alive
77 else // get value from enigma2 settings file
79 FILE *f = fopen(configfile.c_str(), "r");
87 if (!fgets(line, 1024, f))
89 if (!strncmp(line, entry, strlen(entry) ))
91 if (strlen(line) && line[strlen(line)-1] == '\r')
92 line[strlen(line)-1] = 0;
93 if (strlen(line) && line[strlen(line)-1] == '\n')
94 line[strlen(line)-1] = 0;
95 std::string tmp = line;
96 int posEqual = tmp.find("=", 0);
97 configvalue = tmp.substr(posEqual+1);
106 static std::string getFileContent(const char *file)
108 std::string filecontent;
112 FILE *f = fopen(file, "r");
120 if (!fgets(line, 1024, f))
122 std::string tmp = line;
123 std::string password;
124 int pwdpos = tmp.find(".password=", 0);
125 if( pwdpos != std::string::npos)
127 filecontent += tmp.substr(0,pwdpos +10);
128 for ( int pos = pwdpos +10; pos < tmp.length()-1; ++pos )
143 static std::string execCommand(char* cmd) {
144 FILE* pipe = popen(cmd, "r");
147 char buffer[STDBUFFER_SIZE];
148 std::string result = "";
151 if(!fgets(buffer,STDBUFFER_SIZE, pipe))
159 extern std::string execCommand();
160 extern std::string getConfigFileValue();
161 extern std::string getFileContent();
162 extern std::string getLogBuffer();
164 #define INFOFILE "/maintainer.info"
166 void bsodFatal(const char *component)
169 sprintf(logfile, "/media/hdd/enigma2_crash_%u.log", (unsigned int)time(0));
170 FILE *f = fopen(logfile, "wb");
172 std::string lines = getLogBuffer();
174 /* find python-tracebacks, and extract " File "-strings */
177 char crash_emailaddr[256] = CRASH_EMAILADDR;
178 char crash_component[256] = "enigma2";
181 snprintf(crash_component, 256, component);
184 while ((start = lines.find("\n File \"", start)) != std::string::npos)
187 size_t end = lines.find("\"", start);
188 if (end == std::string::npos)
190 end = lines.rfind("/", end);
191 /* skip a potential prefix to the path */
192 unsigned int path_prefix = lines.find("/usr/", start);
193 if (path_prefix != std::string::npos && path_prefix < end)
196 if (end == std::string::npos)
198 if (end - start >= (256 - strlen(INFOFILE)))
201 snprintf(filename, 256, "%s%s", lines.substr(start, end - start).c_str(), INFOFILE);
202 FILE *cf = fopen(filename, "r");
205 fgets(crash_emailaddr, sizeof crash_emailaddr, cf);
206 if (*crash_emailaddr && crash_emailaddr[strlen(crash_emailaddr)-1] == '\n')
207 crash_emailaddr[strlen(crash_emailaddr)-1] = 0;
209 fgets(crash_component, sizeof crash_component, cf);
210 if (*crash_component && crash_component[strlen(crash_component)-1] == '\n')
211 crash_component[strlen(crash_component)-1] = 0;
220 char crashtime[STDBUFFER_SIZE];
221 sprintf(crashtime, "%s",ctime(&t));
222 if (strlen(crashtime) && crashtime[strlen(crashtime)-1] == '\n')
223 crashtime[strlen(crashtime)-1] = 0;
224 fprintf(f, "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n<opendreambox>\n");
225 fprintf(f, "\t<enigma2>\n");
226 fprintf(f, "\t\t<crashdate>%s</crashdate>\n", crashtime);
227 #ifdef ENIGMA2_CHECKOUT_TAG
228 fprintf(f, "\t\t<checkouttag>" ENIGMA2_CHECKOUT_TAG "</checkouttag>\n");
230 fprintf(f, "\t\t<compiledate>" __DATE__ "</compiledate>\n");
232 #ifdef ENIGMA2_CHECKOUT_ROOT
233 fprintf(f, "\t\t<checkoutroot>" ENIGMA2_CHECKOUT_ROOT "</checkoutroot>\n");
235 fprintf(f, "\t\t<contactemail>%s</contactemail>\n", crash_emailaddr);
236 fprintf(f, "\t\t<!-- Please email this crashlog to above address -->\n");
237 std::string activeSkin = getConfigFileValue("config.skin.primary_skin");
238 if (activeSkin != "Error")
240 if (activeSkin == "")
241 activeSkin = "Default Skin";
242 fprintf(f, "\t\t<skin>%s</skin>\n", activeSkin.c_str());
244 fprintf(f, "\t</enigma2>\n");
246 fprintf(f, "\t<image>\n");
247 std::string model = getFileContent("/proc/stb/info/model");
248 if (model != "Error")
250 char modelname[STDBUFFER_SIZE];
251 sprintf(modelname, "%s",model.c_str());
252 if (strlen(modelname) && modelname[strlen(modelname)-1] == '\n')
253 modelname[strlen(modelname)-1] = 0;
254 fprintf(f, "\t\t<dreamboxmodel>%s</dreamboxmodel>\n", modelname);
256 std::string kernel = getFileContent("/proc/cmdline");
257 if (kernel != "Error")
259 char kernelcmd[STDBUFFER_SIZE];
260 sprintf(kernelcmd, "%s",kernel.c_str());
261 if (strlen(kernelcmd) && kernelcmd[strlen(kernelcmd)-1] == '\n')
262 kernelcmd[strlen(kernelcmd)-1] = 0;
263 fprintf(f, "\t\t<kernelcmdline>%s</kernelcmdline>\n", kernelcmd);
265 std::string sendAnonCrashlog = getConfigFileValue("config.plugins.crashlogautosubmit.sendAnonCrashlog");
266 if (sendAnonCrashlog == "False" || sendAnonCrashlog == "false") // defaults to true... default anonymized crashlogs
268 std::string ca = getFileContent("/proc/stb/info/ca");
271 char dreamboxca[STDBUFFER_SIZE];
272 sprintf(dreamboxca, "%s",ca.c_str());
273 if (strlen(dreamboxca) && dreamboxca[strlen(dreamboxca)-1] == '\n')
274 dreamboxca[strlen(dreamboxca)-1] = 0;
275 fprintf(f, "\t\t<dreamboxca>\n\t\t<![CDATA[\n%s\n\t\t]]>\n\t\t</dreamboxca>\n", dreamboxca);
277 std::string settings = getFileContent("/etc/enigma2/settings");
278 if (settings != "Error")
280 fprintf(f, "\t\t<enigma2settings>\n\t\t<![CDATA[\n%s\t\t]]>\n\t\t</enigma2settings>\n", settings.c_str());
283 std::string addNetwork = getConfigFileValue("config.plugins.crashlogautosubmit.addNetwork");
284 if (addNetwork == "True" || addNetwork == "true")
286 std::string nwinterfaces = getFileContent("/etc/network/interfaces");
287 if (nwinterfaces != "Error")
289 fprintf(f, "\t\t<networkinterfaces>\n\t\t<![CDATA[\n%s\t\t]]>\n\t\t</networkinterfaces>\n", nwinterfaces.c_str());
291 std::string dns = getFileContent("/etc/resolv.conf");
294 fprintf(f, "\t\t<dns>\n\t\t<![CDATA[\n%s\t\t]]>\n\t\t</dns>\n", dns.c_str());
296 std::string defaultgw = getFileContent("/etc/default_gw");
297 if (defaultgw != "Error")
299 char gateway[STDBUFFER_SIZE];
300 sprintf(gateway, "%s",defaultgw.c_str());
301 if (strlen(gateway) && gateway[strlen(gateway)-1] == '\n')
302 gateway[strlen(gateway)-1] = 0;
303 fprintf(f, "\t\t<defaultgateway>\n\t\t<![CDATA[\n%s\t\t]]>\n\t\t</defaultgateway>\n", gateway);
306 std::string addWlan = getConfigFileValue("config.plugins.crashlogautosubmit.addWlan");
307 if (addWlan == "True" || addWlan == "true")
309 std::string wpasupplicant = getFileContent("/etc/wpa_supplicant.conf");
310 if (wpasupplicant != "Error")
312 fprintf(f, "\t\t<wpasupplicant>\n\t\t<![CDATA[\n%s\t\t]]>\n\t\t</wpasupplicant>\n", wpasupplicant.c_str());
315 std::string imageversion = getFileContent("/etc/image-version");
316 if (imageversion != "Error")
318 fprintf(f, "\t\t<imageversion>\n\t\t<![CDATA[\n%s\t\t]]>\n\t\t</imageversion>\n", imageversion.c_str());
320 std::string imageissue = getFileContent("/etc/issue.net");
321 if (imageissue != "Error")
323 fprintf(f, "\t\t<imageissue>\n\t\t<![CDATA[\n%s\t\t]]>\n\t\t</imageissue>\n", imageissue.c_str());
325 fprintf(f, "\t</image>\n");
327 fprintf(f, "\t<software>\n");
328 std::string installedplugins = execCommand("ipkg list_installed | grep enigma2");
329 fprintf(f, "\t\t<enigma2software>\n\t\t<![CDATA[\n%s\t\t]]>\n\t\t</enigma2software>\n", installedplugins.c_str());
330 std::string dreambox = execCommand("ipkg list_installed | grep dream");
331 fprintf(f, "\t\t<dreamboxsoftware>\n\t\t<![CDATA[\n%s\t\t]]>\n\t\t</dreamboxsoftware>\n", dreambox.c_str());
332 std::string gstreamer = execCommand("ipkg list_installed | grep gst");
333 fprintf(f, "\t\t<gstreamersoftware>\n\t\t<![CDATA[\n%s\t\t]]>\n\t\t</gstreamersoftware>\n", gstreamer.c_str());
334 fprintf(f, "\t</software>\n");
336 fprintf(f, "\t<crashlogs>\n");
337 std::string buffer = getLogBuffer();
338 fprintf(f, "\t\t<enigma2crashlog>\n\t\t<![CDATA[\n%s\t\t]]>\n\t\t</enigma2crashlog>\n", buffer.c_str());
339 std::string pythonmd5 = execCommand("find /usr/lib/enigma2/python/ -name \"*.py\" | xargs md5sum");
340 fprintf(f, "\t\t<pythonMD5sum>\n\t\t<![CDATA[\n%s\t\t]]>\n\t\t</pythonMD5sum>\n", pythonmd5.c_str());
341 fprintf(f, "\t</crashlogs>\n");
343 fprintf(f, "\n</opendreambox>\n");
350 gSDLDC::getInstance(my_dc);
353 gFBDC::getInstance(my_dc);
359 p.resetClip(eRect(ePoint(0, 0), my_dc->size()));
360 #ifdef ENIGMA2_CHECKOUT_TAG
361 if (ENIGMA2_CHECKOUT_TAG[0] == 'T') /* tagged checkout (release) */
362 p.setBackgroundColor(gRGB(0x0000C0));
363 else if (ENIGMA2_CHECKOUT_TAG[0] == 'D') /* dated checkout (daily experimental build) */
367 unsigned int col = 0;
374 p.setBackgroundColor(gRGB(col));
377 p.setBackgroundColor(gRGB(0x008000));
380 p.setForegroundColor(gRGB(0xFFFFFF));
382 ePtr<gFont> font = new gFont("Regular", 20);
386 eRect usable_area = eRect(100, 70, my_dc->size().width() - 150, 100);
389 snprintf(text, 512, "We are really sorry. Your Dreambox encountered "
390 "a software problem, and needs to be restarted. "
391 "Please send the logfile created in /hdd/ to %s.\n"
392 "Your Dreambox restarts in 10 seconds!\n"
394 crash_emailaddr, crash_component);
396 p.renderText(usable_area, text, gPainter::RT_WRAP|gPainter::RT_HALIGN_LEFT);
398 usable_area = eRect(100, 170, my_dc->size().width() - 180, my_dc->size().height() - 20);
402 size_t start = std::string::npos + 1;
405 start = lines.rfind('\n', start - 1);
406 if (start == std::string::npos)
413 font = new gFont("Regular", 14);
416 p.renderText(usable_area,
417 lines.substr(start), gPainter::RT_HALIGN_LEFT);
424 #if defined(__MIPSEL__)
425 void oops(const mcontext_t &context, int dumpcode)
427 eDebug("PC: %08lx", (unsigned long)context.pc);
431 eDebugNoNewLine(" %08x", (int)context.gregs[i]);
435 /* this is temporary debug stuff. */
436 if (dumpcode && ((unsigned long)context.pc) > 0x10000) /* not a zero pointer */
438 eDebug("As a final action, i will try to dump a bit of code.");
439 eDebug("I just hope that this won't crash.");
441 eDebugNoNewLine("%08lx:", (unsigned long)context.pc);
442 for (i=0; i<0x20; ++i)
443 eDebugNoNewLine(" %02x", ((unsigned char*)context.pc)[i]);
448 #warning "no oops support!"
449 #define NO_OOPS_SUPPORT
452 void handleFatalSignal(int signum, siginfo_t *si, void *ctx)
454 ucontext_t *uc = (ucontext_t*)ctx;
456 #ifndef NO_OOPS_SUPPORT
457 oops(uc->uc_mcontext, signum == SIGSEGV || signum == SIGABRT);
460 bsodFatal("enigma2, signal");
463 void bsodCatchSignals()
465 struct sigaction act;
466 act.sa_handler = SIG_DFL;
467 act.sa_sigaction = handleFatalSignal;
468 act.sa_flags = SA_RESTART | SA_SIGINFO;
469 if (sigemptyset(&act.sa_mask) == -1)
470 perror("sigemptyset");
472 /* start handling segfaults etc. */
473 sigaction(SIGSEGV, &act, 0);
474 sigaction(SIGILL, &act, 0);
475 sigaction(SIGBUS, &act, 0);
476 sigaction(SIGABRT, &act, 0);
481 logOutput.connect(addToLogbuffer);