ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

logport.c
Go to the documentation of this file.
00001 /*
00002  * PROJECT:          ReactOS kernel
00003  * LICENSE:          GPL - See COPYING in the top level directory
00004  * FILE:             services/eventlog/logport.c
00005  * PURPOSE:          Event logging service
00006  * COPYRIGHT:        Copyright 2002 Eric Kohl
00007  *                   Copyright 2005 Saveliy Tretiakov
00008  */
00009 
00010 /* INCLUDES *****************************************************************/
00011 
00012 #include "eventlog.h"
00013 
00014 /* GLOBALS ******************************************************************/
00015 
00016 HANDLE ConnectPortHandle = NULL;
00017 HANDLE MessagePortHandle = NULL;
00018 extern BOOL onLiveCD;
00019 
00020 /* FUNCTIONS ****************************************************************/
00021 
00022 NTSTATUS WINAPI PortThreadRoutine(PVOID Param)
00023 {
00024     NTSTATUS Status = STATUS_SUCCESS;
00025 
00026     Status = InitLogPort();
00027     if (!NT_SUCCESS(Status))
00028         return Status;
00029 
00030     while (NT_SUCCESS(Status))
00031         Status = ProcessPortMessage();
00032 
00033     if (ConnectPortHandle != NULL)
00034         NtClose(ConnectPortHandle);
00035 
00036     if (MessagePortHandle != NULL)
00037         NtClose(MessagePortHandle);
00038 
00039     return Status;
00040 }
00041 
00042 NTSTATUS InitLogPort(VOID)
00043 {
00044     OBJECT_ATTRIBUTES ObjectAttributes;
00045     UNICODE_STRING PortName;
00046     PORT_MESSAGE Request;
00047     NTSTATUS Status;
00048 
00049     ConnectPortHandle = NULL;
00050     MessagePortHandle = NULL;
00051 
00052     RtlInitUnicodeString(&PortName, L"\\ErrorLogPort");
00053     InitializeObjectAttributes(&ObjectAttributes, &PortName, 0, NULL, NULL);
00054 
00055     Status = NtCreatePort(&ConnectPortHandle,
00056                           &ObjectAttributes,
00057                           0,
00058                           0x100,
00059                           0x2000);
00060 
00061     if (!NT_SUCCESS(Status))
00062     {
00063         DPRINT1("NtCreatePort() failed (Status %lx)\n", Status);
00064         goto ByeBye;
00065     }
00066 
00067     Status = NtListenPort(ConnectPortHandle, &Request);
00068 
00069     if (!NT_SUCCESS(Status))
00070     {
00071         DPRINT1("NtListenPort() failed (Status %lx)\n", Status);
00072         goto ByeBye;
00073     }
00074 
00075     Status = NtAcceptConnectPort(&MessagePortHandle, ConnectPortHandle,
00076                                  NULL, TRUE, NULL, NULL);
00077 
00078     if (!NT_SUCCESS(Status))
00079     {
00080         DPRINT1("NtAcceptConnectPort() failed (Status %lx)\n", Status);
00081         goto ByeBye;
00082     }
00083 
00084     Status = NtCompleteConnectPort(MessagePortHandle);
00085     if (!NT_SUCCESS(Status))
00086     {
00087         DPRINT1("NtCompleteConnectPort() failed (Status %lx)\n", Status);
00088         goto ByeBye;
00089     }
00090 
00091   ByeBye:
00092     if (!NT_SUCCESS(Status))
00093     {
00094         if (ConnectPortHandle != NULL)
00095             NtClose(ConnectPortHandle);
00096 
00097         if (MessagePortHandle != NULL)
00098             NtClose(MessagePortHandle);
00099     }
00100     return Status;
00101 }
00102 
00103 NTSTATUS ProcessPortMessage(VOID)
00104 {
00105     IO_ERROR_LPC Request;
00106     PIO_ERROR_LOG_MESSAGE Message;
00107     PEVENTLOGRECORD pRec;
00108     ULONG ulRecNum;
00109     DWORD dwRecSize;
00110     NTSTATUS Status;
00111     PLOGFILE SystemLog = NULL;
00112 
00113     DPRINT("ProcessPortMessage() called\n");
00114 
00115     SystemLog = LogfListItemByName(L"System");
00116 
00117     while (TRUE)
00118     {
00119         Status = NtReplyWaitReceivePort(MessagePortHandle,
00120                                         0,
00121                                         NULL,
00122                                         &Request.Header);
00123 
00124         if (!NT_SUCCESS(Status))
00125         {
00126             DPRINT1("NtReplyWaitReceivePort() failed (Status %lx)\n", Status);
00127             break;
00128         }
00129 
00130         DPRINT("Received message\n");
00131 
00132         if (Request.Header.u2.s2.Type == LPC_PORT_CLOSED)
00133         {
00134             DPRINT("Port closed\n");
00135             return STATUS_SUCCESS;
00136         }
00137 
00138         if (Request.Header.u2.s2.Type == LPC_REQUEST)
00139         {
00140             DPRINT("Received request\n");
00141         }
00142         else if (Request.Header.u2.s2.Type == LPC_DATAGRAM)
00143         {
00144             DPRINT("Received datagram\n");
00145             Message = (PIO_ERROR_LOG_MESSAGE) & Request.Message;
00146             ulRecNum = SystemLog ? SystemLog->Header.CurrentRecordNumber : 0;
00147 
00148             pRec = (PEVENTLOGRECORD) LogfAllocAndBuildNewRecord(&dwRecSize,
00149                     ulRecNum, Message->Type, Message->EntryData.EventCategory,
00150                     Message->EntryData.ErrorCode,
00151                     (WCHAR *) (((PBYTE) Message) + Message->DriverNameOffset),
00152                     L"MyComputer",  /* FIXME */
00153                     0,
00154                     NULL,
00155                     Message->EntryData.NumberOfStrings,
00156                     (WCHAR *) (((PBYTE) Message) + Message->EntryData.StringOffset),
00157                     Message->EntryData.DumpDataSize,
00158                     (LPVOID) (((PBYTE) Message) + sizeof(IO_ERROR_LOG_PACKET) -
00159                         sizeof(ULONG)));
00160 
00161             if (pRec == NULL)
00162             {
00163                 DPRINT("LogfAllocAndBuildNewRecord failed!\n");
00164                 return STATUS_NO_MEMORY;
00165             }
00166 
00167             DPRINT("dwRecSize = %d\n", dwRecSize);
00168 
00169             DPRINT("\n --- EVENTLOG RECORD ---\n");
00170             PRINT_RECORD(pRec);
00171             DPRINT("\n");
00172 
00173             if (!onLiveCD && SystemLog)
00174             {
00175                 if (!LogfWriteData(SystemLog, dwRecSize, (PBYTE) pRec))
00176                     DPRINT("LogfWriteData failed!\n");
00177                 else
00178                     DPRINT("Data written to Log!\n");
00179             }
00180 
00181             LogfFreeRecord(pRec);
00182         }
00183     }
00184 
00185     return Status;
00186 }

Generated on Sat May 26 2012 04:16:36 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.