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 |
*
|
|
1999.6.1
by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file |
4 |
* Copyright (C) 2008 Sun Microsystems, Inc.
|
1300.5.2
by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then |
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 |
||
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
20 |
#include <config.h> |
1300.5.2
by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then |
21 |
|
22 |
#include <signal.h> |
|
23 |
||
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
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> |
|
2154.2.24
by Brian Aker
Merge in all changes for current_session, etc. |
32 |
#include <drizzled/current_session.h> |
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
33 |
#include <drizzled/util/backtrace.h> |
2241.3.1
by Olaf van der Spek
Refactor Session::status_var |
34 |
#include <drizzled/statistics_variables.h> |
2241.3.2
by Olaf van der Spek
Refactor Session::variables |
35 |
#include <drizzled/system_variables.h> |
1300.5.2
by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then |
36 |
|
37 |
using namespace drizzled; |
|
38 |
||
39 |
static uint32_t killed_threads; |
|
40 |
static bool segfaulted= false; |
|
41 |
||
42 |
/*
|
|
43 |
* We declare these extern "C" because they are passed to system callback functions
|
|
44 |
* and Sun Studio does not like it when those don't have C linkage. We prefix them
|
|
45 |
* because extern "C"-ing something effectively removes the namespace from the
|
|
46 |
* linker symbols, meaning they would be exporting symbols like "print_signal_warning
|
|
47 |
*/
|
|
48 |
extern "C" |
|
49 |
{
|
|
50 |
||
51 |
void drizzled_print_signal_warning(int sig) |
|
52 |
{
|
|
53 |
if (global_system_variables.log_warnings) |
|
2126.3.3
by Brian Aker
Merge in error message rework. Many error messages are fixed in this patch. |
54 |
errmsg_printf(error::WARN, _("Got signal %d from thread %"PRIu32), |
1300.5.2
by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then |
55 |
sig, global_thread_id); |
56 |
#ifndef HAVE_BSD_SIGNALS
|
|
1300.5.23
by Monty Taylor
Merged in revs removing depend on the plugin tree. |
57 |
sigset_t set; |
58 |
sigemptyset(&set); |
|
59 |
||
60 |
struct sigaction sa; |
|
61 |
sa.sa_handler= drizzled_print_signal_warning; |
|
62 |
sa.sa_mask= set; |
|
63 |
sa.sa_flags= 0; |
|
64 |
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 |
65 |
#endif
|
66 |
if (sig == SIGALRM) |
|
67 |
alarm(2); /* reschedule alarm */ |
|
68 |
}
|
|
69 |
||
70 |
/** Called when a thread is aborted. */
|
|
71 |
void drizzled_end_thread_signal(int ) |
|
72 |
{
|
|
1932.3.13
by Brian Aker
Cleanup session ownership rules such that we know exactly when session has |
73 |
Session *session= current_session; |
1300.5.2
by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then |
74 |
if (session) |
75 |
{
|
|
2282.1.2
by Olaf van der Spek
Session Cache |
76 |
Session::shared_ptr session_ptr(session::Cache::find(session->getSessionId())); |
1932.3.13
by Brian Aker
Cleanup session ownership rules such that we know exactly when session has |
77 |
if (not session_ptr) // We need to make we have a lock on session before we do anything with it. |
78 |
return; |
|
79 |
||
1689.5.1
by Joseph Daly
remove increment calls |
80 |
killed_threads++; |
1932.3.13
by Brian Aker
Cleanup session ownership rules such that we know exactly when session has |
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()); |
|
1300.5.2
by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then |
85 |
}
|
86 |
}
|
|
87 |
||
1711.6.6
by Brian Aker
Remove the code surrounding stack trace. |
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
|
|
105 |
}
|
|
106 |
||
1300.5.2
by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then |
107 |
void drizzled_handle_segfault(int sig) |
108 |
{
|
|
109 |
time_t curr_time; |
|
110 |
struct tm tm; |
|
111 |
||
112 |
/*
|
|
113 |
Strictly speaking, one needs a mutex here
|
|
114 |
but since we have got SIGSEGV already, things are a mess
|
|
115 |
so not having the mutex is not as bad as possibly using a buggy
|
|
116 |
mutex - so we keep things simple
|
|
117 |
*/
|
|
118 |
if (segfaulted) |
|
119 |
{
|
|
120 |
fprintf(stderr, _("Fatal signal %d while backtracing\n"), sig); |
|
121 |
exit(1); |
|
122 |
}
|
|
123 |
||
124 |
segfaulted= true; |
|
125 |
||
126 |
curr_time= time(NULL); |
|
127 |
if(curr_time == (time_t)-1) |
|
128 |
{
|
|
1300.5.11
by Monty Taylor
Merged in trunk. |
129 |
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 |
130 |
exit(1); |
131 |
}
|
|
132 |
||
133 |
localtime_r(&curr_time, &tm); |
|
134 |
||
1300.5.11
by Monty Taylor
Merged in trunk. |
135 |
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 |
136 |
"This could be because you hit a bug. It is also possible that "
|
137 |
"this binary\n or one of the libraries it was linked against is " |
|
138 |
"corrupt, improperly built,\n or misconfigured. This error can " |
|
1300.5.11
by Monty Taylor
Merged in trunk. |
139 |
"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 |
140 |
tm.tm_year % 100, tm.tm_mon+1, tm.tm_mday, |
141 |
tm.tm_hour, tm.tm_min, tm.tm_sec, |
|
142 |
sig); |
|
143 |
fprintf(stderr, _("We will try our best to scrape up some info that " |
|
144 |
"will hopefully help diagnose\n" |
|
145 |
"the problem, but since we have already crashed, "
|
|
146 |
"something is definitely wrong\nand this may fail.\n\n")); |
|
147 |
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 |
148 |
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 |
149 |
fprintf(stderr, "connection_count=%u\n", uint32_t(connection_count)); |
150 |
fprintf(stderr, _("It is possible that drizzled could use up to \n" |
|
1711.6.7
by Brian Aker
Improved message reporting during a crash. |
151 |
"(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 |
152 |
"bytes of memory\n" |
153 |
"Hope that's ok; if not, decrease some variables in the "
|
|
154 |
"equation.\n\n")); |
|
1711.6.7
by Brian Aker
Improved message reporting during a crash. |
155 |
|
2363.1.4
by Brian Aker
Fixes bug where true/false would not be interpreted correctly/displayed correctly. |
156 |
call_backtrace(); |
1711.6.7
by Brian Aker
Improved message reporting during a crash. |
157 |
|
1711.6.6
by Brian Aker
Remove the code surrounding stack trace. |
158 |
write_core(sig); |
1300.5.2
by Monty Taylor
Changed build to build the almost all of drizzle into libdrizzled and then |
159 |
|
160 |
exit(1); |
|
161 |
}
|
|
162 |
||
163 |
} /* extern "C" */ |