migrate substitution keywords to SVN
[reactos.git] / reactos / subsys / csrss / csrss.c
1 /* $Id$
2 *
3 * csrss.c - Client/Server Runtime subsystem
4 *
5 * ReactOS Operating System
6 *
7 * --------------------------------------------------------------------
8 *
9 * This software is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of the
12 * License, or (at your option) any later version.
13 *
14 * This software is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this software; see the file COPYING.LIB. If not, write
21 * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
22 * MA 02139, USA.
23 *
24 * --------------------------------------------------------------------
25 *
26 * 19990417 (Emanuele Aliberti)
27 * Do nothing native application skeleton
28 * 19990528 (Emanuele Aliberti)
29 * Compiled successfully with egcs 1.1.2
30 * 19990605 (Emanuele Aliberti)
31 * First standalone run under ReactOS (it
32 * actually does nothing but running).
33 */
34 #include <ddk/ntddk.h>
35 #include <ntdll/rtl.h>
36 #include <csrss/csrss.h>
37 #include <rosrtl/string.h>
38
39 #include "api.h"
40
41 /* Native process' entry point */
42
43 VOID STDCALL NtProcessStartup(PPEB Peb)
44 {
45 PRTL_USER_PROCESS_PARAMETERS ProcParams;
46 PWSTR ArgBuffer;
47 PWSTR *argv;
48 ULONG argc = 0;
49 int i = 0;
50 int afterlastspace = 0;
51 OBJECT_ATTRIBUTES ObjectAttributes;
52 HANDLE CsrssInitEvent;
53 UNICODE_STRING UnicodeString;
54 NTSTATUS Status;
55
56 ProcParams = RtlNormalizeProcessParams (Peb->ProcessParameters);
57
58 argv = (PWSTR *)RtlAllocateHeap (Peb->ProcessHeap,
59 0, 512 * sizeof(PWSTR));
60 ArgBuffer = (PWSTR)RtlAllocateHeap (Peb->ProcessHeap,
61 0,
62 ProcParams->CommandLine.Length + sizeof(WCHAR));
63 memcpy (ArgBuffer,
64 ProcParams->CommandLine.Buffer,
65 ProcParams->CommandLine.Length + sizeof(WCHAR));
66
67 while (ArgBuffer[i])
68 {
69 if (ArgBuffer[i] == L' ')
70 {
71 argc++;
72 ArgBuffer[i] = L'\0';
73 argv[argc-1] = &(ArgBuffer[afterlastspace]);
74 i++;
75 while (ArgBuffer[i] == L' ')
76 i++;
77 afterlastspace = i;
78 }
79 else
80 {
81 i++;
82 }
83 }
84
85 if (ArgBuffer[afterlastspace] != L'\0')
86 {
87 argc++;
88 ArgBuffer[i] = L'\0';
89 argv[argc-1] = &(ArgBuffer[afterlastspace]);
90 }
91
92 RtlRosInitUnicodeStringFromLiteral(&UnicodeString,
93 L"\\CsrssInitDone");
94 InitializeObjectAttributes(&ObjectAttributes,
95 &UnicodeString,
96 EVENT_ALL_ACCESS,
97 0,
98 NULL);
99 Status = NtOpenEvent(&CsrssInitEvent,
100 EVENT_ALL_ACCESS,
101 &ObjectAttributes);
102 if (!NT_SUCCESS(Status))
103 {
104 DbgPrint("CSR: Failed to open csrss notification event\n");
105 }
106 if (CsrServerInitialization (argc, argv) == TRUE)
107 {
108
109 NtSetEvent(CsrssInitEvent,
110 NULL);
111
112 RtlFreeHeap (Peb->ProcessHeap,
113 0, argv);
114 RtlFreeHeap (Peb->ProcessHeap,
115 0,
116 ArgBuffer);
117
118 /* terminate the current thread only */
119 NtTerminateThread( NtCurrentThread(), 0 );
120 }
121 else
122 {
123 DisplayString( L"CSR: Subsystem initialization failed.\n" );
124
125 RtlFreeHeap (Peb->ProcessHeap,
126 0, argv);
127 RtlFreeHeap (Peb->ProcessHeap,
128 0,
129 ArgBuffer);
130
131 /*
132 * Tell SM we failed.
133 */
134 NtTerminateProcess( NtCurrentProcess(), 0 );
135 }
136 }
137
138 /* EOF */