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/debug.h"
74
#include "drizzled/definition/cache.h"
76
#include "drizzled/plugin/event_observer.h"
78
#include "drizzled/message/cache.h"
80
#include "drizzled/visibility.h"
82
82
#include <google/protobuf/stubs/common.h>
84
#include <drizzled/refresh_version.h>
86
84
#if TIME_WITH_SYS_TIME
87
85
# include <sys/time.h>
367
375
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"));
377
po::options_description config_options("Config File Options");
378
po::options_description long_options("Kernel Options");
379
po::options_description plugin_load_options("Plugin Loading Options");
380
po::options_description plugin_options("Plugin Options");
381
po::options_description initial_options("Config and Plugin Loading");
382
po::options_description full_options("Kernel and Plugin Loading and Plugin");
375
383
vector<string> unknown_options;
376
384
vector<string> defaults_file_list;
377
385
po::variables_map vm;
387
fs::path data_home(LOCALSTATEDIR);
388
fs::path full_data_home(LOCALSTATEDIR);
379
390
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();
395
fs::path& getFullDataHome()
397
return full_data_home;
400
fs::path& getDataHome()
405
fs::path& getDataHomeCatalog()
407
static fs::path data_home_catalog(getDataHome());
408
return data_home_catalog;
404
412
/****************************************************************************
405
413
** Code to end drizzled
406
414
****************************************************************************/
540
547
tmp_user_info= getpwnam(user);
541
548
if ((!tmp_user_info || user_id != tmp_user_info->pw_uid) &&
542
549
global_system_variables.log_warnings)
543
errmsg_printf(error::WARN, _("One can only use the --user switch "
550
errmsg_printf(ERRMSG_LVL_WARN, _("One can only use the --user switch "
544
551
"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"));
557
errmsg_printf(ERRMSG_LVL_ERROR, _("Fatal error: Please read \"Security\" section of "
558
"the manual to find out how to run drizzled as root!\n"));
555
if (not strcmp(user, "root"))
561
if (!strcmp(user,"root"))
556
562
return NULL; // Avoid problem with dynamic libraries
558
564
if (!(tmp_user_info= getpwnam(user)))
666
672
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"))
674
if (progname[0] != FN_LIBCHAR)
676
/* We have a relative path and need to find the absolute */
677
char working_dir[FN_REFLEN];
678
char *working_dir_ptr= working_dir;
679
working_dir_ptr= getcwd(working_dir_ptr, FN_REFLEN);
680
string new_path(working_dir);
681
if (*(new_path.end()-1) != '/')
682
new_path.push_back('/');
683
if (progname[0] == '.' && progname[1] == '/')
684
new_path.append(progname.substr(2));
686
new_path.append(progname);
687
progname.swap(new_path);
690
/* Now, trim off the exe name */
691
string progdir(progname.substr(0, progname.rfind(FN_LIBCHAR)+1));
692
if (progdir.rfind(".libs/") != string::npos)
694
progdir.assign(progdir.substr(0, progdir.rfind(".libs/")));
696
string testlofile(progdir);
697
testlofile.append("drizzled.lo");
698
string testofile(progdir);
699
testofile.append("drizzled.o");
700
struct stat testfile_stat;
701
if (not (stat(testlofile.c_str(), &testfile_stat) && stat(testofile.c_str(), &testfile_stat)))
678
703
/* We are in a source dir! Plugin dir is ../plugin/.libs */
679
base_plugin_dir= progdir.parent_path();
704
size_t last_libchar_pos= progdir.rfind(FN_LIBCHAR,progdir.size()-2)+1;
705
base_plugin_dir= progdir.substr(0,last_libchar_pos);
680
706
base_plugin_dir /= "plugin";
681
707
base_plugin_dir /= ".libs";
1101
1133
global_system_variables.time_zone= my_tz_SYSTEM;
1103
char ret_hostname[FN_REFLEN];
1104
if (gethostname(ret_hostname,sizeof(ret_hostname)) < 0)
1135
if (gethostname(glob_hostname,sizeof(glob_hostname)) < 0)
1106
errmsg_printf(error::WARN,
1107
_("gethostname failed, using '%s' as hostname"),
1108
getServerHostname().c_str());
1137
strncpy(glob_hostname, STRING_WITH_LEN("localhost"));
1138
errmsg_printf(ERRMSG_LVL_WARN, _("gethostname failed, using '%s' as hostname"),
1109
1140
pid_file= "drizzle";
1113
setServerHostname(ret_hostname);
1114
pid_file= getServerHostname();
1144
pid_file= glob_hostname;
1116
1146
pid_file.replace_extension(".pid");
1120
1150
config_options.add_options()
1121
1151
("help,?", po::value<bool>(&opt_help)->default_value(false)->zero_tokens(),
1122
1152
_("Display this help and exit."))
1123
("daemon,d", po::value<bool>(&opt_daemon)->default_value(false)->zero_tokens(),
1124
_("Run as a daemon."))
1125
1153
("no-defaults", po::value<bool>()->default_value(false)->zero_tokens(),
1126
1154
_("Configuration file defaults are not used if no-defaults is set"))
1127
1155
("defaults-file", po::value<vector<string> >()->composing()->notifier(&compose_defaults_file_list),
1162
1190
("completion-type", po::value<uint32_t>(&global_system_variables.completion_type)->default_value(0)->notifier(&check_limits_completion_type),
1163
1191
_("Default completion type."))
1164
1192
("core-file", _("Write core on errors."))
1165
("datadir", po::value<fs::path>(&getDataHome()),
1193
("datadir", po::value<fs::path>(&data_home),
1166
1194
_("Path to the database root."))
1167
1195
("default-storage-engine", po::value<string>(),
1168
1196
_("Set the default storage engine for tables."))
1199
1227
_("Path for temporary files."))
1200
1228
("transaction-isolation", po::value<string>(),
1201
1229
_("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),
1230
("transaction-message-threshold", po::value<size_t>(&global_system_variables.transaction_message_threshold)->default_value(1024*1024)->notifier(&check_limits_transaction_message_threshold),
1203
1231
_("Max message size written to transaction log, valid values 131072 - 1048576 bytes."))
1204
1232
("user,u", po::value<string>(),
1205
1233
_("Run drizzled daemon as user."))
1393
1419
catch (po::validation_error &err)
1395
errmsg_printf(error::ERROR,
1421
errmsg_printf(ERRMSG_LVL_ERROR,
1397
1423
"Use --help to get a list of available options\n"),
1398
1424
internal::my_progname, err.what());
1399
1425
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
1428
/* At this point, we've read all the options we need to read from files and
1412
1429
collected most of them into unknown options - now let's load everything
1415
1432
if (plugin_init(plugins, plugin_options))
1417
errmsg_printf(error::ERROR, _("Failed to initialize plugins\n"));
1434
errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to initialize plugins\n"));
1418
1435
unireg_abort(1);
1512
1530
const CHARSET_INFO * const default_collation= get_charset_by_name(default_collation_name);
1513
1531
if (not default_collation)
1515
errmsg_printf(error::ERROR, _(ER(ER_UNKNOWN_COLLATION)), default_collation_name);
1533
errmsg_printf(ERRMSG_LVL_ERROR, _(ER(ER_UNKNOWN_COLLATION)), default_collation_name);
1518
1536
if (not my_charset_same(default_charset_info, default_collation))
1520
errmsg_printf(error::ERROR, _(ER(ER_COLLATION_CHARSET_MISMATCH)),
1538
errmsg_printf(ERRMSG_LVL_ERROR, _(ER(ER_COLLATION_CHARSET_MISMATCH)),
1521
1539
default_collation_name,
1522
1540
default_charset_info->csname);
1721
1739
{"help", '?', N_("Display this help and exit."),
1722
1740
(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
1742
{"auto-increment-increment", OPT_AUTO_INCREMENT,
1728
1743
N_("Auto-increment columns are incremented by this"),
1729
1744
(char**) &global_system_variables.auto_increment_increment,
2320
2336
if (errno != EEXIST)
2322
errmsg_printf(error::ERROR, _("There was an error creating the '%s' part of the path '%s'. Please check the path exists and is writable.\n"), fs::path(drizzle_tmpdir).leaf().c_str(), drizzle_tmpdir.c_str());
2338
errmsg_printf(ERRMSG_LVL_ERROR, _("There was an error creating the '%s' part of the path '%s'. Please check the path exists and is writable.\n"), fs::path(drizzle_tmpdir).leaf().c_str(), drizzle_tmpdir.c_str());
2327
2343
if (stat(drizzle_tmpdir.c_str(), &buf) || (S_ISDIR(buf.st_mode) == false))
2329
errmsg_printf(error::ERROR, _("There was an error opening the path '%s', please check the path exists and is writable.\n"), drizzle_tmpdir.c_str());
2345
errmsg_printf(ERRMSG_LVL_ERROR, _("There was an error opening the path '%s', please check the path exists and is writable.\n"), drizzle_tmpdir.c_str());