2002-06-25 21:10:14 +00:00
|
|
|
/*
|
|
|
|
* ReactOS kernel
|
|
|
|
* Copyright (C) 2002 ReactOS Team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
2005-06-01 21:57:52 +00:00
|
|
|
/*
|
2002-06-25 21:10:14 +00:00
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS kernel
|
|
|
|
* FILE: services/eventlog/logport.c
|
|
|
|
* PURPOSE: Event logger service
|
|
|
|
* PROGRAMMER: Eric Kohl
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
2002-09-08 10:23:54 +00:00
|
|
|
#include <windows.h>
|
2005-06-24 01:31:23 +00:00
|
|
|
#define NTOS_MODE_USER
|
|
|
|
#include <ndk/ntndk.h>
|
2002-06-25 21:10:14 +00:00
|
|
|
|
|
|
|
#include "eventlog.h"
|
|
|
|
|
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
|
|
|
|
/* GLOBALS ******************************************************************/
|
|
|
|
|
|
|
|
HANDLE PortThreadHandle = NULL;
|
|
|
|
HANDLE ConnectPortHandle = NULL;
|
|
|
|
HANDLE MessagePortHandle = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
/* FUNCTIONS ****************************************************************/
|
|
|
|
|
|
|
|
static NTSTATUS
|
2005-06-01 21:57:52 +00:00
|
|
|
InitLogPort(VOID)
|
2002-06-25 21:10:14 +00:00
|
|
|
{
|
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
|
|
UNICODE_STRING PortName;
|
2005-08-16 23:05:33 +00:00
|
|
|
PORT_MESSAGE Request;
|
2002-06-25 21:10:14 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
ConnectPortHandle = NULL;
|
|
|
|
MessagePortHandle = NULL;
|
|
|
|
|
2003-11-24 16:41:41 +00:00
|
|
|
RtlInitUnicodeString(&PortName,
|
2002-06-25 21:10:14 +00:00
|
|
|
L"\\ErrorLogPort");
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&PortName,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
Status = NtCreatePort(&ConnectPortHandle,
|
|
|
|
&ObjectAttributes,
|
|
|
|
0,
|
|
|
|
0x100,
|
|
|
|
0x2000);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2003-11-20 11:09:49 +00:00
|
|
|
{
|
|
|
|
DPRINT1("NtCreatePort() failed (Status %lx)\n", Status);
|
|
|
|
goto ByeBye;
|
|
|
|
}
|
2002-06-25 21:10:14 +00:00
|
|
|
|
|
|
|
Status = NtListenPort(ConnectPortHandle,
|
2005-08-16 23:05:33 +00:00
|
|
|
&Request);
|
2002-06-25 21:10:14 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2003-11-20 11:09:49 +00:00
|
|
|
{
|
|
|
|
DPRINT1("NtListenPort() failed (Status %lx)\n", Status);
|
|
|
|
goto ByeBye;
|
|
|
|
}
|
2002-06-25 21:10:14 +00:00
|
|
|
|
|
|
|
Status = NtAcceptConnectPort(&MessagePortHandle,
|
2003-11-20 11:09:49 +00:00
|
|
|
ConnectPortHandle,
|
|
|
|
NULL,
|
|
|
|
TRUE,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
2005-06-01 21:57:52 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2003-11-20 11:09:49 +00:00
|
|
|
{
|
|
|
|
DPRINT1("NtAcceptConnectPort() failed (Status %lx)\n", Status);
|
|
|
|
goto ByeBye;
|
|
|
|
}
|
2002-06-25 21:10:14 +00:00
|
|
|
|
2005-06-01 21:57:52 +00:00
|
|
|
Status = NtCompleteConnectPort(MessagePortHandle);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2003-11-20 11:09:49 +00:00
|
|
|
{
|
|
|
|
DPRINT1("NtCompleteConnectPort() failed (Status %lx)\n", Status);
|
|
|
|
goto ByeBye;
|
|
|
|
}
|
2002-06-25 21:10:14 +00:00
|
|
|
|
|
|
|
ByeBye:
|
2005-06-01 21:57:52 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2003-11-20 11:09:49 +00:00
|
|
|
{
|
|
|
|
if (ConnectPortHandle != NULL)
|
2005-06-01 21:57:52 +00:00
|
|
|
NtClose(ConnectPortHandle);
|
2002-06-25 21:10:14 +00:00
|
|
|
|
2003-11-20 11:09:49 +00:00
|
|
|
if (MessagePortHandle != NULL)
|
2005-06-01 21:57:52 +00:00
|
|
|
NtClose(MessagePortHandle);
|
2003-11-20 11:09:49 +00:00
|
|
|
}
|
2002-06-25 21:10:14 +00:00
|
|
|
|
2003-11-20 11:09:49 +00:00
|
|
|
return Status;
|
2002-06-25 21:10:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS
|
|
|
|
ProcessPortMessage(VOID)
|
|
|
|
{
|
2005-08-16 23:05:33 +00:00
|
|
|
IO_ERROR_LPC Request;
|
2003-11-20 11:09:49 +00:00
|
|
|
PIO_ERROR_LOG_MESSAGE Message;
|
2003-11-24 16:41:41 +00:00
|
|
|
//#ifndef NDEBUG
|
|
|
|
ULONG i;
|
|
|
|
PWSTR p;
|
|
|
|
//#endif
|
2002-06-25 21:10:14 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
|
2003-11-20 11:09:49 +00:00
|
|
|
|
|
|
|
DPRINT1("ProcessPortMessage() called\n");
|
|
|
|
|
|
|
|
Status = STATUS_SUCCESS;
|
2002-06-25 21:10:14 +00:00
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
Status = NtReplyWaitReceivePort(MessagePortHandle,
|
|
|
|
0,
|
2003-11-20 11:09:49 +00:00
|
|
|
NULL,
|
|
|
|
&Request.Header);
|
2002-06-25 21:10:14 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2003-11-20 11:09:49 +00:00
|
|
|
DPRINT1("NtReplyWaitReceivePort() failed (Status %lx)\n", Status);
|
|
|
|
break;
|
2002-06-25 21:10:14 +00:00
|
|
|
}
|
|
|
|
|
2005-06-01 21:57:52 +00:00
|
|
|
DPRINT("Received message\n");
|
2003-11-20 11:09:49 +00:00
|
|
|
|
2005-08-11 09:01:30 +00:00
|
|
|
if (Request.Header.u2.s2.Type == LPC_PORT_CLOSED)
|
2003-11-20 11:09:49 +00:00
|
|
|
{
|
2005-06-01 21:57:52 +00:00
|
|
|
DPRINT("Port closed\n");
|
2003-11-20 11:09:49 +00:00
|
|
|
|
2005-06-01 21:57:52 +00:00
|
|
|
return STATUS_SUCCESS;
|
2003-11-20 11:09:49 +00:00
|
|
|
}
|
2005-08-11 09:01:30 +00:00
|
|
|
if (Request.Header.u2.s2.Type == LPC_REQUEST)
|
2002-06-25 21:10:14 +00:00
|
|
|
{
|
2005-06-01 21:57:52 +00:00
|
|
|
DPRINT("Received request\n");
|
2002-06-25 21:10:14 +00:00
|
|
|
|
|
|
|
}
|
2005-08-11 09:01:30 +00:00
|
|
|
else if (Request.Header.u2.s2.Type == LPC_DATAGRAM)
|
2002-06-25 21:10:14 +00:00
|
|
|
{
|
2005-06-01 21:57:52 +00:00
|
|
|
DPRINT("Received datagram\n");
|
2003-11-20 11:09:49 +00:00
|
|
|
|
|
|
|
|
2005-08-16 23:05:33 +00:00
|
|
|
Message = (PIO_ERROR_LOG_MESSAGE)&Request.Message;
|
2003-11-20 11:09:49 +00:00
|
|
|
|
2005-06-01 21:57:52 +00:00
|
|
|
DPRINT("Message->Type %hx\n", Message->Type);
|
|
|
|
DPRINT("Message->Size %hu\n", Message->Size);
|
2003-11-24 16:41:41 +00:00
|
|
|
|
|
|
|
//#ifndef NDEBUG
|
2005-06-01 21:57:52 +00:00
|
|
|
DbgPrint("\n Error mesage:\n");
|
|
|
|
DbgPrint("Error code: %lx\n", Message->EntryData.ErrorCode);
|
|
|
|
DbgPrint("Retry count: %u\n", Message->EntryData.RetryCount);
|
|
|
|
DbgPrint("Sequence number: %lu\n", Message->EntryData.SequenceNumber);
|
2003-11-24 16:41:41 +00:00
|
|
|
|
|
|
|
if (Message->DriverNameLength != 0)
|
|
|
|
{
|
2005-06-01 21:57:52 +00:00
|
|
|
DbgPrint("Driver name: %.*S\n",
|
|
|
|
Message->DriverNameLength / sizeof(WCHAR),
|
|
|
|
(PWCHAR)((ULONG_PTR)Message + Message->DriverNameOffset));
|
2003-11-24 16:41:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Message->EntryData.NumberOfStrings != 0)
|
|
|
|
{
|
|
|
|
p = (PWSTR)((ULONG_PTR)&Message->EntryData + Message->EntryData.StringOffset);
|
|
|
|
for (i = 0; i < Message->EntryData.NumberOfStrings; i++)
|
|
|
|
{
|
2005-06-01 21:57:52 +00:00
|
|
|
DbgPrint("String %lu: %S\n", i, p);
|
2003-11-24 16:41:41 +00:00
|
|
|
p += wcslen(p) + 1;
|
|
|
|
}
|
|
|
|
DbgPrint("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
//#endif
|
2005-06-01 21:57:52 +00:00
|
|
|
|
|
|
|
/* FIXME: Enqueue message */
|
|
|
|
|
2002-06-25 21:10:14 +00:00
|
|
|
}
|
|
|
|
}
|
2003-11-20 11:09:49 +00:00
|
|
|
|
|
|
|
return Status;
|
2002-06-25 21:10:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static NTSTATUS STDCALL
|
|
|
|
PortThreadRoutine(PVOID Param)
|
|
|
|
{
|
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
|
|
|
|
Status = InitLogPort();
|
|
|
|
if (!NT_SUCCESS(Status))
|
2005-06-01 21:57:52 +00:00
|
|
|
return Status;
|
2002-06-25 21:10:14 +00:00
|
|
|
|
2003-11-20 11:09:49 +00:00
|
|
|
while (NT_SUCCESS(Status))
|
2002-06-25 21:10:14 +00:00
|
|
|
{
|
|
|
|
Status = ProcessPortMessage();
|
|
|
|
}
|
|
|
|
|
2003-11-20 11:09:49 +00:00
|
|
|
if (ConnectPortHandle != NULL)
|
2005-06-01 21:57:52 +00:00
|
|
|
NtClose(ConnectPortHandle);
|
2003-11-20 11:09:49 +00:00
|
|
|
|
|
|
|
if (MessagePortHandle != NULL)
|
2005-06-01 21:57:52 +00:00
|
|
|
NtClose(MessagePortHandle);
|
2003-11-20 11:09:49 +00:00
|
|
|
|
2005-06-01 21:57:52 +00:00
|
|
|
return Status;
|
2002-06-25 21:10:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
StartPortThread(VOID)
|
|
|
|
{
|
|
|
|
DWORD ThreadId;
|
|
|
|
|
|
|
|
PortThreadHandle = CreateThread(NULL,
|
|
|
|
0x1000,
|
2003-11-14 17:13:36 +00:00
|
|
|
(LPTHREAD_START_ROUTINE)PortThreadRoutine,
|
2002-06-25 21:10:14 +00:00
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
&ThreadId);
|
|
|
|
|
2005-06-01 21:57:52 +00:00
|
|
|
return (PortThreadHandle != NULL);
|
2002-06-25 21:10:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|