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>
321
320
const char *in_additional_cond= "<IN COND>";
322
321
const char *in_having_cond= "<IN HAVING>";
323
type::Decimal decimal_zero;
324
324
/* classes for comparation parsing/processing */
326
326
FILE *stderror_file=0;
328
drizzle_system_variables global_system_variables;
329
drizzle_system_variables max_system_variables;
330
global_counters current_global_counters;
328
struct drizzle_system_variables global_system_variables;
329
struct drizzle_system_variables max_system_variables;
330
struct global_counters current_global_counters;
332
DRIZZLED_API const CHARSET_INFO *system_charset_info;
333
const CHARSET_INFO *files_charset_info;
332
const CHARSET_INFO *system_charset_info, *files_charset_info ;
334
333
const CHARSET_INFO *table_alias_charset;
335
334
const CHARSET_INFO *character_set_filesystem;
367
376
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"));
378
po::options_description config_options("Config File Options");
379
po::options_description long_options("Kernel Options");
380
po::options_description plugin_load_options("Plugin Loading Options");
381
po::options_description plugin_options("Plugin Options");
382
po::options_description initial_options("Config and Plugin Loading");
383
po::options_description full_options("Kernel and Plugin Loading and Plugin");
375
384
vector<string> unknown_options;
376
385
vector<string> defaults_file_list;
377
386
po::variables_map vm;
388
fs::path data_home(LOCALSTATEDIR);
389
fs::path full_data_home(LOCALSTATEDIR);
379
391
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();
396
fs::path& getFullDataHome()
398
return full_data_home;
401
fs::path& getDataHome()
406
fs::path& getDataHomeCatalog()
408
static fs::path data_home_catalog(getDataHome());
409
return data_home_catalog;
404
413
/****************************************************************************
405
414
** Code to end drizzled
406
415
****************************************************************************/
513
517
(void) unlink(pid_file.file_string().c_str()); // This may not always exist
515
519
if (print_message && server_start_time)
516
errmsg_printf(drizzled::error::INFO, _(ER(ER_SHUTDOWN_COMPLETE)),internal::my_progname);
520
errmsg_printf(ERRMSG_LVL_INFO, _(ER(ER_SHUTDOWN_COMPLETE)),internal::my_progname);
522
boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
518
session::Cache::singleton().shutdownFirst();
525
/* do the broadcast inside the lock to ensure that my_end() is not called */
526
COND_server_end.notify_all();
521
530
The following lines may never be executed as the main thread may have
540
549
tmp_user_info= getpwnam(user);
541
550
if ((!tmp_user_info || user_id != tmp_user_info->pw_uid) &&
542
551
global_system_variables.log_warnings)
543
errmsg_printf(error::WARN, _("One can only use the --user switch "
552
errmsg_printf(ERRMSG_LVL_WARN, _("One can only use the --user switch "
544
553
"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"));
559
errmsg_printf(ERRMSG_LVL_ERROR, _("Fatal error: Please read \"Security\" section of "
560
"the manual to find out how to run drizzled as root!\n"));
555
if (not strcmp(user, "root"))
563
if (!strcmp(user,"root"))
556
564
return NULL; // Avoid problem with dynamic libraries
558
566
if (!(tmp_user_info= getpwnam(user)))
666
674
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"))
676
if (progname[0] != FN_LIBCHAR)
678
/* We have a relative path and need to find the absolute */
679
char working_dir[FN_REFLEN];
680
char *working_dir_ptr= working_dir;
681
working_dir_ptr= getcwd(working_dir_ptr, FN_REFLEN);
682
string new_path(working_dir);
683
if (*(new_path.end()-1) != '/')
684
new_path.push_back('/');
685
if (progname[0] == '.' && progname[1] == '/')
686
new_path.append(progname.substr(2));
688
new_path.append(progname);
689
progname.swap(new_path);
692
/* Now, trim off the exe name */
693
string progdir(progname.substr(0, progname.rfind(FN_LIBCHAR)+1));
694
if (progdir.rfind(".libs/") != string::npos)
696
progdir.assign(progdir.substr(0, progdir.rfind(".libs/")));
698
string testlofile(progdir);
699
testlofile.append("drizzled.lo");
700
string testofile(progdir);
701
testofile.append("drizzled.o");
702
struct stat testfile_stat;
703
if (not (stat(testlofile.c_str(), &testfile_stat) && stat(testofile.c_str(), &testfile_stat)))
678
705
/* We are in a source dir! Plugin dir is ../plugin/.libs */
679
base_plugin_dir= progdir.parent_path();
706
size_t last_libchar_pos= progdir.rfind(FN_LIBCHAR,progdir.size()-2)+1;
707
base_plugin_dir= progdir.substr(0,last_libchar_pos);
680
708
base_plugin_dir /= "plugin";
681
709
base_plugin_dir /= ".libs";
1101
1135
global_system_variables.time_zone= my_tz_SYSTEM;
1103
char ret_hostname[FN_REFLEN];
1104
if (gethostname(ret_hostname,sizeof(ret_hostname)) < 0)
1137
if (gethostname(glob_hostname,sizeof(glob_hostname)) < 0)
1106
errmsg_printf(error::WARN,
1107
_("gethostname failed, using '%s' as hostname"),
1108
getServerHostname().c_str());
1139
strncpy(glob_hostname, STRING_WITH_LEN("localhost"));
1140
errmsg_printf(ERRMSG_LVL_WARN, _("gethostname failed, using '%s' as hostname"),
1109
1142
pid_file= "drizzle";
1113
setServerHostname(ret_hostname);
1114
pid_file= getServerHostname();
1146
pid_file= glob_hostname;
1116
1148
pid_file.replace_extension(".pid");
1120
1152
config_options.add_options()
1121
1153
("help,?", po::value<bool>(&opt_help)->default_value(false)->zero_tokens(),
1122
1154
_("Display this help and exit."))
1123
("daemon,d", po::value<bool>(&opt_daemon)->default_value(false)->zero_tokens(),
1124
_("Run as a daemon."))
1125
1155
("no-defaults", po::value<bool>()->default_value(false)->zero_tokens(),
1126
1156
_("Configuration file defaults are not used if no-defaults is set"))
1127
1157
("defaults-file", po::value<vector<string> >()->composing()->notifier(&compose_defaults_file_list),
1162
1192
("completion-type", po::value<uint32_t>(&global_system_variables.completion_type)->default_value(0)->notifier(&check_limits_completion_type),
1163
1193
_("Default completion type."))
1164
1194
("core-file", _("Write core on errors."))
1165
("datadir", po::value<fs::path>(&getDataHome()),
1195
("datadir", po::value<fs::path>(&data_home),
1166
1196
_("Path to the database root."))
1167
1197
("default-storage-engine", po::value<string>(),
1168
1198
_("Set the default storage engine for tables."))
1199
1229
_("Path for temporary files."))
1200
1230
("transaction-isolation", po::value<string>(),
1201
1231
_("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),
1232
("transaction-message-threshold", po::value<size_t>(&global_system_variables.transaction_message_threshold)->default_value(1024*1024)->notifier(&check_limits_transaction_message_threshold),
1203
1233
_("Max message size written to transaction log, valid values 131072 - 1048576 bytes."))
1204
1234
("user,u", po::value<string>(),
1205
1235
_("Run drizzled daemon as user."))
1393
1421
catch (po::validation_error &err)
1395
errmsg_printf(error::ERROR,
1423
errmsg_printf(ERRMSG_LVL_ERROR,
1397
1425
"Use --help to get a list of available options\n"),
1398
1426
internal::my_progname, err.what());
1399
1427
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
1430
/* At this point, we've read all the options we need to read from files and
1412
1431
collected most of them into unknown options - now let's load everything
1415
1434
if (plugin_init(plugins, plugin_options))
1417
errmsg_printf(error::ERROR, _("Failed to initialize plugins\n"));
1436
errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to initialize plugins\n"));
1418
1437
unireg_abort(1);
1512
1532
const CHARSET_INFO * const default_collation= get_charset_by_name(default_collation_name);
1513
1533
if (not default_collation)
1515
errmsg_printf(error::ERROR, _(ER(ER_UNKNOWN_COLLATION)), default_collation_name);
1535
errmsg_printf(ERRMSG_LVL_ERROR, _(ER(ER_UNKNOWN_COLLATION)), default_collation_name);
1518
1538
if (not my_charset_same(default_charset_info, default_collation))
1520
errmsg_printf(error::ERROR, _(ER(ER_COLLATION_CHARSET_MISMATCH)),
1540
errmsg_printf(ERRMSG_LVL_ERROR, _(ER(ER_COLLATION_CHARSET_MISMATCH)),
1521
1541
default_collation_name,
1522
1542
default_charset_info->csname);
1721
1741
{"help", '?', N_("Display this help and exit."),
1722
1742
(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
1744
{"auto-increment-increment", OPT_AUTO_INCREMENT,
1728
1745
N_("Auto-increment columns are incremented by this"),
1729
1746
(char**) &global_system_variables.auto_increment_increment,