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.
19 /* $Id: logport.c,v 1.8 2003/11/24 16:41:41 ekohl Exp $
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
23 * FILE: services/eventlog/logport.c
24 * PURPOSE: Event logger service
25 * PROGRAMMER: Eric Kohl
28 /* INCLUDES *****************************************************************/
32 #define NTOS_MODE_USER
44 /* GLOBALS ******************************************************************/
46 HANDLE PortThreadHandle
= NULL
;
47 HANDLE ConnectPortHandle
= NULL
;
48 HANDLE MessagePortHandle
= NULL
;
51 /* FUNCTIONS ****************************************************************/
56 OBJECT_ATTRIBUTES ObjectAttributes
;
57 UNICODE_STRING PortName
;
58 LPC_MAX_MESSAGE Request
;
61 ConnectPortHandle
= NULL
;
62 MessagePortHandle
= NULL
;
64 RtlInitUnicodeString(&PortName
,
66 InitializeObjectAttributes(&ObjectAttributes
,
72 Status
= NtCreatePort(&ConnectPortHandle
,
77 if (!NT_SUCCESS(Status
))
79 DPRINT1("NtCreatePort() failed (Status %lx)\n", Status
);
83 Status
= NtListenPort(ConnectPortHandle
,
85 if (!NT_SUCCESS(Status
))
87 DPRINT1("NtListenPort() failed (Status %lx)\n", Status
);
91 Status
= NtAcceptConnectPort(&MessagePortHandle
,
97 if (!NT_SUCCESS (Status
))
99 DPRINT1("NtAcceptConnectPort() failed (Status %lx)\n", Status
);
103 Status
= NtCompleteConnectPort (MessagePortHandle
);
104 if (!NT_SUCCESS (Status
))
106 DPRINT1("NtCompleteConnectPort() failed (Status %lx)\n", Status
);
111 if (!NT_SUCCESS (Status
))
113 if (ConnectPortHandle
!= NULL
)
114 NtClose (ConnectPortHandle
);
116 if (MessagePortHandle
!= NULL
)
117 NtClose (MessagePortHandle
);
125 ProcessPortMessage(VOID
)
127 LPC_MAX_MESSAGE Request
;
128 PIO_ERROR_LOG_MESSAGE Message
;
136 DPRINT1("ProcessPortMessage() called\n");
138 Status
= STATUS_SUCCESS
;
142 Status
= NtReplyWaitReceivePort(MessagePortHandle
,
146 if (!NT_SUCCESS(Status
))
148 DPRINT1("NtReplyWaitReceivePort() failed (Status %lx)\n", Status
);
152 DPRINT ("Received message\n");
154 if (Request
.Header
.MessageType
== LPC_PORT_CLOSED
)
156 DPRINT ("Port closed\n");
158 return (STATUS_UNSUCCESSFUL
);
160 if (Request
.Header
.MessageType
== LPC_REQUEST
)
162 DPRINT ("Received request\n");
165 else if (Request
.Header
.MessageType
== LPC_DATAGRAM
)
167 DPRINT ("Received datagram\n");
170 Message
= (PIO_ERROR_LOG_MESSAGE
)&Request
.Data
;
172 DPRINT ("Message->Type %hx\n", Message
->Type
);
173 DPRINT ("Message->Size %hu\n", Message
->Size
);
176 DbgPrint ("\n Error mesage:\n");
177 DbgPrint ("Error code: %lx\n", Message
->EntryData
.ErrorCode
);
178 DbgPrint ("Retry count: %u\n", Message
->EntryData
.RetryCount
);
179 DbgPrint ("Sequence number: %lu\n", Message
->EntryData
.SequenceNumber
);
181 if (Message
->DriverNameLength
!= 0)
183 DbgPrint ("Driver name: %.*S\n",
184 Message
->DriverNameLength
/ sizeof(WCHAR
),
185 (PWCHAR
)((ULONG_PTR
)Message
+ Message
->DriverNameOffset
));
188 if (Message
->EntryData
.NumberOfStrings
!= 0)
190 p
= (PWSTR
)((ULONG_PTR
)&Message
->EntryData
+ Message
->EntryData
.StringOffset
);
191 for (i
= 0; i
< Message
->EntryData
.NumberOfStrings
; i
++)
193 DbgPrint ("String %lu: %S\n", i
, p
);
207 static NTSTATUS STDCALL
208 PortThreadRoutine(PVOID Param
)
210 NTSTATUS Status
= STATUS_SUCCESS
;
212 Status
= InitLogPort();
213 if (!NT_SUCCESS(Status
))
216 while (NT_SUCCESS(Status
))
218 Status
= ProcessPortMessage();
221 if (ConnectPortHandle
!= NULL
)
222 NtClose (ConnectPortHandle
);
224 if (MessagePortHandle
!= NULL
)
225 NtClose (MessagePortHandle
);
232 StartPortThread(VOID
)
236 PortThreadHandle
= CreateThread(NULL
,
238 (LPTHREAD_START_ROUTINE
)PortThreadRoutine
,
243 return((PortThreadHandle
!= NULL
));