150
160
#endif /* __i386__ && HAVE_FPU_CONTROL_H && _FPU_DOUBLE */
153
#include "drizzled/internal/my_pthread.h" // For thr_setconcurency()
155
#include <drizzled/gettext.h>
158
164
extern "C" int gethostname(char *name, int namelen);
162
using namespace drizzled;
167
const char *show_comp_option_name[]= {"YES", "NO", "DISABLED"};
168
static const char *optimizer_switch_names[]=
170
"no_materialization", "no_semijoin",
174
/* Corresponding defines are named OPTIMIZER_SWITCH_XXX */
175
static const unsigned int optimizer_switch_names_len[]=
177
/*no_materialization*/ 19,
181
TYPELIB optimizer_switch_typelib= { array_elements(optimizer_switch_names)-1,"",
182
optimizer_switch_names,
183
(unsigned int *)optimizer_switch_names_len };
185
168
static const char *tc_heuristic_recover_names[]=
187
170
"COMMIT", "ROLLBACK", NULL
941
892
#define SA_NODEFER 0
944
static void init_signals(void)
949
if (!(test_flags.test(TEST_NO_STACKTRACE) ||
950
test_flags.test(TEST_CORE_ON_SIGNAL)))
952
sa.sa_flags = SA_RESETHAND | SA_NODEFER;
953
sigemptyset(&sa.sa_mask);
954
sigprocmask(SIG_SETMASK,&sa.sa_mask,NULL);
957
sa.sa_handler=handle_segfault;
958
sigaction(SIGSEGV, &sa, NULL);
959
sigaction(SIGABRT, &sa, NULL);
961
sigaction(SIGBUS, &sa, NULL);
963
sigaction(SIGILL, &sa, NULL);
964
sigaction(SIGFPE, &sa, NULL);
967
if (test_flags.test(TEST_CORE_ON_SIGNAL))
969
/* Change limits so that we will get a core file */
971
rl.rlim_cur = rl.rlim_max = RLIM_INFINITY;
972
if (setrlimit(RLIMIT_CORE, &rl) && global_system_variables.log_warnings)
973
errmsg_printf(ERRMSG_LVL_WARN,
974
_("setrlimit could not change the size of core files "
975
"to 'infinity'; We may not be able to generate a "
976
"core file on signals"));
978
(void) sigemptyset(&set);
979
my_sigset(SIGPIPE,SIG_IGN);
980
sigaddset(&set,SIGPIPE);
981
#ifndef IGNORE_SIGHUP_SIGQUIT
982
sigaddset(&set,SIGQUIT);
983
sigaddset(&set,SIGHUP);
985
sigaddset(&set,SIGTERM);
987
/* Fix signals if blocked by parents (can happen on Mac OS X) */
988
sigemptyset(&sa.sa_mask);
990
sa.sa_handler = print_signal_warning;
991
sigaction(SIGTERM, &sa, (struct sigaction*) 0);
993
sa.sa_handler = print_signal_warning;
994
sigaction(SIGHUP, &sa, (struct sigaction*) 0);
996
sigaddset(&set,SIGTSTP);
998
if (test_flags.test(TEST_SIGINT))
1000
my_sigset(thr_kill_signal, end_thread_signal);
1002
sigdelset(&set, thr_kill_signal);
1005
sigaddset(&set,SIGINT);
1006
sigprocmask(SIG_SETMASK,&set,NULL);
1007
pthread_sigmask(SIG_SETMASK,&set,NULL);
1011
void my_message_sql(uint32_t error, const char *str, myf MyFlags);
1014
897
All global error messages are sent here where the first one is stored
1017
void my_message_sql(uint32_t error, const char *str, myf MyFlags)
900
static void my_message_sql(uint32_t error, const char *str, myf MyFlags)
1019
902
Session *session;
1172
1055
{"Com", (char*) com_status_vars, SHOW_ARRAY},
1173
1056
{"Connections", (char*) &global_thread_id, SHOW_INT_NOFLUSH},
1174
1057
{"Created_tmp_disk_tables", (char*) offsetof(STATUS_VAR, created_tmp_disk_tables), SHOW_LONG_STATUS},
1175
{"Created_tmp_files", (char*) &my_tmp_file_created,SHOW_INT},
1058
{"Created_tmp_files", (char*) &internal::my_tmp_file_created,SHOW_INT},
1176
1059
{"Created_tmp_tables", (char*) offsetof(STATUS_VAR, created_tmp_tables), SHOW_LONG_STATUS},
1177
1060
{"Flush_commands", (char*) &refresh_version, SHOW_INT_NOFLUSH},
1178
1061
{"Handler_commit", (char*) offsetof(STATUS_VAR, ha_commit_count), SHOW_LONG_STATUS},
1198
1081
{"Key_writes", (char*) offsetof(KEY_CACHE, global_cache_write), SHOW_KEY_CACHE_LONGLONG},
1199
1082
{"Last_query_cost", (char*) offsetof(STATUS_VAR, last_query_cost), SHOW_DOUBLE_STATUS},
1200
1083
{"Max_used_connections", (char*) &max_used_connections, SHOW_INT},
1201
{"Open_files", (char*) &my_file_opened, SHOW_INT_NOFLUSH},
1202
{"Open_streams", (char*) &my_stream_opened, SHOW_INT_NOFLUSH},
1084
{"Open_files", (char*) &internal::my_file_opened, SHOW_INT_NOFLUSH},
1085
{"Open_streams", (char*) &internal::my_stream_opened, SHOW_INT_NOFLUSH},
1203
1086
{"Open_table_definitions", (char*) &show_table_definitions_cont, SHOW_FUNC},
1204
1087
{"Open_tables", (char*) &show_open_tables_cont, SHOW_FUNC},
1205
{"Opened_files", (char*) &my_file_total_opened, SHOW_INT_NOFLUSH},
1088
{"Opened_files", (char*) &internal::my_file_total_opened, SHOW_INT_NOFLUSH},
1206
1089
{"Opened_tables", (char*) offsetof(STATUS_VAR, opened_tables), SHOW_LONG_STATUS},
1207
1090
{"Opened_table_definitions", (char*) offsetof(STATUS_VAR, opened_shares), SHOW_LONG_STATUS},
1208
1091
{"Questions", (char*) offsetof(STATUS_VAR, questions), SHOW_LONG_STATUS},
1511
1394
unireg_abort(1);
1514
#if defined(MCL_CURRENT)
1515
if (locked_in_memory && !getuid())
1517
if (setreuid((uid_t)-1, 0) == -1)
1518
{ // this should never happen
1519
sql_perror("setreuid");
1522
if (mlockall(MCL_CURRENT))
1524
if (global_system_variables.log_warnings)
1525
errmsg_printf(ERRMSG_LVL_WARN, _("Failed to lock memory. Errno: %d\n"),errno);
1526
locked_in_memory= 0;
1529
set_user(drizzled_user, user_info);
1535
1397
init_update_queries();
1540
int main(int argc, char **argv)
1542
#if defined(ENABLE_NLS)
1543
# if defined(HAVE_LOCALE_H)
1544
setlocale(LC_ALL, "");
1546
bindtextdomain("drizzle", LOCALEDIR);
1547
textdomain("drizzle");
1550
plugin::Registry &plugins= plugin::Registry::singleton();
1551
plugin::Client *client;
1554
MY_INIT(argv[0]); // init my_sys library & pthreads
1555
/* nothing should come before this line ^^^ */
1557
/* Set signal used to kill Drizzle */
1558
#if defined(SIGUSR2)
1559
thr_kill_signal= thd_lib_detected == THD_LIB_LT ? SIGINT : SIGUSR2;
1561
thr_kill_signal= SIGINT;
1564
if (init_common_variables(DRIZZLE_CONFIG_NAME,
1565
argc, argv, load_default_groups))
1566
unireg_abort(1); // Will do exit
1571
select_thread=pthread_self();
1572
select_thread_in_use=1;
1574
if (chdir(drizzle_real_data_home) && !opt_help)
1576
errmsg_printf(ERRMSG_LVL_ERROR, _("Data directory %s does not exist\n"), drizzle_real_data_home);
1579
drizzle_data_home= drizzle_data_home_buff;
1580
drizzle_data_home[0]=FN_CURLIB; // all paths are relative from here
1581
drizzle_data_home[1]=0;
1582
drizzle_data_home_len= 2;
1584
if ((user_info= check_user(drizzled_user)))
1586
#if defined(MCL_CURRENT)
1587
if (locked_in_memory) // getuid() == 0 here
1588
set_effective_user(user_info);
1591
set_user(drizzled_user, user_info);
1599
if (init_server_components(plugins))
1602
if (plugin::Listen::setup())
1606
init signals & alarm
1607
After this we can't quit by a simple unireg_abort
1609
error_handler_hook= my_message_sql;
1611
if (drizzle_rm_tmp_tables() ||
1612
my_tz_init((Session *)0, default_tz_name))
1615
select_thread_in_use=0;
1616
(void) pthread_kill(signal_thread, SIGTERM);
1618
(void) unlink(pidfile_name); // Not needed anymore
1625
errmsg_printf(ERRMSG_LVL_INFO, _(ER(ER_STARTUP)), my_progname,
1626
PANDORA_RELEASE_VERSION, COMPILATION_COMMENT);
1629
/* Listen for new connections and start new session for each connection
1630
accepted. The listen.getClient() method will return NULL when the server
1631
should be shutdown. */
1632
while ((client= plugin::Listen::getClient()) != NULL)
1634
if (!(session= new Session(client)))
1640
/* If we error on creation we drop the connection and delete the session. */
1641
if (session->schedule())
1642
Session::unlink(session);
1645
/* (void) pthread_attr_destroy(&connection_attrib); */
1648
(void) pthread_mutex_lock(&LOCK_thread_count);
1649
select_thread_in_use=0; // For close_connections
1650
(void) pthread_mutex_unlock(&LOCK_thread_count);
1651
(void) pthread_cond_broadcast(&COND_thread_count);
1653
/* Wait until cleanup is done */
1654
(void) pthread_mutex_lock(&LOCK_thread_count);
1655
while (!ready_to_exit)
1656
pthread_cond_wait(&COND_server_end,&LOCK_thread_count);
1657
(void) pthread_mutex_unlock(&LOCK_thread_count);
1660
plugin::Registry::shutdown();
1667
1403
/****************************************************************************
1668
1404
Handle start options
1669
1405
******************************************************************************/
1818
1554
(char**) &global_system_variables.log_warnings,
1819
1555
(char**) &max_system_variables.log_warnings, 0, GET_BOOL, OPT_ARG, 1, 0, 0,
1821
{"memlock", OPT_MEMLOCK,
1822
N_("Lock drizzled in memory."),
1823
(char**) &locked_in_memory,
1824
(char**) &locked_in_memory, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1825
1557
{"pid-file", OPT_PID_FILE,
1826
1558
N_("Pid file used by safe_mysqld."),
1827
1559
(char**) &pidfile_name_ptr, (char**) &pidfile_name_ptr, 0, GET_STR,
2068
1800
(char**) &global_system_variables.tmp_table_size,
2069
1801
(char**) &max_system_variables.tmp_table_size, 0, GET_ULL,
2070
1802
REQUIRED_ARG, 16*1024*1024L, 1024, MAX_MEM_TABLE_SIZE, 0, 1, 0},
2071
{"transaction_alloc_block_size", OPT_TRANS_ALLOC_BLOCK_SIZE,
2072
N_("Allocation block size for transactions to be stored in binary log"),
2073
(char**) &global_system_variables.trans_alloc_block_size,
2074
(char**) &max_system_variables.trans_alloc_block_size, 0, GET_UINT,
2075
REQUIRED_ARG, QUERY_ALLOC_BLOCK_SIZE, 1024, ULONG_MAX, 0, 1024, 0},
2076
{"transaction_prealloc_size", OPT_TRANS_PREALLOC_SIZE,
2077
N_("Persistent buffer for transactions to be stored in binary log"),
2078
(char**) &global_system_variables.trans_prealloc_size,
2079
(char**) &max_system_variables.trans_prealloc_size, 0, GET_UINT,
2080
REQUIRED_ARG, TRANS_ALLOC_PREALLOC_SIZE, 1024, ULONG_MAX, 0, 1024, 0},
2081
1803
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
2397
2116
static void fix_paths(string &progname)
2399
2118
char buff[FN_REFLEN],*pos,rp_buff[PATH_MAX];
2400
convert_dirname(drizzle_home,drizzle_home,NULL);
2119
internal::convert_dirname(drizzle_home,drizzle_home,NULL);
2401
2120
/* Resolve symlinks to allow 'drizzle_home' to be a relative symlink */
2402
2121
#if defined(HAVE_BROKEN_REALPATH)
2403
my_load_path(drizzle_home, drizzle_home, NULL);
2122
internal::my_load_path(drizzle_home, drizzle_home, NULL);
2405
2124
if (!realpath(drizzle_home,rp_buff))
2406
my_load_path(rp_buff, drizzle_home, NULL);
2125
internal::my_load_path(rp_buff, drizzle_home, NULL);
2407
2126
rp_buff[FN_REFLEN-1]= '\0';
2408
2127
strcpy(drizzle_home,rp_buff);
2409
2128
/* Ensure that drizzle_home ends in FN_LIBCHAR */
2414
2133
pos[0]= FN_LIBCHAR;
2417
convert_dirname(drizzle_real_data_home,drizzle_real_data_home,NULL);
2418
(void) fn_format(buff, drizzle_real_data_home, "", "",
2136
internal::convert_dirname(drizzle_real_data_home,drizzle_real_data_home,NULL);
2137
(void) internal::fn_format(buff, drizzle_real_data_home, "", "",
2419
2138
(MY_RETURN_REAL_PATH|MY_RESOLVE_SYMLINKS));
2420
(void) unpack_dirname(drizzle_unpacked_real_data_home, buff);
2421
convert_dirname(language,language,NULL);
2422
(void) my_load_path(drizzle_home, drizzle_home,""); // Resolve current dir
2423
(void) my_load_path(drizzle_real_data_home, drizzle_real_data_home,drizzle_home);
2424
(void) my_load_path(pidfile_name, pidfile_name,drizzle_real_data_home);
2139
(void) internal::unpack_dirname(drizzle_unpacked_real_data_home, buff);
2140
internal::convert_dirname(language,language,NULL);
2141
(void) internal::my_load_path(drizzle_home, drizzle_home,""); // Resolve current dir
2142
(void) internal::my_load_path(drizzle_real_data_home, drizzle_real_data_home,drizzle_home);
2143
(void) internal::my_load_path(pidfile_name, pidfile_name,drizzle_real_data_home);
2426
2145
if (opt_plugin_dir_ptr == NULL)
2465
2184
size_t last_libchar_pos= progdir.rfind(FN_LIBCHAR,progdir.size()-2)+1;
2466
2185
string source_plugindir(progdir.substr(0,last_libchar_pos));
2467
2186
source_plugindir.append("plugin/.libs");
2468
(void) my_load_path(opt_plugin_dir, source_plugindir.c_str(), "");
2187
(void) internal::my_load_path(opt_plugin_dir, source_plugindir.c_str(), "");
2473
(void) my_load_path(opt_plugin_dir, opt_plugin_dir_ptr, drizzle_home);
2192
(void) internal::my_load_path(opt_plugin_dir, opt_plugin_dir_ptr, drizzle_home);
2475
2194
opt_plugin_dir_ptr= opt_plugin_dir;
2477
2196
const char *sharedir= get_relative_path(PKGDATADIR);
2478
if (test_if_hard_path(sharedir))
2197
if (internal::test_if_hard_path(sharedir))
2479
2198
strncpy(buff,sharedir,sizeof(buff)-1);
2482
2201
strcpy(buff, drizzle_home);
2483
2202
strncat(buff, sharedir, sizeof(buff)-strlen(drizzle_home)-1);
2485
convert_dirname(buff,buff,NULL);
2486
(void) my_load_path(language,language,buff);
2204
internal::convert_dirname(buff,buff,NULL);
2205
(void) internal::my_load_path(language,language,buff);
2489
2208
char *tmp_string;
2242
} /* namespace drizzled */
2244
using namespace drizzled;
2247
static void init_signals(void)
2250
struct sigaction sa;
2252
if (!(test_flags.test(TEST_NO_STACKTRACE) ||
2253
test_flags.test(TEST_CORE_ON_SIGNAL)))
2255
sa.sa_flags = SA_RESETHAND | SA_NODEFER;
2256
sigemptyset(&sa.sa_mask);
2257
sigprocmask(SIG_SETMASK,&sa.sa_mask,NULL);
2260
sa.sa_handler=handle_segfault;
2261
sigaction(SIGSEGV, &sa, NULL);
2262
sigaction(SIGABRT, &sa, NULL);
2264
sigaction(SIGBUS, &sa, NULL);
2266
sigaction(SIGILL, &sa, NULL);
2267
sigaction(SIGFPE, &sa, NULL);
2270
if (test_flags.test(TEST_CORE_ON_SIGNAL))
2272
/* Change limits so that we will get a core file */
2274
rl.rlim_cur = rl.rlim_max = RLIM_INFINITY;
2275
if (setrlimit(RLIMIT_CORE, &rl) && global_system_variables.log_warnings)
2276
errmsg_printf(ERRMSG_LVL_WARN,
2277
_("setrlimit could not change the size of core files "
2278
"to 'infinity'; We may not be able to generate a "
2279
"core file on signals"));
2281
(void) sigemptyset(&set);
2282
my_sigset(SIGPIPE,SIG_IGN);
2283
sigaddset(&set,SIGPIPE);
2284
#ifndef IGNORE_SIGHUP_SIGQUIT
2285
sigaddset(&set,SIGQUIT);
2286
sigaddset(&set,SIGHUP);
2288
sigaddset(&set,SIGTERM);
2290
/* Fix signals if blocked by parents (can happen on Mac OS X) */
2291
sigemptyset(&sa.sa_mask);
2293
sa.sa_handler = print_signal_warning;
2294
sigaction(SIGTERM, &sa, (struct sigaction*) 0);
2296
sa.sa_handler = print_signal_warning;
2297
sigaction(SIGHUP, &sa, (struct sigaction*) 0);
2299
sigaddset(&set,SIGTSTP);
2301
if (test_flags.test(TEST_SIGINT))
2303
my_sigset(thr_kill_signal, end_thread_signal);
2305
sigdelset(&set, thr_kill_signal);
2308
sigaddset(&set,SIGINT);
2309
sigprocmask(SIG_SETMASK,&set,NULL);
2310
pthread_sigmask(SIG_SETMASK,&set,NULL);
2314
int main(int argc, char **argv)
2316
#if defined(ENABLE_NLS)
2317
# if defined(HAVE_LOCALE_H)
2318
setlocale(LC_ALL, "");
2320
bindtextdomain("drizzle", LOCALEDIR);
2321
textdomain("drizzle");
2324
plugin::Registry &plugins= plugin::Registry::singleton();
2325
plugin::Client *client;
2328
MY_INIT(argv[0]); // init my_sys library & pthreads
2329
/* nothing should come before this line ^^^ */
2331
/* Set signal used to kill Drizzle */
2332
#if defined(SIGUSR2)
2333
thr_kill_signal= internal::thd_lib_detected == THD_LIB_LT ? SIGINT : SIGUSR2;
2335
thr_kill_signal= SIGINT;
2338
if (init_common_variables(DRIZZLE_CONFIG_NAME,
2339
argc, argv, load_default_groups))
2340
unireg_abort(1); // Will do exit
2345
select_thread=pthread_self();
2346
select_thread_in_use=1;
2348
if (chdir(drizzle_real_data_home) && !opt_help)
2350
errmsg_printf(ERRMSG_LVL_ERROR, _("Data directory %s does not exist\n"), drizzle_real_data_home);
2353
drizzle_data_home= drizzle_data_home_buff;
2354
drizzle_data_home[0]=FN_CURLIB; // all paths are relative from here
2355
drizzle_data_home[1]=0;
2356
drizzle_data_home_len= 2;
2358
if ((user_info= check_user(drizzled_user)))
2360
set_user(drizzled_user, user_info);
2368
if (init_server_components(plugins))
2371
if (plugin::Listen::setup())
2375
init signals & alarm
2376
After this we can't quit by a simple unireg_abort
2378
error_handler_hook= my_message_sql;
2380
if (drizzle_rm_tmp_tables() ||
2381
my_tz_init((Session *)0, default_tz_name))
2384
select_thread_in_use=0;
2385
(void) pthread_kill(signal_thread, SIGTERM);
2387
(void) unlink(pidfile_name); // Not needed anymore
2394
errmsg_printf(ERRMSG_LVL_INFO, _(ER(ER_STARTUP)), internal::my_progname,
2395
PANDORA_RELEASE_VERSION, COMPILATION_COMMENT);
2398
/* Listen for new connections and start new session for each connection
2399
accepted. The listen.getClient() method will return NULL when the server
2400
should be shutdown. */
2401
while ((client= plugin::Listen::getClient()) != NULL)
2403
if (!(session= new Session(client)))
2409
/* If we error on creation we drop the connection and delete the session. */
2410
if (session->schedule())
2411
Session::unlink(session);
2414
/* (void) pthread_attr_destroy(&connection_attrib); */
2417
(void) pthread_mutex_lock(&LOCK_thread_count);
2418
select_thread_in_use=0; // For close_connections
2419
(void) pthread_mutex_unlock(&LOCK_thread_count);
2420
(void) pthread_cond_broadcast(&COND_thread_count);
2422
/* Wait until cleanup is done */
2423
(void) pthread_mutex_lock(&LOCK_thread_count);
2424
while (!ready_to_exit)
2425
pthread_cond_wait(&COND_server_end,&LOCK_thread_count);
2426
(void) pthread_mutex_unlock(&LOCK_thread_count);
2429
plugin::Registry::shutdown();