2 * The olsr.org Optimized Link-State Routing daemon (olsrd)
\r
3 * Copyright (c) 2004, Thomas Lopatic (thomas@lopatic.de)
\r
4 * All rights reserved.
\r
6 * Redistribution and use in source and binary forms, with or without
\r
7 * modification, are permitted provided that the following conditions
\r
10 * * Redistributions of source code must retain the above copyright
\r
11 * notice, this list of conditions and the following disclaimer.
\r
12 * * Redistributions in binary form must reproduce the above copyright
\r
13 * notice, this list of conditions and the following disclaimer in
\r
14 * the documentation and/or other materials provided with the
\r
16 * * Neither the name of olsr.org, olsrd nor the names of its
\r
17 * contributors may be used to endorse or promote products derived
\r
18 * from this software without specific prior written permission.
\r
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
\r
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
\r
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
\r
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
\r
24 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
\r
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
\r
26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
\r
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
\r
28 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
\r
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
\r
30 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
\r
31 * POSSIBILITY OF SUCH DAMAGE.
\r
33 * Visit http://www.olsr.org for more information.
\r
35 * If you find this software useful feel free to make a donation
\r
36 * to the project. For more information see the website or contact
\r
37 * the copyright holders.
\r
39 * $Id: shim.c,v 1.4 2004/11/21 01:21:10 tlopatic Exp $
\r
42 #include <windows.h>
\r
44 void EntryPoint(void)
\r
46 STARTUPINFO StartInfo;
\r
47 PROCESS_INFORMATION ProcInfo;
\r
51 char NewCmdLine[MAX_PATH + 500];
\r
56 Handles[0] = OpenEvent(EVENT_ALL_ACCESS, FALSE, "TheOlsrdShimEvent");
\r
58 if (Handles[0] == NULL)
\r
60 MessageBox(NULL, "Cannot open event.", "Shim Error", MB_ICONERROR | MB_OK);
\r
64 CmdLine = GetCommandLine();
\r
68 while (*CmdLine != 0)
\r
70 if (*CmdLine == '"')
\r
73 else if (*CmdLine == ' ' && !Quotes)
\r
81 MessageBox(NULL, "Missing arguments.", "Shim Error", MB_ICONERROR | MB_OK);
\r
85 GetModuleFileName(NULL, NewCmdLine, MAX_PATH);
\r
87 for (Walker = NewCmdLine; *Walker != 0; Walker++);
\r
89 while (*Walker != '\\')
\r
106 while ((*Walker++ = *CmdLine++) != 0);
\r
108 for (i = 0; i < sizeof (STARTUPINFO); i++)
\r
109 ((char *)&StartInfo)[i] = 0;
\r
111 StartInfo.cb = sizeof (STARTUPINFO);
\r
113 if (!CreateProcess(NULL, NewCmdLine, NULL, NULL, TRUE,
\r
114 CREATE_NEW_PROCESS_GROUP, NULL, NULL, &StartInfo, &ProcInfo))
\r
116 MessageBox(NULL, "Cannot execute OLSR server.", "Shim Error", MB_ICONERROR | MB_OK);
\r
120 Handles[1] = ProcInfo.hProcess;
\r
122 Res = WaitForMultipleObjects(2, Handles, FALSE, INFINITE);
\r
124 if (Res == WAIT_OBJECT_0)
\r
126 GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, ProcInfo.dwProcessId);
\r
127 WaitForSingleObject(ProcInfo.hProcess, INFINITE);
\r
130 CloseHandle(ProcInfo.hThread);
\r
131 CloseHandle(ProcInfo.hProcess);
\r