737
#if defined(BACKTRACE_DEMANGLE)
739
extern "C" char *my_demangle(const char *mangled_name, int *status)
741
return abi::__cxa_demangle(mangled_name, NULL, NULL, status);
745
extern "C" void handle_segfault(int sig);
747
extern "C" void handle_segfault(int sig)
753
Strictly speaking, one needs a mutex here
754
but since we have got SIGSEGV already, things are a mess
755
so not having the mutex is not as bad as possibly using a buggy
756
mutex - so we keep things simple
760
fprintf(stderr, _("Fatal signal %d while backtracing\n"), sig);
766
curr_time= time(NULL);
767
if(curr_time == (time_t)-1)
769
fprintf(stderr, "Fetal: time() call failed\n");
773
localtime_r(&curr_time, &tm);
775
fprintf(stderr,"%02d%02d%02d %2d:%02d:%02d - drizzled got signal %d;\n"
776
"This could be because you hit a bug. It is also possible that "
777
"this binary\n or one of the libraries it was linked against is "
778
"corrupt, improperly built,\n or misconfigured. This error can "
779
"also be caused by malfunctioning hardware.\n",
780
tm.tm_year % 100, tm.tm_mon+1, tm.tm_mday,
781
tm.tm_hour, tm.tm_min, tm.tm_sec,
783
fprintf(stderr, _("We will try our best to scrape up some info that "
784
"will hopefully help diagnose\n"
785
"the problem, but since we have already crashed, "
786
"something is definitely wrong\nand this may fail.\n\n"));
787
fprintf(stderr, "key_buffer_size=%u\n",
788
(uint32_t) dflt_key_cache->key_cache_mem_size);
789
fprintf(stderr, "read_buffer_size=%ld\n", (long) global_system_variables.read_buff_size);
790
fprintf(stderr, "max_used_connections=%u\n", max_used_connections);
791
fprintf(stderr, "connection_count=%u\n", uint32_t(connection_count));
792
fprintf(stderr, _("It is possible that drizzled could use up to \n"
793
"key_buffer_size + (read_buffer_size + "
794
"sort_buffer_size)*thread_count\n"
796
"Hope that's ok; if not, decrease some variables in the "
799
#ifdef HAVE_STACKTRACE
800
Session *session= current_session;
802
if (! (test_flags.test(TEST_NO_STACKTRACE)))
804
fprintf(stderr,"session: 0x%lx\n",(long) session);
805
fprintf(stderr,_("Attempting backtrace. You can use the following "
806
"information to find out\n"
807
"where drizzled died. If you see no messages after this, "
809
"terribly wrong...\n"));
810
print_stacktrace(session ? (unsigned char*) session->thread_stack : (unsigned char*) 0,
811
my_thread_stack_size);
815
const char *kreason= "UNKNOWN";
816
switch (session->killed) {
817
case Session::NOT_KILLED:
818
kreason= "NOT_KILLED";
820
case Session::KILL_BAD_DATA:
821
kreason= "KILL_BAD_DATA";
823
case Session::KILL_CONNECTION:
824
kreason= "KILL_CONNECTION";
826
case Session::KILL_QUERY:
827
kreason= "KILL_QUERY";
829
case Session::KILLED_NO_VALUE:
830
kreason= "KILLED_NO_VALUE";
833
fprintf(stderr, _("Trying to get some variables.\n"
834
"Some pointers may be invalid and cause the "
835
"dump to abort...\n"));
836
safe_print_str("session->query", session->query.c_str(), 1024);
837
fprintf(stderr, "session->thread_id=%"PRIu32"\n", (uint32_t) session->thread_id);
838
fprintf(stderr, "session->killed=%s\n", kreason);
841
#endif /* HAVE_STACKTRACE */
843
if (calling_initgroups)
844
fprintf(stderr, _("\nThis crash occurred while the server was calling "
845
"initgroups(). This is\n"
846
"often due to the use of a drizzled that is statically "
847
"linked against glibc\n"
848
"and configured to use LDAP in /etc/nsswitch.conf. "
849
"You will need to either\n"
850
"upgrade to a version of glibc that does not have this "
851
"problem (2.3.4 or\n"
852
"later when used with nscd), disable LDAP in your "
853
"nsswitch.conf, or use a\n"
854
"drizzled that is not statically linked.\n"));
856
if (internal::thd_lib_detected == THD_LIB_LT && !getenv("LD_ASSUME_KERNEL"))
858
_("\nYou are running a statically-linked LinuxThreads binary "
859
"on an NPTL system.\n"
860
"This can result in crashes on some distributions due "
861
"to LT/NPTL conflicts.\n"
862
"You should either build a dynamically-linked binary, or force "
864
"to be used with the LD_ASSUME_KERNEL environment variable. "
866
"the documentation for your distribution on how to do that.\n"));
868
#ifdef HAVE_WRITE_CORE
869
if (test_flags.test(TEST_CORE_ON_SIGNAL))
871
fprintf(stderr, _("Writing a core file\n"));
880
701
#ifndef SA_RESETHAND
881
702
#define SA_RESETHAND 0
889
All global error messages are sent here where the first one is stored
892
static void my_message_sql(uint32_t error, const char *str, myf MyFlags)
711
const char *load_default_groups[]=
896
Put here following assertion when situation with EE_* error codes
899
if ((session= current_session))
901
if (MyFlags & ME_FATALERROR)
902
session->is_fatal_error= 1;
905
TODO: There are two exceptions mechanism (Session and sp_rcontext),
906
this could be improved by having a common stack of handlers.
908
if (session->handle_error(error, str,
909
DRIZZLE_ERROR::WARN_LEVEL_ERROR))
913
session->lex->current_select == 0 if lex structure is not inited
914
(not query command (COM_QUERY))
916
if (! (session->lex->current_select &&
917
session->lex->current_select->no_error && !session->is_fatal_error))
919
if (! session->main_da.is_error()) // Return only first message
922
error= ER_UNKNOWN_ERROR;
925
session->main_da.set_error_status(error, str);
929
if (!session->no_warnings_for_error && !session->is_fatal_error)
932
Suppress infinite recursion if there a memory allocation error
935
session->no_warnings_for_error= true;
936
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, error, str);
937
session->no_warnings_for_error= false;
940
if (!session || MyFlags & ME_NOREFRESH)
941
errmsg_printf(ERRMSG_LVL_ERROR, "%s: %s",internal::my_progname,str);
945
static const char *load_default_groups[]= {
946
DRIZZLE_CONFIG_NAME, "server", 0, 0};
713
DRIZZLE_CONFIG_NAME, "server", 0, 0
948
716
static int show_starttime(drizzle_show_var *var, char *buff)
1446
1214
NO_ARG, 0, 0, 0, 0, 0, 0},
1447
1215
{"datadir", 'h',
1448
1216
N_("Path to the database root."),
1449
(char**) &drizzle_data_home,
1450
(char**) &drizzle_data_home, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1217
(char**) &data_home,
1218
(char**) &data_home, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1451
1219
{"default-storage-engine", OPT_STORAGE_ENGINE,
1452
1220
N_("Set the default storage engine (table type) for tables."),
1453
1221
(char**)&default_storage_engine_str, (char**)&default_storage_engine_str,
2065
1832
pos[0]= FN_LIBCHAR;
2068
internal::convert_dirname(drizzle_real_data_home,drizzle_real_data_home,NULL);
2069
(void) internal::fn_format(buff, drizzle_real_data_home, "", "",
1835
internal::convert_dirname(data_home_real,data_home_real,NULL);
1836
(void) internal::fn_format(buff, data_home_real, "", "",
2070
1837
(MY_RETURN_REAL_PATH|MY_RESOLVE_SYMLINKS));
2071
(void) internal::unpack_dirname(drizzle_unpacked_real_data_home, buff);
1838
(void) internal::unpack_dirname(data_home_real_unpacked, buff);
2072
1839
internal::convert_dirname(language,language,NULL);
2073
1840
(void) internal::my_load_path(drizzle_home, drizzle_home,""); // Resolve current dir
2074
(void) internal::my_load_path(drizzle_real_data_home, drizzle_real_data_home,drizzle_home);
2075
(void) internal::my_load_path(pidfile_name, pidfile_name,drizzle_real_data_home);
1841
(void) internal::my_load_path(data_home_real, data_home_real,drizzle_home);
1842
(void) internal::my_load_path(pidfile_name, pidfile_name,data_home_real);
2077
1844
if (opt_plugin_dir_ptr == NULL)
2174
1941
} /* namespace drizzled */
2176
using namespace drizzled;
2179
static void init_signals(void)
2182
struct sigaction sa;
2184
if (!(test_flags.test(TEST_NO_STACKTRACE) ||
2185
test_flags.test(TEST_CORE_ON_SIGNAL)))
2187
sa.sa_flags = SA_RESETHAND | SA_NODEFER;
2188
sigemptyset(&sa.sa_mask);
2189
sigprocmask(SIG_SETMASK,&sa.sa_mask,NULL);
2192
sa.sa_handler=handle_segfault;
2193
sigaction(SIGSEGV, &sa, NULL);
2194
sigaction(SIGABRT, &sa, NULL);
2196
sigaction(SIGBUS, &sa, NULL);
2198
sigaction(SIGILL, &sa, NULL);
2199
sigaction(SIGFPE, &sa, NULL);
2202
if (test_flags.test(TEST_CORE_ON_SIGNAL))
2204
/* Change limits so that we will get a core file */
2206
rl.rlim_cur = rl.rlim_max = RLIM_INFINITY;
2207
if (setrlimit(RLIMIT_CORE, &rl) && global_system_variables.log_warnings)
2208
errmsg_printf(ERRMSG_LVL_WARN,
2209
_("setrlimit could not change the size of core files "
2210
"to 'infinity'; We may not be able to generate a "
2211
"core file on signals"));
2213
(void) sigemptyset(&set);
2214
my_sigset(SIGPIPE,SIG_IGN);
2215
sigaddset(&set,SIGPIPE);
2216
#ifndef IGNORE_SIGHUP_SIGQUIT
2217
sigaddset(&set,SIGQUIT);
2218
sigaddset(&set,SIGHUP);
2220
sigaddset(&set,SIGTERM);
2222
/* Fix signals if blocked by parents (can happen on Mac OS X) */
2223
sigemptyset(&sa.sa_mask);
2225
sa.sa_handler = print_signal_warning;
2226
sigaction(SIGTERM, &sa, (struct sigaction*) 0);
2228
sa.sa_handler = print_signal_warning;
2229
sigaction(SIGHUP, &sa, (struct sigaction*) 0);
2231
sigaddset(&set,SIGTSTP);
2233
if (test_flags.test(TEST_SIGINT))
2235
my_sigset(thr_kill_signal, end_thread_signal);
2237
sigdelset(&set, thr_kill_signal);
2240
sigaddset(&set,SIGINT);
2241
sigprocmask(SIG_SETMASK,&set,NULL);
2242
pthread_sigmask(SIG_SETMASK,&set,NULL);
2246
int main(int argc, char **argv)
2248
#if defined(ENABLE_NLS)
2249
# if defined(HAVE_LOCALE_H)
2250
setlocale(LC_ALL, "");
2252
bindtextdomain("drizzle", LOCALEDIR);
2253
textdomain("drizzle");
2256
plugin::Registry &plugins= plugin::Registry::singleton();
2257
plugin::Client *client;
2260
MY_INIT(argv[0]); // init my_sys library & pthreads
2261
/* nothing should come before this line ^^^ */
2263
/* Set signal used to kill Drizzle */
2264
#if defined(SIGUSR2)
2265
thr_kill_signal= internal::thd_lib_detected == THD_LIB_LT ? SIGINT : SIGUSR2;
2267
thr_kill_signal= SIGINT;
2270
if (init_common_variables(DRIZZLE_CONFIG_NAME,
2271
argc, argv, load_default_groups))
2272
unireg_abort(1); // Will do exit
2277
select_thread=pthread_self();
2278
select_thread_in_use=1;
2280
if (chdir(drizzle_real_data_home) && !opt_help)
2282
errmsg_printf(ERRMSG_LVL_ERROR, _("Data directory %s does not exist\n"), drizzle_real_data_home);
2285
drizzle_data_home= drizzle_data_home_buff;
2286
drizzle_data_home[0]=FN_CURLIB; // all paths are relative from here
2287
drizzle_data_home[1]=0;
2288
drizzle_data_home_len= 2;
2290
if ((user_info= check_user(drizzled_user)))
2292
set_user(drizzled_user, user_info);
2300
if (init_server_components(plugins))
2304
* This check must be done after init_server_components for now
2305
* because we don't yet have plugin dependency tracking...
2307
* ReplicationServices::evaluateRegisteredPlugins() will print error messages to stderr
2308
* via errmsg_printf().
2312
* not checking return since unireg_abort() hangs
2314
ReplicationServices &replication_services= ReplicationServices::singleton();
2315
(void) replication_services.evaluateRegisteredPlugins();
2317
if (plugin::Listen::setup())
2321
init signals & alarm
2322
After this we can't quit by a simple unireg_abort
2324
error_handler_hook= my_message_sql;
2326
assert(plugin::num_trx_monitored_objects > 0);
2327
if (drizzle_rm_tmp_tables() ||
2328
my_tz_init((Session *)0, default_tz_name))
2331
select_thread_in_use=0;
2332
(void) pthread_kill(signal_thread, SIGTERM);
2334
(void) unlink(pidfile_name); // Not needed anymore
2341
errmsg_printf(ERRMSG_LVL_INFO, _(ER(ER_STARTUP)), internal::my_progname,
2342
PANDORA_RELEASE_VERSION, COMPILATION_COMMENT);
2345
/* Listen for new connections and start new session for each connection
2346
accepted. The listen.getClient() method will return NULL when the server
2347
should be shutdown. */
2348
while ((client= plugin::Listen::getClient()) != NULL)
2350
if (!(session= new Session(client)))
2356
/* If we error on creation we drop the connection and delete the session. */
2357
if (session->schedule())
2358
Session::unlink(session);
2361
/* (void) pthread_attr_destroy(&connection_attrib); */
2364
(void) pthread_mutex_lock(&LOCK_thread_count);
2365
select_thread_in_use=0; // For close_connections
2366
(void) pthread_mutex_unlock(&LOCK_thread_count);
2367
(void) pthread_cond_broadcast(&COND_thread_count);
2369
/* Wait until cleanup is done */
2370
(void) pthread_mutex_lock(&LOCK_thread_count);
2371
while (!ready_to_exit)
2372
pthread_cond_wait(&COND_server_end,&LOCK_thread_count);
2373
(void) pthread_mutex_unlock(&LOCK_thread_count);
2376
plugin::Registry::shutdown();