1 /* $Id: services.c,v 1.4 2001/10/21 19:09:06 chorns Exp $
3 * service control manager
5 * ReactOS Operating System
7 * --------------------------------------------------------------------
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.
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.
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,
27 * - Services.exe is NOT a native application, it is a GUI app.
30 /* INCLUDES *****************************************************************/
32 #define NTOS_MODE_USER
40 /* GLOBALS ******************************************************************/
42 #define PIPE_BUFSIZE 1024
43 #define PIPE_TIMEOUT 1000
46 /* FUNCTIONS *****************************************************************/
48 void PrintString (char* fmt
,...)
54 vsprintf(buffer
, fmt
, ap
);
57 OutputDebugStringA(buffer
);
61 BOOL
ScmCreateStartEvent(PHANDLE StartEvent
)
65 hEvent
= CreateEvent(NULL
,
68 _T("SvcctrlStartEvent_A3725DX"));
71 if (GetLastError() == ERROR_ALREADY_EXISTS
)
73 hEvent
= OpenEvent(EVENT_ALL_ACCESS
,
75 "SvcctrlStartEvent_A3725DX");
94 ScmNamedPipeHandleRequest(
100 DbgPrint("SCM READ: %s\n", Request
);
113 CHAR chRequest
[PIPE_BUFSIZE
];
114 CHAR chReply
[PIPE_BUFSIZE
];
121 DPRINT("Accepting SCM commands through named pipe\n");
123 hPipe
= (HANDLE
)Context
;
133 if (!fSuccess
|| cbBytesRead
== 0)
138 if (ScmNamedPipeHandleRequest(&chRequest
, cbBytesRead
, &chReply
, &cbReplyBytes
))
140 fSuccess
= WriteFile(
146 if (!fSuccess
|| cbReplyBytes
!= cbWritten
)
153 FlushFileBuffers(hPipe
);
154 DisconnectNamedPipe(hPipe
);
157 return ERROR_SUCCESS
;
161 BOOL
ScmCreateNamedPipe(VOID
)
168 hPipe
= CreateNamedPipe(
169 "\\\\.\\pipe\\Ntsvcs",
171 PIPE_TYPE_MESSAGE
| PIPE_READMODE_MESSAGE
| PIPE_WAIT
,
172 PIPE_UNLIMITED_INSTANCES
,
177 if (hPipe
== INVALID_HANDLE_VALUE
)
179 DPRINT("CreateNamedPipe() failed (%d)\n", GetLastError());
183 fConnected
= ConnectNamedPipe(
185 NULL
) ? TRUE
: (GetLastError() == ERROR_PIPE_CONNECTED
);
188 DPRINT("Pipe connected\n");
190 hThread
= CreateThread(
199 DPRINT("Could not create thread (%d)\n", GetLastError());
201 DisconnectNamedPipe(hPipe
);
208 DPRINT("Pipe not connected\n");
219 WinMain(HINSTANCE hInstance
,
220 HINSTANCE hPrevInstance
,
224 HANDLE hScmStartEvent
;
227 PrintString("Service Control Manager\n");
229 /* Create start event */
230 if (!ScmCreateStartEvent(&hScmStartEvent
))
232 PrintString("SERVICES: Failed to create start event\n");
239 /* FIXME: more initialization */
241 /* FIXME: create service database */
242 // ScmCreateServiceDB();
244 /* FIXME: update service database */
245 // ScmGetBootAndSystemDriverState();
247 /* Create named pipe */
248 if (!ScmCreateNamedPipe())
250 PrintString("SERVICES: Failed to create named pipe\n");
254 /* FIXME: create listener thread for pipe */
256 /* FIXME: register process as service process */
257 // RegisterServiceProcess();
259 PrintString("SERVICES: Initialized.\n");
261 /* Signal start event */
262 SetEvent(hScmStartEvent
);
264 /* FIXME: register event handler (used for system shutdown) */
265 // SetConsoleCtrlHandler(...);
268 /* FIXME: start auto-start services */
269 // ScmAutoStartServices();
271 /* FIXME: more to do ? */
274 PrintString("SERVICES: Running.\n");
276 hEvent
= CreateEvent(NULL
,
280 WaitForSingleObject(hEvent
, INFINITE
);
288 PrintString("SERVICES: Finished.\n");