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.
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
43 /* GLOBALS ******************************************************************/
45 HANDLE PortThreadHandle
= NULL
;
46 HANDLE ConnectPortHandle
= NULL
;
47 HANDLE MessagePortHandle
= NULL
;
50 /* FUNCTIONS ****************************************************************/
55 OBJECT_ATTRIBUTES ObjectAttributes
;
56 UNICODE_STRING PortName
;
57 LPC_MAX_MESSAGE Request
;
60 ConnectPortHandle
= NULL
;
61 MessagePortHandle
= NULL
;
63 RtlInitUnicodeString(&PortName
,
65 InitializeObjectAttributes(&ObjectAttributes
,
71 Status
= NtCreatePort(&ConnectPortHandle
,
76 if (!NT_SUCCESS(Status
))
78 DPRINT1("NtCreatePort() failed (Status %lx)\n", Status
);
82 Status
= NtListenPort(ConnectPortHandle
,
84 if (!NT_SUCCESS(Status
))
86 DPRINT1("NtListenPort() failed (Status %lx)\n", Status
);
90 Status
= NtAcceptConnectPort(&MessagePortHandle
,
96 if (!NT_SUCCESS (Status
))
98 DPRINT1("NtAcceptConnectPort() failed (Status %lx)\n", Status
);
102 Status
= NtCompleteConnectPort (MessagePortHandle
);
103 if (!NT_SUCCESS (Status
))
105 DPRINT1("NtCompleteConnectPort() failed (Status %lx)\n", Status
);
110 if (!NT_SUCCESS (Status
))
112 if (ConnectPortHandle
!= NULL
)
113 NtClose (ConnectPortHandle
);
115 if (MessagePortHandle
!= NULL
)
116 NtClose (MessagePortHandle
);
124 ProcessPortMessage(VOID
)
126 LPC_MAX_MESSAGE Request
;
127 PIO_ERROR_LOG_MESSAGE Message
;
135 DPRINT1("ProcessPortMessage() called\n");
137 Status
= STATUS_SUCCESS
;
141 Status
= NtReplyWaitReceivePort(MessagePortHandle
,
145 if (!NT_SUCCESS(Status
))
147 DPRINT1("NtReplyWaitReceivePort() failed (Status %lx)\n", Status
);
151 DPRINT ("Received message\n");
153 if (Request
.Header
.MessageType
== LPC_PORT_CLOSED
)
155 DPRINT ("Port closed\n");
157 return (STATUS_UNSUCCESSFUL
);
159 if (Request
.Header
.MessageType
== LPC_REQUEST
)
161 DPRINT ("Received request\n");
164 else if (Request
.Header
.MessageType
== LPC_DATAGRAM
)
166 DPRINT ("Received datagram\n");
169 Message
= (PIO_ERROR_LOG_MESSAGE
)&Request
.Data
;
171 DPRINT ("Message->Type %hx\n", Message
->Type
);
172 DPRINT ("Message->Size %hu\n", Message
->Size
);
175 DbgPrint ("\n Error mesage:\n");
176 DbgPrint ("Error code: %lx\n", Message
->EntryData
.ErrorCode
);
177 DbgPrint ("Retry count: %u\n", Message
->EntryData
.RetryCount
);
178 DbgPrint ("Sequence number: %lu\n", Message
->EntryData
.SequenceNumber
);
180 if (Message
->DriverNameLength
!= 0)
182 DbgPrint ("Driver name: %.*S\n",
183 Message
->DriverNameLength
/ sizeof(WCHAR
),
184 (PWCHAR
)((ULONG_PTR
)Message
+ Message
->DriverNameOffset
));
187 if (Message
->EntryData
.NumberOfStrings
!= 0)
189 p
= (PWSTR
)((ULONG_PTR
)&Message
->EntryData
+ Message
->EntryData
.StringOffset
);
190 for (i
= 0; i
< Message
->EntryData
.NumberOfStrings
; i
++)
192 DbgPrint ("String %lu: %S\n", i
, p
);
206 static NTSTATUS STDCALL
207 PortThreadRoutine(PVOID Param
)
209 NTSTATUS Status
= STATUS_SUCCESS
;
211 Status
= InitLogPort();
212 if (!NT_SUCCESS(Status
))
215 while (NT_SUCCESS(Status
))
217 Status
= ProcessPortMessage();
220 if (ConnectPortHandle
!= NULL
)
221 NtClose (ConnectPortHandle
);
223 if (MessagePortHandle
!= NULL
)
224 NtClose (MessagePortHandle
);
231 StartPortThread(VOID
)
235 PortThreadHandle
= CreateThread(NULL
,
237 (LPTHREAD_START_ROUTINE
)PortThreadRoutine
,
242 return((PortThreadHandle
!= NULL
));