370
355
static void drizzle_init_variables(void);
371
356
static void get_options();
372
static void fix_paths();
357
static const char *get_relative_path(const char *path);
358
static void fix_paths(string progname);
374
360
static void usage(void);
375
361
void close_connections(void);
377
fs::path base_plugin_dir(PKGPLUGINDIR);
379
po::options_description config_options("Config File Options");
380
363
po::options_description long_options("Kernel Options");
381
po::options_description plugin_load_options("Plugin Loading Options");
382
364
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");
385
365
vector<string> unknown_options;
386
366
vector<string> defaults_file_list;
387
367
po::variables_map vm;
389
fs::path data_home(LOCALSTATEDIR);
390
fs::path full_data_home(LOCALSTATEDIR);
392
369
po::variables_map &getVariablesMap()
397
fs::path& getDataHome()
402
fs::path& getDataHomeCatalog()
404
static fs::path data_home_catalog(getDataHome());
405
return data_home_catalog;
409
374
/****************************************************************************
410
375
** Code to end drizzled
441
406
statements and inform their clients that the server is about to die.
411
LOCK_thread_count.lock(); // For unlink from list
413
for( SessionList::iterator it= getSessionList().begin(); it != getSessionList().end(); ++it )
445
boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
446
session::Cache::list list= session::Cache::singleton().getCache();
448
for (session::Cache::list::iterator it= list.begin(); it != list.end(); ++it )
450
Session::shared_ptr tmp(*it);
452
tmp->setKilled(Session::KILL_CONNECTION);
453
tmp->scheduler->killSession(tmp.get());
454
DRIZZLE_CONNECTION_DONE(tmp->thread_id);
416
tmp->killed= Session::KILL_CONNECTION;
417
tmp->scheduler->killSession(tmp);
418
DRIZZLE_CONNECTION_DONE(tmp->thread_id);
421
LOCK_thread_count.unlock(); // For unlink from list
460
if (session::Cache::singleton().count())
423
if (connection_count)
461
424
sleep(2); // Give threads time to die
470
boost::mutex::scoped_lock scopedLock(session::Cache::singleton().mutex());
471
session::Cache::list list= session::Cache::singleton().getCache();
433
LOCK_thread_count.lock(); // For unlink from list
434
if (getSessionList().empty())
436
LOCK_thread_count.unlock();
439
tmp= getSessionList().front();
477
440
/* Close before unlock, avoiding crash. See LP bug#436685 */
478
list.front()->client->close();
441
tmp->client->close();
442
LOCK_thread_count.unlock();
447
cleanup all memory and end program nicely.
449
If SIGNALS_DONT_BREAK_READ is defined, this function is called
450
by the main thread. To get Drizzle to shut down nicely in this case
451
(Mac OS X) we have to call exit() instead if pthread_exit().
454
This function never returns.
456
void unireg_end(void)
459
internal::my_thread_end();
460
#if defined(SIGNALS_DONT_BREAK_READ)
463
pthread_exit(0); // Exit is in main thread
483
468
void unireg_abort(int exit_code)
487
472
errmsg_printf(ERRMSG_LVL_ERROR, _("Aborting\n"));
473
else if (opt_help || opt_help_extended)
490
475
clean_up(!opt_help && (exit_code));
491
476
internal::my_end();
659
650
DRIZZLE_CONFIG_NAME, "server", 0, 0
662
static void find_plugin_dir(string progname)
664
if (progname[0] != FN_LIBCHAR)
666
/* We have a relative path and need to find the absolute */
667
char working_dir[FN_REFLEN];
668
char *working_dir_ptr= working_dir;
669
working_dir_ptr= getcwd(working_dir_ptr, FN_REFLEN);
670
string new_path(working_dir);
671
if (*(new_path.end()-1) != '/')
672
new_path.push_back('/');
673
if (progname[0] == '.' && progname[1] == '/')
674
new_path.append(progname.substr(2));
676
new_path.append(progname);
677
progname.swap(new_path);
680
/* Now, trim off the exe name */
681
string progdir(progname.substr(0, progname.rfind(FN_LIBCHAR)+1));
682
if (progdir.rfind(".libs/") != string::npos)
684
progdir.assign(progdir.substr(0, progdir.rfind(".libs/")));
686
string testlofile(progdir);
687
testlofile.append("drizzled.lo");
688
string testofile(progdir);
689
testofile.append("drizzled.o");
690
struct stat testfile_stat;
691
if (not (stat(testlofile.c_str(), &testfile_stat) && stat(testofile.c_str(), &testfile_stat)))
693
/* We are in a source dir! Plugin dir is ../plugin/.libs */
694
size_t last_libchar_pos= progdir.rfind(FN_LIBCHAR,progdir.size()-2)+1;
695
base_plugin_dir= progdir.substr(0,last_libchar_pos);
696
base_plugin_dir /= "plugin";
697
base_plugin_dir /= ".libs";
700
if (plugin_dir.root_directory() == "")
702
fs::path full_plugin_dir(fs::system_complete(base_plugin_dir));
703
full_plugin_dir /= plugin_dir;
704
plugin_dir= full_plugin_dir;
708
static void notify_plugin_dir(fs::path in_plugin_dir)
710
plugin_dir= in_plugin_dir;
711
if (plugin_dir.root_directory() == "")
713
fs::path full_plugin_dir(fs::system_complete(basedir));
714
full_plugin_dir /= plugin_dir;
715
plugin_dir= full_plugin_dir;
719
static void expand_secure_file_priv(fs::path in_secure_file_priv)
721
secure_file_priv= fs::system_complete(in_secure_file_priv);
724
653
static void check_limits_aii(uint64_t in_auto_increment_increment)
726
655
global_system_variables.auto_increment_increment= 1;
1031
981
global_system_variables.tmp_table_size= in_tmp_table_size;
1034
static void check_limits_transaction_message_threshold(size_t in_transaction_message_threshold)
1036
global_system_variables.transaction_message_threshold= 1024*1024;
1037
if ((int64_t) in_transaction_message_threshold < 128*1024 || (int64_t)in_transaction_message_threshold > 1024*1024)
1039
cout << N_("Error: Invalid Value for transaction_message_threshold valid values are between 131072 - 1048576 bytes");
1042
global_system_variables.transaction_message_threshold= in_transaction_message_threshold;
984
static pair<string, string> parse_size_suffixes(string s)
986
size_t equal_pos= s.find("=");
987
if (equal_pos != string::npos)
989
string arg_key(s.substr(0, equal_pos));
990
string arg_val(s.substr(equal_pos+1));
994
size_t size_suffix_pos= arg_val.find_last_of("kmgKMG");
995
if (size_suffix_pos == arg_val.size()-1)
997
char suffix= arg_val[size_suffix_pos];
998
string size_val(arg_val.substr(0, size_suffix_pos));
1000
uint64_t base_size= boost::lexical_cast<uint64_t>(size_val);
1001
uint64_t new_size= 0;
1007
new_size= base_size * 1024;
1011
new_size= base_size * 1024 * 1024;
1015
new_size= base_size * 1024 * 1024 * 1024;
1018
return make_pair(arg_key,
1019
boost::lexical_cast<string>(new_size));
1024
/* Screw it, let the normal parser take over */
1028
return make_pair(string(""), string(""));
1031
static pair<string, string> parse_size_arg(string s)
1033
if (s.find("--") == 0)
1035
return parse_size_suffixes(s.substr(2));
1037
return make_pair(string(""), string(""));
1045
1040
static void process_defaults_files()
1138
1133
strncpy(glob_hostname, STRING_WITH_LEN("localhost"));
1139
1134
errmsg_printf(ERRMSG_LVL_WARN, _("gethostname failed, using '%s' as hostname"),
1140
1135
glob_hostname);
1141
pid_file= "drizzle";
1136
strncpy(pidfile_name, STRING_WITH_LEN("drizzle"));
1145
pid_file= glob_hostname;
1147
pid_file.replace_extension(".pid");
1149
system_config_dir /= "drizzle";
1151
config_options.add_options()
1139
strncpy(pidfile_name, glob_hostname, sizeof(pidfile_name)-5);
1140
strcpy(internal::fn_ext(pidfile_name),".pid"); // Add proper extension
1142
std::string system_config_dir_drizzle(SYSCONFDIR);
1143
system_config_dir_drizzle.append("/drizzle");
1145
std::string system_config_file_drizzle("drizzled.cnf");
1147
long_options.add_options()
1148
("help-extended", po::value<bool>(&opt_help_extended)->default_value(false)->zero_tokens(),
1149
N_("Display this help and exit after initializing plugins."))
1152
1150
("help,?", po::value<bool>(&opt_help)->default_value(false)->zero_tokens(),
1153
1151
N_("Display this help and exit."))
1154
("no-defaults", po::value<bool>()->default_value(false)->zero_tokens(),
1155
N_("Configuration file defaults are not used if no-defaults is set"))
1156
("defaults-file", po::value<vector<string> >()->composing()->notifier(&compose_defaults_file_list),
1157
N_("Configuration file to use"))
1158
("config-dir", po::value<fs::path>(&system_config_dir),
1159
N_("Base location for config files"))
1160
("plugin-dir", po::value<fs::path>(&plugin_dir)->notifier(¬ify_plugin_dir),
1161
N_("Directory for plugins."))
1164
plugin_load_options.add_options()
1165
("plugin-add", po::value<vector<string> >()->composing()->notifier(&compose_plugin_add),
1166
N_("Optional comma separated list of plugins to load at startup in addition "
1167
"to the default list of plugins. "
1168
"[for example: --plugin_add=crc32,logger_gearman]"))
1169
("plugin-remove", po::value<vector<string> >()->composing()->notifier(&compose_plugin_remove),
1170
N_("Optional comma separated list of plugins to not load at startup. Effectively "
1171
"removes a plugin from the list of plugins to be loaded. "
1172
"[for example: --plugin_remove=crc32,logger_gearman]"))
1173
("plugin-load", po::value<string>()->notifier(¬ify_plugin_load)->default_value(PANDORA_PLUGIN_LIST),
1174
N_("Optional comma separated list of plugins to load at starup instead of "
1175
"the default plugin load list. "
1176
"[for example: --plugin_load=crc32,logger_gearman]"))
1179
long_options.add_options()
1180
1152
("auto-increment-increment", po::value<uint64_t>(&global_system_variables.auto_increment_increment)->default_value(1)->notifier(&check_limits_aii),
1181
1153
N_("Auto-increment columns are incremented by this"))
1182
1154
("auto-increment-offset", po::value<uint64_t>(&global_system_variables.auto_increment_offset)->default_value(1)->notifier(&check_limits_aio),
1183
1155
N_("Offset added to Auto-increment columns. Used when auto-increment-increment != 1"))
1184
("basedir,b", po::value<fs::path>(&basedir),
1156
("basedir,b", po::value<string>(),
1185
1157
N_("Path to installation directory. All paths are usually resolved "
1186
1158
"relative to this."))
1187
1159
("chroot,r", po::value<string>(),
1191
1163
("completion-type", po::value<uint32_t>(&global_system_variables.completion_type)->default_value(0)->notifier(&check_limits_completion_type),
1192
1164
N_("Default completion type."))
1193
1165
("core-file", N_("Write core on errors."))
1194
("datadir", po::value<fs::path>(&data_home),
1166
("datadir,h", po::value<string>(),
1195
1167
N_("Path to the database root."))
1196
1168
("default-storage-engine", po::value<string>(),
1197
N_("Set the default storage engine for tables."))
1169
N_("Set the default storage engine (table type) for tables."))
1198
1170
("default-time-zone", po::value<string>(),
1199
1171
N_("Set the default time zone."))
1200
1172
("exit-info,T", po::value<long>(),
1201
1173
N_("Used for debugging; Use at your own risk!"))
1202
1174
("gdb", po::value<bool>(&opt_debugging)->default_value(false)->zero_tokens(),
1203
1175
N_("Set up signals usable for debugging"))
1176
("language,L", po::value<string>(),
1204
1178
("lc-time-name", po::value<string>(),
1205
1179
N_("Set the language used for the month names and the days of the week."))
1206
("log-warnings,W", po::value<bool>(&global_system_variables.log_warnings)->default_value(false)->zero_tokens(),
1180
("log-warnings,W", po::value<string>(),
1207
1181
N_("Log some not critical warnings to the log file."))
1208
("pid-file", po::value<fs::path>(&pid_file),
1209
N_("Pid file used by drizzled."))
1182
("pid-file", po::value<string>(),
1183
N_("Pid file used by safe_mysqld."))
1210
1184
("port-open-timeout", po::value<uint32_t>(&drizzled_bind_timeout)->default_value(0),
1211
N_("Maximum time in seconds to wait for the port to become free. "))
1212
("replicate-query", po::value<bool>(&global_system_variables.replicate_query)->default_value(false)->zero_tokens(),
1213
N_("Include the SQL query in replicated protobuf messages."))
1214
("secure-file-priv", po::value<fs::path>(&secure_file_priv)->notifier(expand_secure_file_priv),
1185
N_("Maximum time in seconds to wait for the port to become free. "
1186
"(Default: no wait)"))
1187
("secure-file-priv", po::value<string>(),
1215
1188
N_("Limit LOAD DATA, SELECT ... OUTFILE, and LOAD_FILE() to files "
1216
1189
"within specified directory"))
1217
1190
("server-id", po::value<uint32_t>(&server_id)->default_value(0),
1228
1201
N_("Path for temporary files."))
1229
1202
("transaction-isolation", po::value<string>(),
1230
1203
N_("Default transaction isolation level."))
1231
("transaction-message-threshold", po::value<size_t>(&global_system_variables.transaction_message_threshold)->default_value(1024*1024)->notifier(&check_limits_transaction_message_threshold),
1232
N_("Max message size written to transaction log, valid values 131072 - 1048576 bytes."))
1233
1204
("user,u", po::value<string>(),
1234
1205
N_("Run drizzled daemon as user."))
1236
1207
N_("Output version information and exit."))
1237
("back-log", po::value<back_log_constraints>(&back_log),
1208
("back-log", po::value<uint32_t>(&back_log)->default_value(50)->notifier(&check_limits_back_log),
1238
1209
N_("The number of outstanding connection requests Drizzle can have. This "
1239
1210
"comes into play when the main Drizzle thread gets very many connection "
1240
1211
"requests in a very short time."))
1249
1220
N_("The maximum length of the result of function group_concat."))
1250
1221
("join-buffer-size", po::value<uint64_t>(&global_system_variables.join_buff_size)->default_value(128*1024L)->notifier(&check_limits_join_buffer_size),
1251
1222
N_("The size of the buffer that is used for full joins."))
1252
("join-heap-threshold",
1253
po::value<uint64_t>()->default_value(0),
1254
N_("A global cap on the amount of memory that can be allocated by session join buffers (0 means unlimited)"))
1255
("max-allowed-packet", po::value<uint32_t>(&global_system_variables.max_allowed_packet)->default_value(64*1024*1024L)->notifier(&check_limits_map),
1223
("max-allowed-packet", po::value<uint32_t>(&global_system_variables.max_allowed_packet)->default_value(1024*1024L)->notifier(&check_limits_map),
1256
1224
N_("Max packetlength to send/receive from to server."))
1257
1225
("max-connect-errors", po::value<uint64_t>(&max_connect_errors)->default_value(MAX_CONNECT_ERRORS)->notifier(&check_limits_mce),
1258
1226
N_("If there is more than this number of interrupted connections from a "
1289
1257
"automatically pick a reasonable value; if set to MAX_TABLES+2, the "
1290
1258
"optimizer will switch to the original find_best (used for "
1291
1259
"testing/comparison)."))
1260
("plugin-dir", po::value<string>(),
1261
N_("Directory for plugins."))
1262
("plugin-add", po::value<vector<string> >()->composing()->notifier(&compose_plugin_add),
1263
N_("Optional comma separated list of plugins to load at startup in addition "
1264
"to the default list of plugins. "
1265
"[for example: --plugin_add=crc32,logger_gearman]"))
1266
("plugin-remove", po::value<vector<string> >()->composing()->notifier(&compose_plugin_remove),
1267
N_("Optional comma separated list of plugins to not load at startup. Effectively "
1268
"removes a plugin from the list of plugins to be loaded. "
1269
"[for example: --plugin_remove=crc32,logger_gearman]"))
1270
("plugin-load", po::value<string>()->notifier(¬ify_plugin_load)->default_value(PANDORA_PLUGIN_LIST),
1271
N_("Optional comma separated list of plugins to load at starup instead of "
1272
"the default plugin load list. "
1273
"[for example: --plugin_load=crc32,logger_gearman]"))
1292
1274
("preload-buffer-size", po::value<uint64_t>(&global_system_variables.preload_buff_size)->default_value(32*1024L)->notifier(&check_limits_pbs),
1293
1275
N_("The size of the buffer that is allocated when preloading indexes"))
1294
1276
("query-alloc-block-size",
1305
1287
N_("Each thread that does a sequential scan allocates a buffer of this "
1306
1288
"size for each table it scans. If you do many sequential scans, you may "
1307
1289
"want to increase this value."))
1308
("read-buffer-threshold",
1309
po::value<uint64_t>()->default_value(0),
1310
N_("A global cap on the size of read-buffer-size (0 means unlimited)"))
1311
1290
("read-rnd-buffer-size",
1312
1291
po::value<uint32_t>(&global_system_variables.read_rnd_buff_size)->default_value(256*1024L)->notifier(&check_limits_read_rnd_buffer_size),
1313
1292
N_("When reading rows in sorted order after a sort, the rows are read "
1314
1293
"through this buffer to avoid a disk seeks. If not set, then it's set "
1315
1294
"to the value of record_buffer."))
1316
("read-rnd-threshold",
1317
po::value<uint64_t>()->default_value(0),
1318
N_("A global cap on the size of read-rnd-buffer-size (0 means unlimited)"))
1319
1295
("scheduler", po::value<string>(),
1320
1296
N_("Select scheduler to be used (by default multi-thread)."))
1321
1297
("sort-buffer-size",
1322
1298
po::value<size_t>(&global_system_variables.sortbuff_size)->default_value(MAX_SORT_MEMORY)->notifier(&check_limits_sort_buffer_size),
1323
1299
N_("Each thread that needs to do a sort allocates a buffer of this size."))
1324
("sort-heap-threshold",
1325
po::value<uint64_t>()->default_value(0),
1326
N_("A global cap on the amount of memory that can be allocated by session sort buffers (0 means unlimited)"))
1327
1300
("table-definition-cache", po::value<size_t>(&table_def_size)->default_value(128)->notifier(&check_limits_tdc),
1328
1301
N_("The number of cached table definitions."))
1329
1302
("table-open-cache", po::value<uint64_t>(&table_cache_size)->default_value(TABLE_OPEN_CACHE_DEFAULT)->notifier(&check_limits_toc),
1337
1310
po::value<uint64_t>(&global_system_variables.tmp_table_size)->default_value(16*1024*1024L)->notifier(&check_limits_tmp_table_size),
1338
1311
N_("If an internal in-memory temporary table exceeds this size, Drizzle will"
1339
1312
" automatically convert it to an on-disk MyISAM table."))
1313
("no-defaults", po::value<bool>()->default_value(false)->zero_tokens(),
1314
N_("Configuration file defaults are not used if no-defaults is set"))
1315
("defaults-file", po::value<vector<string> >()->composing()->notifier(&compose_defaults_file_list),
1316
N_("Configuration file to use"))
1317
("config-dir", po::value<string>()->default_value(system_config_dir_drizzle),
1318
N_("Base location for config files"))
1342
full_options.add(long_options);
1343
full_options.add(plugin_load_options);
1345
initial_options.add(config_options);
1346
initial_options.add(plugin_load_options);
1321
// Disable allow_guessing
1348
1322
int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
1349
/* Get options about where config files and the like are */
1350
1324
po::parsed_options parsed= po::command_line_parser(argc, argv).style(style).
1351
options(initial_options).allow_unregistered().run();
1325
options(long_options).allow_unregistered().extra_parser(parse_size_arg).run();
1352
1326
unknown_options=
1353
1327
po::collect_unrecognized(parsed.options, po::include_positional);
1365
1339
if (not vm["no-defaults"].as<bool>())
1367
fs::path system_config_file_drizzle(system_config_dir);
1368
system_config_file_drizzle /= "drizzled.cnf";
1369
1341
defaults_file_list.insert(defaults_file_list.begin(),
1370
system_config_file_drizzle.file_string());
1372
fs::path config_conf_d_location(system_config_dir);
1373
config_conf_d_location /= "conf.d";
1376
CachedDirectory config_conf_d(config_conf_d_location.file_string());
1377
if (not config_conf_d.fail())
1342
system_config_file_drizzle);
1345
string config_conf_d_location(vm["config-dir"].as<string>());
1346
config_conf_d_location.append("/conf.d");
1347
CachedDirectory config_conf_d(config_conf_d_location);
1348
if (not config_conf_d.fail())
1351
for (CachedDirectory::Entries::const_iterator iter= config_conf_d.getEntries().begin();
1352
iter != config_conf_d.getEntries().end();
1380
for (CachedDirectory::Entries::const_iterator iter= config_conf_d.getEntries().begin();
1381
iter != config_conf_d.getEntries().end();
1355
string file_entry((*iter)->filename);
1357
if (not file_entry.empty()
1358
&& file_entry != "."
1359
&& file_entry != "..")
1384
string file_entry((*iter)->filename);
1386
if (not file_entry.empty()
1387
&& file_entry != "."
1388
&& file_entry != "..")
1390
fs::path the_entry(config_conf_d_location);
1391
the_entry /= file_entry;
1392
defaults_file_list.push_back(the_entry.file_string());
1361
string the_entry(config_conf_d_location);
1362
the_entry.push_back('/');
1363
the_entry.append(file_entry);
1364
defaults_file_list.push_back(the_entry);
1398
/* TODO: here is where we should add a process_env_vars */
1400
/* We need a notify here so that plugin_init will work properly */
1405
catch (po::validation_error &err)
1407
errmsg_printf(ERRMSG_LVL_ERROR,
1409
"Use --help to get a list of available options\n"),
1410
internal::my_progname, err.what());
1414
1370
process_defaults_files();
1416
/* Process with notify a second time because a config file may contain
1417
plugin loader options */
1423
catch (po::validation_error &err)
1425
errmsg_printf(ERRMSG_LVL_ERROR,
1427
"Use --help to get a list of available options\n"),
1428
internal::my_progname, err.what());
1432
/* At this point, we've read all the options we need to read from files and
1433
collected most of them into unknown options - now let's load everything
1436
if (plugin_init(plugins, plugin_options))
1438
errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to initialize plugins\n"));
1442
full_options.add(plugin_options);
1444
vector<string> final_unknown_options;
1447
po::parsed_options final_parsed=
1448
po::command_line_parser(unknown_options).style(style).
1449
options(full_options).extra_parser(dpo::parse_size_arg).run();
1451
final_unknown_options=
1452
po::collect_unrecognized(final_parsed.options, po::include_positional);
1454
po::store(final_parsed, vm);
1457
catch (po::validation_error &err)
1459
errmsg_printf(ERRMSG_LVL_ERROR,
1461
"Use --help to get a list of available options\n"),
1462
internal::my_progname, err.what());
1465
catch (po::invalid_command_line_syntax &err)
1467
errmsg_printf(ERRMSG_LVL_ERROR,
1469
"Use --help to get a list of available options\n"),
1470
internal::my_progname, err.what());
1473
catch (po::unknown_option &err)
1475
errmsg_printf(ERRMSG_LVL_ERROR,
1476
_("%s\nUse --help to get a list of available options\n"),
1485
catch (po::validation_error &err)
1487
errmsg_printf(ERRMSG_LVL_ERROR,
1489
"Use --help to get a list of available options\n"),
1490
internal::my_progname, err.what());
1602
1474
/* Allow storage engine to give real error messages */
1603
1475
ha_init_errors();
1477
if (plugin_init(plugins, plugin_options))
1479
errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to initialize plugins\n"));
1484
if (opt_help || opt_help_extended)
1607
1485
unireg_abort(0);
1609
if (plugin_finalize(plugins))
1487
vector<string> final_unknown_options;
1490
// Disable allow_guessing
1491
int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
1492
po::parsed_options parsed=
1493
po::command_line_parser(unknown_options).style(style).
1494
options(plugin_options).extra_parser(parse_size_arg).run();
1496
final_unknown_options=
1497
po::collect_unrecognized(parsed.options, po::include_positional);
1499
po::store(parsed, vm);
1502
catch (po::invalid_command_line_syntax &err)
1504
errmsg_printf(ERRMSG_LVL_ERROR,
1506
"Use --help to get a list of available options\n"),
1507
internal::my_progname, err.what());
1510
catch (po::unknown_option &err)
1512
errmsg_printf(ERRMSG_LVL_ERROR,
1513
_("%s\nUse --help to get a list of available options\n"),
1520
plugin_finalize(plugins);
1614
1522
string scheduler_name;
1615
1523
if (opt_scheduler)
1744
1652
{"help", '?', N_("Display this help and exit."),
1745
1653
(char**) &opt_help, (char**) &opt_help, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
1655
{"help-extended", '?',
1656
N_("Display this help and exit after initializing plugins."),
1657
(char**) &opt_help_extended, (char**) &opt_help_extended,
1658
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1747
1659
{"auto-increment-increment", OPT_AUTO_INCREMENT,
1748
1660
N_("Auto-increment columns are incremented by this"),
1749
1661
(char**) &global_system_variables.auto_increment_increment,
1750
1662
(char**) &max_system_variables.auto_increment_increment, 0, GET_ULL,
1751
OPT_ARG, 1, 1, INT64_MAX, 0, 1, 0 },
1663
OPT_ARG, 1, 1, UINT64_MAX, 0, 1, 0 },
1752
1664
{"auto-increment-offset", OPT_AUTO_INCREMENT_OFFSET,
1753
1665
N_("Offset added to Auto-increment columns. Used when "
1754
1666
"auto-increment-increment != 1"),
1755
1667
(char**) &global_system_variables.auto_increment_offset,
1756
1668
(char**) &max_system_variables.auto_increment_offset, 0, GET_ULL, OPT_ARG,
1757
1, 1, INT64_MAX, 0, 1, 0 },
1669
1, 1, UINT64_MAX, 0, 1, 0 },
1758
1670
{"basedir", 'b',
1759
1671
N_("Path to installation directory. All paths are usually resolved "
1760
1672
"relative to this."),
1761
NULL, NULL, 0, GET_STR, REQUIRED_ARG,
1673
(char**) &drizzle_home_ptr, (char**) &drizzle_home_ptr, 0, GET_STR, REQUIRED_ARG,
1762
1674
0, 0, 0, 0, 0, 0},
1763
1675
{"chroot", 'r',
1764
1676
N_("Chroot drizzled daemon during startup."),
1779
1691
NO_ARG, 0, 0, 0, 0, 0, 0},
1780
1692
{"datadir", 'h',
1781
1693
N_("Path to the database root."),
1782
NULL, NULL, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1694
(char**) &data_home,
1695
(char**) &data_home, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1783
1696
{"default-storage-engine", OPT_STORAGE_ENGINE,
1784
1697
N_("Set the default storage engine (table type) for tables."),
1785
1698
(char**)&default_storage_engine_str, (char**)&default_storage_engine_str,
1798
1711
N_("Set up signals usable for debugging"),
1799
1712
(char**) &opt_debugging, (char**) &opt_debugging,
1800
1713
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1716
(char**) &language_ptr, (char**) &language_ptr, 0, GET_STR, REQUIRED_ARG,
1801
1718
{"lc-time-names", OPT_LC_TIME_NAMES,
1802
1719
N_("Set the language used for the month names and the days of the week."),
1803
1720
(char**) &lc_time_names_name,
1809
1726
(char**) &max_system_variables.log_warnings, 0, GET_BOOL, OPT_ARG, 1, 0, 0,
1811
1728
{"pid-file", OPT_PID_FILE,
1812
N_("Pid file used by drizzled."),
1813
NULL, NULL, 0, GET_STR,
1729
N_("Pid file used by safe_mysqld."),
1730
(char**) &pidfile_name_ptr, (char**) &pidfile_name_ptr, 0, GET_STR,
1814
1731
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1815
1732
{"port-open-timeout", OPT_PORT_OPEN_TIMEOUT,
1816
1733
N_("Maximum time in seconds to wait for the port to become free. "
1894
1811
N_("Max packetlength to send/receive from to server."),
1895
1812
(char**) &global_system_variables.max_allowed_packet,
1896
1813
(char**) &max_system_variables.max_allowed_packet, 0, GET_UINT32,
1897
REQUIRED_ARG, 64*1024*1024L, 1024, 1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
1814
REQUIRED_ARG, 1024*1024L, 1024, 1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
1898
1815
{"max_connect_errors", OPT_MAX_CONNECT_ERRORS,
1899
1816
N_("If there is more than this number of interrupted connections from a "
1900
1817
"host this host will be blocked from further connections."),
1909
1826
N_("Don't allow creation of heap tables bigger than this."),
1910
1827
(char**) &global_system_variables.max_heap_table_size,
1911
1828
(char**) &max_system_variables.max_heap_table_size, 0, GET_ULL,
1912
REQUIRED_ARG, 16*1024*1024L, 16384, (int64_t)MAX_MEM_TABLE_SIZE,
1829
REQUIRED_ARG, 16*1024*1024L, 16384, MAX_MEM_TABLE_SIZE,
1913
1830
MALLOC_OVERHEAD, 1024, 0},
1914
1831
{"max_join_size", OPT_MAX_JOIN_SIZE,
1915
1832
N_("Joins that are probably going to read more than max_join_size records "
1966
1883
0, GET_UINT, OPT_ARG, 0, 0, MAX_TABLES+2, 0, 1, 0},
1967
1884
{"plugin_dir", OPT_PLUGIN_DIR,
1968
1885
N_("Directory for plugins."),
1886
(char**) &opt_plugin_dir_ptr, (char**) &opt_plugin_dir_ptr, 0,
1970
1887
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1971
1888
{"plugin_add", OPT_PLUGIN_ADD,
1972
1889
N_("Optional comma separated list of plugins to load at startup in addition "
2053
1970
(char**) &my_thread_stack_size,
2054
1971
(char**) &my_thread_stack_size, 0, GET_SIZE,
2055
1972
REQUIRED_ARG,DEFAULT_THREAD_STACK,
2056
UINT32_C(1024*512), (int64_t)SIZE_MAX, 0, 1024, 0},
1973
UINT32_C(1024*512), SIZE_MAX, 0, 1024, 0},
2057
1974
{"tmp_table_size", OPT_TMP_TABLE_SIZE,
2058
1975
N_("If an internal in-memory temporary table exceeds this size, Drizzle will"
2059
1976
" automatically convert it to an on-disk MyISAM table."),
2060
1977
(char**) &global_system_variables.tmp_table_size,
2061
1978
(char**) &max_system_variables.tmp_table_size, 0, GET_ULL,
2062
REQUIRED_ARG, 16*1024*1024L, 1024, (int64_t)MAX_MEM_TABLE_SIZE, 0, 1, 0},
1979
REQUIRED_ARG, 16*1024*1024L, 1024, MAX_MEM_TABLE_SIZE, 0, 1, 0},
2063
1980
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
2136
2053
character_set_filesystem= &my_charset_bin;
2138
2055
/* Things with default values that are not zero */
2056
drizzle_home_ptr= drizzle_home;
2057
pidfile_name_ptr= pidfile_name;
2058
language_ptr= language;
2059
data_home= data_home_real;
2139
2060
session_startup_options= (OPTION_AUTO_IS_NULL | OPTION_SQL_NOTES);
2140
2061
refresh_version= 1L; /* Increments on each reload */
2141
2062
global_thread_id= 1UL;
2142
session::Cache::singleton().getCache().clear();
2063
getSessionList().clear();
2065
/* Set directory paths */
2066
strncpy(language, LANGUAGE, sizeof(language)-1);
2067
strncpy(data_home_real, get_relative_path(LOCALSTATEDIR),
2068
sizeof(data_home_real)-1);
2069
data_home_buff[0]=FN_CURLIB; // all paths are relative from here
2070
data_home_buff[1]=0;
2144
2073
/* Variables in libraries */
2145
2074
default_character_set_name= "utf8";
2216
2159
vm["user"].as<string>().c_str(), drizzled_user);
2162
if (vm.count("language"))
2164
strncpy(language, vm["language"].as<string>().c_str(), sizeof(language)-1);
2219
2167
if (vm.count("version"))
2221
2169
print_version();
2225
if (vm.count("sort-heap-threshold"))
2227
if ((vm["sort-heap-threshold"].as<uint64_t>() > 0) and
2228
(vm["sort-heap-threshold"].as<uint64_t>() <
2229
global_system_variables.sortbuff_size))
2231
cout << N_("Error: sort-heap-threshold cannot be less than sort-buffer-size") << endl;
2235
global_sort_buffer.setMaxSize(vm["sort-heap-threshold"].as<uint64_t>());
2238
if (vm.count("join-heap-threshold"))
2240
if ((vm["join-heap-threshold"].as<uint64_t>() > 0) and
2241
(vm["join-heap-threshold"].as<uint64_t>() <
2242
global_system_variables.join_buff_size))
2244
cout << N_("Error: join-heap-threshold cannot be less than join-buffer-size") << endl;
2248
global_join_buffer.setMaxSize(vm["join-heap-threshold"].as<uint64_t>());
2251
if (vm.count("read-rnd-threshold"))
2253
if ((vm["read-rnd-threshold"].as<uint64_t>() > 0) and
2254
(vm["read-rnd-threshold"].as<uint64_t>() <
2255
global_system_variables.read_rnd_buff_size))
2257
cout << N_("Error: read-rnd-threshold cannot be less than read-rnd-buffer-size") << endl;
2261
global_read_rnd_buffer.setMaxSize(vm["read-rnd-threshold"].as<uint64_t>());
2264
if (vm.count("read-buffer-threshold"))
2266
if ((vm["read-buffer-threshold"].as<uint64_t>() > 0) and
2267
(vm["read-buffer-threshold"].as<uint64_t>() <
2268
global_system_variables.read_buff_size))
2270
cout << N_("Error: read-buffer-threshold cannot be less than read-buffer-size") << endl;
2274
global_read_buffer.setMaxSize(vm["read-buffer-threshold"].as<uint64_t>());
2173
if (vm.count("log-warnings"))
2175
if (vm["log-warnings"].as<string>().empty())
2176
global_system_variables.log_warnings++;
2177
else if (vm["log-warnings"].as<string>().compare("0"))
2178
global_system_variables.log_warnings= 0L;
2180
global_system_variables.log_warnings= atoi(vm["log-warnings"].as<string>().c_str());
2277
2183
if (vm.count("exit-info"))
2347
static void fix_paths()
2349
fs::path pid_file_path(pid_file);
2350
if (pid_file_path.root_path().string() == "")
2352
pid_file_path= getDataHome();
2353
pid_file_path /= pid_file;
2355
pid_file= fs::system_complete(pid_file_path);
2258
static const char *get_relative_path(const char *path)
2260
if (internal::test_if_hard_path(path) &&
2261
(strncmp(path, PREFIX, strlen(PREFIX)) == 0) &&
2262
strcmp(PREFIX,FN_ROOTDIR))
2264
if (strlen(PREFIX) < strlen(path))
2265
path+=(size_t) strlen(PREFIX);
2266
while (*path == FN_LIBCHAR)
2273
static void fix_paths(string progname)
2275
char buff[FN_REFLEN],*pos,rp_buff[PATH_MAX];
2276
internal::convert_dirname(drizzle_home,drizzle_home,NULL);
2277
/* Resolve symlinks to allow 'drizzle_home' to be a relative symlink */
2278
#if defined(HAVE_BROKEN_REALPATH)
2279
internal::my_load_path(drizzle_home, drizzle_home, NULL);
2281
if (!realpath(drizzle_home,rp_buff))
2282
internal::my_load_path(rp_buff, drizzle_home, NULL);
2283
rp_buff[FN_REFLEN-1]= '\0';
2284
strcpy(drizzle_home,rp_buff);
2285
/* Ensure that drizzle_home ends in FN_LIBCHAR */
2286
pos= strchr(drizzle_home, '\0');
2288
if (pos[-1] != FN_LIBCHAR)
2293
internal::convert_dirname(data_home_real,data_home_real,NULL);
2294
(void) internal::fn_format(buff, data_home_real, "", "",
2295
(MY_RETURN_REAL_PATH|MY_RESOLVE_SYMLINKS));
2296
internal::convert_dirname(language,language,NULL);
2297
(void) internal::my_load_path(drizzle_home, drizzle_home,""); // Resolve current dir
2298
(void) internal::my_load_path(data_home_real, data_home_real,drizzle_home);
2299
(void) internal::my_load_path(pidfile_name, pidfile_name,data_home_real);
2301
if (opt_plugin_dir_ptr == NULL)
2303
/* No plugin dir has been specified. Figure out where the plugins are */
2304
if (progname[0] != FN_LIBCHAR)
2306
/* We have a relative path and need to find the absolute */
2307
char working_dir[FN_REFLEN];
2308
char *working_dir_ptr= working_dir;
2309
working_dir_ptr= getcwd(working_dir_ptr, FN_REFLEN);
2310
string new_path(working_dir);
2311
if (*(new_path.end()-1) != '/')
2312
new_path.push_back('/');
2313
if (progname[0] == '.' && progname[1] == '/')
2314
new_path.append(progname.substr(2));
2316
new_path.append(progname);
2317
progname.swap(new_path);
2320
/* Now, trim off the exe name */
2321
string progdir(progname.substr(0, progname.rfind(FN_LIBCHAR)+1));
2322
if (progdir.rfind(".libs/") != string::npos)
2324
progdir.assign(progdir.substr(0, progdir.rfind(".libs/")));
2326
string testlofile(progdir);
2327
testlofile.append("drizzled.lo");
2328
string testofile(progdir);
2329
testofile.append("drizzled.o");
2330
struct stat testfile_stat;
2331
if (stat(testlofile.c_str(), &testfile_stat) && stat(testofile.c_str(), &testfile_stat))
2333
/* neither drizzled.lo or drizzled.o exist - we are not in a source dir.
2336
(void) internal::my_load_path(opt_plugin_dir, get_relative_path(PKGPLUGINDIR),
2341
/* We are in a source dir! Plugin dir is ../plugin/.libs */
2342
size_t last_libchar_pos= progdir.rfind(FN_LIBCHAR,progdir.size()-2)+1;
2343
string source_plugindir(progdir.substr(0,last_libchar_pos));
2344
source_plugindir.append("plugin/.libs");
2345
(void) internal::my_load_path(opt_plugin_dir, source_plugindir.c_str(), "");
2350
(void) internal::my_load_path(opt_plugin_dir, opt_plugin_dir_ptr, drizzle_home);
2352
opt_plugin_dir_ptr= opt_plugin_dir;
2354
const char *sharedir= get_relative_path(PKGDATADIR);
2355
if (internal::test_if_hard_path(sharedir))
2356
strncpy(buff,sharedir,sizeof(buff)-1);
2359
strcpy(buff, drizzle_home);
2360
strncat(buff, sharedir, sizeof(buff)-strlen(drizzle_home)-1);
2362
internal::convert_dirname(buff,buff,NULL);
2363
(void) internal::my_load_path(language,language,buff);
2365
if (not opt_help and not opt_help_extended)
2359
2367
const char *tmp_string= getenv("TMPDIR") ? getenv("TMPDIR") : NULL;
2360
2368
struct stat buf;