Author: ekohl
Date: Mon Dec 26 13:54:05 2011
New Revision: 54763
URL:
http://svn.reactos.org/svn/reactos?rev=54763&view=rev
Log:
[EVENTLOG]
- Replace the log file critical section by a resource and use shared locks for read
actions and exclusive locks for write actions.
- Add stubs for clear and backup actions.
Modified:
trunk/reactos/base/services/eventlog/eventlog.h
trunk/reactos/base/services/eventlog/file.c
trunk/reactos/base/services/eventlog/rpc.c
Modified: trunk/reactos/base/services/eventlog/eventlog.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/eventlog/eve…
==============================================================================
--- trunk/reactos/base/services/eventlog/eventlog.h [iso-8859-1] (original)
+++ trunk/reactos/base/services/eventlog/eventlog.h [iso-8859-1] Mon Dec 26 13:54:05 2011
@@ -88,7 +88,7 @@
EVENTLOGHEADER Header;
WCHAR *LogName;
WCHAR *FileName;
- CRITICAL_SECTION cs;
+ RTL_RESOURCE Lock;
PEVENT_OFFSET_INFO OffsetInfo;
ULONG OffsetInfoSize;
ULONG OffsetInfoNext;
@@ -140,6 +140,14 @@
BOOL LogfWriteData(PLOGFILE LogFile,
DWORD BufSize,
PBYTE Buffer);
+
+NTSTATUS
+LogfClearFile(PLOGFILE LogFile,
+ PUNICODE_STRING BackupFileName);
+
+NTSTATUS
+LogfBackupFile(PLOGFILE LogFile,
+ PUNICODE_STRING BackupFileName);
PLOGFILE LogfCreate(WCHAR * LogName,
WCHAR * FileName);
Modified: trunk/reactos/base/services/eventlog/file.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/eventlog/fil…
==============================================================================
--- trunk/reactos/base/services/eventlog/file.c [iso-8859-1] (original)
+++ trunk/reactos/base/services/eventlog/file.c [iso-8859-1] Mon Dec 26 13:54:05 2011
@@ -364,7 +364,8 @@
if (!bResult)
goto fail;
- InitializeCriticalSection(&LogFile->cs);
+ RtlInitializeResource(&LogFile->Lock);
+
LogfListAddItem(LogFile);
return LogFile;
@@ -391,13 +392,13 @@
if (LogFile == NULL)
return;
- EnterCriticalSection(&LogFile->cs);
+ RtlAcquireResourceExclusive(&LogFile->Lock, TRUE);
FlushFileBuffers(LogFile->hFile);
CloseHandle(LogFile->hFile);
LogfListRemoveItem(LogFile);
- DeleteCriticalSection(&LogFile->cs);
+ RtlDeleteResource(&LogFile->Lock);
HeapFree(MyHeap, 0, LogFile->LogName);
HeapFree(MyHeap, 0, LogFile->FileName);
@@ -727,7 +728,8 @@
}
dwRecNum = *RecordNumber;
- EnterCriticalSection(&LogFile->cs);
+
+ RtlAcquireResourceShared(&LogFile->Lock, TRUE);
*BytesRead = 0;
*BytesNeeded = 0;
@@ -736,7 +738,7 @@
if (!dwOffset)
{
- LeaveCriticalSection(&LogFile->cs);
+ RtlReleaseResource(&LogFile->Lock);
return ERROR_HANDLE_EOF;
}
@@ -756,7 +758,7 @@
if (dwRecSize > BufSize)
{
*BytesNeeded = dwRecSize;
- LeaveCriticalSection(&LogFile->cs);
+ RtlReleaseResource(&LogFile->Lock);
return ERROR_INSUFFICIENT_BUFFER;
}
@@ -857,12 +859,12 @@
*BytesRead = dwBufferUsage;
* RecordNumber = dwRecNum;
- LeaveCriticalSection(&LogFile->cs);
+ RtlReleaseResource(&LogFile->Lock);
return ERROR_SUCCESS;
Done:
DPRINT1("LogfReadEvent failed with %x\n",GetLastError());
- LeaveCriticalSection(&LogFile->cs);
+ RtlReleaseResource(&LogFile->Lock);
return GetLastError();
}
@@ -883,11 +885,11 @@
GetSystemTime(&st);
SystemTimeToEventTime(&st, &((PEVENTLOGRECORD) Buffer)->TimeWritten);
- EnterCriticalSection(&LogFile->cs);
+ RtlAcquireResourceExclusive(&LogFile->Lock, TRUE);
if (!GetFileSizeEx(LogFile->hFile, &logFileSize))
{
- LeaveCriticalSection(&LogFile->cs);
+ RtlReleaseResource(&LogFile->Lock);
return FALSE;
}
@@ -906,7 +908,7 @@
{
DPRINT1("Failed to allocate buffer for OldestRecord!\n");
HeapFree(GetProcessHeap(), 0, RecBuf);
- LeaveCriticalSection(&LogFile->cs);
+ RtlReleaseResource(&LogFile->Lock);
return FALSE;
}
@@ -920,7 +922,7 @@
{
DPRINT1("SetFilePointer() failed! %d\n", GetLastError());
HeapFree(GetProcessHeap(), 0, RecBuf);
- LeaveCriticalSection(&LogFile->cs);
+ RtlReleaseResource(&LogFile->Lock);
return FALSE;
}
@@ -928,14 +930,14 @@
{
DPRINT1("ReadFile() failed!\n");
HeapFree(GetProcessHeap(), 0, RecBuf);
- LeaveCriticalSection(&LogFile->cs);
+ RtlReleaseResource(&LogFile->Lock);
return FALSE;
}
if (RecBuf->Reserved != LOGFILE_SIGNATURE)
{
DPRINT1("LogFile corrupt!\n");
- LeaveCriticalSection(&LogFile->cs);
+ RtlReleaseResource(&LogFile->Lock);
return FALSE;
}
@@ -963,14 +965,14 @@
FILE_BEGIN) == INVALID_SET_FILE_POINTER)
{
DPRINT1("SetFilePointer() failed! %d\n", GetLastError());
- LeaveCriticalSection(&LogFile->cs);
+ RtlReleaseResource(&LogFile->Lock);
return FALSE;
}
if (!WriteFile(LogFile->hFile, Buffer, BufSize, &dwWritten, NULL))
{
DPRINT1("WriteFile() failed! %d\n", GetLastError());
- LeaveCriticalSection(&LogFile->cs);
+ RtlReleaseResource(&LogFile->Lock);
return FALSE;
}
@@ -978,7 +980,7 @@
LogFile->Header.CurrentRecordNumber,
WriteOffSet))
{
- LeaveCriticalSection(&LogFile->cs);
+ RtlReleaseResource(&LogFile->Lock);
return FALSE;
}
@@ -997,7 +999,7 @@
FILE_BEGIN) == INVALID_SET_FILE_POINTER)
{
DPRINT1("SetFilePointer() failed! %d\n", GetLastError());
- LeaveCriticalSection(&LogFile->cs);
+ RtlReleaseResource(&LogFile->Lock);
return FALSE;
}
@@ -1019,7 +1021,7 @@
NULL))
{
DPRINT1("WriteFile() failed! %d\n", GetLastError());
- LeaveCriticalSection(&LogFile->cs);
+ RtlReleaseResource(&LogFile->Lock);
return FALSE;
}
@@ -1027,7 +1029,7 @@
INVALID_SET_FILE_POINTER)
{
DPRINT1("SetFilePointer() failed! %d\n", GetLastError());
- LeaveCriticalSection(&LogFile->cs);
+ RtlReleaseResource(&LogFile->Lock);
return FALSE;
}
@@ -1038,20 +1040,54 @@
NULL))
{
DPRINT1("WriteFile failed! LastError = %d\n", GetLastError());
- LeaveCriticalSection(&LogFile->cs);
+ RtlReleaseResource(&LogFile->Lock);
return FALSE;
}
if (!FlushFileBuffers(LogFile->hFile))
{
- LeaveCriticalSection(&LogFile->cs);
DPRINT1("FlushFileBuffers() failed! %d\n", GetLastError());
- return FALSE;
- }
-
- LeaveCriticalSection(&LogFile->cs);
+ RtlReleaseResource(&LogFile->Lock);
+ return FALSE;
+ }
+
+ RtlReleaseResource(&LogFile->Lock);
return TRUE;
}
+
+
+NTSTATUS
+LogfClearFile(PLOGFILE LogFile,
+ PUNICODE_STRING BackupFileName)
+{
+ RtlAcquireResourceExclusive(&LogFile->Lock, TRUE);
+
+ if (BackupFileName->Length > 0)
+ {
+ /* FIXME: Write a backup file */
+ }
+
+ LogfInitializeNew(LogFile);
+
+ RtlReleaseResource(&LogFile->Lock);
+
+ return STATUS_SUCCESS;
+}
+
+
+NTSTATUS
+LogfBackupFile(PLOGFILE LogFile,
+ PUNICODE_STRING BackupFileName)
+{
+// RtlAcquireResourceShared(&LogFile->Lock, TRUE);
+
+ /* FIXME: Write a backup file */
+
+// RtlReleaseResource(&LogFile->Lock);
+
+ return STATUS_NOT_IMPLEMENTED;
+}
+
/* Returns 0 if nothing found. */
ULONG LogfOffsetByNumber(PLOGFILE LogFile, DWORD RecordNumber)
Modified: trunk/reactos/base/services/eventlog/rpc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/eventlog/rpc…
==============================================================================
--- trunk/reactos/base/services/eventlog/rpc.c [iso-8859-1] (original)
+++ trunk/reactos/base/services/eventlog/rpc.c [iso-8859-1] Mon Dec 26 13:54:05 2011
@@ -161,7 +161,8 @@
PRPC_UNICODE_STRING BackupFileName)
{
PLOGHANDLE lpLogHandle;
- PLOGFILE lpLogFile;
+
+ DPRINT("ElfrClearELFW()\n");
lpLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
if (!lpLogHandle)
@@ -169,16 +170,8 @@
return STATUS_INVALID_HANDLE;
}
- lpLogFile = lpLogHandle->LogFile;
-
- if (BackupFileName->Length > 0)
- {
- /* FIXME: Write a backup file */
- }
-
- LogfInitializeNew(lpLogFile);
-
- return STATUS_SUCCESS;
+ return LogfClearFile(lpLogHandle->LogFile,
+ (PUNICODE_STRING)BackupFileName);
}
@@ -187,9 +180,20 @@
IELF_HANDLE LogHandle,
PRPC_UNICODE_STRING BackupFileName)
{
- UNIMPLEMENTED;
- return STATUS_NOT_IMPLEMENTED;
-}
+ PLOGHANDLE lpLogHandle;
+
+ DPRINT("ElfrBackupELFW()\n");
+
+ lpLogHandle = ElfGetLogHandleEntryByHandle(LogHandle);
+ if (!lpLogHandle)
+ {
+ return STATUS_INVALID_HANDLE;
+ }
+
+ return LogfBackupFile(lpLogHandle->LogFile,
+ (PUNICODE_STRING)BackupFileName);
+}
+
/* Function 2 */
NTSTATUS ElfrCloseEL(
@@ -279,6 +283,8 @@
RPC_CLIENT_ID ClientId,
DWORD Event)
{
+ DPRINT("ElfrChangeNotify()");
+
UNIMPLEMENTED;
return STATUS_NOT_IMPLEMENTED;
}