Home · All Namespaces · All Classes · Main Classes
Defines | Functions | Variables

src/appletdb/mcpwrongapplets.cpp File Reference

#include <signal.h>
#include <execinfo.h>
#include <MGConfItem>
#include <QFileInfo>
#include <QDateTime>
#include <QtDebug>
#include <QApplication>
#include "mcpwrongapplets.h"
#include "mcpappletdb.h"
#include "mcpappletmetadata.h"
#include "mcpdebug.h"
Include dependency graph for mcpwrongapplets.cpp:

Go to the source code of this file.

Defines

#define KEY_SEPARATOR   "/"
#define BACKTRACE_SIZE   128

Functions

bool backtrace_line_is_an_applet (const char *line, const char **start, const char **end)
void mark_applet_as_bad (const char *full_path)
bool some_crash_happened (void)
void termination_signal_handler (int signum)

Variables

const QString keyPath = "/apps/mcontrolpanel/badplugins"
const QString mcpTimeStampPath = "/mcpTimeStamp"

Define Documentation

#define BACKTRACE_SIZE   128

Definition at line 47 of file mcpwrongapplets.cpp.

#define KEY_SEPARATOR   "/"

Definition at line 36 of file mcpwrongapplets.cpp.


Function Documentation

bool backtrace_line_is_an_applet ( const char *  line,
const char **  start,
const char **  end 
)

Definition at line 50 of file mcpwrongapplets.cpp.

{
    *start = strstr(line, "/usr/lib/mcontrolpanel/applets/");
    if (*start == 0)
        return false;

    *end = *start;
    while (**end != '\0' && **end != '(')
        ++(*end);

    return true;
}

void mark_applet_as_bad ( const char *  full_path  ) 

Definition at line 67 of file mcpwrongapplets.cpp.

{
    MGConfItem  conf(keyPath + full_path + KEY_SEPARATOR + "CrashDateTime");
    QDateTime     now = QDateTime::currentDateTime ();

    conf.set (now.toString());
}

bool some_crash_happened ( void   ) 

Returns true if an applet crash has been discovered.

Definition at line 80 of file mcpwrongapplets.cpp.

{
    void     *backtrace_array [BACKTRACE_SIZE];
    char    **backtrace_strings;
    size_t    backtrace_size;
    const char     *start, *end;

    MCP_WARNING ("Crash...");
    backtrace_size = backtrace (backtrace_array, BACKTRACE_SIZE);
    backtrace_strings = backtrace_symbols (backtrace_array, backtrace_size);

    /*
     * Let's print the backtrace from the stack.
     */
    fprintf (stderr, "--- Crash backtrace of MControlPanel ---\n");
    for (size_t i = 0; i < backtrace_size; i++) {
        fprintf (stderr, "%03u %s\n", i, backtrace_strings[i]);
    }
    fprintf (stderr, "------------------------------------------\n");
    fflush (stderr);

    /*
     * Let's see if any of the functions is actually in some applet.
     */
    for (size_t i = 0; i < backtrace_size; i++) {
        if (!backtrace_line_is_an_applet (backtrace_strings[i], &start, &end))
            continue;

        *const_cast<char*>(end) = '\0';
        MCP_WARNING ("*** Marking this applet: '%s'", start);
        mark_applet_as_bad (start);
        MCP_WARNING ("*** Done");
        return true;
    }

    return false;
}

Here is the call graph for this function:

void termination_signal_handler ( int  signum  ) 

Definition at line 120 of file mcpwrongapplets.cpp.

{
    MCP_DEBUG ("*** signum = %d", signum);
    switch (signum) {
        case SIGTERM:
        case SIGHUP:
        case SIGINT:
        case SIGQUIT:
            /*
             * These are the signals that are not caused by any bug in the code.
             * We can do something with these, but now we just exit.
             */
            exit (0);
            break;
       
        case SIGILL:
        case SIGSEGV:
        case SIGBUS:
        case SIGABRT:
        case SIGFPE:
            /*
             * And here are those that are caused by errors.
             */
            if (!some_crash_happened ())
                exit (0);
            break;
    }

    /*
     * If we discovered an applet crash we raise the same signal so that the
     * parent will know that we need to be restarted.
     */
    signal (signum, SIG_DFL);
    raise (signum);
}

Here is the call graph for this function:


Variable Documentation

const QString keyPath = "/apps/mcontrolpanel/badplugins"

Definition at line 40 of file mcpwrongapplets.cpp.

const QString mcpTimeStampPath = "/mcpTimeStamp"

Definition at line 41 of file mcpwrongapplets.cpp.


Copyright © 2009 Nokia Corporation Generated on Thu Nov 4 2010 18:21:33
Doxygen 1.7.1
DirectUI