744
#if defined(BACKTRACE_DEMANGLE)
746
extern "C" char *my_demangle(const char *mangled_name, int *status)
748
return abi::__cxa_demangle(mangled_name, NULL, NULL, status);
752
extern "C" void handle_segfault(int sig);
754
extern "C" void handle_segfault(int sig)
760
Strictly speaking, one needs a mutex here
761
but since we have got SIGSEGV already, things are a mess
762
so not having the mutex is not as bad as possibly using a buggy
763
mutex - so we keep things simple
767
fprintf(stderr, _("Fatal signal %d while backtracing\n"), sig);
773
curr_time= time(NULL);
774
if(curr_time == (time_t)-1)
776
fprintf(stderr, "Fetal: time() call failed\n");
780
localtime_r(&curr_time, &tm);
782
fprintf(stderr,"%02d%02d%02d %2d:%02d:%02d - drizzled got signal %d;\n"
783
"This could be because you hit a bug. It is also possible that "
784
"this binary\n or one of the libraries it was linked against is "
785
"corrupt, improperly built,\n or misconfigured. This error can "
786
"also be caused by malfunctioning hardware.\n",
787
tm.tm_year % 100, tm.tm_mon+1, tm.tm_mday,
788
tm.tm_hour, tm.tm_min, tm.tm_sec,
790
fprintf(stderr, _("We will try our best to scrape up some info that "
791
"will hopefully help diagnose\n"
792
"the problem, but since we have already crashed, "
793
"something is definitely wrong\nand this may fail.\n\n"));
794
fprintf(stderr, "key_buffer_size=%u\n",
795
(uint32_t) dflt_key_cache->key_cache_mem_size);
796
fprintf(stderr, "read_buffer_size=%ld\n", (long) global_system_variables.read_buff_size);
797
fprintf(stderr, "max_used_connections=%u\n", max_used_connections);
798
fprintf(stderr, "connection_count=%u\n", uint32_t(connection_count));
799
fprintf(stderr, _("It is possible that drizzled could use up to \n"
800
"key_buffer_size + (read_buffer_size + "
801
"sort_buffer_size)*thread_count\n"
803
"Hope that's ok; if not, decrease some variables in the "
806
#ifdef HAVE_STACKTRACE
807
Session *session= current_session;
809
if (! (test_flags.test(TEST_NO_STACKTRACE)))
811
fprintf(stderr,"session: 0x%lx\n",(long) session);
812
fprintf(stderr,_("Attempting backtrace. You can use the following "
813
"information to find out\n"
814
"where drizzled died. If you see no messages after this, "
816
"terribly wrong...\n"));
817
print_stacktrace(session ? (unsigned char*) session->thread_stack : (unsigned char*) 0,
818
my_thread_stack_size);
822
const char *kreason= "UNKNOWN";
823
switch (session->killed) {
824
case Session::NOT_KILLED:
825
kreason= "NOT_KILLED";
827
case Session::KILL_BAD_DATA:
828
kreason= "KILL_BAD_DATA";
830
case Session::KILL_CONNECTION:
831
kreason= "KILL_CONNECTION";
833
case Session::KILL_QUERY:
834
kreason= "KILL_QUERY";
836
case Session::KILLED_NO_VALUE:
837
kreason= "KILLED_NO_VALUE";
840
fprintf(stderr, _("Trying to get some variables.\n"
841
"Some pointers may be invalid and cause the "
842
"dump to abort...\n"));
843
safe_print_str("session->query", session->query, 1024);
844
fprintf(stderr, "session->thread_id=%"PRIu32"\n", (uint32_t) session->thread_id);
845
fprintf(stderr, "session->killed=%s\n", kreason);
848
#endif /* HAVE_STACKTRACE */
850
if (calling_initgroups)
851
fprintf(stderr, _("\nThis crash occurred while the server was calling "
852
"initgroups(). This is\n"
853
"often due to the use of a drizzled that is statically "
854
"linked against glibc\n"
855
"and configured to use LDAP in /etc/nsswitch.conf. "
856
"You will need to either\n"
857
"upgrade to a version of glibc that does not have this "
858
"problem (2.3.4 or\n"
859
"later when used with nscd), disable LDAP in your "
860
"nsswitch.conf, or use a\n"
861
"drizzled that is not statically linked.\n"));
863
if (internal::thd_lib_detected == THD_LIB_LT && !getenv("LD_ASSUME_KERNEL"))
865
_("\nYou are running a statically-linked LinuxThreads binary "
866
"on an NPTL system.\n"
867
"This can result in crashes on some distributions due "
868
"to LT/NPTL conflicts.\n"
869
"You should either build a dynamically-linked binary, or force "
871
"to be used with the LD_ASSUME_KERNEL environment variable. "
873
"the documentation for your distribution on how to do that.\n"));
875
#ifdef HAVE_WRITE_CORE
876
if (test_flags.test(TEST_CORE_ON_SIGNAL))
878
fprintf(stderr, _("Writing a core file\n"));
887
711
#ifndef SA_RESETHAND
888
712
#define SA_RESETHAND 0
896
All global error messages are sent here where the first one is stored
899
static void my_message_sql(uint32_t error, const char *str, myf MyFlags)
721
const char *load_default_groups[]=
903
Put here following assertion when situation with EE_* error codes
906
if ((session= current_session))
908
if (MyFlags & ME_FATALERROR)
909
session->is_fatal_error= 1;
912
TODO: There are two exceptions mechanism (Session and sp_rcontext),
913
this could be improved by having a common stack of handlers.
915
if (session->handle_error(error, str,
916
DRIZZLE_ERROR::WARN_LEVEL_ERROR))
920
session->lex->current_select == 0 if lex structure is not inited
921
(not query command (COM_QUERY))
923
if (! (session->lex->current_select &&
924
session->lex->current_select->no_error && !session->is_fatal_error))
926
if (! session->main_da.is_error()) // Return only first message
929
error= ER_UNKNOWN_ERROR;
932
session->main_da.set_error_status(error, str);
936
if (!session->no_warnings_for_error && !session->is_fatal_error)
939
Suppress infinite recursion if there a memory allocation error
942
session->no_warnings_for_error= true;
943
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, error, str);
944
session->no_warnings_for_error= false;
947
if (!session || MyFlags & ME_NOREFRESH)
948
errmsg_printf(ERRMSG_LVL_ERROR, "%s: %s",internal::my_progname,str);
952
static const char *load_default_groups[]= {
953
DRIZZLE_CONFIG_NAME, "server", 0, 0};
723
DRIZZLE_CONFIG_NAME, "server", 0, 0
955
726
static int show_starttime(SHOW_VAR *var, char *buff)
2248
2018
} /* namespace drizzled */
2250
using namespace drizzled;
2253
static void init_signals(void)
2256
struct sigaction sa;
2258
if (!(test_flags.test(TEST_NO_STACKTRACE) ||
2259
test_flags.test(TEST_CORE_ON_SIGNAL)))
2261
sa.sa_flags = SA_RESETHAND | SA_NODEFER;
2262
sigemptyset(&sa.sa_mask);
2263
sigprocmask(SIG_SETMASK,&sa.sa_mask,NULL);
2266
sa.sa_handler=handle_segfault;
2267
sigaction(SIGSEGV, &sa, NULL);
2268
sigaction(SIGABRT, &sa, NULL);
2270
sigaction(SIGBUS, &sa, NULL);
2272
sigaction(SIGILL, &sa, NULL);
2273
sigaction(SIGFPE, &sa, NULL);
2276
if (test_flags.test(TEST_CORE_ON_SIGNAL))
2278
/* Change limits so that we will get a core file */
2280
rl.rlim_cur = rl.rlim_max = RLIM_INFINITY;
2281
if (setrlimit(RLIMIT_CORE, &rl) && global_system_variables.log_warnings)
2282
errmsg_printf(ERRMSG_LVL_WARN,
2283
_("setrlimit could not change the size of core files "
2284
"to 'infinity'; We may not be able to generate a "
2285
"core file on signals"));
2287
(void) sigemptyset(&set);
2288
my_sigset(SIGPIPE,SIG_IGN);
2289
sigaddset(&set,SIGPIPE);
2290
#ifndef IGNORE_SIGHUP_SIGQUIT
2291
sigaddset(&set,SIGQUIT);
2292
sigaddset(&set,SIGHUP);
2294
sigaddset(&set,SIGTERM);
2296
/* Fix signals if blocked by parents (can happen on Mac OS X) */
2297
sigemptyset(&sa.sa_mask);
2299
sa.sa_handler = print_signal_warning;
2300
sigaction(SIGTERM, &sa, (struct sigaction*) 0);
2302
sa.sa_handler = print_signal_warning;
2303
sigaction(SIGHUP, &sa, (struct sigaction*) 0);
2305
sigaddset(&set,SIGTSTP);
2307
if (test_flags.test(TEST_SIGINT))
2309
my_sigset(thr_kill_signal, end_thread_signal);
2311
sigdelset(&set, thr_kill_signal);
2314
sigaddset(&set,SIGINT);
2315
sigprocmask(SIG_SETMASK,&set,NULL);
2316
pthread_sigmask(SIG_SETMASK,&set,NULL);
2320
int main(int argc, char **argv)
2322
#if defined(ENABLE_NLS)
2323
# if defined(HAVE_LOCALE_H)
2324
setlocale(LC_ALL, "");
2326
bindtextdomain("drizzle", LOCALEDIR);
2327
textdomain("drizzle");
2330
plugin::Registry &plugins= plugin::Registry::singleton();
2331
plugin::Client *client;
2334
MY_INIT(argv[0]); // init my_sys library & pthreads
2335
/* nothing should come before this line ^^^ */
2337
/* Set signal used to kill Drizzle */
2338
#if defined(SIGUSR2)
2339
thr_kill_signal= internal::thd_lib_detected == THD_LIB_LT ? SIGINT : SIGUSR2;
2341
thr_kill_signal= SIGINT;
2344
if (init_common_variables(DRIZZLE_CONFIG_NAME,
2345
argc, argv, load_default_groups))
2346
unireg_abort(1); // Will do exit
2351
select_thread=pthread_self();
2352
select_thread_in_use=1;
2354
if (chdir(drizzle_real_data_home) && !opt_help)
2356
errmsg_printf(ERRMSG_LVL_ERROR, _("Data directory %s does not exist\n"), drizzle_real_data_home);
2359
drizzle_data_home= drizzle_data_home_buff;
2360
drizzle_data_home[0]=FN_CURLIB; // all paths are relative from here
2361
drizzle_data_home[1]=0;
2362
drizzle_data_home_len= 2;
2364
if ((user_info= check_user(drizzled_user)))
2366
set_user(drizzled_user, user_info);
2374
if (init_server_components(plugins))
2377
if (plugin::Listen::setup())
2381
init signals & alarm
2382
After this we can't quit by a simple unireg_abort
2384
error_handler_hook= my_message_sql;
2386
if (drizzle_rm_tmp_tables() ||
2387
my_tz_init((Session *)0, default_tz_name))
2390
select_thread_in_use=0;
2391
(void) pthread_kill(signal_thread, SIGTERM);
2393
(void) unlink(pidfile_name); // Not needed anymore
2400
errmsg_printf(ERRMSG_LVL_INFO, _(ER(ER_STARTUP)), internal::my_progname,
2401
PANDORA_RELEASE_VERSION, COMPILATION_COMMENT);
2404
/* Listen for new connections and start new session for each connection
2405
accepted. The listen.getClient() method will return NULL when the server
2406
should be shutdown. */
2407
while ((client= plugin::Listen::getClient()) != NULL)
2409
if (!(session= new Session(client)))
2415
/* If we error on creation we drop the connection and delete the session. */
2416
if (session->schedule())
2417
Session::unlink(session);
2420
/* (void) pthread_attr_destroy(&connection_attrib); */
2423
(void) pthread_mutex_lock(&LOCK_thread_count);
2424
select_thread_in_use=0; // For close_connections
2425
(void) pthread_mutex_unlock(&LOCK_thread_count);
2426
(void) pthread_cond_broadcast(&COND_thread_count);
2428
/* Wait until cleanup is done */
2429
(void) pthread_mutex_lock(&LOCK_thread_count);
2430
while (!ready_to_exit)
2431
pthread_cond_wait(&COND_server_end,&LOCK_thread_count);
2432
(void) pthread_mutex_unlock(&LOCK_thread_count);
2435
plugin::Registry::shutdown();