Fixed the Logging system to actually be able to handle errors. Database is also fixed to use directories.
This commit is contained in:
@@ -11,7 +11,7 @@ namespace ehs
|
||||
{
|
||||
int code = chdir(dir);
|
||||
if (code == -1)
|
||||
EHS_LOG_INT("Error", 0, strerror(errno));
|
||||
EHS_LOG_INT(LogType::ERR, 0, strerror(errno));
|
||||
}
|
||||
|
||||
Str_8 FileSystem::GetWorkingDir()
|
||||
@@ -19,7 +19,7 @@ namespace ehs
|
||||
char result[EHS_MAX_PATH];
|
||||
|
||||
if (!getcwd(result, EHS_MAX_PATH))
|
||||
EHS_LOG_INT("Error", 0, strerror(errno));
|
||||
EHS_LOG_INT(LogType::ERR, 0, strerror(errno));
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -27,6 +27,6 @@ namespace ehs
|
||||
void FileSystem::SetOwner(const Str_8& dir, const UInt_32 userId, const UInt_32 groupId)
|
||||
{
|
||||
if (chown(dir, userId, groupId) == -1)
|
||||
EHS_LOG_INT("Error", 0, strerror(errno));
|
||||
EHS_LOG_INT(LogType::ERR, 0, strerror(errno));
|
||||
}
|
||||
}
|
@@ -10,7 +10,7 @@ namespace ehs
|
||||
return;
|
||||
|
||||
if (!CloseHandle(hdl))
|
||||
EHS_LOG_INT("Error", 0, "Failed to uninitialize mutex with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to uninitialize mutex with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
}
|
||||
|
||||
Mutex::Mutex()
|
||||
@@ -43,7 +43,7 @@ namespace ehs
|
||||
hdl = CreateMutexW(nullptr, FALSE, nullptr);
|
||||
if (!hdl)
|
||||
{
|
||||
EHS_LOG_INT("Error", 0, "Failed to create mutex with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to create mutex with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace ehs
|
||||
return;
|
||||
|
||||
if (!CloseHandle(hdl))
|
||||
EHS_LOG_INT("Error", 0, "Failed to uninitialize mutex with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to uninitialize mutex with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
|
||||
initialized = false;
|
||||
}
|
||||
@@ -68,7 +68,7 @@ namespace ehs
|
||||
|
||||
if (WaitForSingleObject(hdl, EHS_INFINITE) == WAIT_FAILED)
|
||||
{
|
||||
EHS_LOG_INT("Error", 0, "Failed to lock mutex with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to lock mutex with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace ehs
|
||||
return;
|
||||
|
||||
if (!ReleaseMutex(hdl))
|
||||
EHS_LOG_INT("Error", 0, "Failed to unlock mutex with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to unlock mutex with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
|
||||
locked = false;
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@ namespace ehs
|
||||
return;
|
||||
|
||||
if (dlclose(hdl))
|
||||
EHS_LOG_INT("Error", 0, "Failed to close.");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to close.");
|
||||
}
|
||||
|
||||
Open::Open()
|
||||
@@ -77,7 +77,7 @@ namespace ehs
|
||||
hdl = dlopen(filePath, RTLD_LAZY);
|
||||
if (!hdl)
|
||||
{
|
||||
EHS_LOG_INT("Error", 0, dlerror());
|
||||
EHS_LOG_INT(LogType::ERR, 0, dlerror());
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -88,7 +88,7 @@ namespace ehs
|
||||
return;
|
||||
|
||||
if (dlclose(hdl))
|
||||
EHS_LOG_INT("Error", 0, "Failed to close.");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to close.");
|
||||
|
||||
hdl = nullptr;
|
||||
}
|
||||
@@ -102,7 +102,7 @@ namespace ehs
|
||||
if (!func)
|
||||
{
|
||||
dlerror();
|
||||
EHS_LOG_INT("Error", 0, "Undefined symbol, \"" + symbol + "\".");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Undefined symbol, \"" + symbol + "\".");
|
||||
Release();
|
||||
return nullptr;
|
||||
}
|
||||
|
@@ -13,7 +13,7 @@ namespace ehs
|
||||
return;
|
||||
|
||||
if (sem_destroy(&hdl) == -1)
|
||||
EHS_LOG_INT("Error", 0, "Failed to release semaphore with error #" + Str_8::FromNum(errno) + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to release semaphore with error #" + Str_8::FromNum(errno) + ".");
|
||||
|
||||
valid = false;
|
||||
}
|
||||
@@ -92,14 +92,14 @@ namespace ehs
|
||||
{
|
||||
sem_t* result = sem_open("/" + GetName(), O_CREAT | O_EXCL, S_IRUSR | S_IWUSR, GetInitial());
|
||||
if (!result)
|
||||
EHS_LOG_INT("Error", 0, "Failed to create semaphore with error #" + Str_8::FromNum(errno) + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to create semaphore with error #" + Str_8::FromNum(errno) + ".");
|
||||
|
||||
hdl = *result;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sem_init(&hdl, 0, GetInitial()) == -1)
|
||||
EHS_LOG_INT("Error", 0, "Failed to create semaphore with error #" + Str_8::FromNum(errno) + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to create semaphore with error #" + Str_8::FromNum(errno) + ".");
|
||||
}
|
||||
|
||||
valid = true;
|
||||
@@ -111,7 +111,7 @@ namespace ehs
|
||||
return;
|
||||
|
||||
if (sem_destroy(&hdl) == -1)
|
||||
EHS_LOG_INT("Error", 0, "Failed to release semaphore with error #" + Str_8::FromNum(errno) + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to release semaphore with error #" + Str_8::FromNum(errno) + ".");
|
||||
|
||||
hdl = {};
|
||||
|
||||
@@ -124,7 +124,7 @@ namespace ehs
|
||||
return;
|
||||
|
||||
if (sem_post(&hdl) == -1)
|
||||
EHS_LOG_INT("Error", 0, "Failed to signal semaphore with error #" + Str_8::FromNum(errno) + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to signal semaphore with error #" + Str_8::FromNum(errno) + ".");
|
||||
}
|
||||
|
||||
bool Semaphore::Wait(const UInt_32 timeout)
|
||||
@@ -148,7 +148,7 @@ namespace ehs
|
||||
{
|
||||
int code = errno;
|
||||
if (code != ETIMEDOUT)
|
||||
EHS_LOG_INT("Error", 0, "Failed to wait for semaphore with error #" + Str_8::FromNum(errno) + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to wait for semaphore with error #" + Str_8::FromNum(errno) + ".");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@@ -12,7 +12,7 @@ namespace ehs
|
||||
if (!CloseHandle(hdl))
|
||||
{
|
||||
DWORD code = GetLastError();
|
||||
EHS_LOG_INT("Error", 0, Str_8("Failed to free semaphore with error #") + code + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 0, Str_8("Failed to free semaphore with error #") + code + ".");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace ehs
|
||||
|
||||
hdl = CreateSemaphoreW(nullptr, (LONG)GetInitial(), EHS_SINT_32_MAX, UTF::To_16(GetName()));
|
||||
if (!hdl)
|
||||
EHS_LOG_INT("Error", 0, Str_8("Failed to create semaphore with error #") + GetLastError() + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 0, Str_8("Failed to create semaphore with error #") + GetLastError() + ".");
|
||||
}
|
||||
|
||||
void Semaphore::Release()
|
||||
@@ -93,7 +93,7 @@ namespace ehs
|
||||
if (!CloseHandle(hdl))
|
||||
{
|
||||
DWORD code = GetLastError();
|
||||
EHS_LOG_INT("Error", 0, Str_8("Failed to free semaphore with error #") + code + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 0, Str_8("Failed to free semaphore with error #") + code + ".");
|
||||
}
|
||||
hdl = nullptr;
|
||||
}
|
||||
@@ -104,7 +104,7 @@ namespace ehs
|
||||
return;
|
||||
|
||||
if (!ReleaseSemaphore(hdl, (LONG)inc, nullptr))
|
||||
EHS_LOG_INT("Error", 0, Str_8("Failed to release semaphore with error #") + GetLastError() + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 0, Str_8("Failed to release semaphore with error #") + GetLastError() + ".");
|
||||
}
|
||||
|
||||
bool Semaphore::Wait(const UInt_32 timeout)
|
||||
@@ -115,12 +115,12 @@ namespace ehs
|
||||
DWORD result = WaitForSingleObject(hdl, timeout);
|
||||
if (result == WAIT_ABANDONED)
|
||||
{
|
||||
EHS_LOG_INT("Error", 0, "Wait abandoned.");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Wait abandoned.");
|
||||
return false;
|
||||
}
|
||||
else if (result == WAIT_FAILED)
|
||||
{
|
||||
EHS_LOG_INT("Error", 1, Str_8("Wait failed with error #") + GetLastError() + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 1, Str_8("Wait failed with error #") + GetLastError() + ".");
|
||||
return false;
|
||||
}
|
||||
else if (result == WAIT_TIMEOUT)
|
||||
|
@@ -60,7 +60,7 @@ namespace ehs
|
||||
#if defined(EHS_OS_WINDOWS)
|
||||
hdl = CreateThread(nullptr, stackSize, (LPTHREAD_START_ROUTINE)cb, args, 0, (DWORD*)&id);
|
||||
if (!hdl)
|
||||
EHS_LOG_INT("Error", 0, "Failed to start thread with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to start thread with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
#elif defined(EHS_OS_LINUX)
|
||||
UInt_64* rArgs = new UInt_64[sizeof(UInt_64) * 2];
|
||||
rArgs[0] = (UInt_64)cb;
|
||||
@@ -79,7 +79,7 @@ namespace ehs
|
||||
unsigned int r = WaitForSingleObject(hdl, timeout);
|
||||
if (r == WAIT_ABANDONED)
|
||||
{
|
||||
EHS_LOG_INT("Error", 0, "Abandoned wait because a mutex was not released.");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Abandoned wait because a mutex was not released.");
|
||||
return false;
|
||||
}
|
||||
else if (r == WAIT_TIMEOUT)
|
||||
@@ -88,7 +88,7 @@ namespace ehs
|
||||
}
|
||||
else if (r == WAIT_FAILED)
|
||||
{
|
||||
EHS_LOG_INT("Error", 1, "Failed to wait for thread with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 1, "Failed to wait for thread with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ namespace ehs
|
||||
#elif defined(EHS_OS_LINUX)
|
||||
int code = pthread_join((pthread_t)hdl, nullptr);
|
||||
if (code != 0)
|
||||
EHS_LOG_INT("Error", 1, "Failed to wait for thread with error #" + Str_8::FromNum(code) + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 1, "Failed to wait for thread with error #" + Str_8::FromNum(code) + ".");
|
||||
|
||||
hdl = EHS_INVALID_THREAD;
|
||||
#endif
|
||||
@@ -112,7 +112,7 @@ namespace ehs
|
||||
#if defined(EHS_OS_WINDOWS)
|
||||
if (!CloseHandle(hdl))
|
||||
{
|
||||
EHS_LOG_INT("Error", 0, "Failed to detach thread with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to detach thread with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
return;
|
||||
}
|
||||
#elif defined(EHS_OS_LINUX)
|
||||
@@ -155,7 +155,7 @@ namespace ehs
|
||||
|
||||
taskHdl = AvSetMmThreadCharacteristicsW(UTF::To_16(task), (LPDWORD)&taskIndex);
|
||||
if (!taskHdl)
|
||||
EHS_LOG_INT("Error", 0, "Failed to set the thread's characteristics with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to set the thread's characteristics with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
}
|
||||
|
||||
void Thread::SetTaskType_16(const Str_16& task)
|
||||
@@ -165,7 +165,7 @@ namespace ehs
|
||||
|
||||
taskHdl = AvSetMmThreadCharacteristicsW(task, (LPDWORD)&taskIndex);
|
||||
if (!taskHdl)
|
||||
EHS_LOG_INT("Error", 0, "Failed to set the thread's characteristics with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to set the thread's characteristics with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
}
|
||||
|
||||
void Thread::SetTaskType_8(const Str_8& task)
|
||||
@@ -175,7 +175,7 @@ namespace ehs
|
||||
|
||||
taskHdl = AvSetMmThreadCharacteristicsW(UTF::To_16(task), (LPDWORD)&taskIndex);
|
||||
if (!taskHdl)
|
||||
EHS_LOG_INT("Error", 0, "Failed to set the thread's characteristics with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to set the thread's characteristics with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
}
|
||||
|
||||
void Thread::RevertTaskType()
|
||||
@@ -184,7 +184,7 @@ namespace ehs
|
||||
return;
|
||||
|
||||
if (!AvRevertMmThreadCharacteristics(taskHdl))
|
||||
EHS_LOG_INT("Error", 0, "Failed to revert the thread's characteristics with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to revert the thread's characteristics with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
|
||||
taskIndex = 0;
|
||||
}
|
||||
@@ -212,7 +212,7 @@ namespace ehs
|
||||
|
||||
mainTaskHdl = AvSetMmThreadCharacteristicsW(UTF::To_16(task), (LPDWORD)&mainTaskIndex);
|
||||
if (!mainTaskHdl)
|
||||
EHS_LOG_INT("Error", 0, "Failed to set the main thread's characteristics with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to set the main thread's characteristics with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
}
|
||||
|
||||
void Thread::SetMainTaskType_16(const Str_16& task)
|
||||
@@ -222,7 +222,7 @@ namespace ehs
|
||||
|
||||
mainTaskHdl = AvSetMmThreadCharacteristicsW(task, (LPDWORD)&mainTaskIndex);
|
||||
if (!mainTaskHdl)
|
||||
EHS_LOG_INT("Error", 0, "Failed to set the main thread's characteristics with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to set the main thread's characteristics with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
}
|
||||
|
||||
void Thread::SetMainTaskType_8(const Str_8& task)
|
||||
@@ -232,7 +232,7 @@ namespace ehs
|
||||
|
||||
mainTaskHdl = AvSetMmThreadCharacteristicsW(UTF::To_16(task), (LPDWORD)&mainTaskIndex);
|
||||
if (!mainTaskHdl)
|
||||
EHS_LOG_INT("Error", 0, "Failed to set the main thread's characteristics with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to set the main thread's characteristics with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
}
|
||||
|
||||
void Thread::RevertMainTaskType()
|
||||
@@ -241,7 +241,7 @@ namespace ehs
|
||||
return;
|
||||
|
||||
if (!AvRevertMmThreadCharacteristics(mainTaskHdl))
|
||||
EHS_LOG_INT("Error", 0, "Failed to revert the main thread's characteristics with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to revert the main thread's characteristics with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
|
||||
mainTaskIndex = 0;
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ namespace ehs
|
||||
void User::GetId(UInt_32* const real, UInt_32* const effective, UInt_32* const saved)
|
||||
{
|
||||
if (getresuid(real, effective, saved) == -1)
|
||||
EHS_LOG_INT("Error", 0, strerror(errno));
|
||||
EHS_LOG_INT(LogType::ERR, 0, strerror(errno));
|
||||
}
|
||||
|
||||
Str_8 User::GetName()
|
||||
@@ -18,7 +18,7 @@ namespace ehs
|
||||
SInt_64 max = sysconf(_SC_LOGIN_NAME_MAX);
|
||||
if (max == -1)
|
||||
{
|
||||
EHS_LOG_INT("Error", 0, strerror(errno));
|
||||
EHS_LOG_INT(LogType::ERR, 0, strerror(errno));
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace ehs
|
||||
if (getlogin_r(name, max) == -1)
|
||||
{
|
||||
delete[] name;
|
||||
EHS_LOG_INT("Error", 1, strerror(errno));
|
||||
EHS_LOG_INT(LogType::ERR, 1, strerror(errno));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user