~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/signal_handler.cc

  • Committer: Brian Aker
  • Date: 2010-08-18 19:37:19 UTC
  • mto: This revision was merged to the branch mainline in revision 1720.
  • Revision ID: brian@tangent.org-20100818193719-bxxzn1pi22styowd
created function that can be used to simply crash the server.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
#include <execinfo.h>
 
34
#include <cxxabi.h>
 
35
#endif // __GNUC__
34
36
 
35
37
using namespace drizzled;
36
38
 
49
51
void drizzled_print_signal_warning(int sig)
50
52
{
51
53
  if (global_system_variables.log_warnings)
52
 
    errmsg_printf(ERRMSG_LVL_WARN, _("Got signal %d from thread %"PRIu32),
 
54
    errmsg_printf(ERRMSG_LVL_WARN, _("Got signal %d from thread %"PRIu64),
53
55
                  sig, global_thread_id);
54
56
#ifndef HAVE_BSD_SIGNALS
55
57
  sigset_t set;
68
70
/** Called when a thread is aborted. */
69
71
void drizzled_end_thread_signal(int )
70
72
{
71
 
  Session *session= current_session;
 
73
  Session *session=current_session;
72
74
  if (session)
73
75
  {
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
76
    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());
 
77
    session->scheduler->killSessionNow(session);
 
78
    DRIZZLE_CONNECTION_DONE(session->thread_id);
83
79
  }
 
80
  return;
84
81
}
85
82
 
86
83
static void write_core(int sig)
102
99
#endif
103
100
}
104
101
 
 
102
#define BACKTRACE_STACK_SIZE 50
105
103
void drizzled_handle_segfault(int sig)
106
104
{
107
105
  time_t curr_time;
151
149
                    "Hope that's ok; if not, decrease some variables in the "
152
150
                    "equation.\n\n"));
153
151
 
154
 
  drizzled::util::custom_backtrace();
 
152
#ifdef __GNUC__
 
153
  {
 
154
    void *array[BACKTRACE_STACK_SIZE];
 
155
    size_t size;
 
156
    char **strings;
 
157
 
 
158
    size= backtrace (array, BACKTRACE_STACK_SIZE);
 
159
    strings= backtrace_symbols (array, size);
 
160
 
 
161
    std::cerr << "Number of stack frames obtained: " << size <<  std::endl;
 
162
 
 
163
    for (size_t x= 1; x < size; x++) 
 
164
    {
 
165
      size_t sz= 200;
 
166
      char *function= (char *)malloc(sz);
 
167
      char *begin= 0;
 
168
      char *end= 0;
 
169
 
 
170
      for (char *j = strings[x]; *j; ++j)
 
171
      {
 
172
        if (*j == '(') {
 
173
          begin = j;
 
174
        }
 
175
        else if (*j == '+') {
 
176
          end = j;
 
177
        }
 
178
      }
 
179
      if (begin && end)
 
180
      {
 
181
        begin++;
 
182
        *end= NULL;
 
183
 
 
184
        int status;
 
185
        char *ret = abi::__cxa_demangle(begin, function, &sz, &status);
 
186
        if (ret) 
 
187
        {
 
188
          function= ret;
 
189
        }
 
190
        else
 
191
        {
 
192
          std::strncpy(function, begin, sz);
 
193
          std::strncat(function, "()", sz);
 
194
          function[sz-1] = NULL;
 
195
        }
 
196
        std::cerr << function << std::endl;
 
197
      }
 
198
      else
 
199
      {
 
200
        std::cerr << strings[x] << std::endl;
 
201
      }
 
202
      free(function);
 
203
    }
 
204
 
 
205
 
 
206
    free (strings);
 
207
  }
 
208
#endif // __GNUC__
155
209
 
156
210
  write_core(sig);
157
211