comparison Core/Toolbox.cpp @ 3459:cbbe0bb80bd4

explicit error message if missing /etc/localtime
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 09 Jul 2019 09:31:53 +0200
parents 962e5f00744b
children 7d72e43f4a2d
comparison
equal deleted inserted replaced
3458:4e34fd3e226a 3459:cbbe0bb80bd4
142 # endif 142 # endif
143 #endif 143 #endif
144 144
145 145
146 146
147 #if defined(__unix__) && ORTHANC_SANDBOXED != 1
148 # include "SystemToolbox.h" // Check out "InitializeGlobalLocale()"
149 #endif
150
147 151
148 152
149 namespace Orthanc 153 namespace Orthanc
150 { 154 {
151 void Toolbox::LinesIterator::FindEndOfLine() 155 void Toolbox::LinesIterator::FindEndOfLine()
1414 #if ORTHANC_ENABLE_LOCALE == 1 1418 #if ORTHANC_ENABLE_LOCALE == 1
1415 static std::auto_ptr<std::locale> globalLocale_; 1419 static std::auto_ptr<std::locale> globalLocale_;
1416 1420
1417 static bool SetGlobalLocale(const char* locale) 1421 static bool SetGlobalLocale(const char* locale)
1418 { 1422 {
1419 globalLocale_.reset(NULL);
1420
1421 try 1423 try
1422 { 1424 {
1423 if (locale == NULL) 1425 if (locale == NULL)
1424 { 1426 {
1425 LOG(WARNING) << "Falling back to system-wide default locale"; 1427 LOG(WARNING) << "Falling back to system-wide default locale";
1429 { 1431 {
1430 LOG(INFO) << "Using locale: \"" << locale << "\" for case-insensitive comparison of strings"; 1432 LOG(INFO) << "Using locale: \"" << locale << "\" for case-insensitive comparison of strings";
1431 globalLocale_.reset(new std::locale(locale)); 1433 globalLocale_.reset(new std::locale(locale));
1432 } 1434 }
1433 } 1435 }
1434 catch (std::runtime_error&) 1436 catch (std::runtime_error& e)
1435 { 1437 {
1438 LOG(ERROR) << "Cannot set globale locale to "
1439 << (locale ? std::string(locale) : "(null)")
1440 << ": " << e.what();
1441 globalLocale_.reset(NULL);
1436 } 1442 }
1437 1443
1438 return (globalLocale_.get() != NULL); 1444 return (globalLocale_.get() != NULL);
1439 } 1445 }
1440 1446
1535 } 1541 }
1536 1542
1537 void Toolbox::InitializeGlobalLocale(const char* locale) 1543 void Toolbox::InitializeGlobalLocale(const char* locale)
1538 { 1544 {
1539 InitializeIcu(); 1545 InitializeIcu();
1546
1547 #if defined(__unix__) && ORTHANC_SANDBOXED != 1
1548 static const char* LOCALTIME = "/etc/localtime";
1549
1550 if (!SystemToolbox::IsExistingFile(LOCALTIME))
1551 {
1552 // Check out file
1553 // "boost_1_69_0/libs/locale/src/icu/time_zone.cpp": Direct
1554 // access is made to this file if ICU is not used. Crash arises
1555 // in Boost if the file is a symbolic link to a non-existing
1556 // file (such as in Ubuntu 16.04 base Docker image).
1557 throw OrthancException(
1558 ErrorCode_InternalError,
1559 "On UNIX-like systems, the file " + std::string(LOCALTIME) +
1560 " must be present on the filesystem (install \"tzdata\" package on Debian)");
1561 }
1562 #endif
1540 1563
1541 // Make Orthanc use English, United States locale 1564 // Make Orthanc use English, United States locale
1542 // Linux: use "en_US.UTF-8" 1565 // Linux: use "en_US.UTF-8"
1543 // Windows: use "" 1566 // Windows: use ""
1544 // Wine: use NULL 1567 // Wine: use NULL