mirror of
https://github.com/monero-project/monero.git
synced 2024-11-18 00:37:43 +00:00
Fix startup crash when using a locale boost does not like
There are various locale related bugs in various versions of boost, where exceptions are thrown in boost::filesystem APIs when the current locale is not to boost's liking. It's not clear what "not to boost's liking" means in detail, though "en" and "en_US.UTF-8" are not to its liking. Fix it by running a test function that's known to throw in such a case, and resetting LANG and LC_ALL to C if an exception is thrown. In simplewallet, the locale is queried before that so the correct translations will still be used.
This commit is contained in:
parent
0c1dae32b4
commit
f3724aef88
7 changed files with 33 additions and 1 deletions
|
@ -94,6 +94,8 @@ int main(int argc, char* argv[])
|
||||||
uint32_t log_level = 0;
|
uint32_t log_level = 0;
|
||||||
uint64_t block_stop = 0;
|
uint64_t block_stop = 0;
|
||||||
|
|
||||||
|
tools::sanitize_locale();
|
||||||
|
|
||||||
boost::filesystem::path default_data_path {tools::get_default_data_dir()};
|
boost::filesystem::path default_data_path {tools::get_default_data_dir()};
|
||||||
boost::filesystem::path default_testnet_data_path {default_data_path / "testnet"};
|
boost::filesystem::path default_testnet_data_path {default_data_path / "testnet"};
|
||||||
boost::filesystem::path output_file_path;
|
boost::filesystem::path output_file_path;
|
||||||
|
|
|
@ -42,6 +42,8 @@ int main(int argc, char* argv[])
|
||||||
uint64_t block_stop = 0;
|
uint64_t block_stop = 0;
|
||||||
bool blocks_dat = false;
|
bool blocks_dat = false;
|
||||||
|
|
||||||
|
tools::sanitize_locale();
|
||||||
|
|
||||||
boost::filesystem::path default_data_path {tools::get_default_data_dir()};
|
boost::filesystem::path default_data_path {tools::get_default_data_dir()};
|
||||||
boost::filesystem::path default_testnet_data_path {default_data_path / "testnet"};
|
boost::filesystem::path default_testnet_data_path {default_data_path / "testnet"};
|
||||||
boost::filesystem::path output_file_path;
|
boost::filesystem::path output_file_path;
|
||||||
|
|
|
@ -538,6 +538,8 @@ int main(int argc, char* argv[])
|
||||||
std::string m_config_folder;
|
std::string m_config_folder;
|
||||||
std::string db_arg_str;
|
std::string db_arg_str;
|
||||||
|
|
||||||
|
tools::sanitize_locale();
|
||||||
|
|
||||||
boost::filesystem::path default_data_path {tools::get_default_data_dir()};
|
boost::filesystem::path default_data_path {tools::get_default_data_dir()};
|
||||||
boost::filesystem::path default_testnet_data_path {default_data_path / "testnet"};
|
boost::filesystem::path default_testnet_data_path {default_data_path / "testnet"};
|
||||||
std::string import_file_path;
|
std::string import_file_path;
|
||||||
|
|
|
@ -43,6 +43,7 @@ using namespace epee;
|
||||||
#else
|
#else
|
||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace tools
|
namespace tools
|
||||||
|
@ -389,4 +390,22 @@ std::string get_nix_version_display_string()
|
||||||
#endif
|
#endif
|
||||||
return std::error_code(code, std::system_category());
|
return std::error_code(code, std::system_category());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool sanitize_locale()
|
||||||
|
{
|
||||||
|
// boost::filesystem throws for "invalid" locales, such as en_US.UTF-8, or kjsdkfs,
|
||||||
|
// so reset it here before any calls to it
|
||||||
|
try
|
||||||
|
{
|
||||||
|
boost::filesystem::path p {std::string("test")};
|
||||||
|
p /= std::string("test");
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
setenv("LC_ALL", "C", 1);
|
||||||
|
setenv("LANG", "C", 1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,6 +88,8 @@ namespace tools
|
||||||
*/
|
*/
|
||||||
std::error_code replace_file(const std::string& replacement_name, const std::string& replaced_name);
|
std::error_code replace_file(const std::string& replacement_name, const std::string& replaced_name);
|
||||||
|
|
||||||
|
bool sanitize_locale();
|
||||||
|
|
||||||
inline crypto::hash get_proof_of_trust_hash(const nodetool::proof_of_trust& pot)
|
inline crypto::hash get_proof_of_trust_hash(const nodetool::proof_of_trust& pot)
|
||||||
{
|
{
|
||||||
std::string s;
|
std::string s;
|
||||||
|
|
|
@ -54,6 +54,8 @@ int main(int argc, char const * argv[])
|
||||||
_note_c("dbg/main", "Begin of main()");
|
_note_c("dbg/main", "Begin of main()");
|
||||||
// TODO parse the debug options like set log level right here at start
|
// TODO parse the debug options like set log level right here at start
|
||||||
|
|
||||||
|
tools::sanitize_locale();
|
||||||
|
|
||||||
epee::string_tools::set_module_name_and_folder(argv[0]);
|
epee::string_tools::set_module_name_and_folder(argv[0]);
|
||||||
|
|
||||||
// Build argument description
|
// Build argument description
|
||||||
|
|
|
@ -2164,6 +2164,9 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
//TRY_ENTRY();
|
//TRY_ENTRY();
|
||||||
|
|
||||||
|
std::string lang = i18n_get_language();
|
||||||
|
tools::sanitize_locale();
|
||||||
|
|
||||||
string_tools::set_module_name_and_folder(argv[0]);
|
string_tools::set_module_name_and_folder(argv[0]);
|
||||||
|
|
||||||
po::options_description desc_general(sw::tr("General options"));
|
po::options_description desc_general(sw::tr("General options"));
|
||||||
|
@ -2212,7 +2215,7 @@ int main(int argc, char* argv[])
|
||||||
po::positional_options_description positional_options;
|
po::positional_options_description positional_options;
|
||||||
positional_options.add(arg_command.name, -1);
|
positional_options.add(arg_command.name, -1);
|
||||||
|
|
||||||
i18n_set_language("translations", "monero");
|
i18n_set_language("translations", "monero", lang);
|
||||||
|
|
||||||
po::options_description desc_all;
|
po::options_description desc_all;
|
||||||
desc_all.add(desc_general).add(desc_params);
|
desc_all.add(desc_general).add(desc_params);
|
||||||
|
|
Loading…
Reference in a new issue