40
39
#include <boost/filesystem.hpp>
41
40
#include <boost/detail/atomic_count.hpp>
43
#include <drizzled/cached_directory.h>
44
#include <drizzled/charset.h>
45
#include <drizzled/data_home.h>
46
#include <drizzled/debug.h>
47
#include <drizzled/definition/cache.h>
48
#include <drizzled/drizzled.h>
42
#include "drizzled/internal/my_sys.h"
43
#include "drizzled/internal/my_bit.h"
44
#include <drizzled/my_hash.h>
45
#include <drizzled/error.h>
49
46
#include <drizzled/errmsg_print.h>
50
#include <drizzled/error.h>
51
#include <drizzled/global_buffer.h>
52
#include <drizzled/internal/my_bit.h>
53
#include <drizzled/internal/my_sys.h>
47
#include <drizzled/tztime.h>
48
#include <drizzled/sql_base.h>
49
#include <drizzled/show.h>
50
#include <drizzled/sql_parse.h>
54
51
#include <drizzled/item/cmpfunc.h>
52
#include <drizzled/session.h>
55
53
#include <drizzled/item/create.h>
56
#include <drizzled/message/cache.h>
57
#include <drizzled/module/load_list.h>
58
#include <drizzled/module/registry.h>
59
#include <drizzled/my_hash.h>
60
#include <drizzled/plugin/client.h>
61
#include <drizzled/plugin/error_message.h>
62
#include <drizzled/plugin/event_observer.h>
63
#include <drizzled/plugin/listen.h>
64
#include <drizzled/plugin/monitored_in_transaction.h>
65
#include <drizzled/plugin/scheduler.h>
66
#include <drizzled/plugin/storage_engine.h>
67
#include <drizzled/plugin/xa_resource_manager.h>
68
#include <drizzled/probes.h>
69
#include <drizzled/replication_services.h> /* For ReplicationServices::evaluateRegisteredPlugins() */
70
#include <drizzled/session.h>
71
#include <drizzled/session/cache.h>
72
#include <drizzled/show.h>
73
#include <drizzled/sql_base.h>
74
#include <drizzled/sql_parse.h>
75
#include <drizzled/temporal_format.h> /* For init_temporal_formats() */
76
#include <drizzled/tztime.h>
77
54
#include <drizzled/unireg.h>
78
#include <plugin/myisam/myisam.h>
79
#include <drizzled/typelib.h>
80
#include <drizzled/visibility.h>
55
#include "drizzled/temporal_format.h" /* For init_temporal_formats() */
56
#include "drizzled/plugin/listen.h"
57
#include "drizzled/plugin/error_message.h"
58
#include "drizzled/plugin/client.h"
59
#include "drizzled/plugin/scheduler.h"
60
#include "drizzled/plugin/xa_resource_manager.h"
61
#include "drizzled/plugin/monitored_in_transaction.h"
62
#include "drizzled/replication_services.h" /* For ReplicationServices::evaluateRegisteredPlugins() */
63
#include "drizzled/probes.h"
64
#include "drizzled/session/cache.h"
65
#include "drizzled/charset.h"
66
#include "plugin/myisam/myisam.h"
67
#include "drizzled/drizzled.h"
68
#include "drizzled/module/registry.h"
69
#include "drizzled/module/load_list.h"
70
#include "drizzled/global_buffer.h"
72
#include "drizzled/definition/cache.h"
74
#include "drizzled/plugin/event_observer.h"
76
#include "drizzled/message/cache.h"
82
78
#include <google/protobuf/stubs/common.h>
84
#include <drizzled/refresh_version.h>
86
80
#if TIME_WITH_SYS_TIME
87
81
# include <sys/time.h>
252
246
bool calling_initgroups= false; /**< Used in SIGSEGV handler. */
254
248
uint32_t drizzled_bind_timeout;
249
std::bitset<12> test_flags;
255
250
uint32_t dropping_tables, ha_open_options;
256
251
uint32_t tc_heuristic_recover= 0;
257
252
uint64_t session_startup_options;
258
253
back_log_constraints back_log(50);
259
DRIZZLED_API uint32_t server_id;
260
255
uint64_t table_cache_size;
261
256
size_t table_def_size;
257
uint64_t max_connect_errors;
262
258
uint32_t global_thread_id= 1UL;
263
259
pid_t current_pid;
321
321
const char *in_additional_cond= "<IN COND>";
322
322
const char *in_having_cond= "<IN HAVING>";
324
type::Decimal decimal_zero;
324
325
/* classes for comparation parsing/processing */
326
327
FILE *stderror_file=0;
328
drizzle_system_variables global_system_variables;
329
drizzle_system_variables max_system_variables;
330
global_counters current_global_counters;
329
struct drizzle_system_variables global_system_variables;
330
struct drizzle_system_variables max_system_variables;
331
struct global_counters current_global_counters;
332
DRIZZLED_API const CHARSET_INFO *system_charset_info;
333
const CHARSET_INFO *files_charset_info;
333
const CHARSET_INFO *system_charset_info, *files_charset_info ;
334
334
const CHARSET_INFO *table_alias_charset;
335
335
const CHARSET_INFO *character_set_filesystem;
367
377
fs::path base_plugin_dir(PKGPLUGINDIR);
369
po::options_description config_options(_("Config File Options"));
370
po::options_description long_options(_("Kernel Options"));
371
po::options_description plugin_load_options(_("Plugin Loading Options"));
372
po::options_description plugin_options(_("Plugin Options"));
373
po::options_description initial_options(_("Config and Plugin Loading"));
374
po::options_description full_options(_("Kernel and Plugin Loading and Plugin"));
379
po::options_description config_options("Config File Options");
380
po::options_description long_options("Kernel Options");
381
po::options_description plugin_load_options("Plugin Loading Options");
382
po::options_description plugin_options("Plugin Options");
383
po::options_description initial_options("Config and Plugin Loading");
384
po::options_description full_options("Kernel and Plugin Loading and Plugin");
375
385
vector<string> unknown_options;
376
386
vector<string> defaults_file_list;
377
387
po::variables_map vm;
389
fs::path data_home(LOCALSTATEDIR);
390
fs::path full_data_home(LOCALSTATEDIR);
379
392
po::variables_map &getVariablesMap()
387
std::string &getGlobHostname()
389
static std::string glob_hostname("localhost");
390
return glob_hostname;
393
void setServerHostname(const std::string &hostname)
395
getGlobHostname()= hostname;
399
const std::string &getServerHostname()
401
return getGlobHostname();
397
fs::path& getFullDataHome()
399
return full_data_home;
402
fs::path& getDataHome()
407
fs::path& getDataHomeCatalog()
409
static fs::path data_home_catalog(getDataHome());
410
return data_home_catalog;
404
414
/****************************************************************************
405
415
** Code to end drizzled
406
416
****************************************************************************/
513
518
(void) unlink(pid_file.file_string().c_str()); // This may not always exist
515
520
if (print_message && server_start_time)
516
errmsg_printf(drizzled::error::INFO, _(ER(ER_SHUTDOWN_COMPLETE)),internal::my_progname);
521
errmsg_printf(ERRMSG_LVL_INFO, _(ER(ER_SHUTDOWN_COMPLETE)),internal::my_progname);
523
boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
518
session::Cache::singleton().shutdownFirst();
526
/* do the broadcast inside the lock to ensure that my_end() is not called */
527
COND_server_end.notify_all();
521
531
The following lines may never be executed as the main thread may have
540
550
tmp_user_info= getpwnam(user);
541
551
if ((!tmp_user_info || user_id != tmp_user_info->pw_uid) &&
542
552
global_system_variables.log_warnings)
543
errmsg_printf(error::WARN, _("One can only use the --user switch "
553
errmsg_printf(ERRMSG_LVL_WARN, _("One can only use the --user switch "
544
554
"if running as root\n"));
550
errmsg_printf(error::ERROR, _("Fatal error: Please read \"Security\" section of "
551
"the manual to find out how to run drizzled as root"));
560
errmsg_printf(ERRMSG_LVL_ERROR, _("Fatal error: Please read \"Security\" section of "
561
"the manual to find out how to run drizzled as root!\n"));
555
if (not strcmp(user, "root"))
564
if (!strcmp(user,"root"))
556
565
return NULL; // Avoid problem with dynamic libraries
558
567
if (!(tmp_user_info= getpwnam(user)))
666
675
static void find_plugin_dir(string progname)
668
fs::path full_progname(fs::system_complete(progname));
670
fs::path progdir(full_progname.parent_path());
671
if (progdir.filename() == ".libs")
673
progdir= progdir.parent_path();
676
if (fs::exists(progdir / "drizzled.lo") || fs::exists(progdir / "drizzled.o"))
677
if (progname[0] != FN_LIBCHAR)
679
/* We have a relative path and need to find the absolute */
680
char working_dir[FN_REFLEN];
681
char *working_dir_ptr= working_dir;
682
working_dir_ptr= getcwd(working_dir_ptr, FN_REFLEN);
683
string new_path(working_dir);
684
if (*(new_path.end()-1) != '/')
685
new_path.push_back('/');
686
if (progname[0] == '.' && progname[1] == '/')
687
new_path.append(progname.substr(2));
689
new_path.append(progname);
690
progname.swap(new_path);
693
/* Now, trim off the exe name */
694
string progdir(progname.substr(0, progname.rfind(FN_LIBCHAR)+1));
695
if (progdir.rfind(".libs/") != string::npos)
697
progdir.assign(progdir.substr(0, progdir.rfind(".libs/")));
699
string testlofile(progdir);
700
testlofile.append("drizzled.lo");
701
string testofile(progdir);
702
testofile.append("drizzled.o");
703
struct stat testfile_stat;
704
if (not (stat(testlofile.c_str(), &testfile_stat) && stat(testofile.c_str(), &testfile_stat)))
678
706
/* We are in a source dir! Plugin dir is ../plugin/.libs */
679
base_plugin_dir= progdir.parent_path();
707
size_t last_libchar_pos= progdir.rfind(FN_LIBCHAR,progdir.size()-2)+1;
708
base_plugin_dir= progdir.substr(0,last_libchar_pos);
680
709
base_plugin_dir /= "plugin";
681
710
base_plugin_dir /= ".libs";
1101
1147
global_system_variables.time_zone= my_tz_SYSTEM;
1103
char ret_hostname[FN_REFLEN];
1104
if (gethostname(ret_hostname,sizeof(ret_hostname)) < 0)
1149
if (gethostname(glob_hostname,sizeof(glob_hostname)) < 0)
1106
errmsg_printf(error::WARN,
1107
_("gethostname failed, using '%s' as hostname"),
1108
getServerHostname().c_str());
1151
strncpy(glob_hostname, STRING_WITH_LEN("localhost"));
1152
errmsg_printf(ERRMSG_LVL_WARN, _("gethostname failed, using '%s' as hostname"),
1109
1154
pid_file= "drizzle";
1113
setServerHostname(ret_hostname);
1114
pid_file= getServerHostname();
1158
pid_file= glob_hostname;
1116
1160
pid_file.replace_extension(".pid");
1120
1164
config_options.add_options()
1121
1165
("help,?", po::value<bool>(&opt_help)->default_value(false)->zero_tokens(),
1122
1166
_("Display this help and exit."))
1123
("daemon,d", po::value<bool>(&opt_daemon)->default_value(false)->zero_tokens(),
1124
_("Run as a daemon."))
1125
1167
("no-defaults", po::value<bool>()->default_value(false)->zero_tokens(),
1126
1168
_("Configuration file defaults are not used if no-defaults is set"))
1127
1169
("defaults-file", po::value<vector<string> >()->composing()->notifier(&compose_defaults_file_list),
1162
1204
("completion-type", po::value<uint32_t>(&global_system_variables.completion_type)->default_value(0)->notifier(&check_limits_completion_type),
1163
1205
_("Default completion type."))
1164
1206
("core-file", _("Write core on errors."))
1165
("datadir", po::value<fs::path>(&getDataHome()),
1207
("datadir", po::value<fs::path>(&data_home),
1166
1208
_("Path to the database root."))
1167
1209
("default-storage-engine", po::value<string>(),
1168
1210
_("Set the default storage engine for tables."))
1199
1241
_("Path for temporary files."))
1200
1242
("transaction-isolation", po::value<string>(),
1201
1243
_("Default transaction isolation level."))
1202
("transaction-message-threshold", po::value<size_t>(&transaction_message_threshold)->default_value(1024*1024)->notifier(&check_limits_transaction_message_threshold),
1244
("transaction-message-threshold", po::value<size_t>(&global_system_variables.transaction_message_threshold)->default_value(1024*1024)->notifier(&check_limits_transaction_message_threshold),
1203
1245
_("Max message size written to transaction log, valid values 131072 - 1048576 bytes."))
1204
1246
("user,u", po::value<string>(),
1205
1247
_("Run drizzled daemon as user."))
1225
1267
_("A global cap on the amount of memory that can be allocated by session join buffers (0 means unlimited)"))
1226
1268
("max-allowed-packet", po::value<uint32_t>(&global_system_variables.max_allowed_packet)->default_value(64*1024*1024L)->notifier(&check_limits_map),
1227
1269
_("Max packetlength to send/receive from to server."))
1270
("max-connect-errors", po::value<uint64_t>(&max_connect_errors)->default_value(MAX_CONNECT_ERRORS)->notifier(&check_limits_mce),
1271
_("If there is more than this number of interrupted connections from a "
1272
"host this host will be blocked from further connections."))
1228
1273
("max-error-count", po::value<uint64_t>(&global_system_variables.max_error_count)->default_value(DEFAULT_ERROR_COUNT)->notifier(&check_limits_max_err_cnt),
1229
1274
_("Max number of errors/warnings to store for a statement."))
1230
1275
("max-heap-table-size", po::value<uint64_t>(&global_system_variables.max_heap_table_size)->default_value(16*1024*1024L)->notifier(&check_limits_mhts),
1393
1436
catch (po::validation_error &err)
1395
errmsg_printf(error::ERROR,
1438
errmsg_printf(ERRMSG_LVL_ERROR,
1397
1440
"Use --help to get a list of available options\n"),
1398
1441
internal::my_progname, err.what());
1399
1442
unireg_abort(1);
1405
int init_remaining_variables(module::Registry &plugins)
1407
int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
1409
current_pid= getpid(); /* Save for later ref */
1411
1445
/* At this point, we've read all the options we need to read from files and
1412
1446
collected most of them into unknown options - now let's load everything
1415
1449
if (plugin_init(plugins, plugin_options))
1417
errmsg_printf(error::ERROR, _("Failed to initialize plugins\n"));
1451
errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to initialize plugins\n"));
1418
1452
unireg_abort(1);
1512
1547
const CHARSET_INFO * const default_collation= get_charset_by_name(default_collation_name);
1513
1548
if (not default_collation)
1515
errmsg_printf(error::ERROR, _(ER(ER_UNKNOWN_COLLATION)), default_collation_name);
1550
errmsg_printf(ERRMSG_LVL_ERROR, _(ER(ER_UNKNOWN_COLLATION)), default_collation_name);
1518
1553
if (not my_charset_same(default_charset_info, default_collation))
1520
errmsg_printf(error::ERROR, _(ER(ER_COLLATION_CHARSET_MISMATCH)),
1555
errmsg_printf(ERRMSG_LVL_ERROR, _(ER(ER_COLLATION_CHARSET_MISMATCH)),
1521
1556
default_collation_name,
1522
1557
default_charset_info->csname);
1721
1757
{"help", '?', N_("Display this help and exit."),
1722
1758
(char**) &opt_help, (char**) &opt_help, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
1724
{"daemon", 'd', N_("Run as daemon."),
1725
(char**) &opt_daemon, (char**) &opt_daemon, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
1727
1760
{"auto-increment-increment", OPT_AUTO_INCREMENT,
1728
1761
N_("Auto-increment columns are incremented by this"),
1729
1762
(char**) &global_system_variables.auto_increment_increment,
1849
1882
(char**) &global_system_variables.max_allowed_packet,
1850
1883
(char**) &max_system_variables.max_allowed_packet, 0, GET_UINT32,
1851
1884
REQUIRED_ARG, 64*1024*1024L, 1024, 1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
1885
{"max_connect_errors", OPT_MAX_CONNECT_ERRORS,
1886
N_("If there is more than this number of interrupted connections from a "
1887
"host this host will be blocked from further connections."),
1888
(char**) &max_connect_errors, (char**) &max_connect_errors, 0, GET_UINT64,
1889
REQUIRED_ARG, MAX_CONNECT_ERRORS, 1, ULONG_MAX, 0, 1, 0},
1852
1890
{"max_heap_table_size", OPT_MAX_HEP_TABLE_SIZE,
1853
1891
N_("Don't allow creation of heap tables bigger than this."),
1854
1892
(char**) &global_system_variables.max_heap_table_size,