Author: ekohl
Date: Mon Jan 16 23:23:29 2012
New Revision: 54987
URL:
http://svn.reactos.org/svn/reactos?rev=54987&view=rev
Log:
[EVENTLOG]
- LogfCreate: Use NtCreateFile instead of CreateFile
- Implement ElfCreateBackupLogHandle
Modified:
trunk/reactos/base/services/eventlog/eventlog.c
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.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/eventlog/eve…
==============================================================================
--- trunk/reactos/base/services/eventlog/eventlog.c [iso-8859-1] (original)
+++ trunk/reactos/base/services/eventlog/eventlog.c [iso-8859-1] Mon Jan 16 23:23:29 2012
@@ -267,7 +267,9 @@
DWORD MaxValueLen, ValueLen, Type, ExpandedLen;
WCHAR *Buf = NULL, *Expanded = NULL;
LONG Result;
- PLOGFILE pLogf;
+ PLOGFILE pLogf = NULL;
+ UNICODE_STRING FileName;
+ NTSTATUS Status;
DPRINT("LoadLogFile: %S\n", LogName);
@@ -314,13 +316,21 @@
ExpandEnvironmentStrings(Buf, Expanded, ExpandedLen);
+ if (!RtlDosPathNameToNtPathName_U(Expanded, &FileName,
+ NULL, NULL))
+ {
+ DPRINT1("Can't convert path!\n");
+ HeapFree(MyHeap, 0, Expanded);
+ HeapFree(MyHeap, 0, Buf);
+ return NULL;
+ }
+
DPRINT("%S -> %S\n", Buf, Expanded);
- pLogf = LogfCreate(LogName, Expanded);
-
- if (pLogf == NULL)
- {
- DPRINT1("Failed to create %S!\n", Expanded);
+ Status = LogfCreate(&pLogf, LogName, &FileName);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("Failed to create %S! (Status %08lx)\n", Expanded, Status);
}
HeapFree(MyHeap, 0, Buf);
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 Jan 16 23:23:29 2012
@@ -102,12 +102,17 @@
WCHAR szName[1];
} EVENTSOURCE, *PEVENTSOURCE;
+
+/* Log Handle Flags */
+#define LOG_HANDLE_BACKUP_FILE 1
+
typedef struct _LOGHANDLE
{
LIST_ENTRY LogHandleListEntry;
PEVENTSOURCE EventSource;
PLOGFILE LogFile;
ULONG CurrentRecord;
+ ULONG Flags;
WCHAR szName[1];
} LOGHANDLE, *PLOGHANDLE;
@@ -149,8 +154,10 @@
LogfBackupFile(PLOGFILE LogFile,
PUNICODE_STRING BackupFileName);
-PLOGFILE LogfCreate(WCHAR * LogName,
- WCHAR * FileName);
+NTSTATUS
+LogfCreate(PLOGFILE *Logfile,
+ WCHAR * LogName,
+ PUNICODE_STRING FileName);
VOID LogfClose(PLOGFILE LogFile);
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 Jan 16 23:23:29 2012
@@ -288,104 +288,127 @@
return TRUE;
}
-PLOGFILE LogfCreate(WCHAR * LogName, WCHAR * FileName)
-{
- PLOGFILE LogFile;
+
+NTSTATUS
+LogfCreate(PLOGFILE *LogFile,
+ WCHAR * LogName,
+ PUNICODE_STRING FileName)
+{
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ IO_STATUS_BLOCK IoStatusBlock;
+ PLOGFILE pLogFile;
BOOL bResult, bCreateNew = FALSE;
-
- LogFile = (LOGFILE *) HeapAlloc(MyHeap, HEAP_ZERO_MEMORY, sizeof(LOGFILE));
- if (!LogFile)
+ NTSTATUS Status = STATUS_SUCCESS;
+
+ pLogFile = (LOGFILE *) HeapAlloc(MyHeap, HEAP_ZERO_MEMORY, sizeof(LOGFILE));
+ if (!pLogFile)
{
DPRINT1("Can't allocate heap!\n");
- return NULL;
- }
-
- LogFile->hFile = CreateFile(FileName,
- GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ,
- NULL,
- OPEN_ALWAYS,
- FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
- NULL);
-
- if (LogFile->hFile == INVALID_HANDLE_VALUE)
- {
- DPRINT1("Can't create file %S.\n", FileName);
- HeapFree(MyHeap, 0, LogFile);
- return NULL;
- }
-
- bCreateNew = (GetLastError() == ERROR_ALREADY_EXISTS) ? FALSE : TRUE;
-
- LogFile->LogName =
+ return STATUS_NO_MEMORY;
+ }
+
+ InitializeObjectAttributes(&ObjectAttributes,
+ FileName,
+ OBJ_CASE_INSENSITIVE,
+ NULL,
+ NULL);
+
+ Status = NtCreateFile(&pLogFile->hFile,
+ GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE,
+ &ObjectAttributes,
+ &IoStatusBlock,
+ NULL,
+ FILE_ATTRIBUTE_NORMAL,
+ FILE_SHARE_READ,
+ FILE_OPEN_IF,
+ FILE_SYNCHRONOUS_IO_NONALERT,
+ NULL,
+ 0);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("Can't create file %wZ (Status: 0x%08lx)\n", FileName,
Status);
+ goto fail;
+ }
+
+ bCreateNew = (IoStatusBlock.Information == FILE_CREATED) ? TRUE: FALSE;
+
+ pLogFile->LogName =
(WCHAR *) HeapAlloc(MyHeap,
HEAP_ZERO_MEMORY,
(lstrlenW(LogName) + 1) * sizeof(WCHAR));
-
- if (LogFile->LogName)
- lstrcpyW(LogFile->LogName, LogName);
- else
+ if (pLogFile->LogName == NULL)
{
DPRINT1("Can't allocate heap\n");
- HeapFree(MyHeap, 0, LogFile);
- return NULL;
- }
-
- LogFile->FileName =
+ Status = STATUS_NO_MEMORY;
+ goto fail;
+ }
+
+ lstrcpyW(pLogFile->LogName, LogName);
+
+ pLogFile->FileName =
(WCHAR *) HeapAlloc(MyHeap,
HEAP_ZERO_MEMORY,
- (lstrlenW(FileName) + 1) * sizeof(WCHAR));
-
- if (LogFile->FileName)
- lstrcpyW(LogFile->FileName, FileName);
- else
+ (lstrlenW(FileName->Buffer) + 1) * sizeof(WCHAR));
+ if (pLogFile->FileName == NULL)
{
DPRINT1("Can't allocate heap\n");
+ Status = STATUS_NO_MEMORY;
goto fail;
}
- LogFile->OffsetInfo =
+ lstrcpyW(pLogFile->FileName, FileName->Buffer);
+
+ pLogFile->OffsetInfo =
(PEVENT_OFFSET_INFO) HeapAlloc(MyHeap,
HEAP_ZERO_MEMORY,
sizeof(EVENT_OFFSET_INFO) * 64);
-
- if (!LogFile->OffsetInfo)
+ if (pLogFile->OffsetInfo == NULL)
{
DPRINT1("Can't allocate heap\n");
+ Status = STATUS_NO_MEMORY;
goto fail;
}
- LogFile->OffsetInfoSize = 64;
+ pLogFile->OffsetInfoSize = 64;
if (bCreateNew)
- bResult = LogfInitializeNew(LogFile);
+ bResult = LogfInitializeNew(pLogFile);
else
- bResult = LogfInitializeExisting(LogFile);
+ bResult = LogfInitializeExisting(pLogFile);
if (!bResult)
+ {
+ Status = STATUS_UNSUCCESSFUL;
goto fail;
-
- RtlInitializeResource(&LogFile->Lock);
-
- LogfListAddItem(LogFile);
- return LogFile;
+ }
+
+ RtlInitializeResource(&pLogFile->Lock);
+
+ LogfListAddItem(pLogFile);
fail:
- if (LogFile)
- {
- if (LogFile->OffsetInfo)
- HeapFree(MyHeap, 0, LogFile->OffsetInfo);
-
- if (LogFile->FileName)
- HeapFree(MyHeap, 0, LogFile->FileName);
-
- if (LogFile->LogName)
- HeapFree(MyHeap, 0, LogFile->LogName);
-
- HeapFree(MyHeap, 0, LogFile);
- }
-
- return NULL;
+ if (!NT_SUCCESS(Status))
+ {
+ if ((pLogFile->hFile != NULL) && (pLogFile->hFile !=
INVALID_HANDLE_VALUE))
+ CloseHandle(pLogFile->hFile);
+
+ if (pLogFile->OffsetInfo)
+ HeapFree(MyHeap, 0, pLogFile->OffsetInfo);
+
+ if (pLogFile->FileName)
+ HeapFree(MyHeap, 0, pLogFile->FileName);
+
+ if (pLogFile->LogName)
+ HeapFree(MyHeap, 0, pLogFile->LogName);
+
+ HeapFree(MyHeap, 0, pLogFile);
+ }
+ else
+ {
+ *LogFile = pLogFile;
+ }
+
+ return Status;
}
VOID LogfClose(PLOGFILE LogFile)
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 Jan 16 23:23:29 2012
@@ -142,8 +142,48 @@
ElfCreateBackupLogHandle(PLOGHANDLE *LogHandle,
PUNICODE_STRING FileName)
{
+ PLOGHANDLE lpLogHandle;
+
+ NTSTATUS Status = STATUS_SUCCESS;
+
DPRINT("ElfCreateBackupLogHandle(FileName: %wZ)\n", FileName);
- return STATUS_NOT_IMPLEMENTED;
+
+ lpLogHandle = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(LOGHANDLE));
+ if (lpLogHandle == NULL)
+ {
+ DPRINT1("Failed to allocate Heap!\n");
+ return STATUS_NO_MEMORY;
+ }
+
+ /* Create the log file */
+ Status = LogfCreate(&lpLogHandle->LogFile,
+ NULL,
+ FileName);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("Failed to create the log file! (Status 0x%08lx)\n", Status);
+ goto Done;
+ }
+
+ /* Set the backup flag */
+ lpLogHandle->Flags |= LOG_HANDLE_BACKUP_FILE;
+
+ /* Get the current record */
+ lpLogHandle->CurrentRecord = LogfGetOldestRecord(lpLogHandle->LogFile);
+
+Done:
+ if (NT_SUCCESS(Status))
+ {
+ /* Append log handle */
+ InsertTailList(&LogHandleListHead, &lpLogHandle->LogHandleListEntry);
+ *LogHandle = lpLogHandle;
+ }
+ else
+ {
+ HeapFree(GetProcessHeap(), 0, lpLogHandle);
+ }
+
+ return Status;
}
@@ -169,6 +209,10 @@
if (!ElfGetLogHandleEntryByHandle(lpLogHandle))
return STATUS_INVALID_HANDLE;
+
+ /* Close the log file if it is a backup file */
+ if (lpLogHandle->Flags & LOG_HANDLE_BACKUP_FILE)
+ LogfClose(lpLogHandle->LogFile);
RemoveEntryList(&lpLogHandle->LogHandleListEntry);
HeapFree(GetProcessHeap(),0,lpLogHandle);