/* Bacula® - The Network Backup Solution Copyright (C) 2007-2007 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. This program is Free Software; you can redistribute it and/or modify it under the terms of version two of the GNU General Public License as published by the Free Software Foundation and included in the file LICENSE. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Bacula® is a registered trademark of John Walker. The licensor of Bacula is the Free Software Foundation Europe (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, Switzerland, email:ftf@fsfeurope.org. */ /* * * Kern Sibbald, August 2007 * * Version $Id: main.cpp 5622 2007-09-22 09:08:29Z kerns $ * * Note, some of the original Bacula Windows startup and service handling code * was derived from VNC code that was used in apcupsd then ported to * Bacula. However, since then the code has been significantly enhanced * and largely rewritten. * * Evidently due to the nature of Windows startup code and service * handling code, certain similarities remain. Thanks to the original * VNC authors. * * This is a generic main routine, which is used by all three * of the daemons. Each one compiles it with slightly different * #defines. * */ #include "bacula.h" #include "win32.h" #include #include #undef _WIN32_IE #define _WIN32_IE 0x0401 #undef _WIN32_WINNT #define _WIN32_WINNT 0x0501 #include /* Globals */ HINSTANCE appInstance; DWORD mainthreadId; bool opt_debug = false; bool have_service_api; DWORD service_thread_id = 0; #define MAX_COMMAND_ARGS 100 static char *command_args[MAX_COMMAND_ARGS] = {LC_APP_NAME, NULL}; static int num_command_args = 1; static pid_t main_pid; static pthread_t main_tid; const char usage[] = APP_NAME "[/debug] [/service] [/run] [/kill] [/install] [/remove] [/help]\n"; /* * * Main Windows entry point. * * We parse the command line and either calls the main App * or starts up the service. */ int WINAPI WinMain(HINSTANCE Instance, HINSTANCE /*PrevInstance*/, PSTR CmdLine, int /*show*/) { char *cmdLine = CmdLine; char *wordPtr, *tempPtr; int i, quote; OSVERSIONINFO osversioninfo; osversioninfo.dwOSVersionInfoSize = sizeof(osversioninfo); /* Save the application instance and main thread id */ appInstance = Instance; mainthreadId = GetCurrentThreadId(); if (GetVersionEx(&osversioninfo) && osversioninfo.dwPlatformId == VER_PLATFORM_WIN32_NT) { have_service_api = true; } main_pid = getpid(); main_tid = pthread_self(); INITCOMMONCONTROLSEX initCC = { sizeof(INITCOMMONCONTROLSEX), ICC_STANDARD_CLASSES }; InitCommonControlsEx(&initCC); /* * Funny things happen with the command line if the * execution comes from c:/Program Files/bacula/bacula.exe * We get a command line like: Files/bacula/bacula.exe" options * I.e. someone stops scanning command line on a space, not * realizing that the filename is quoted!!!!!!!!!! * So if first character is not a double quote and * the last character before first space is a double * quote, we throw away the junk. */ wordPtr = cmdLine; while (*wordPtr && *wordPtr != ' ') wordPtr++; if (wordPtr > cmdLine) /* backup to char before space */ wordPtr--; /* if first character is not a quote and last is, junk it */ if (*cmdLine != '"' && *wordPtr == '"') { cmdLine = wordPtr + 1; } /* * Build Unix style argc *argv[] for the main "Unix" code * stripping out any Windows options */ /* Don't NULL command_args[0] !!! */ for (i=1;i