~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/signal_handler.cc

  • Committer: Brian Aker
  • Date: 2010-10-15 05:30:39 UTC
  • mfrom: (1843.8.7 trunk-drizzle)
  • Revision ID: brian@tangent.org-20101015053039-ebmv3hnn1yaq4wqy
Merge in refactoring on table (broken it up by type, this will allow me to
insert the new locking).

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
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include <config.h>
 
20
#include "config.h"
21
21
 
22
22
#include <signal.h>
23
23
 
24
 
#include <drizzled/signal_handler.h>
25
 
#include <drizzled/drizzled.h>
26
 
#include <drizzled/session.h>
27
 
#include <drizzled/session/cache.h>
28
 
#include <drizzled/internal/my_sys.h>
29
 
#include <drizzled/probes.h>
30
 
#include <drizzled/plugin.h>
31
 
#include <drizzled/plugin/scheduler.h>
32
 
#include <drizzled/current_session.h>
 
24
#include "drizzled/signal_handler.h"
 
25
#include "drizzled/drizzled.h"
 
26
#include "drizzled/session.h"
 
27
#include "drizzled/internal/my_sys.h"
 
28
#include "drizzled/probes.h"
 
29
#include "drizzled/plugin.h"
 
30
#include "drizzled/plugin/scheduler.h"
33
31
 
34
 
#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__
35
38
 
36
39
using namespace drizzled;
37
40
 
50
53
void drizzled_print_signal_warning(int sig)
51
54
{
52
55
  if (global_system_variables.log_warnings)
53
 
    errmsg_printf(error::WARN, _("Got signal %d from thread %"PRIu32),
 
56
    errmsg_printf(ERRMSG_LVL_WARN, _("Got signal %d from thread %"PRIu64),
54
57
                  sig, global_thread_id);
55
58
#ifndef HAVE_BSD_SIGNALS
56
59
  sigset_t set;
69
72
/** Called when a thread is aborted. */
70
73
void drizzled_end_thread_signal(int )
71
74
{
72
 
  Session *session= current_session;
 
75
  Session *session=current_session;
73
76
  if (session)
74
77
  {
75
 
    Session::shared_ptr session_ptr(session::Cache::singleton().find(session->getSessionId()));
76
 
    if (not session_ptr) // We need to make we have a lock on session before we do anything with it.
77
 
      return;
78
 
 
79
78
    killed_threads++;
80
 
 
81
 
    // We need to get the ID before we kill off the session
82
 
    session_ptr->scheduler->killSessionNow(session_ptr);
83
 
    DRIZZLE_CONNECTION_DONE(session_ptr->getSessionId());
 
79
    session->scheduler->killSessionNow(session);
 
80
    DRIZZLE_CONNECTION_DONE(session->thread_id);
84
81
  }
 
82
  return;
85
83
}
86
84
 
87
85
static void write_core(int sig)
103
101
#endif
104
102
}
105
103
 
 
104
#define BACKTRACE_STACK_SIZE 50
106
105
void drizzled_handle_segfault(int sig)
107
106
{
108
107
  time_t curr_time;
152
151
                    "Hope that's ok; if not, decrease some variables in the "
153
152
                    "equation.\n\n"));
154
153
 
155
 
  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= '\0';
 
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] = '\0';
 
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__
156
213
 
157
214
  write_core(sig);
158
215