1300.5.2
by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
4 |
* Copyright (C) 2008 Sun Microsystems
|
|
5 |
*
|
|
6 |
* This program is free software; you can redistribute it and/or modify
|
|
7 |
* it under the terms of the GNU General Public License as published by
|
|
8 |
* the Free Software Foundation; version 2 of the License.
|
|
9 |
*
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
* GNU General Public License for more details.
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License
|
|
16 |
* along with this program; if not, write to the Free Software
|
|
17 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
18 |
*/
|
|
19 |
||
20 |
#include "config.h" |
|
21 |
||
22 |
#include <signal.h> |
|
23 |
||
1300.5.22
by Monty Taylor
Moved and reworked a wrapper around sigset - which we shouldn't be using |
24 |
#include "drizzled/signal_handler.h" |
1300.5.2
by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then |
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" |
|
1711.6.7
by Brian Aker
Improved message reporting during a crash. |
31 |
|
1861.5.1
by Brian Aker
This just fixes our current catalog to be displayed properly. |
32 |
#include "drizzled/util/backtrace.h" |
1300.5.2
by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then |
33 |
|
34 |
using namespace drizzled; |
|
35 |
||
36 |
static uint32_t killed_threads; |
|
37 |
static bool segfaulted= false; |
|
38 |
||
39 |
/*
|
|
40 |
* We declare these extern "C" because they are passed to system callback functions
|
|
41 |
* and Sun Studio does not like it when those don't have C linkage. We prefix them
|
|
42 |
* because extern "C"-ing something effectively removes the namespace from the
|
|
43 |
* linker symbols, meaning they would be exporting symbols like "print_signal_warning
|
|
44 |
*/
|
|
45 |
extern "C" |
|
46 |
{
|
|
47 |
||
48 |
void drizzled_print_signal_warning(int sig) |
|
49 |
{
|
|
50 |
if (global_system_variables.log_warnings) |
|
51 |
errmsg_printf(ERRMSG_LVL_WARN, _("Got signal %d from thread %"PRIu64), |
|
52 |
sig, global_thread_id); |
|
53 |
#ifndef HAVE_BSD_SIGNALS
|
|
1300.5.23
by Monty Taylor
Merged in revs removing depend on the plugin tree. |
54 |
sigset_t set; |
55 |
sigemptyset(&set); |
|
56 |
||
57 |
struct sigaction sa; |
|
58 |
sa.sa_handler= drizzled_print_signal_warning; |
|
59 |
sa.sa_mask= set; |
|
60 |
sa.sa_flags= 0; |
|
61 |
sigaction(sig, &sa, NULL); /* int. thread system calls */ |
|
1300.5.2
by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then |
62 |
#endif
|
63 |
if (sig == SIGALRM) |
|
64 |
alarm(2); /* reschedule alarm */ |
|
65 |
}
|
|
66 |
||
67 |
/** Called when a thread is aborted. */
|
|
68 |
void drizzled_end_thread_signal(int ) |
|
69 |
{
|
|
70 |
Session *session=current_session; |
|
71 |
if (session) |
|
72 |
{
|
|
1689.5.1
by Joseph Daly
remove increment calls |
73 |
killed_threads++; |
1300.5.2
by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then |
74 |
session->scheduler->killSessionNow(session); |
75 |
DRIZZLE_CONNECTION_DONE(session->thread_id); |
|
76 |
}
|
|
77 |
return; |
|
78 |
}
|
|
79 |
||
1711.6.6
by Brian Aker
Remove the code surrounding stack trace. |
80 |
static void write_core(int sig) |
81 |
{
|
|
82 |
signal(sig, SIG_DFL); |
|
83 |
#ifdef HAVE_gcov
|
|
84 |
/*
|
|
85 |
For GCOV build, crashing will prevent the writing of code coverage
|
|
86 |
information from this process, causing gcov output to be incomplete.
|
|
87 |
So we force the writing of coverage information here before terminating.
|
|
88 |
*/
|
|
89 |
extern void __gcov_flush(void); |
|
90 |
__gcov_flush(); |
|
91 |
#endif
|
|
92 |
pthread_kill(pthread_self(), sig); |
|
93 |
#if defined(P_MYID) && !defined(SCO)
|
|
94 |
/* On Solaris, the above kill is not enough */
|
|
95 |
sigsend(P_PID,P_MYID,sig); |
|
96 |
#endif
|
|
97 |
}
|
|
98 |
||
1300.5.2
by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then |
99 |
void drizzled_handle_segfault(int sig) |
100 |
{
|
|
101 |
time_t curr_time; |
|
102 |
struct tm tm; |
|
103 |
||
104 |
/*
|
|
105 |
Strictly speaking, one needs a mutex here
|
|
106 |
but since we have got SIGSEGV already, things are a mess
|
|
107 |
so not having the mutex is not as bad as possibly using a buggy
|
|
108 |
mutex - so we keep things simple
|
|
109 |
*/
|
|
110 |
if (segfaulted) |
|
111 |
{
|
|
112 |
fprintf(stderr, _("Fatal signal %d while backtracing\n"), sig); |
|
113 |
exit(1); |
|
114 |
}
|
|
115 |
||
116 |
segfaulted= true; |
|
117 |
||
118 |
curr_time= time(NULL); |
|
119 |
if(curr_time == (time_t)-1) |
|
120 |
{
|
|
1300.5.11
by Monty Taylor
Merged in trunk. |
121 |
fprintf(stderr, _("Fatal: time() call failed\n")); |
1300.5.2
by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then |
122 |
exit(1); |
123 |
}
|
|
124 |
||
125 |
localtime_r(&curr_time, &tm); |
|
126 |
||
1300.5.11
by Monty Taylor
Merged in trunk. |
127 |
fprintf(stderr,_("%02d%02d%02d %2d:%02d:%02d - drizzled got signal %d;\n" |
1300.5.2
by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then |
128 |
"This could be because you hit a bug. It is also possible that "
|
129 |
"this binary\n or one of the libraries it was linked against is " |
|
130 |
"corrupt, improperly built,\n or misconfigured. This error can " |
|
1300.5.11
by Monty Taylor
Merged in trunk. |
131 |
"also be caused by malfunctioning hardware.\n"), |
1300.5.2
by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then |
132 |
tm.tm_year % 100, tm.tm_mon+1, tm.tm_mday, |
133 |
tm.tm_hour, tm.tm_min, tm.tm_sec, |
|
134 |
sig); |
|
135 |
fprintf(stderr, _("We will try our best to scrape up some info that " |
|
136 |
"will hopefully help diagnose\n" |
|
137 |
"the problem, but since we have already crashed, "
|
|
138 |
"something is definitely wrong\nand this may fail.\n\n")); |
|
139 |
fprintf(stderr, "read_buffer_size=%ld\n", (long) global_system_variables.read_buff_size); |
|
1561.3.14
by Joe Daly
fix compiler warning (hopefully) change lu to PRIu64 |
140 |
fprintf(stderr, "max_used_connections=%"PRIu64"\n", current_global_counters.max_used_connections); |
1300.5.2
by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then |
141 |
fprintf(stderr, "connection_count=%u\n", uint32_t(connection_count)); |
142 |
fprintf(stderr, _("It is possible that drizzled could use up to \n" |
|
1711.6.7
by Brian Aker
Improved message reporting during a crash. |
143 |
"(read_buffer_size + sort_buffer_size)*thread_count\n" |
1300.5.2
by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then |
144 |
"bytes of memory\n" |
145 |
"Hope that's ok; if not, decrease some variables in the "
|
|
146 |
"equation.\n\n")); |
|
1711.6.7
by Brian Aker
Improved message reporting during a crash. |
147 |
|
1861.5.1
by Brian Aker
This just fixes our current catalog to be displayed properly. |
148 |
drizzled::util::custom_backtrace(); |
1711.6.7
by Brian Aker
Improved message reporting during a crash. |
149 |
|
1711.6.6
by Brian Aker
Remove the code surrounding stack trace. |
150 |
write_core(sig); |
1300.5.2
by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then |
151 |
|
152 |
exit(1); |
|
153 |
}
|
|
154 |
||
155 |
} /* extern "C" */ |