~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 20:55:22 UTC
  • mfrom: (1711.6.3 staging)
  • Revision ID: brian@tangent.org-20100818205522-esgel82hp9kyl3l2
Merge mutex patch

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>
33
 
#include <drizzled/util/backtrace.h>
34
 
#include <drizzled/statistics_variables.h>
35
 
#include <drizzled/system_variables.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"
 
31
#include "plugin/myisam/keycache.h"
36
32
 
37
33
using namespace drizzled;
38
34
 
51
47
void drizzled_print_signal_warning(int sig)
52
48
{
53
49
  if (global_system_variables.log_warnings)
54
 
    errmsg_printf(error::WARN, _("Got signal %d from thread %"PRIu32),
 
50
    errmsg_printf(ERRMSG_LVL_WARN, _("Got signal %d from thread %"PRIu64),
55
51
                  sig, global_thread_id);
56
52
#ifndef HAVE_BSD_SIGNALS
57
53
  sigset_t set;
70
66
/** Called when a thread is aborted. */
71
67
void drizzled_end_thread_signal(int )
72
68
{
73
 
  Session *session= current_session;
 
69
  Session *session=current_session;
74
70
  if (session)
75
71
  {
76
 
    Session::shared_ptr session_ptr(session::Cache::find(session->getSessionId()));
77
 
    if (not session_ptr) // We need to make we have a lock on session before we do anything with it.
78
 
      return;
79
 
 
80
72
    killed_threads++;
81
 
 
82
 
    // We need to get the ID before we kill off the session
83
 
    session_ptr->scheduler->killSessionNow(session_ptr);
84
 
    DRIZZLE_CONNECTION_DONE(session_ptr->getSessionId());
 
73
    session->scheduler->killSessionNow(session);
 
74
    DRIZZLE_CONNECTION_DONE(session->thread_id);
85
75
  }
86
 
}
87
 
 
88
 
static void write_core(int sig)
89
 
{
90
 
  signal(sig, SIG_DFL);
91
 
#ifdef HAVE_gcov
92
 
  /*
93
 
    For GCOV build, crashing will prevent the writing of code coverage
94
 
    information from this process, causing gcov output to be incomplete.
95
 
    So we force the writing of coverage information here before terminating.
96
 
  */
97
 
  extern void __gcov_flush(void);
98
 
  __gcov_flush();
99
 
#endif
100
 
  pthread_kill(pthread_self(), sig);
101
 
#if defined(P_MYID) && !defined(SCO)
102
 
  /* On Solaris, the above kill is not enough */
103
 
  sigsend(P_PID,P_MYID,sig);
104
 
#endif
 
76
  return;
105
77
}
106
78
 
107
79
void drizzled_handle_segfault(int sig)
148
120
  fprintf(stderr, "max_used_connections=%"PRIu64"\n", current_global_counters.max_used_connections);
149
121
  fprintf(stderr, "connection_count=%u\n", uint32_t(connection_count));
150
122
  fprintf(stderr, _("It is possible that drizzled could use up to \n"
151
 
                    "(read_buffer_size + sort_buffer_size)*thread_count\n"
 
123
                    "key_buffer_size + (read_buffer_size + "
 
124
                    "sort_buffer_size)*thread_count\n"
152
125
                    "bytes of memory\n"
153
126
                    "Hope that's ok; if not, decrease some variables in the "
154
127
                    "equation.\n\n"));
155
128
 
156
 
  call_backtrace();
157
 
 
158
 
  write_core(sig);
 
129
#ifdef HAVE_STACKTRACE
 
130
  Session *session= current_session;
 
131
 
 
132
  if (! (test_flags.test(TEST_NO_STACKTRACE)))
 
133
  {
 
134
    fprintf(stderr,"session: 0x%lx\n",(long) session);
 
135
    fprintf(stderr,_("Attempting backtrace. You can use the following "
 
136
                     "information to find out\n"
 
137
                     "where drizzled died. If you see no messages after this, "
 
138
                     "something went\n"
 
139
                     "terribly wrong...\n"));
 
140
    print_stacktrace(session ? (unsigned char*) session->thread_stack : (unsigned char*) 0,
 
141
                     my_thread_stack_size);
 
142
  }
 
143
  if (session)
 
144
  {
 
145
    const char *kreason= "UNKNOWN";
 
146
    switch (session->killed) {
 
147
    case Session::NOT_KILLED:
 
148
      kreason= "NOT_KILLED";
 
149
      break;
 
150
    case Session::KILL_BAD_DATA:
 
151
      kreason= "KILL_BAD_DATA";
 
152
      break;
 
153
    case Session::KILL_CONNECTION:
 
154
      kreason= "KILL_CONNECTION";
 
155
      break;
 
156
    case Session::KILL_QUERY:
 
157
      kreason= "KILL_QUERY";
 
158
      break;
 
159
    case Session::KILLED_NO_VALUE:
 
160
      kreason= "KILLED_NO_VALUE";
 
161
      break;
 
162
    }
 
163
    fprintf(stderr, _("Trying to get some variables.\n"
 
164
                      "Some pointers may be invalid and cause the "
 
165
                      "dump to abort...\n"));
 
166
    safe_print_str("session->query", session->query, 1024);
 
167
    fprintf(stderr, "session->thread_id=%"PRIu32"\n", (uint32_t) session->thread_id);
 
168
    fprintf(stderr, "session->killed=%s\n", kreason);
 
169
  }
 
170
  fflush(stderr);
 
171
#endif /* HAVE_STACKTRACE */
 
172
 
 
173
  if (calling_initgroups)
 
174
    fprintf(stderr, _("\nThis crash occurred while the server was calling "
 
175
                      "initgroups(). This is\n"
 
176
                      "often due to the use of a drizzled that is statically "
 
177
                      "linked against glibc\n"
 
178
                      "and configured to use LDAP in /etc/nsswitch.conf. "
 
179
                      "You will need to either\n"
 
180
                      "upgrade to a version of glibc that does not have this "
 
181
                      "problem (2.3.4 or\n"
 
182
                      "later when used with nscd), disable LDAP in your "
 
183
                      "nsswitch.conf, or use a\n"
 
184
                      "drizzled that is not statically linked.\n"));
 
185
 
 
186
  if (internal::thd_lib_detected == THD_LIB_LT && !getenv("LD_ASSUME_KERNEL"))
 
187
    fprintf(stderr,
 
188
            _("\nYou are running a statically-linked LinuxThreads binary "
 
189
              "on an NPTL system.\n"
 
190
              "This can result in crashes on some distributions due "
 
191
              "to LT/NPTL conflicts.\n"
 
192
              "You should either build a dynamically-linked binary, or force "
 
193
              "LinuxThreads\n"
 
194
              "to be used with the LD_ASSUME_KERNEL environment variable. "
 
195
              "Please consult\n"
 
196
              "the documentation for your distribution on how to do that.\n"));
 
197
 
 
198
#ifdef HAVE_WRITE_CORE
 
199
  if (test_flags.test(TEST_CORE_ON_SIGNAL))
 
200
  {
 
201
    fprintf(stderr, _("Writing a core file\n"));
 
202
    fflush(stderr);
 
203
    write_core(sig);
 
204
  }
 
205
#endif
159
206
 
160
207
  exit(1);
161
208
}