mirror of
https://github.com/reactos/reactos.git
synced 2025-01-03 21:09:19 +00:00
Reduce code dublication
svn path=/trunk/; revision=22737
This commit is contained in:
parent
ff6b13eb13
commit
36e0982b7e
4 changed files with 34 additions and 55 deletions
|
@ -178,7 +178,8 @@ BOOL LoadLogFiles(HKEY eventlogKey)
|
|||
INT main()
|
||||
{
|
||||
WCHAR LogPath[MAX_PATH];
|
||||
PLOGFILE pLogf;
|
||||
PLOGFILE pLogf;
|
||||
INT RetCode = 0;
|
||||
LONG result;
|
||||
HKEY elogKey;
|
||||
|
||||
|
@ -189,15 +190,8 @@ INT main()
|
|||
if(MyHeap==NULL)
|
||||
{
|
||||
DPRINT1("FATAL ERROR, can't create heap.\n");
|
||||
|
||||
DeleteCriticalSection(&LogListCs);
|
||||
// Close all log files.
|
||||
for(pLogf = LogListHead; pLogf; pLogf = ((PLOGFILE)pLogf)->Next)
|
||||
{
|
||||
LogfClose(pLogf);
|
||||
}
|
||||
|
||||
return 1;
|
||||
RetCode = 1;
|
||||
goto bye_bye;
|
||||
}
|
||||
|
||||
GetWindowsDirectory(LogPath, MAX_PATH);
|
||||
|
@ -217,17 +211,8 @@ INT main()
|
|||
if(result != ERROR_SUCCESS)
|
||||
{
|
||||
DPRINT1("Fatal error: can't open eventlog registry key.\n");
|
||||
|
||||
DeleteCriticalSection(&LogListCs);
|
||||
|
||||
// Close all log files.
|
||||
for(pLogf = LogListHead; pLogf; pLogf = ((PLOGFILE)pLogf)->Next)
|
||||
{
|
||||
LogfClose(pLogf);
|
||||
}
|
||||
|
||||
HeapDestroy(MyHeap);
|
||||
return 1;
|
||||
RetCode = 1;
|
||||
goto bye_bye;
|
||||
}
|
||||
|
||||
LoadLogFiles(elogKey);
|
||||
|
@ -235,16 +220,16 @@ INT main()
|
|||
|
||||
StartServiceCtrlDispatcher(ServiceTable);
|
||||
|
||||
bye_bye:
|
||||
DeleteCriticalSection(&LogListCs);
|
||||
|
||||
// Close all log files.
|
||||
for(pLogf = LogListHead; pLogf; pLogf = ((PLOGFILE)pLogf)->Next)
|
||||
{
|
||||
LogfClose(pLogf);
|
||||
}
|
||||
|
||||
HeapDestroy(MyHeap);
|
||||
return 0;
|
||||
if(MyHeap) HeapDestroy(MyHeap);
|
||||
|
||||
return RetCode;
|
||||
}
|
||||
|
||||
VOID EventTimeToSystemTime(DWORD EventTime,
|
||||
|
|
|
@ -140,7 +140,7 @@ BOOL LogfAddOffsetInformation(PLOGFILE LogFile,
|
|||
ULONG ulNumber,
|
||||
ULONG ulOffset);
|
||||
|
||||
DWORD LogfBuildNewRecord(PBYTE Buffer,
|
||||
PBYTE LogfAllocAndBuildNewRecord(LPDWORD lpRecSize,
|
||||
DWORD dwRecordNumber,
|
||||
WORD wType,
|
||||
WORD wCategory,
|
||||
|
@ -154,6 +154,8 @@ DWORD LogfBuildNewRecord(PBYTE Buffer,
|
|||
DWORD dwDataSize,
|
||||
LPVOID lpRawData);
|
||||
|
||||
inline void LogfFreeRecord(LPVOID Rec);
|
||||
|
||||
/* eventlog.c */
|
||||
VOID PRINT_HEADER(PFILE_HEADER header);
|
||||
|
||||
|
|
|
@ -618,7 +618,7 @@ BOOL LogfAddOffsetInformation(PLOGFILE LogFile,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
DWORD LogfBuildNewRecord(PBYTE Buffer,
|
||||
PBYTE LogfAllocAndBuildNewRecord(LPDWORD lpRecSize,
|
||||
DWORD dwRecordNumber,
|
||||
WORD wType,
|
||||
WORD wCategory,
|
||||
|
@ -637,6 +637,7 @@ DWORD LogfBuildNewRecord(PBYTE Buffer,
|
|||
SYSTEMTIME SysTime;
|
||||
WCHAR *str;
|
||||
UINT i, pos, nStrings;
|
||||
PBYTE Buffer;
|
||||
|
||||
dwRecSize = sizeof(EVENTLOGRECORD) + (lstrlenW(ComputerName) +
|
||||
lstrlenW(SourceName) + 2)*sizeof(WCHAR);
|
||||
|
@ -654,12 +655,13 @@ DWORD LogfBuildNewRecord(PBYTE Buffer,
|
|||
if(dwRecSize % 4 != 0) dwRecSize += 4 - (dwRecSize % 4);
|
||||
dwRecSize+=4;
|
||||
|
||||
Buffer = HeapAlloc(MyHeap, HEAP_ZERO_MEMORY, dwRecSize);
|
||||
if(!Buffer)
|
||||
{
|
||||
return dwRecSize;
|
||||
DPRINT1("Can't allocate heap!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ZeroMemory(Buffer, dwRecSize);
|
||||
pRec = (PEVENTLOGRECORD)Buffer;
|
||||
pRec->Length = dwRecSize;
|
||||
pRec->Reserved = LOGFILE_SIGNATURE;
|
||||
|
@ -711,6 +713,12 @@ DWORD LogfBuildNewRecord(PBYTE Buffer,
|
|||
|
||||
if(pos % 4 != 0) pos += 4 - (pos % 4);
|
||||
*((PDWORD)(Buffer+pos)) = dwRecSize;
|
||||
|
||||
return TRUE;
|
||||
|
||||
*lpRecSize = dwRecSize;
|
||||
return Buffer;
|
||||
}
|
||||
|
||||
inline void LogfFreeRecord(LPVOID Rec)
|
||||
{
|
||||
HeapFree(MyHeap, 0, Rec);
|
||||
}
|
||||
|
|
|
@ -120,7 +120,8 @@ NTSTATUS ProcessPortMessage(VOID)
|
|||
IO_ERROR_LPC Request;
|
||||
PIO_ERROR_LOG_MESSAGE Message;
|
||||
PEVENTLOGRECORD pRec;
|
||||
ULONG ulRecNum, ulRecSize ;
|
||||
ULONG ulRecNum;
|
||||
DWORD dwRecSize;
|
||||
NTSTATUS Status;
|
||||
PLOGFILE SystemLog = NULL;
|
||||
|
||||
|
@ -160,7 +161,7 @@ NTSTATUS ProcessPortMessage(VOID)
|
|||
Message = (PIO_ERROR_LOG_MESSAGE)&Request.Message;
|
||||
ulRecNum = SystemLog ? SystemLog->Header.NextRecord : 0;
|
||||
|
||||
ulRecSize = LogfBuildNewRecord(NULL,
|
||||
pRec = (PEVENTLOGRECORD)LogfAllocAndBuildNewRecord(&dwRecSize,
|
||||
ulRecNum,
|
||||
Message->Type,
|
||||
Message->EntryData.EventCategory,
|
||||
|
@ -175,30 +176,13 @@ NTSTATUS ProcessPortMessage(VOID)
|
|||
(LPVOID)(((PBYTE)Message)
|
||||
+sizeof(IO_ERROR_LOG_PACKET)-sizeof(ULONG)));
|
||||
|
||||
DPRINT("ulRecSize = %d\n", ulRecSize);
|
||||
|
||||
pRec = HeapAlloc(MyHeap, 0, ulRecSize);
|
||||
|
||||
if(pRec == NULL)
|
||||
{
|
||||
DPRINT("Can't allocate heap!\n");
|
||||
DPRINT("LogfAllocAndBuildNewRecord failed!\n");
|
||||
return STATUS_NO_MEMORY;
|
||||
}
|
||||
|
||||
LogfBuildNewRecord((PBYTE)pRec,
|
||||
ulRecNum,
|
||||
Message->Type,
|
||||
Message->EntryData.EventCategory,
|
||||
Message->EntryData.ErrorCode,
|
||||
(WCHAR*)(((PBYTE)Message)+Message->DriverNameOffset),
|
||||
L"MyComputer", /* FIXME */
|
||||
0,
|
||||
NULL,
|
||||
Message->EntryData.NumberOfStrings,
|
||||
(WCHAR*)(((PBYTE)Message)+Message->EntryData.StringOffset),
|
||||
Message->EntryData.DumpDataSize,
|
||||
(LPVOID)(((PBYTE)Message)
|
||||
+sizeof(IO_ERROR_LOG_PACKET)-sizeof(ULONG)));
|
||||
|
||||
DPRINT("dwRecSize = %d\n", dwRecSize);
|
||||
|
||||
DPRINT("\n --- EVENTLOG RECORD ---\n");
|
||||
PRINT_RECORD(pRec);
|
||||
|
@ -206,12 +190,12 @@ NTSTATUS ProcessPortMessage(VOID)
|
|||
|
||||
if(!onLiveCD && SystemLog)
|
||||
{
|
||||
if(!LogfWriteData(SystemLog, ulRecSize, (PBYTE)pRec))
|
||||
if(!LogfWriteData(SystemLog, dwRecSize, (PBYTE)pRec))
|
||||
DPRINT("LogfWriteData failed!\n");
|
||||
else DPRINT("Data written to Log!\n");
|
||||
}
|
||||
|
||||
HeapFree(MyHeap, 0, pRec);
|
||||
LogfFreeRecord(pRec);
|
||||
}
|
||||
}
|
||||
return Status;
|
||||
|
|
Loading…
Reference in a new issue