~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/signal_handler.cc

  • Committer: patrick crews
  • Date: 2010-09-29 15:15:19 UTC
  • mfrom: (1099.4.188 drizzle)
  • Revision ID: gleebix@gmail.com-20100929151519-6mrmzd1ciw2p9nws
Tags: 2010.09.1802
Update translations

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
24
24
#include "drizzled/signal_handler.h"
25
25
#include "drizzled/drizzled.h"
26
26
#include "drizzled/session.h"
27
 
#include "drizzled/session/cache.h"
28
27
#include "drizzled/internal/my_sys.h"
29
28
#include "drizzled/probes.h"
30
29
#include "drizzled/plugin.h"
31
30
#include "drizzled/plugin/scheduler.h"
32
31
 
33
 
#include "drizzled/util/backtrace.h"
 
32
#ifdef __GNUC__
 
33
#ifdef HAVE_BACKTRACE
 
34
#include <execinfo.h>
 
35
#include <cxxabi.h>
 
36
#endif // HAVE_BACKTRACE
 
37
#endif // __GNUC__
34
38
 
35
39
using namespace drizzled;
36
40
 
49
53
void drizzled_print_signal_warning(int sig)
50
54
{
51
55
  if (global_system_variables.log_warnings)
52
 
    errmsg_printf(error::WARN, _("Got signal %d from thread %"PRIu32),
 
56
    errmsg_printf(ERRMSG_LVL_WARN, _("Got signal %d from thread %"PRIu64),
53
57
                  sig, global_thread_id);
54
58
#ifndef HAVE_BSD_SIGNALS
55
59
  sigset_t set;
68
72
/** Called when a thread is aborted. */
69
73
void drizzled_end_thread_signal(int )
70
74
{
71
 
  Session *session= current_session;
 
75
  Session *session=current_session;
72
76
  if (session)
73
77
  {
74
 
    Session::shared_ptr session_ptr(session::Cache::singleton().find(session->getSessionId()));
75
 
    if (not session_ptr) // We need to make we have a lock on session before we do anything with it.
76
 
      return;
77
 
 
78
78
    killed_threads++;
79
 
 
80
 
    // We need to get the ID before we kill off the session
81
 
    session_ptr->scheduler->killSessionNow(session_ptr);
82
 
    DRIZZLE_CONNECTION_DONE(session_ptr->getSessionId());
 
79
    session->scheduler->killSessionNow(session);
 
80
    DRIZZLE_CONNECTION_DONE(session->thread_id);
83
81
  }
 
82
  return;
84
83
}
85
84
 
86
85
static void write_core(int sig)
102
101
#endif
103
102
}
104
103
 
 
104
#define BACKTRACE_STACK_SIZE 50
105
105
void drizzled_handle_segfault(int sig)
106
106
{
107
107
  time_t curr_time;
151
151
                    "Hope that's ok; if not, decrease some variables in the "
152
152
                    "equation.\n\n"));
153
153
 
154
 
  drizzled::util::custom_backtrace();
 
154
#ifdef __GNUC__
 
155
#ifdef HAVE_BACKTRACE
 
156
  {
 
157
    void *array[BACKTRACE_STACK_SIZE];
 
158
    size_t size;
 
159
    char **strings;
 
160
 
 
161
    size= backtrace(array, BACKTRACE_STACK_SIZE);
 
162
    strings= backtrace_symbols(array, size);
 
163
 
 
164
    std::cerr << "Number of stack frames obtained: " << size <<  std::endl;
 
165
 
 
166
    for (size_t x= 1; x < size; x++) 
 
167
    {
 
168
      size_t sz= 200;
 
169
      char *function= (char *)malloc(sz);
 
170
      char *begin= 0;
 
171
      char *end= 0;
 
172
 
 
173
      for (char *j = strings[x]; *j; ++j)
 
174
      {
 
175
        if (*j == '(') {
 
176
          begin = j;
 
177
        }
 
178
        else if (*j == '+') {
 
179
          end = j;
 
180
        }
 
181
      }
 
182
      if (begin && end)
 
183
      {
 
184
        begin++;
 
185
        *end= NULL;
 
186
 
 
187
        int status;
 
188
        char *ret = abi::__cxa_demangle(begin, function, &sz, &status);
 
189
        if (ret) 
 
190
        {
 
191
          function= ret;
 
192
        }
 
193
        else
 
194
        {
 
195
          std::strncpy(function, begin, sz);
 
196
          std::strncat(function, "()", sz);
 
197
          function[sz-1] = NULL;
 
198
        }
 
199
        std::cerr << function << std::endl;
 
200
      }
 
201
      else
 
202
      {
 
203
        std::cerr << strings[x] << std::endl;
 
204
      }
 
205
      free(function);
 
206
    }
 
207
 
 
208
 
 
209
    free (strings);
 
210
  }
 
211
#endif // HAVE_BACKTRACE
 
212
#endif // __GNUC__
155
213
 
156
214
  write_core(sig);
157
215