Skip to content

Commit

Permalink
core: use raw_log for critical path
Browse files Browse the repository at this point in the history
  • Loading branch information
Chilledheart committed Oct 22, 2024
1 parent 560f18b commit 7ad0b23
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/core/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ std::string GetHomeDir() {
return home_dir;
}
#if defined(__ANDROID__)
DLOG(WARNING) << "OS_ANDROID: Home directory lookup not yet implemented.";
RAW_LOG(ERROR, "OS_ANDROID: Home directory lookup not yet implemented.");
#endif
// Fall back on temp dir if no home directory is defined.
std::string rv;
Expand Down
4 changes: 2 additions & 2 deletions src/core/utils_freebsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ uint64_t GetMonotonicTime() {
if (!started) {
ret = clock_gettime(CLOCK_MONOTONIC, &start_ts);
if (ret < 0) {
PLOG(WARNING) << "clock_gettime failed";
RAW_LOG(FATAL, "clock_gettime failed");
return 0;
}
started = true;
Expand All @@ -40,7 +40,7 @@ uint64_t GetMonotonicTime() {

ret = clock_gettime(CLOCK_MONOTONIC, &ts);
if (ret < 0) {
PLOG(WARNING) << "clock_gettime failed";
RAW_LOG(FATAL, "clock_gettime failed");
return 0;
}
ts.tv_sec -= start_ts.tv_sec;
Expand Down
6 changes: 3 additions & 3 deletions src/core/utils_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ bool SetCurrentThreadName(const std::string& name) {
int err = prctl(PR_SET_NAME, name.c_str());
// We expect EPERM failures in sandboxed processes, just ignore those.
if (err < 0 && errno != EPERM)
PLOG(ERROR) << "prctl(PR_SET_NAME)";
RAW_LOG(WARNING, "prctl(PR_SET_NAME)");
return err == 0;
}

Expand All @@ -166,7 +166,7 @@ uint64_t GetMonotonicTime() {
if (!started) {
ret = clock_gettime(CLOCK_MONOTONIC_RAW, &start_ts);
if (ret < 0) {
PLOG(WARNING) << "clock_gettime failed";
RAW_LOG(FATAL, "clock_gettime failed");
return 0;
}
started = true;
Expand All @@ -175,7 +175,7 @@ uint64_t GetMonotonicTime() {

ret = clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
if (ret < 0) {
PLOG(WARNING) << "clock_gettime failed";
RAW_LOG(FATAL, "clock_gettime failed");
return 0;
}
ts.tv_sec -= start_ts.tv_sec;
Expand Down
4 changes: 2 additions & 2 deletions src/core/utils_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ bool GetExecutablePath(std::string* path) {
*path = link_path;
return true;
} else {
PLOG(WARNING) << "Internal error: realpath failed";
RAW_LOG(WARNING, "Internal error: realpath failed");
}
} else {
PLOG(WARNING) << "Internal error: _NSGetExecutablePath failed";
RAW_LOG(WARNING, "Internal error: _NSGetExecutablePath failed");
}
*path = main_exe_path;
return false;
Expand Down
36 changes: 18 additions & 18 deletions src/core/utils_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,18 @@ static uint64_t GetMonotonicTimeQPC() {

if (!started) {
if (!QueryPerformanceFrequency(&Frequency)) {
LOG(WARNING) << "QueryPerformanceFrequency failed";
RAW_LOG(FATAL, "QueryPerformanceFrequency failed");
return 0;
}
if (!QueryPerformanceCounter(&StartTime)) {
LOG(WARNING) << "QueryPerformanceCounter failed";
RAW_LOG(FATAL, "QueryPerformanceCounter failed");
return 0;
}
started = true;
}
// Activity to be timed
if (!QueryPerformanceCounter(&CurrentTime)) {
LOG(WARNING) << "QueryPerformanceCounter failed";
RAW_LOG(FATAL, "QueryPerformanceCounter failed");
return 0;
}

Expand Down Expand Up @@ -304,15 +304,15 @@ static void CheckDynamicLibraries() {
std::wstring exe(_MAX_PATH, L'\0');
const auto exeLength = GetModuleFileNameW(nullptr, const_cast<wchar_t*>(exe.c_str()), exe.size() + 1);
if (!exeLength || exeLength >= exe.size() + 1) {
PLOG(FATAL) << "Could not get executable path!";
RAW_LOG(FATAL, "Could not get executable path!");
}
exe.resize(exeLength);
const auto last1 = exe.find_last_of('\\');
const auto last2 = exe.find_last_of('/');
const auto last = std::max((last1 == std::wstring::npos) ? -1 : static_cast<int>(last1),
(last2 == std::wstring::npos) ? -1 : static_cast<int>(last2));
if (last < 0) {
LOG(FATAL) << "Could not get executable directory!";
RAW_LOG(FATAL, "Could not get executable directory!");
}
// In the ANSI version of this function,
// the name is limited to MAX_PATH characters.
Expand All @@ -337,7 +337,7 @@ static void CheckDynamicLibraries() {
if (error == ERROR_FILE_NOT_FOUND) {
return;
}
PLOG(FATAL) << "Could not enumerate executable path!";
RAW_LOG(FATAL, "Could not enumerate executable path!");
}

do {
Expand All @@ -350,13 +350,13 @@ static void CheckDynamicLibraries() {
[&findData](const wchar_t* dll) { return dll && _wcsicmp(dll, findData.cFileName) == 0; })) {
continue;
}
std::wostringstream os;
os << L"\nUnknown DLL library \"" << findData.cFileName << L"\" found in the directory with " << me << L".\n\n"
<< L"This may be a virus or a malicious program. \n\n"
<< L"Please remove all DLL libraries from this directory:\n\n"
<< exe.substr(0, last) << L"\n\n"
<< "Alternatively, you can move " << me << L" to a new directory.";
LOG(FATAL) << SysWideToUTF8(os.str());
std::ostringstream os;
os << "\nUnknown DLL library \"" << findData.cFileName << "\" found in the directory with " << me << ".\n\n"
<< "This may be a virus or a malicious program. \n\n"
<< "Please remove all DLL libraries from this directory:\n\n"
<< exe.substr(0, last) << "\n\n"
<< "Alternatively, you can move " << me << " to a new directory.";
RAW_LOG(FATAL, os.str().c_str());
} while (FindNextFileW(findHandle, &findData));
FindClose(findHandle);
}
Expand All @@ -372,13 +372,13 @@ bool EnableSecureDllLoading() {
if (!set_default_dll_directories) {
// Don't assert because this is known to be missing on Windows 7 without
// KB2533623.
PLOG(WARNING) << "SetDefaultDllDirectories unavailable";
RAW_LOG(WARNING, "SetDefaultDllDirectories unavailable");
CheckDynamicLibraries();
return true;
}

if (!set_default_dll_directories(LOAD_LIBRARY_SEARCH_SYSTEM32)) {
PLOG(WARNING) << "Encountered error calling SetDefaultDllDirectories!";
RAW_LOG(WARNING, "Encountered error calling SetDefaultDllDirectories!");
CheckDynamicLibraries();
return true;
}
Expand Down Expand Up @@ -417,7 +417,7 @@ void GetWindowsVersion(int* major, int* minor, int* build_number, int* os_type)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
if (!GetVersionExW(&version_info)) {
PLOG(WARNING) << "Interal error: GetVersionExW failed";
RAW_LOG(FATAL, "Interal error: GetVersionExW failed");
}
#pragma GCC diagnostic pop

Expand All @@ -433,7 +433,7 @@ void GetWindowsVersion(int* major, int* minor, int* build_number, int* os_type)
DWORD dwOsType;
// https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getproductinfo
if (!GetProductInfo(version_info.dwMajorVersion, version_info.dwMinorVersion, 0, 0, &dwOsType)) {
PLOG(WARNING) << "Interal error: GetProductInfo failed";
RAW_LOG(ERROR, "Interal error: GetProductInfo failed");
}

*os_type = dwOsType;
Expand Down Expand Up @@ -477,7 +477,7 @@ bool GetExecutablePath(std::wstring* exe_path) {
// Insufficient space is determined by a return value equal to the size of
// the buffer passed in.
if (len == 0 || len == _MAX_PATH) {
PLOG(WARNING) << "Internal error: GetModuleFileNameW failed";
RAW_LOG(FATAL, "Internal error: GetModuleFileNameW failed");
*exe_path = SysUTF8ToWide(main_exe_path);
return false;
}
Expand Down

0 comments on commit 7ad0b23

Please sign in to comment.