354
356
static void drizzle_init_variables(void);
355
357
static void get_options();
356
358
static const char *get_relative_path(const char *path);
357
static void fix_paths(string progname);
359
static void fix_paths();
359
361
static void usage(void);
360
362
void close_connections(void);
364
fs::path base_plugin_dir(PKGPLUGINDIR);
366
po::options_description config_options("Config File Options");
362
367
po::options_description long_options("Kernel Options");
368
po::options_description plugin_load_options("Plugin Loading Options");
363
369
po::options_description plugin_options("Plugin Options");
370
po::options_description initial_options("Config and Plugin Loading");
371
po::options_description full_options("Kernel and Plugin Loading and Plugin");
364
372
vector<string> unknown_options;
365
373
vector<string> defaults_file_list;
366
374
po::variables_map vm;
674
682
DRIZZLE_CONFIG_NAME, "server", 0, 0
685
static void find_plugin_dir(string progname)
687
if (progname[0] != FN_LIBCHAR)
689
/* We have a relative path and need to find the absolute */
690
char working_dir[FN_REFLEN];
691
char *working_dir_ptr= working_dir;
692
working_dir_ptr= getcwd(working_dir_ptr, FN_REFLEN);
693
string new_path(working_dir);
694
if (*(new_path.end()-1) != '/')
695
new_path.push_back('/');
696
if (progname[0] == '.' && progname[1] == '/')
697
new_path.append(progname.substr(2));
699
new_path.append(progname);
700
progname.swap(new_path);
703
/* Now, trim off the exe name */
704
string progdir(progname.substr(0, progname.rfind(FN_LIBCHAR)+1));
705
if (progdir.rfind(".libs/") != string::npos)
707
progdir.assign(progdir.substr(0, progdir.rfind(".libs/")));
709
string testlofile(progdir);
710
testlofile.append("drizzled.lo");
711
string testofile(progdir);
712
testofile.append("drizzled.o");
713
struct stat testfile_stat;
714
if (not (stat(testlofile.c_str(), &testfile_stat) && stat(testofile.c_str(), &testfile_stat)))
716
/* We are in a source dir! Plugin dir is ../plugin/.libs */
717
size_t last_libchar_pos= progdir.rfind(FN_LIBCHAR,progdir.size()-2)+1;
718
base_plugin_dir= progdir.substr(0,last_libchar_pos);
719
base_plugin_dir /= "plugin";
720
base_plugin_dir /= ".libs";
722
(void) internal::my_load_path(opt_plugin_dir, fs::path(fs::system_complete(base_plugin_dir)).file_string().c_str(), "");
725
static void notify_plugin_dir(string in_plugin_dir)
727
if (not in_plugin_dir.empty())
729
(void) internal::my_load_path(opt_plugin_dir, in_plugin_dir.c_str(), drizzle_home);
677
733
static void check_limits_aii(uint64_t in_auto_increment_increment)
679
735
global_system_variables.auto_increment_increment= 1;
1082
1138
ifstream input_defaults_file(file_location.c_str());
1084
1140
po::parsed_options file_parsed=
1085
po::parse_config_file(input_defaults_file, long_options, true);
1141
po::parse_config_file(input_defaults_file, full_options, true);
1086
1142
vector<string> file_unknown=
1087
1143
po::collect_unrecognized(file_parsed.options, po::include_positional);
1169
1226
std::string system_config_file_drizzle("drizzled.cnf");
1171
long_options.add_options()
1228
config_options.add_options()
1172
1229
("help-extended", po::value<bool>(&opt_help_extended)->default_value(false)->zero_tokens(),
1173
1230
N_("Display this help and exit after initializing plugins."))
1174
1231
("help,?", po::value<bool>(&opt_help)->default_value(false)->zero_tokens(),
1175
1232
N_("Display this help and exit."))
1233
("no-defaults", po::value<bool>()->default_value(false)->zero_tokens(),
1234
N_("Configuration file defaults are not used if no-defaults is set"))
1235
("defaults-file", po::value<vector<string> >()->composing()->notifier(&compose_defaults_file_list),
1236
N_("Configuration file to use"))
1237
("config-dir", po::value<string>()->default_value(system_config_dir_drizzle),
1238
N_("Base location for config files"))
1239
("plugin-dir", po::value<string>()->notifier(¬ify_plugin_dir),
1240
N_("Directory for plugins."))
1243
plugin_load_options.add_options()
1244
("plugin-add", po::value<vector<string> >()->composing()->notifier(&compose_plugin_add),
1245
N_("Optional comma separated list of plugins to load at startup in addition "
1246
"to the default list of plugins. "
1247
"[for example: --plugin_add=crc32,logger_gearman]"))
1248
("plugin-remove", po::value<vector<string> >()->composing()->notifier(&compose_plugin_remove),
1249
N_("Optional comma separated list of plugins to not load at startup. Effectively "
1250
"removes a plugin from the list of plugins to be loaded. "
1251
"[for example: --plugin_remove=crc32,logger_gearman]"))
1252
("plugin-load", po::value<string>()->notifier(¬ify_plugin_load)->default_value(PANDORA_PLUGIN_LIST),
1253
N_("Optional comma separated list of plugins to load at starup instead of "
1254
"the default plugin load list. "
1255
"[for example: --plugin_load=crc32,logger_gearman]"))
1258
long_options.add_options()
1176
1259
("auto-increment-increment", po::value<uint64_t>(&global_system_variables.auto_increment_increment)->default_value(1)->notifier(&check_limits_aii),
1177
1260
N_("Auto-increment columns are incremented by this"))
1178
1261
("auto-increment-offset", po::value<uint64_t>(&global_system_variables.auto_increment_offset)->default_value(1)->notifier(&check_limits_aio),
1281
1364
"automatically pick a reasonable value; if set to MAX_TABLES+2, the "
1282
1365
"optimizer will switch to the original find_best (used for "
1283
1366
"testing/comparison)."))
1284
("plugin-dir", po::value<string>(),
1285
N_("Directory for plugins."))
1286
("plugin-add", po::value<vector<string> >()->composing()->notifier(&compose_plugin_add),
1287
N_("Optional comma separated list of plugins to load at startup in addition "
1288
"to the default list of plugins. "
1289
"[for example: --plugin_add=crc32,logger_gearman]"))
1290
("plugin-remove", po::value<vector<string> >()->composing()->notifier(&compose_plugin_remove),
1291
N_("Optional comma separated list of plugins to not load at startup. Effectively "
1292
"removes a plugin from the list of plugins to be loaded. "
1293
"[for example: --plugin_remove=crc32,logger_gearman]"))
1294
("plugin-load", po::value<string>()->notifier(¬ify_plugin_load)->default_value(PANDORA_PLUGIN_LIST),
1295
N_("Optional comma separated list of plugins to load at starup instead of "
1296
"the default plugin load list. "
1297
"[for example: --plugin_load=crc32,logger_gearman]"))
1298
1367
("preload-buffer-size", po::value<uint64_t>(&global_system_variables.preload_buff_size)->default_value(32*1024L)->notifier(&check_limits_pbs),
1299
1368
N_("The size of the buffer that is allocated when preloading indexes"))
1300
1369
("query-alloc-block-size",
1334
1403
po::value<uint64_t>(&global_system_variables.tmp_table_size)->default_value(16*1024*1024L)->notifier(&check_limits_tmp_table_size),
1335
1404
N_("If an internal in-memory temporary table exceeds this size, Drizzle will"
1336
1405
" automatically convert it to an on-disk MyISAM table."))
1337
("no-defaults", po::value<bool>()->default_value(false)->zero_tokens(),
1338
N_("Configuration file defaults are not used if no-defaults is set"))
1339
("defaults-file", po::value<vector<string> >()->composing()->notifier(&compose_defaults_file_list),
1340
N_("Configuration file to use"))
1341
("config-dir", po::value<string>()->default_value(system_config_dir_drizzle),
1342
N_("Base location for config files"))
1345
// Disable allow_guessing
1408
full_options.add(long_options);
1409
full_options.add(plugin_load_options);
1411
initial_options.add(config_options);
1412
initial_options.add(plugin_load_options);
1346
1414
int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
1415
/* Get options about where config files and the like are */
1348
1416
po::parsed_options parsed= po::command_line_parser(argc, argv).style(style).
1349
options(long_options).allow_unregistered().extra_parser(parse_size_arg).run();
1417
options(initial_options).allow_unregistered().run();
1350
1418
unknown_options=
1351
1419
po::collect_unrecognized(parsed.options, po::include_positional);
1394
1461
process_defaults_files();
1462
/* TODO: here is where we should add a process_env_vars */
1464
/* We need a notify here so that plugin_init will work properly */
1466
/* At this point, we've read all the options we need to read from files and
1467
collected most of them into unknown options - now let's load everything
1470
if (plugin_init(plugins, plugin_options))
1472
errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to initialize plugins\n"));
1476
full_options.add(plugin_options);
1478
vector<string> final_unknown_options;
1481
po::parsed_options final_parsed=
1482
po::command_line_parser(unknown_options).style(style).
1483
options(full_options).extra_parser(parse_size_arg).run();
1485
final_unknown_options=
1486
po::collect_unrecognized(final_parsed.options, po::include_positional);
1488
po::store(final_parsed, vm);
1491
catch (po::invalid_command_line_syntax &err)
1493
errmsg_printf(ERRMSG_LVL_ERROR,
1495
"Use --help to get a list of available options\n"),
1496
internal::my_progname, err.what());
1499
catch (po::unknown_option &err)
1501
errmsg_printf(ERRMSG_LVL_ERROR,
1502
_("%s\nUse --help to get a list of available options\n"),
1395
1507
po::notify(vm);
1498
1613
/* Allow storage engine to give real error messages */
1499
1614
ha_init_errors();
1501
if (plugin_init(plugins, plugin_options))
1503
errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to initialize plugins\n"));
1508
1617
if (opt_help || opt_help_extended)
1509
1618
unireg_abort(0);
1511
vector<string> final_unknown_options;
1514
// Disable allow_guessing
1515
int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
1516
po::parsed_options parsed=
1517
po::command_line_parser(unknown_options).style(style).
1518
options(plugin_options).extra_parser(parse_size_arg).run();
1520
final_unknown_options=
1521
po::collect_unrecognized(parsed.options, po::include_positional);
1523
po::store(parsed, vm);
1526
catch (po::invalid_command_line_syntax &err)
1528
errmsg_printf(ERRMSG_LVL_ERROR,
1530
"Use --help to get a list of available options\n"),
1531
internal::my_progname, err.what());
1534
catch (po::unknown_option &err)
1536
errmsg_printf(ERRMSG_LVL_ERROR,
1537
_("%s\nUse --help to get a list of available options\n"),
1544
plugin_finalize(plugins);
1620
if (plugin_finalize(plugins))
1546
1625
string scheduler_name;
1547
1626
if (opt_scheduler)
1906
1985
0, GET_UINT, OPT_ARG, 0, 0, MAX_TABLES+2, 0, 1, 0},
1907
1986
{"plugin_dir", OPT_PLUGIN_DIR,
1908
1987
N_("Directory for plugins."),
1909
(char**) &opt_plugin_dir_ptr, (char**) &opt_plugin_dir_ptr, 0,
1910
1989
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1911
1990
{"plugin_add", OPT_PLUGIN_ADD,
1912
1991
N_("Optional comma separated list of plugins to load at startup in addition "
2031
2110
printf(_("Usage: %s [OPTIONS]\n"), internal::my_progname);
2033
2112
po::options_description all_options("Drizzled Options");
2113
all_options.add(config_options);
2114
all_options.add(plugin_load_options);
2034
2115
all_options.add(long_options);
2035
2116
all_options.add(plugin_options);
2036
2117
cout << all_options << endl;
2311
2392
internal::convert_dirname(language,language,NULL);
2312
2393
(void) internal::my_load_path(drizzle_home, drizzle_home,""); // Resolve current dir
2313
(void) internal::my_load_path(pidfile_name, pidfile_name,
2314
getDataHome().c_str());
2316
if (opt_plugin_dir_ptr == NULL)
2318
/* No plugin dir has been specified. Figure out where the plugins are */
2319
if (progname[0] != FN_LIBCHAR)
2321
/* We have a relative path and need to find the absolute */
2322
char working_dir[FN_REFLEN];
2323
char *working_dir_ptr= working_dir;
2324
working_dir_ptr= getcwd(working_dir_ptr, FN_REFLEN);
2325
string new_path(working_dir);
2326
if (*(new_path.end()-1) != '/')
2327
new_path.push_back('/');
2328
if (progname[0] == '.' && progname[1] == '/')
2329
new_path.append(progname.substr(2));
2331
new_path.append(progname);
2332
progname.swap(new_path);
2335
/* Now, trim off the exe name */
2336
string progdir(progname.substr(0, progname.rfind(FN_LIBCHAR)+1));
2337
if (progdir.rfind(".libs/") != string::npos)
2339
progdir.assign(progdir.substr(0, progdir.rfind(".libs/")));
2341
string testlofile(progdir);
2342
testlofile.append("drizzled.lo");
2343
string testofile(progdir);
2344
testofile.append("drizzled.o");
2345
struct stat testfile_stat;
2346
if (stat(testlofile.c_str(), &testfile_stat) && stat(testofile.c_str(), &testfile_stat))
2348
/* neither drizzled.lo or drizzled.o exist - we are not in a source dir.
2351
(void) internal::my_load_path(opt_plugin_dir, get_relative_path(PKGPLUGINDIR),
2356
/* We are in a source dir! Plugin dir is ../plugin/.libs */
2357
size_t last_libchar_pos= progdir.rfind(FN_LIBCHAR,progdir.size()-2)+1;
2358
string source_plugindir(progdir.substr(0,last_libchar_pos));
2359
source_plugindir.append("plugin/.libs");
2360
(void) internal::my_load_path(opt_plugin_dir, source_plugindir.c_str(), "");
2365
(void) internal::my_load_path(opt_plugin_dir, opt_plugin_dir_ptr, drizzle_home);
2367
opt_plugin_dir_ptr= opt_plugin_dir;
2395
fs::path pid_file_path(pidfile_name);
2396
if (pid_file_path.root_path().string() == "")
2398
pid_file_path= fs::path(getDataHome());
2399
pid_file_path /= pidfile_name;
2401
strncpy(pidfile_name, pid_file_path.file_string().c_str(), sizeof(pidfile_name)-1);
2369
2404
const char *sharedir= get_relative_path(PKGDATADIR);
2370
2405
if (internal::test_if_hard_path(sharedir))