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 fprintf(f, "\t</enigma2>\n");
239 fprintf(f, "\t<image>\n");
240 std::string model = getFileContent("/proc/stb/info/model");
241 if (model != "Error")
243 char modelname[STDBUFFER_SIZE];
244 sprintf(modelname, "%s",model.c_str());
245 if (strlen(modelname) && modelname[strlen(modelname)-1] == '\n')
246 modelname[strlen(modelname)-1] = 0;
247 fprintf(f, "\t\t<dreamboxmodel>%s</dreamboxmodel>\n", modelname);
249 std::string kernel = getFileContent("/proc/cmdline");
250 if (kernel != "Error")
252 char kernelcmd[STDBUFFER_SIZE];
253 sprintf(kernelcmd, "%s",kernel.c_str());
254 if (strlen(kernelcmd) && kernelcmd[strlen(kernelcmd)-1] == '\n')
255 kernelcmd[strlen(kernelcmd)-1] = 0;
256 fprintf(f, "\t\t<kernelcmdline>%s</kernelcmdline>\n", kernelcmd);
258 std::string sendAnonCrashlog = getConfigFileValue("config.plugins.crashlogautosubmit.sendAnonCrashlog");
259 if (sendAnonCrashlog == "False" || sendAnonCrashlog == "false") // defaults to true... default anonymized crashlogs
261 std::string ca = getFileContent("/proc/stb/info/ca");
264 char dreamboxca[STDBUFFER_SIZE];
265 sprintf(dreamboxca, "%s",ca.c_str());
266 if (strlen(dreamboxca) && dreamboxca[strlen(dreamboxca)-1] == '\n')
267 dreamboxca[strlen(dreamboxca)-1] = 0;
268 fprintf(f, "\t\t<dreamboxca>\n\t\t<![CDATA[\n%s\n\t\t]]>\n\t\t</dreamboxca>\n", dreamboxca);
270 std::string settings = getFileContent("/etc/enigma2/settings");
271 if (settings != "Error")
273 fprintf(f, "\t\t<enigma2settings>\n\t\t<![CDATA[\n%s\t\t]]>\n\t\t</enigma2settings>\n", settings.c_str());
276 std::string addNetwork = getConfigFileValue("config.plugins.crashlogautosubmit.addNetwork");
277 if (addNetwork == "True" || addNetwork == "true")
279 std::string nwinterfaces = getFileContent("/etc/network/interfaces");
280 if (nwinterfaces != "Error")
282 fprintf(f, "\t\t<networkinterfaces>\n\t\t<![CDATA[\n%s\t\t]]>\n\t\t</networkinterfaces>\n", nwinterfaces.c_str());
284 std::string dns = getFileContent("/etc/resolv.conf");
287 fprintf(f, "\t\t<dns>\n\t\t<![CDATA[\n%s\t\t]]>\n\t\t</dns>\n", dns.c_str());
289 std::string defaultgw = getFileContent("/etc/default_gw");
290 if (defaultgw != "Error")
292 char gateway[STDBUFFER_SIZE];
293 sprintf(gateway, "%s",defaultgw.c_str());
294 if (strlen(gateway) && gateway[strlen(gateway)-1] == '\n')
295 gateway[strlen(gateway)-1] = 0;
296 fprintf(f, "\t\t<defaultgateway>\n\t\t<![CDATA[\n%s\t\t]]>\n\t\t</defaultgateway>\n", gateway);
299 std::string addWlan = getConfigFileValue("config.plugins.crashlogautosubmit.addWlan");
300 if (addWlan == "True" || addWlan == "true")
302 std::string wpasupplicant = getFileContent("/etc/wpa_supplicant.conf");
303 if (wpasupplicant != "Error")
305 fprintf(f, "\t\t<wpasupplicant>\n\t\t<![CDATA[\n%s\t\t]]>\n\t\t</wpasupplicant>\n", wpasupplicant.c_str());
308 std::string imageversion = getFileContent("/etc/image-version");
309 if (imageversion != "Error")
311 fprintf(f, "\t\t<imageversion>\n\t\t<![CDATA[\n%s\t\t]]>\n\t\t</imageversion>\n", imageversion.c_str());
313 std::string imageissue = getFileContent("/etc/issue.net");
314 if (imageissue != "Error")
316 fprintf(f, "\t\t<imageissue>\n\t\t<![CDATA[\n%s\t\t]]>\n\t\t</imageissue>\n", imageissue.c_str());
318 fprintf(f, "\t</image>\n");
320 fprintf(f, "\t<software>\n");
321 std::string installedplugins = execCommand("ipkg list_installed | grep enigma2");
322 fprintf(f, "\t\t<enigma2software>\n\t\t<![CDATA[\n%s\t\t]]>\n\t\t</enigma2software>\n", installedplugins.c_str());
323 std::string dreambox = execCommand("ipkg list_installed | grep dream");
324 fprintf(f, "\t\t<dreamboxsoftware>\n\t\t<![CDATA[\n%s\t\t]]>\n\t\t</dreamboxsoftware>\n", dreambox.c_str());
325 std::string gstreamer = execCommand("ipkg list_installed | grep gst");
326 fprintf(f, "\t\t<gstreamersoftware>\n\t\t<![CDATA[\n%s\t\t]]>\n\t\t</gstreamersoftware>\n", gstreamer.c_str());
327 fprintf(f, "\t</software>\n");
329 fprintf(f, "\t<crashlogs>\n");
330 std::string buffer = getLogBuffer();
331 fprintf(f, "\t\t<enigma2crashlog>\n\t\t<![CDATA[\n%s\t\t]]>\n\t\t</enigma2crashlog>\n", buffer.c_str());
332 std::string pythonmd5 = execCommand("find /usr/lib/enigma2/python/ -name \"*.py\" | xargs md5sum");
333 fprintf(f, "\t\t<pythonMD5sum>\n\t\t<![CDATA[\n%s\t\t]]>\n\t\t</pythonMD5sum>\n", pythonmd5.c_str());
334 fprintf(f, "\t</crashlogs>\n");
336 fprintf(f, "\n</opendreambox>\n");
343 gSDLDC::getInstance(my_dc);
346 gFBDC::getInstance(my_dc);
352 p.resetClip(eRect(ePoint(0, 0), my_dc->size()));
353 #ifdef ENIGMA2_CHECKOUT_TAG
354 if (ENIGMA2_CHECKOUT_TAG[0] == 'T') /* tagged checkout (release) */
355 p.setBackgroundColor(gRGB(0x0000C0));
356 else if (ENIGMA2_CHECKOUT_TAG[0] == 'D') /* dated checkout (daily experimental build) */
360 unsigned int col = 0;
367 p.setBackgroundColor(gRGB(col));
370 p.setBackgroundColor(gRGB(0x008000));
373 p.setForegroundColor(gRGB(0xFFFFFF));
375 ePtr<gFont> font = new gFont("Regular", 20);
379 eRect usable_area = eRect(100, 70, my_dc->size().width() - 150, 100);
382 snprintf(text, 512, "We are really sorry. Your Dreambox encountered "
383 "a software problem, and needs to be restarted. "
384 "Please send the logfile created in /hdd/ to %s.\n"
385 "Your Dreambox restarts in 10 seconds!\n"
387 crash_emailaddr, crash_component);
389 p.renderText(usable_area, text, gPainter::RT_WRAP|gPainter::RT_HALIGN_LEFT);
391 usable_area = eRect(100, 170, my_dc->size().width() - 180, my_dc->size().height() - 20);
395 size_t start = std::string::npos + 1;
398 start = lines.rfind('\n', start - 1);
399 if (start == std::string::npos)
406 font = new gFont("Regular", 14);
409 p.renderText(usable_area,
410 lines.substr(start), gPainter::RT_HALIGN_LEFT);
417 #if defined(__MIPSEL__)
418 void oops(const mcontext_t &context, int dumpcode)
420 eDebug("PC: %08lx", (unsigned long)context.pc);
424 eDebugNoNewLine(" %08x", (int)context.gregs[i]);
428 /* this is temporary debug stuff. */
429 if (dumpcode && ((unsigned long)context.pc) > 0x10000) /* not a zero pointer */
431 eDebug("As a final action, i will try to dump a bit of code.");
432 eDebug("I just hope that this won't crash.");
434 eDebugNoNewLine("%08lx:", (unsigned long)context.pc);
435 for (i=0; i<0x20; ++i)
436 eDebugNoNewLine(" %02x", ((unsigned char*)context.pc)[i]);
441 #warning "no oops support!"
442 #define NO_OOPS_SUPPORT
445 void handleFatalSignal(int signum, siginfo_t *si, void *ctx)
447 ucontext_t *uc = (ucontext_t*)ctx;
449 #ifndef NO_OOPS_SUPPORT
450 oops(uc->uc_mcontext, signum == SIGSEGV || signum == SIGABRT);
453 bsodFatal("enigma2, signal");
456 void bsodCatchSignals()
458 struct sigaction act;
459 act.sa_handler = SIG_DFL;
460 act.sa_sigaction = handleFatalSignal;
461 act.sa_flags = SA_RESTART | SA_SIGINFO;
462 if (sigemptyset(&act.sa_mask) == -1)
463 perror("sigemptyset");
465 /* start handling segfaults etc. */
466 sigaction(SIGSEGV, &act, 0);
467 sigaction(SIGILL, &act, 0);
468 sigaction(SIGBUS, &act, 0);
469 sigaction(SIGABRT, &act, 0);
474 logOutput.connect(addToLogbuffer);