61
61
#include "plugin/myisam/myisam.h"
62
62
#include "drizzled/drizzled.h"
63
63
#include "drizzled/module/registry.h"
64
#include "drizzled/module/load_list.h"
65
66
#include <google/protobuf/stubs/common.h>
361
363
po::options_description long_options("Kernel Options");
362
364
po::options_description plugin_options("Plugin Options");
363
365
vector<string> unknown_options;
366
vector<string> defaults_file_list;
364
367
po::variables_map vm;
366
369
po::variables_map &getVariablesMap()
1036
1037
return make_pair(string(""), string(""));
1040
static void process_defaults_files()
1042
for (vector<string>::iterator iter= defaults_file_list.begin();
1043
iter != defaults_file_list.end();
1046
string file_location(vm["config-dir"].as<string>());
1047
if ((*iter)[0] != '/')
1049
/* Relative path - add config dir */
1050
file_location.push_back('/');
1051
file_location.append(*iter);
1055
file_location= *iter;
1058
ifstream input_defaults_file(file_location.c_str());
1060
po::parsed_options file_parsed=
1061
po::parse_config_file(input_defaults_file, long_options, true);
1062
vector<string> file_unknown=
1063
po::collect_unrecognized(file_parsed.options, po::include_positional);
1065
for (vector<string>::iterator it= file_unknown.begin();
1066
it != file_unknown.end();
1069
string new_unknown_opt("--");
1070
new_unknown_opt.append(*it);
1072
if (it != file_unknown.end())
1074
if ((*it) != "true")
1076
new_unknown_opt.push_back('=');
1077
new_unknown_opt.append(*it);
1084
unknown_options.push_back(new_unknown_opt);
1086
store(file_parsed, vm);
1090
static void compose_defaults_file_list(vector<string> in_options)
1092
for (vector<string>::iterator it= in_options.begin();
1093
it != in_options.end();
1096
defaults_file_list.push_back(*it);
1040
1100
int init_common_variables(int argc, char **argv)
1079
1139
strncpy(pidfile_name, glob_hostname, sizeof(pidfile_name)-5);
1080
1140
strcpy(internal::fn_ext(pidfile_name),".pid"); // Add proper extension
1085
1142
std::string system_config_dir_drizzle(SYSCONFDIR);
1086
system_config_dir_drizzle.append("/drizzle/drizzle.cnf");
1143
system_config_dir_drizzle.append("/drizzle");
1145
std::string system_config_file_drizzle("drizzled.cnf");
1088
1147
long_options.add_options()
1089
1148
("help-extended", po::value<bool>(&opt_help_extended)->default_value(false)->zero_tokens(),
1200
1259
"testing/comparison)."))
1201
1260
("plugin-dir", po::value<string>(),
1202
1261
N_("Directory for plugins."))
1203
("plugin-add", po::value<string>(),
1262
("plugin-add", po::value<vector<string> >()->composing()->notifier(&compose_plugin_add),
1204
1263
N_("Optional comma separated list of plugins to load at startup in addition "
1205
1264
"to the default list of plugins. "
1206
1265
"[for example: --plugin_add=crc32,logger_gearman]"))
1207
("plugin-remove", po::value<string>(),
1266
("plugin-remove", po::value<vector<string> >()->composing()->notifier(&compose_plugin_remove),
1208
1267
N_("Optional comma separated list of plugins to not load at startup. Effectively "
1209
1268
"removes a plugin from the list of plugins to be loaded. "
1210
1269
"[for example: --plugin_remove=crc32,logger_gearman]"))
1211
("plugin-load", po::value<string>(),
1270
("plugin-load", po::value<string>()->notifier(¬ify_plugin_load)->default_value(PANDORA_PLUGIN_LIST),
1212
1271
N_("Optional comma separated list of plugins to load at starup instead of "
1213
1272
"the default plugin load list. "
1214
1273
"[for example: --plugin_load=crc32,logger_gearman]"))
1253
1312
" automatically convert it to an on-disk MyISAM table."))
1254
1313
("no-defaults", po::value<bool>()->default_value(false)->zero_tokens(),
1255
1314
N_("Configuration file defaults are not used if no-defaults is set"))
1256
("defaults-file", po::value<string>()->default_value(system_config_dir_drizzle),
1315
("defaults-file", po::value<vector<string> >()->composing()->notifier(&compose_defaults_file_list),
1257
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"))
1260
1321
po::parsed_options parsed= po::command_line_parser(argc, argv).
1272
1333
unireg_abort(1);
1276
if (! vm["no-defaults"].as<bool>())
1278
ifstream system_drizzle_ifs(vm["defaults-file"].as<string>().c_str());
1279
store(po::parse_config_file(system_drizzle_ifs, long_options), vm);
1336
if (not vm["no-defaults"].as<bool>())
1338
defaults_file_list.insert(defaults_file_list.begin(),
1339
system_config_file_drizzle);
1342
string config_conf_d_location(vm["config-dir"].as<string>());
1343
config_conf_d_location.append("/conf.d");
1344
CachedDirectory config_conf_d(config_conf_d_location);
1345
if (not config_conf_d.fail())
1348
for (CachedDirectory::Entries::const_iterator iter= config_conf_d.getEntries().begin();
1349
iter != config_conf_d.getEntries().end();
1352
string file_entry((*iter)->filename);
1354
if (not file_entry.empty()
1355
&& file_entry != "."
1356
&& file_entry != "..")
1358
string the_entry(config_conf_d_location);
1359
the_entry.push_back('/');
1360
the_entry.append(file_entry);
1361
defaults_file_list.push_back(the_entry);
1367
process_defaults_files();
1282
1368
po::notify(vm);
1395
1481
if (opt_help || opt_help_extended)
1396
1482
unireg_abort(0);
1398
po::parsed_options parsed= po::command_line_parser(unknown_options).
1399
options(plugin_options).extra_parser(parse_size_arg).
1400
allow_unregistered().run();
1402
vector<string> final_unknown_options=
1403
po::collect_unrecognized(parsed.options, po::include_positional);
1405
/* we do want to exit if there are any other unknown options */
1406
/** @TODO: We should perhaps remove allowed_unregistered() and catch the
1408
if (final_unknown_options.size() > 0)
1410
errmsg_printf(ERRMSG_LVL_ERROR,
1411
_("%s: Unknown options given (first unknown is '%s').\n"
1412
"Use --help to get a list of available options\n"),
1413
internal::my_progname, final_unknown_options[0].c_str());
1484
vector<string> final_unknown_options;
1487
po::parsed_options parsed=
1488
po::command_line_parser(unknown_options).
1489
options(plugin_options).extra_parser(parse_size_arg).run();
1491
final_unknown_options=
1492
po::collect_unrecognized(parsed.options, po::include_positional);
1419
1494
po::store(parsed, vm);
1423
errmsg_printf(ERRMSG_LVL_ERROR, _("Duplicate entry for command line option\n"));
1427
if (not vm["no-defaults"].as<bool>())
1429
ifstream system_drizzle_ifs(vm["defaults-file"].as<string>().c_str());
1430
store(po::parse_config_file(system_drizzle_ifs, long_options), vm);
1497
catch (po::invalid_command_line_syntax &err)
1499
errmsg_printf(ERRMSG_LVL_ERROR,
1501
"Use --help to get a list of available options\n"),
1502
internal::my_progname, err.what());
1505
catch (po::unknown_option &err)
1507
errmsg_printf(ERRMSG_LVL_ERROR,
1508
_("%s\nUse --help to get a list of available options\n"),
1433
1513
po::notify(vm);
1804
1884
N_("Optional comma separated list of plugins to load at startup in addition "
1805
1885
"to the default list of plugins. "
1806
1886
"[for example: --plugin_add=crc32,logger_gearman]"),
1807
(char**) &opt_plugin_add, (char**) &opt_plugin_add, 0,
1808
1888
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1809
1889
{"plugin_remove", OPT_PLUGIN_ADD,
1810
1890
N_("Optional comma separated list of plugins to not load at startup. Effectively "
1811
1891
"removes a plugin from the list of plugins to be loaded. "
1812
1892
"[for example: --plugin_remove=crc32,logger_gearman]"),
1813
(char**) &opt_plugin_remove, (char**) &opt_plugin_remove, 0,
1814
1894
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1815
1895
{"plugin_load", OPT_PLUGIN_LOAD,
1816
1896
N_("Optional comma separated list of plugins to load at starup instead of "
1817
1897
"the default plugin load list. "
1818
1898
"[for example: --plugin_load=crc32,logger_gearman]"),
1819
(char**) &opt_plugin_load, (char**) &opt_plugin_load, 0,
1820
1900
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1821
1901
{"preload_buffer_size", OPT_PRELOAD_BUFFER_SIZE,
1822
1902
N_("The size of the buffer that is allocated when preloading indexes"),
2133
2213
/* @TODO Make this all strings */
2134
if (vm.count("plugin-remove"))
2136
opt_plugin_remove= (char *)vm["plugin-remove"].as<string>().c_str();
2138
if (vm.count("plugin-add"))
2140
opt_plugin_add= (char *)vm["plugin-add"].as<string>().c_str();
2142
if (vm.count("plugin-load"))
2144
opt_plugin_load= (char *)vm["plugin-load"].as<string>().c_str();
2146
2214
if (vm.count("default-storage-engine"))
2148
2216
default_storage_engine_str= (char *)vm["default-storage-engine"].as<string>().c_str();