3 * Copyright (C) 2002 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS kernel
22 * FILE: services/eventlog/logport.c
23 * PURPOSE: Event logger service
24 * PROGRAMMER: Eric Kohl
27 /* INCLUDES *****************************************************************/
30 #define NTOS_MODE_USER
31 #include <ndk/ntndk.h>
39 /* GLOBALS ******************************************************************/
41 HANDLE PortThreadHandle
= NULL
;
42 HANDLE ConnectPortHandle
= NULL
;
43 HANDLE MessagePortHandle
= NULL
;
46 /* FUNCTIONS ****************************************************************/
51 OBJECT_ATTRIBUTES ObjectAttributes
;
52 UNICODE_STRING PortName
;
56 ConnectPortHandle
= NULL
;
57 MessagePortHandle
= NULL
;
59 RtlInitUnicodeString(&PortName
,
61 InitializeObjectAttributes(&ObjectAttributes
,
67 Status
= NtCreatePort(&ConnectPortHandle
,
72 if (!NT_SUCCESS(Status
))
74 DPRINT1("NtCreatePort() failed (Status %lx)\n", Status
);
78 Status
= NtListenPort(ConnectPortHandle
,
80 if (!NT_SUCCESS(Status
))
82 DPRINT1("NtListenPort() failed (Status %lx)\n", Status
);
86 Status
= NtAcceptConnectPort(&MessagePortHandle
,
92 if (!NT_SUCCESS(Status
))
94 DPRINT1("NtAcceptConnectPort() failed (Status %lx)\n", Status
);
98 Status
= NtCompleteConnectPort(MessagePortHandle
);
99 if (!NT_SUCCESS(Status
))
101 DPRINT1("NtCompleteConnectPort() failed (Status %lx)\n", Status
);
106 if (!NT_SUCCESS(Status
))
108 if (ConnectPortHandle
!= NULL
)
109 NtClose(ConnectPortHandle
);
111 if (MessagePortHandle
!= NULL
)
112 NtClose(MessagePortHandle
);
119 ProcessPortMessage(VOID
)
121 IO_ERROR_LPC Request
;
122 PIO_ERROR_LOG_MESSAGE Message
;
130 DPRINT1("ProcessPortMessage() called\n");
132 Status
= STATUS_SUCCESS
;
136 Status
= NtReplyWaitReceivePort(MessagePortHandle
,
140 if (!NT_SUCCESS(Status
))
142 DPRINT1("NtReplyWaitReceivePort() failed (Status %lx)\n", Status
);
146 DPRINT("Received message\n");
148 if (Request
.Header
.u2
.s2
.Type
== LPC_PORT_CLOSED
)
150 DPRINT("Port closed\n");
152 return STATUS_SUCCESS
;
154 if (Request
.Header
.u2
.s2
.Type
== LPC_REQUEST
)
156 DPRINT("Received request\n");
159 else if (Request
.Header
.u2
.s2
.Type
== LPC_DATAGRAM
)
161 DPRINT("Received datagram\n");
164 Message
= (PIO_ERROR_LOG_MESSAGE
)&Request
.Message
;
166 DPRINT("Message->Type %hx\n", Message
->Type
);
167 DPRINT("Message->Size %hu\n", Message
->Size
);
170 DbgPrint("\n Error mesage:\n");
171 DbgPrint("Error code: %lx\n", Message
->EntryData
.ErrorCode
);
172 DbgPrint("Retry count: %u\n", Message
->EntryData
.RetryCount
);
173 DbgPrint("Sequence number: %lu\n", Message
->EntryData
.SequenceNumber
);
175 if (Message
->DriverNameLength
!= 0)
177 DbgPrint("Driver name: %.*S\n",
178 Message
->DriverNameLength
/ sizeof(WCHAR
),
179 (PWCHAR
)((ULONG_PTR
)Message
+ Message
->DriverNameOffset
));
182 if (Message
->EntryData
.NumberOfStrings
!= 0)
184 p
= (PWSTR
)((ULONG_PTR
)&Message
->EntryData
+ Message
->EntryData
.StringOffset
);
185 for (i
= 0; i
< Message
->EntryData
.NumberOfStrings
; i
++)
187 DbgPrint("String %lu: %S\n", i
, p
);
195 /* FIXME: Enqueue message */
204 static NTSTATUS STDCALL
205 PortThreadRoutine(PVOID Param
)
207 NTSTATUS Status
= STATUS_SUCCESS
;
209 Status
= InitLogPort();
210 if (!NT_SUCCESS(Status
))
213 while (NT_SUCCESS(Status
))
215 Status
= ProcessPortMessage();
218 if (ConnectPortHandle
!= NULL
)
219 NtClose(ConnectPortHandle
);
221 if (MessagePortHandle
!= NULL
)
222 NtClose(MessagePortHandle
);
229 StartPortThread(VOID
)
233 PortThreadHandle
= CreateThread(NULL
,
235 (LPTHREAD_START_ROUTINE
)PortThreadRoutine
,
240 return (PortThreadHandle
!= NULL
);