Esempio n. 1
0
static void sigsegv_cb (int sig_num, siginfo_t *info, void * ucontext)
{
    void *array[50];
    void *caller_address;
    char **messages;
    int size, i;
    sig_ucontext_t *uc;
    FILE *f;

    g_fprintf (stderr, "Got segmentation fault !\n");

// haven't found the way to get caller addr on FreeBSD, and we need to link with -lexecinfo
#if !defined(__FreeBSD__)
    uc = (sig_ucontext_t *)ucontext;

    /* Get the address at the time the signal was raised from the EIP (x86) */
#if defined(__APPLE__)
    #ifdef __i368__
        caller_address = (void *) uc->uc_mcontext->__ss.__eip;
    #else
        caller_address = (void *) uc->uc_mcontext->__ss.__rip;
    #endif
#else /* !__APPLE__ */
    #ifdef __i386__
        caller_address = (void *) uc->uc_mcontext.eip;
    #else
        caller_address = (void *) uc->uc_mcontext.rip;
    #endif
#endif /* !__APPLE__ */

    f = stderr;

    fprintf (f, "signal %d (%s), address is %p from %p\n", sig_num, strsignal (sig_num), info->si_addr, (void *)caller_address);

    size = backtrace (array, 50);

    /* overwrite sigaction with caller's address */
    array[1] = caller_address;

    messages = backtrace_symbols (array, size);

    /* skip first stack frame (points here) */
    for (i = 1; i < size && messages != NULL; ++i) {
        fprintf (f, "[bt]: (%d) %s\n", i, messages[i]);
    }

    fflush (f);

    free (messages);

    LOG_err (APP_LOG, "signal %d (%s), address is %p from %p\n", sig_num, strsignal (sig_num), info->si_addr, (void *)caller_address);
#endif // __FreeBSD__

    // try to unmount FUSE mountpoint
    if (_app && _app->rfuse)
        rfuse_destroy (_app->rfuse);
}
Esempio n. 2
0
File: main.c Progetto: skoobe/riofs
/*{{{ application_destroy */
static void application_destroy (Application *app)
{
    LOG_debug (APP_LOG, "Destroying application !");

    g_free (app->conf_path);
    if (app->read_client_pool)
        client_pool_destroy (app->read_client_pool);
    if (app->write_client_pool)
        client_pool_destroy (app->write_client_pool);
    if (app->ops_client_pool)
        client_pool_destroy (app->ops_client_pool);

    if (app->dir_tree)
        dir_tree_destroy (app->dir_tree);

    if (app->cmng)
        cache_mng_destroy (app->cmng);

    if (app->sigint_ev)
        event_free (app->sigint_ev);
    if (app->sigterm_ev)
        event_free (app->sigterm_ev);
    if (app->sigpipe_ev)
        event_free (app->sigpipe_ev);
    if (app->sigusr1_ev)
        event_free (app->sigusr1_ev);
     if (app->sigusr2_ev)
        event_free (app->sigusr2_ev);

    if (app->service_con)
        http_connection_destroy (app->service_con);

    if (app->stat_srv)
        stat_srv_destroy (app->stat_srv);

    // destroy Fuse
    if (app->rfuse)
        rfuse_destroy (app->rfuse);

    if (app->dns_base)
        evdns_base_free (app->dns_base, 0);
    if (app->evbase)
        event_base_free (app->evbase);

    if (app->uri)
        evhttp_uri_free (app->uri);

    if (app->conf)
        conf_destroy (app->conf);

    if (app->fuse_opts)
        g_free (app->fuse_opts);

#ifdef SSL_ENABLED
    SSL_CTX_free (app->ssl_ctx);
#endif

#ifdef MAGIC_ENABLED
    magic_close(app->magic_ctx);
#endif

    logger_destroy ();

    if (app->f_log)
        fclose (app->f_log);

    if (app->log_file_name)
        g_free (app->log_file_name);

    g_free (app);

    ENGINE_cleanup ();
    CRYPTO_cleanup_all_ex_data ();
    ERR_free_strings ();
    ERR_remove_thread_state (NULL);
    EVP_cleanup ();
}