Skip to content

Commit

Permalink
use config->get<std::filesystem::path>("pid_directory") to obtain pid…
Browse files Browse the repository at this point in the history
… directory
  • Loading branch information
t-horikawa committed Sep 8, 2023
1 parent eb4d344 commit e26c1f4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
21 changes: 11 additions & 10 deletions src/tateyama/configuration/bootstrap_configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

namespace tateyama::configuration {

static const std::string_view DEFAULT_PID_DIR = "/tmp"; // NOLINT and obsolete
static const std::string_view PID_FILE_PREFIX = "tsurugi";
static const char *ENV_CONF = "TSURUGI_CONF"; // NOLINT
static const char *ENV_HOME = "TSURUGI_HOME"; // NOLINT
Expand Down Expand Up @@ -97,18 +96,20 @@ class bootstrap_configuration {
if (env_home != nullptr) {
configuration_->base_path(std::filesystem::path(env_home));
}
std::string directory{DEFAULT_PID_DIR};
if (auto system_config = configuration_->get_section("system"); system_config) {
if (auto pid_dir = system_config->get<std::string>("pid_directory"); pid_dir) {
directory = pid_dir.value();
if (auto pid_dir = system_config->get<std::filesystem::path>("pid_directory"); pid_dir) {
std::filesystem::path directory = pid_dir.value();

std::string pid_file_name(PID_FILE_PREFIX);
pid_file_name += "-";
pid_file_name += digest(std::filesystem::canonical(conf_file_).string());
pid_file_name += ".pid";
lock_file_ = directory / std::filesystem::path(pid_file_name);
valid_ = true;
return;
}
}
std::string pid_file_name(PID_FILE_PREFIX);
pid_file_name += "-";
pid_file_name += digest(std::filesystem::canonical(conf_file_).string());
pid_file_name += ".pid";
lock_file_ = std::filesystem::path(std::string(directory)) / std::filesystem::path(pid_file_name);
valid_ = true;
throw std::runtime_error("error in lock file location");
}
std::string digest(const std::string& path_string) {
auto hash = std::hash<std::string>{}(path_string);
Expand Down
2 changes: 1 addition & 1 deletion src/tateyama/server/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace jogasaki::utils {
"STOCK"
};

std::filesystem::path prepare(std::string location) {
std::filesystem::path prepare(const std::string& location) {
std::filesystem::path dir(location);
dir = dir / "dump";
if (!std::filesystem::exists(dir)) {
Expand Down

0 comments on commit e26c1f4

Please sign in to comment.