290
288
time_t server_start_time;
291
289
time_t flush_status_time;
293
char drizzle_home[FN_REFLEN], pidfile_name[FN_REFLEN], system_time_zone[30];
291
fs::path basedir(PREFIX);
293
fs::path secure_file_priv("");
295
fs::path system_config_dir(SYSCONFDIR);
298
char system_time_zone[30];
294
299
char *default_tz_name;
295
300
char glob_hostname[FN_REFLEN];
371
374
vector<string> unknown_options;
372
375
vector<string> defaults_file_list;
373
376
po::variables_map vm;
378
fs::path data_home(LOCALSTATEDIR);
379
fs::path full_data_home(LOCALSTATEDIR);
376
381
po::variables_map &getVariablesMap()
381
std::string& getDataHome()
386
fs::path& getDataHome()
383
static string data_home(LOCALSTATEDIR);
384
388
return data_home;
387
std::string& getDataHomeCatalog()
391
fs::path& getDataHomeCatalog()
389
static string data_home_catalog(getDataHome());
393
static fs::path data_home_catalog(getDataHome());
390
394
return data_home_catalog;
398
char **getDatadirPtr()
400
return &data_dir_ptr;
403
398
/****************************************************************************
404
399
** Code to end drizzled
527
519
google::protobuf::ShutdownProtobufLibrary();
530
(void) unlink(pidfile_name); // This may not always exist
522
(void) unlink(pid_file.file_string().c_str()); // This may not always exist
532
524
if (print_message && server_start_time)
533
525
errmsg_printf(ERRMSG_LVL_INFO, _(ER(ER_SHUTDOWN_COMPLETE)),internal::my_progname);
718
708
base_plugin_dir /= "plugin";
719
709
base_plugin_dir /= ".libs";
721
(void) internal::my_load_path(opt_plugin_dir, fs::path(fs::system_complete(base_plugin_dir)).file_string().c_str(), "");
724
static void notify_plugin_dir(string in_plugin_dir)
726
if (not in_plugin_dir.empty())
728
(void) internal::my_load_path(opt_plugin_dir, in_plugin_dir.c_str(), drizzle_home);
712
if (plugin_dir.root_directory() == "")
714
fs::path full_plugin_dir(fs::system_complete(base_plugin_dir));
715
full_plugin_dir /= plugin_dir;
716
plugin_dir= full_plugin_dir;
720
static void notify_plugin_dir(fs::path in_plugin_dir)
722
plugin_dir= in_plugin_dir;
723
if (plugin_dir.root_directory() == "")
725
fs::path full_plugin_dir(fs::system_complete(basedir));
726
full_plugin_dir /= plugin_dir;
727
plugin_dir= full_plugin_dir;
731
static void expand_secure_file_priv(fs::path in_secure_file_priv)
733
secure_file_priv= fs::system_complete(in_secure_file_priv);
732
736
static void check_limits_aii(uint64_t in_auto_increment_increment)
908
912
global_system_variables.max_sort_length= in_max_sort_length;
911
static void check_limits_mwlc(uint64_t in_min_examined_row_limit)
913
global_system_variables.min_examined_row_limit= ULONG_MAX;
914
if (in_min_examined_row_limit > ULONG_MAX)
916
cout << N_("Error: Invalid Value for min_examined_row_limit");
919
global_system_variables.min_examined_row_limit= in_min_examined_row_limit;
922
915
static void check_limits_osd(uint32_t in_optimizer_search_depth)
924
917
global_system_variables.optimizer_search_depth= 0;
1133
1126
iter != defaults_file_list.end();
1136
string file_location(vm["config-dir"].as<string>());
1129
fs::path file_location(system_config_dir);
1137
1130
if ((*iter)[0] != '/')
1139
1132
/* Relative path - add config dir */
1140
file_location.push_back('/');
1141
file_location.append(*iter);
1133
file_location /= *iter;
1145
1137
file_location= *iter;
1148
ifstream input_defaults_file(file_location.c_str());
1140
ifstream input_defaults_file(file_location.file_string().c_str());
1150
1142
po::parsed_options file_parsed=
1151
1143
dpo::parse_config_file(input_defaults_file, full_options, true);
1224
1216
strncpy(glob_hostname, STRING_WITH_LEN("localhost"));
1225
1217
errmsg_printf(ERRMSG_LVL_WARN, _("gethostname failed, using '%s' as hostname"),
1226
1218
glob_hostname);
1227
strncpy(pidfile_name, STRING_WITH_LEN("drizzle"));
1219
pid_file= "drizzle";
1230
strncpy(pidfile_name, glob_hostname, sizeof(pidfile_name)-5);
1231
strcpy(internal::fn_ext(pidfile_name),".pid"); // Add proper extension
1233
std::string system_config_dir_drizzle(SYSCONFDIR);
1234
system_config_dir_drizzle.append("/drizzle");
1223
pid_file= glob_hostname;
1225
pid_file.replace_extension(".pid");
1227
system_config_dir /= "drizzle";
1236
1228
std::string system_config_file_drizzle("drizzled.cnf");
1238
1230
config_options.add_options()
1242
1234
N_("Configuration file defaults are not used if no-defaults is set"))
1243
1235
("defaults-file", po::value<vector<string> >()->composing()->notifier(&compose_defaults_file_list),
1244
1236
N_("Configuration file to use"))
1245
("config-dir", po::value<string>()->default_value(system_config_dir_drizzle),
1237
("config-dir", po::value<fs::path>(&system_config_dir),
1246
1238
N_("Base location for config files"))
1247
("plugin-dir", po::value<string>()->notifier(¬ify_plugin_dir),
1239
("plugin-dir", po::value<fs::path>(&plugin_dir)->notifier(¬ify_plugin_dir),
1248
1240
N_("Directory for plugins."))
1268
1260
N_("Auto-increment columns are incremented by this"))
1269
1261
("auto-increment-offset", po::value<uint64_t>(&global_system_variables.auto_increment_offset)->default_value(1)->notifier(&check_limits_aio),
1270
1262
N_("Offset added to Auto-increment columns. Used when auto-increment-increment != 1"))
1271
("basedir,b", po::value<string>(),
1263
("basedir,b", po::value<fs::path>(&basedir),
1272
1264
N_("Path to installation directory. All paths are usually resolved "
1273
1265
"relative to this."))
1274
1266
("chroot,r", po::value<string>(),
1278
1270
("completion-type", po::value<uint32_t>(&global_system_variables.completion_type)->default_value(0)->notifier(&check_limits_completion_type),
1279
1271
N_("Default completion type."))
1280
1272
("core-file", N_("Write core on errors."))
1281
("datadir", po::value<string>(),
1273
("datadir", po::value<fs::path>(&data_home),
1282
1274
N_("Path to the database root."))
1283
1275
("default-storage-engine", po::value<string>(),
1284
1276
N_("Set the default storage engine for tables."))
1292
1284
N_("Set the language used for the month names and the days of the week."))
1293
1285
("log-warnings,W", po::value<bool>(&global_system_variables.log_warnings)->default_value(false)->zero_tokens(),
1294
1286
N_("Log some not critical warnings to the log file."))
1295
("pid-file", po::value<string>(),
1287
("pid-file", po::value<fs::path>(&pid_file),
1296
1288
N_("Pid file used by drizzled."))
1297
1289
("port-open-timeout", po::value<uint32_t>(&drizzled_bind_timeout)->default_value(0),
1298
1290
N_("Maximum time in seconds to wait for the port to become free. "))
1299
("secure-file-priv", po::value<string>(),
1291
("secure-file-priv", po::value<fs::path>(&secure_file_priv)->notifier(expand_secure_file_priv),
1300
1292
N_("Limit LOAD DATA, SELECT ... OUTFILE, and LOAD_FILE() to files "
1301
1293
"within specified directory"))
1302
1294
("server-id", po::value<uint32_t>(&server_id)->default_value(0),
1354
1346
N_("The number of bytes to use when sorting BLOB or TEXT values "
1355
1347
"(only the first max_sort_length bytes of each value are used; the "
1356
1348
"rest are ignored)."))
1357
("max-write-lock-count", po::value<uint64_t>(&max_write_lock_count)->default_value(ULONG_MAX)->notifier(&check_limits_mwlc),
1349
("max-write-lock-count", po::value<uint64_t>(&max_write_lock_count)->default_value(UINT64_MAX),
1358
1350
N_("After this many write locks, allow some read locks to run in between."))
1359
1351
("min-examined-row-limit", po::value<uint64_t>(&global_system_variables.min_examined_row_limit)->default_value(0)->notifier(&check_limits_merl),
1360
1352
N_("Don't log queries which examine less than min_examined_row_limit "
1441
1433
system_config_file_drizzle);
1444
string config_conf_d_location(vm["config-dir"].as<string>());
1445
config_conf_d_location.append("/conf.d");
1446
CachedDirectory config_conf_d(config_conf_d_location);
1436
fs::path config_conf_d_location(system_config_dir);
1437
config_conf_d_location /= "conf.d";
1439
CachedDirectory config_conf_d(config_conf_d_location.file_string());
1447
1440
if (not config_conf_d.fail())
1457
1450
&& file_entry != "."
1458
1451
&& file_entry != "..")
1460
string the_entry(config_conf_d_location);
1461
the_entry.push_back('/');
1462
the_entry.append(file_entry);
1463
defaults_file_list.push_back(the_entry);
1453
fs::path the_entry(config_conf_d_location);
1454
the_entry /= file_entry;
1455
defaults_file_list.push_back(the_entry.file_string());
1776
1768
{"basedir", 'b',
1777
1769
N_("Path to installation directory. All paths are usually resolved "
1778
1770
"relative to this."),
1779
(char**) &drizzle_home_ptr, (char**) &drizzle_home_ptr, 0, GET_STR, REQUIRED_ARG,
1771
NULL, NULL, 0, GET_STR, REQUIRED_ARG,
1780
1772
0, 0, 0, 0, 0, 0},
1781
1773
{"chroot", 'r',
1782
1774
N_("Chroot drizzled daemon during startup."),
1829
1821
{"pid-file", OPT_PID_FILE,
1830
1822
N_("Pid file used by drizzled."),
1831
(char**) &pidfile_name_ptr, (char**) &pidfile_name_ptr, 0, GET_STR,
1823
NULL, NULL, 0, GET_STR,
1832
1824
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1833
1825
{"port-open-timeout", OPT_PORT_OPEN_TIMEOUT,
1834
1826
N_("Maximum time in seconds to wait for the port to become free. "
1838
1830
{"secure-file-priv", OPT_SECURE_FILE_PRIV,
1839
1831
N_("Limit LOAD DATA, SELECT ... OUTFILE, and LOAD_FILE() to files "
1840
1832
"within specified directory"),
1841
(char**) &opt_secure_file_priv, (char**) &opt_secure_file_priv, 0,
1842
1834
GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1843
1835
{"server-id", OPT_SERVER_ID,
1844
1836
N_("Uniquely identifies the server instance in the community of "
2156
2146
character_set_filesystem= &my_charset_bin;
2158
2148
/* Things with default values that are not zero */
2159
drizzle_home_ptr= drizzle_home;
2160
pidfile_name_ptr= pidfile_name;
2161
2149
session_startup_options= (OPTION_AUTO_IS_NULL | OPTION_SQL_NOTES);
2162
2150
refresh_version= 1L; /* Increments on each reload */
2163
2151
global_thread_id= 1UL;
2228
2211
static void get_options()
2231
if (vm.count("base-dir"))
2233
strncpy(drizzle_home,vm["base-dir"].as<string>().c_str(),sizeof(drizzle_home)-1);
2236
if (vm.count("datadir"))
2238
getDataHome()= vm["datadir"].as<string>();
2240
string &data_home_catalog= getDataHomeCatalog();
2214
fs::path &data_home_catalog= getDataHomeCatalog();
2241
2215
data_home_catalog= getDataHome();
2242
data_home_catalog.push_back('/');
2243
data_home_catalog.append("local");
2216
data_home_catalog /= "local";
2245
2218
if (vm.count("user"))
2337
static const char *get_relative_path(const char *path)
2339
if (internal::test_if_hard_path(path) &&
2340
(strncmp(path, PREFIX, strlen(PREFIX)) == 0) &&
2341
strcmp(PREFIX,FN_ROOTDIR))
2343
if (strlen(PREFIX) < strlen(path))
2344
path+=(size_t) strlen(PREFIX);
2345
while (*path == FN_LIBCHAR)
2352
2305
static void fix_paths()
2354
char buff[FN_REFLEN],*pos,rp_buff[PATH_MAX];
2355
internal::convert_dirname(drizzle_home,drizzle_home,NULL);
2356
/* Resolve symlinks to allow 'drizzle_home' to be a relative symlink */
2357
#if defined(HAVE_BROKEN_REALPATH)
2358
internal::my_load_path(drizzle_home, drizzle_home, NULL);
2360
if (!realpath(drizzle_home,rp_buff))
2361
internal::my_load_path(rp_buff, drizzle_home, NULL);
2362
rp_buff[FN_REFLEN-1]= '\0';
2363
strcpy(drizzle_home,rp_buff);
2364
/* Ensure that drizzle_home ends in FN_LIBCHAR */
2365
pos= strchr(drizzle_home, '\0');
2367
if (pos[-1] != FN_LIBCHAR)
2372
(void) internal::my_load_path(drizzle_home, drizzle_home,""); // Resolve current dir
2374
fs::path pid_file_path(pidfile_name);
2307
fs::path pid_file_path(pid_file);
2375
2308
if (pid_file_path.root_path().string() == "")
2377
pid_file_path= fs::path(getDataHome());
2378
pid_file_path /= pidfile_name;
2380
strncpy(pidfile_name, pid_file_path.file_string().c_str(), sizeof(pidfile_name)-1);
2383
const char *sharedir= get_relative_path(PKGDATADIR);
2384
if (internal::test_if_hard_path(sharedir))
2385
strncpy(buff,sharedir,sizeof(buff)-1);
2388
strcpy(buff, drizzle_home);
2389
strncat(buff, sharedir, sizeof(buff)-strlen(drizzle_home)-1);
2391
internal::convert_dirname(buff,buff,NULL);
2310
pid_file_path= getDataHome();
2311
pid_file_path /= pid_file;
2313
pid_file= pid_file_path;
2393
2315
if (not opt_help)
2434
Convert the secure-file-priv option to system format, allowing
2435
a quick strcmp to check if read or write is in an allowed dir
2437
if (vm.count("secure-file-priv"))
2439
internal::convert_dirname(buff, vm["secure-file-priv"].as<string>().c_str(), NULL);
2440
free(opt_secure_file_priv);
2441
opt_secure_file_priv= strdup(buff);
2442
if (opt_secure_file_priv == NULL)
2447
2357
} /* namespace drizzled */