From 12b495a28dcf15b06c4a6e35cc2147d9d13bbdde Mon Sep 17 00:00:00 2001 From: Robert Nelson Date: Wed, 11 Oct 2006 22:40:53 +0000 Subject: [PATCH] Send M_ERROR_TERM and M_ABORT messages to stdout on Windows. Fix cleanup of spool files on Windows. Fix Windows 9x compatibility. Remove /silent option from daemons on Windows. The new default is the same as the old /silent. To enable the message boxes that previously were suppressed by /silent you must add /debug instead. Add new /debug option. This option enables the message boxes that previously were suppressed by the /silent option. In addition the daemons will open a console window if this option is used. Fix bug with service not being removed on migrated installs. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@3548 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/lib/message.c | 2 - bacula/src/stored/stored.c | 12 +++- bacula/src/win32/compat/winapi.c | 49 +++++++------ bacula/src/win32/dird/winbacula.h | 4 +- bacula/src/win32/dird/winmain.cpp | 37 +++++----- bacula/src/win32/dird/winservice.cpp | 6 +- bacula/src/win32/filed/vss_generic.cpp | 70 +++++++++++-------- bacula/src/win32/filed/winmain.cpp | 34 ++++----- bacula/src/win32/filed/winservice.cpp | 10 +-- bacula/src/win32/installer/winbacula.nsi | 36 ++++------ bacula/src/win32/libbac/libbac.vcproj | 12 ++-- bacula/src/win32/libwin32/winbacula.h | 4 +- bacula/src/win32/stored/baculasd/winbacula.h | 4 +- bacula/src/win32/stored/baculasd/winmain.cpp | 31 ++++---- .../src/win32/stored/baculasd/winservice.cpp | 6 +- bacula/src/win32/winapi.h | 6 +- bacula/src/wx-console/console_thread.cpp | 2 - bacula/technotes-1.39 | 36 ++++++++++ 18 files changed, 203 insertions(+), 158 deletions(-) diff --git a/bacula/src/lib/message.c b/bacula/src/lib/message.c index 15a939590e..7b411d5b3c 100755 --- a/bacula/src/lib/message.c +++ b/bacula/src/lib/message.c @@ -596,11 +596,9 @@ void dispatch_message(JCR *jcr, int type, time_t mtime, char *msg) } if (type == M_ABORT || type == M_ERROR_TERM) { -#if !defined(HAVE_WIN32) fputs(dt, stdout); fputs(msg, stdout); /* print this here to INSURE that it is printed */ fflush(stdout); -#endif } /* Now figure out where to send the message */ diff --git a/bacula/src/stored/stored.c b/bacula/src/stored/stored.c index 26205e2024..aa6c47ad07 100644 --- a/bacula/src/stored/stored.c +++ b/bacula/src/stored/stored.c @@ -418,16 +418,24 @@ static void cleanup_old_files() { POOLMEM *cleanup = get_pool_memory(PM_MESSAGE); int len = strlen(me->working_directory); +#if defined(HAVE_WIN32) + pm_strcpy(cleanup, "del /q "); +#else pm_strcpy(cleanup, "/bin/rm -f "); +#endif pm_strcat(cleanup, me->working_directory); - if (len > 0 && me->working_directory[len-1] != '/') { + if (len > 0 && me->working_directory[len-1] != '/' +#if defined(HAVE_WIN32) + && me->working_directory[len-1] != '\\' +#endif + ) { pm_strcat(cleanup, "/"); } pm_strcat(cleanup, my_name); pm_strcat(cleanup, "*.spool"); run_program(cleanup, 0, NULL); free_pool_memory(cleanup); -} +} /* diff --git a/bacula/src/win32/compat/winapi.c b/bacula/src/win32/compat/winapi.c index f08cf623dd..0681c6c6dc 100644 --- a/bacula/src/win32/compat/winapi.c +++ b/bacula/src/win32/compat/winapi.c @@ -34,13 +34,13 @@ t_LookupPrivilegeValue p_LookupPrivilegeValue = NULL; t_SetProcessShutdownParameters p_SetProcessShutdownParameters = NULL; -t_CreateFileA p_CreateFileA = NULL; -t_CreateFileW p_CreateFileW = NULL; -t_CreateDirectoryA p_CreateDirectoryA; -t_CreateDirectoryW p_CreateDirectoryW; +t_CreateFileA p_CreateFileA = NULL; +t_CreateFileW p_CreateFileW = NULL; +t_CreateDirectoryA p_CreateDirectoryA; +t_CreateDirectoryW p_CreateDirectoryW; -t_wunlink p_wunlink = NULL; -t_wmkdir p_wmkdir = NULL; +t_wunlink p_wunlink = NULL; +t_wmkdir p_wmkdir = NULL; t_GetFileAttributesA p_GetFileAttributesA = NULL; t_GetFileAttributesW p_GetFileAttributesW = NULL; @@ -52,22 +52,24 @@ t_SetFileAttributesA p_SetFileAttributesA = NULL; t_SetFileAttributesW p_SetFileAttributesW = NULL; t_BackupRead p_BackupRead = NULL; t_BackupWrite p_BackupWrite = NULL; -t_WideCharToMultiByte p_WideCharToMultiByte = NULL; -t_MultiByteToWideChar p_MultiByteToWideChar = NULL; +t_WideCharToMultiByte p_WideCharToMultiByte = NULL; +t_MultiByteToWideChar p_MultiByteToWideChar = NULL; -t_FindFirstFileA p_FindFirstFileA = NULL; -t_FindFirstFileW p_FindFirstFileW = NULL; +t_AttachConsole p_AttachConsole = NULL; -t_FindNextFileA p_FindNextFileA = NULL; -t_FindNextFileW p_FindNextFileW = NULL; +t_FindFirstFileA p_FindFirstFileA = NULL; +t_FindFirstFileW p_FindFirstFileW = NULL; -t_SetCurrentDirectoryA p_SetCurrentDirectoryA = NULL; -t_SetCurrentDirectoryW p_SetCurrentDirectoryW = NULL; +t_FindNextFileA p_FindNextFileA = NULL; +t_FindNextFileW p_FindNextFileW = NULL; -t_GetCurrentDirectoryA p_GetCurrentDirectoryA = NULL; -t_GetCurrentDirectoryW p_GetCurrentDirectoryW = NULL; +t_SetCurrentDirectoryA p_SetCurrentDirectoryA = NULL; +t_SetCurrentDirectoryW p_SetCurrentDirectoryW = NULL; -t_GetVolumePathNameW p_GetVolumePathNameW = NULL; +t_GetCurrentDirectoryA p_GetCurrentDirectoryA = NULL; +t_GetCurrentDirectoryW p_GetCurrentDirectoryW = NULL; + +t_GetVolumePathNameW p_GetVolumePathNameW = NULL; t_GetVolumeNameForVolumeMountPointW p_GetVolumeNameForVolumeMountPointW = NULL; void @@ -124,9 +126,9 @@ InitWinAPIWrapper() if (g_platform_id != VER_PLATFORM_WIN32_WINDOWS) { p_CreateFileW = (t_CreateFileW) - GetProcAddress(hLib, "CreateFileW"); + GetProcAddress(hLib, "CreateFileW"); p_CreateDirectoryW = (t_CreateDirectoryW) - GetProcAddress(hLib, "CreateDirectoryW"); + GetProcAddress(hLib, "CreateDirectoryW"); /* backup calls */ p_BackupRead = (t_BackupRead) @@ -141,13 +143,13 @@ InitWinAPIWrapper() p_SetFileAttributesW = (t_SetFileAttributesW) GetProcAddress(hLib, "SetFileAttributesW"); p_FindFirstFileW = (t_FindFirstFileW) - GetProcAddress(hLib, "FindFirstFileW"); + GetProcAddress(hLib, "FindFirstFileW"); p_FindNextFileW = (t_FindNextFileW) GetProcAddress(hLib, "FindNextFileW"); p_GetCurrentDirectoryW = (t_GetCurrentDirectoryW) - GetProcAddress(hLib, "GetCurrentDirectoryW"); + GetProcAddress(hLib, "GetCurrentDirectoryW"); p_SetCurrentDirectoryW = (t_SetCurrentDirectoryW) - GetProcAddress(hLib, "SetCurrentDirectoryW"); + GetProcAddress(hLib, "SetCurrentDirectoryW"); /* some special stuff we need for VSS but statically linkage doesn't work on Win 9x */ @@ -155,6 +157,9 @@ InitWinAPIWrapper() GetProcAddress(hLib, "GetVolumePathNameW"); p_GetVolumeNameForVolumeMountPointW = (t_GetVolumeNameForVolumeMountPointW) GetProcAddress(hLib, "GetVolumeNameForVolumeMountPointW"); + + p_AttachConsole = (t_AttachConsole) + GetProcAddress(hLib, "AttachConsole"); } FreeLibrary(hLib); diff --git a/bacula/src/win32/dird/winbacula.h b/bacula/src/win32/dird/winbacula.h index 0e69602848..6a0a4e9a57 100644 --- a/bacula/src/win32/dird/winbacula.h +++ b/bacula/src/win32/dird/winbacula.h @@ -49,7 +49,7 @@ extern int BaculaAppMain(); extern void LogErrorMsg(char *msg); // Standard command-line flag definitions -const char BaculaSilent[] = "/silent"; +const char BaculaOptDebug[] = "/debug"; const char BaculaRunService[] = "/service"; const char BaculaRunAsUserApp[] = "/run"; @@ -61,7 +61,7 @@ const char BaculaRemoveService[] = "/remove"; const char BaculaShowHelp[] = "/help"; // Usage string -const char BaculaUsageText[] = "Bacula [/silent] [/service] [/run] [/kill] [/install] [/remove] [/help]\n"; +const char BaculaUsageText[] = "Bacula [/debug] [/service] [/run] [/kill] [/install] [/remove] [/help]\n"; void LogErrorMsg(char *msg, char *fname, int lineno); #define log_error_message(msg) LogErrorMsg((msg), __FILE__, __LINE__) diff --git a/bacula/src/win32/dird/winmain.cpp b/bacula/src/win32/dird/winmain.cpp index a3f680eaf2..fbd1cabd7f 100644 --- a/bacula/src/win32/dird/winmain.cpp +++ b/bacula/src/win32/dird/winmain.cpp @@ -31,10 +31,10 @@ extern BOOL ReportStatus(DWORD state, DWORD exitcode, DWORD waithint); extern void d_msg(const char *, int, int, const char *, ...); /* Globals */ -HINSTANCE hAppInstance; -const char *szAppName = "Bacula-dir"; -DWORD mainthreadId; -bool silent = false; +HINSTANCE hAppInstance; +const char *szAppName = "Bacula-dir"; +DWORD mainthreadId; +bool opt_debug = false; /* Imported variables */ extern DWORD g_servicethread; @@ -55,7 +55,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, char *szCmdLine = CmdLine; char *wordPtr, *tempPtr; int i, quote; - DWORD dwCharsWritten; /* Save the application instance and main thread id */ hAppInstance = hInstance; @@ -144,10 +143,10 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, /* Now check for command-line arguments */ - /* /silent install quietly -- no prompts */ - if (strnicmp(&szCmdLine[i], BaculaSilent, sizeof(BaculaSilent) - 1) == 0) { - silent = true; - i += sizeof(BaculaSilent) - 1; + /* /debug install quietly -- no prompts */ + if (strnicmp(&szCmdLine[i], BaculaOptDebug, sizeof(BaculaOptDebug) - 1) == 0) { + opt_debug = true; + i += sizeof(BaculaOptDebug) - 1; continue; } @@ -159,11 +158,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, /* /run (this is the default if no command line arguments) */ if (strnicmp(&szCmdLine[i], BaculaRunAsUserApp, sizeof(BaculaRunAsUserApp) - 1) == 0) { /* Bacula is being run as a user-level program */ - if (!AttachConsole(ATTACH_PARENT_PROCESS)) { - AllocConsole(); - } - WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), "\r\n", 2, &dwCharsWritten, NULL); - return BaculaAppMain(); } /* /install */ @@ -196,12 +190,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, return 1; } - /* If no arguments were given then just run */ - if (!AttachConsole(ATTACH_PARENT_PROCESS)) { - AllocConsole(); - } - WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), "\r\n", 2, &dwCharsWritten, NULL); - return BaculaAppMain(); } @@ -258,11 +246,20 @@ int BaculaAppMain() { /* DWORD dwThreadID; */ pthread_t tid; + DWORD dwCharsWritten; InitWinAPIWrapper(); WSA_Init(); + /* If no arguments were given then just run */ + if (p_AttachConsole == NULL || !p_AttachConsole(ATTACH_PARENT_PROCESS)) { + if (opt_debug) { + AllocConsole(); + } + } + WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), "\r\n", 2, &dwCharsWritten, NULL); + /* Set this process to be the last application to be shut down. */ if (p_SetProcessShutdownParameters) { p_SetProcessShutdownParameters(0x100, 0); diff --git a/bacula/src/win32/dird/winservice.cpp b/bacula/src/win32/dird/winservice.cpp index e9169b72fe..1b71b617b5 100644 --- a/bacula/src/win32/dird/winservice.cpp +++ b/bacula/src/win32/dird/winservice.cpp @@ -51,7 +51,7 @@ void set_service_description(SC_HANDLE hSCManager, SC_HANDLE hService, bacService init; -extern bool silent; +extern bool opt_debug; // SERVICE-MODE ROUTINES @@ -267,7 +267,7 @@ _("Provides director services. Bacula -- the network backup solution.")); CloseServiceHandle(hservice); // Everything went fine - if (!silent) { + if (opt_debug) { MessageBox(NULL, _("The Bacula Director service was successfully installed.\n" "The service may be started from the Control Panel and will\n" @@ -314,7 +314,7 @@ bacService::RemoveService() // Now remove the service from the SCM if(DeleteService(hservice)) { - if (!silent) { + if (opt_debug) { MessageBox(NULL, _("The Bacula Director service has been removed"), szAppName, MB_ICONINFORMATION | MB_OK); } } else { diff --git a/bacula/src/win32/filed/vss_generic.cpp b/bacula/src/win32/filed/vss_generic.cpp index f87c6d57c7..328fc9d86e 100644 --- a/bacula/src/win32/filed/vss_generic.cpp +++ b/bacula/src/win32/filed/vss_generic.cpp @@ -198,14 +198,17 @@ VSSClientGeneric::~VSSClientGeneric() BOOL VSSClientGeneric::Initialize(DWORD dwContext, BOOL bDuringRestore) { if (!(p_CreateVssBackupComponents && p_VssFreeSnapshotProperties)) { + Dmsg2(0, "VSSClientGeneric::Initialize: p_CreateVssBackupComponents = 0x%08X, p_VssFreeSnapshotProperties = 0x%08X\n", p_CreateVssBackupComponents, p_VssFreeSnapshotProperties); errno = ENOSYS; return FALSE; } HRESULT hr; - // Initialize COM - if (!m_bCoInitializeCalled) { - if (FAILED(CoInitialize(NULL))) { + // Initialize COM + if (!m_bCoInitializeCalled) { + hr = CoInitialize(NULL); + if (FAILED(hr)) { + Dmsg1(0, "VSSClientGeneric::Initialize: CoInitialize returned 0x%08X\n", hr); errno = b_errno_win32; return FALSE; } @@ -227,13 +230,14 @@ BOOL VSSClientGeneric::Initialize(DWORD dwContext, BOOL bDuringRestore) NULL // Reserved parameter ); - if (FAILED(hr)) { + if (FAILED(hr)) { + Dmsg1(0, "VSSClientGeneric::Initialize: CoInitializeSecurity returned 0x%08X\n", hr); errno = b_errno_win32; return FALSE; } - m_bCoInitializeSecurityCalled = true; + m_bCoInitializeSecurityCalled = true; } - + // Release the IVssBackupComponents interface if (m_pVssObject) { m_pVssObject->Release(); @@ -242,7 +246,8 @@ BOOL VSSClientGeneric::Initialize(DWORD dwContext, BOOL bDuringRestore) // Create the internal backup components object hr = p_CreateVssBackupComponents((IVssBackupComponents**) &m_pVssObject); - if (FAILED(hr)) { + if (FAILED(hr)) { + Dmsg1(0, "VSSClientGeneric::Initialize: CreateVssBackupComponents returned 0x%08X\n", hr); errno = b_errno_win32; return FALSE; } @@ -251,6 +256,7 @@ BOOL VSSClientGeneric::Initialize(DWORD dwContext, BOOL bDuringRestore) if (dwContext != VSS_CTX_BACKUP) { hr = ((IVssBackupComponents*) m_pVssObject)->SetContext(dwContext); if (FAILED(hr)) { + Dmsg1(0, "VSSClientGeneric::Initialize: IVssBackupComponents->SetContext returned 0x%08X\n", hr); errno = b_errno_win32; return FALSE; } @@ -258,31 +264,33 @@ BOOL VSSClientGeneric::Initialize(DWORD dwContext, BOOL bDuringRestore) #endif if (!bDuringRestore) { - // 1. InitializeForBackup - hr = ((IVssBackupComponents*) m_pVssObject)->InitializeForBackup(); - if (FAILED(hr)) { - errno = b_errno_win32; - return FALSE; - } + // 1. InitializeForBackup + hr = ((IVssBackupComponents*) m_pVssObject)->InitializeForBackup(); + if (FAILED(hr)) { + Dmsg1(0, "VSSClientGeneric::Initialize: IVssBackupComponents->InitializeForBackup returned 0x%08X\n", hr); + errno = b_errno_win32; + return FALSE; + } - // 2. SetBackupState - hr = ((IVssBackupComponents*) m_pVssObject)->SetBackupState(true, true, VSS_BT_FULL, false); - if (FAILED(hr)) { - errno = b_errno_win32; - return FALSE; - } - - CComPtr pAsync1; - // 3. GatherWriterMetaData - hr = ((IVssBackupComponents*) m_pVssObject)->GatherWriterMetadata(&pAsync1.p); - if (FAILED(hr)) { - errno = b_errno_win32; - return FALSE; - } - // Waits for the async operation to finish and checks the result - WaitAndCheckForAsyncOperation(pAsync1.p); - } + // 2. SetBackupState + hr = ((IVssBackupComponents*) m_pVssObject)->SetBackupState(true, true, VSS_BT_FULL, false); + if (FAILED(hr)) { + Dmsg1(0, "VSSClientGeneric::Initialize: IVssBackupComponents->SetBackupState returned 0x%08X\n", hr); + errno = b_errno_win32; + return FALSE; + } + CComPtr pAsync1; + // 3. GatherWriterMetaData + hr = ((IVssBackupComponents*) m_pVssObject)->GatherWriterMetadata(&pAsync1.p); + if (FAILED(hr)) { + Dmsg1(0, "VSSClientGeneric::Initialize: IVssBackupComponents->GatherWriterMetadata returned 0x%08X\n", hr); + errno = b_errno_win32; + return FALSE; + } + // Waits for the async operation to finish and checks the result + WaitAndCheckForAsyncOperation(pAsync1.p); + } // We are during restore now? m_bDuringRestore = bDuringRestore; @@ -610,7 +618,7 @@ BOOL VSSClientGeneric::CheckWriterStatus() bstrncpy(str, "\"", sizeof(str)); wchar_2_UTF8(szBuf, bstrWriterName.p, sizeof(szBuf)); bstrncat(str, szBuf, sizeof(str)); - bstrncat(str, "\", State: 0x",sizeof(str)); + bstrncat(str, "\", State: 0x", sizeof(str)); itoa(eWriterStatus, szBuf, sizeof(szBuf)); bstrncat(str, szBuf, sizeof(str)); bstrncat(str, " (", sizeof(str)); diff --git a/bacula/src/win32/filed/winmain.cpp b/bacula/src/win32/filed/winmain.cpp index 85b941cc94..5b540af89c 100644 --- a/bacula/src/win32/filed/winmain.cpp +++ b/bacula/src/win32/filed/winmain.cpp @@ -36,7 +36,7 @@ extern void VSSInit(); HINSTANCE hAppInstance; const char *szAppName = "Bacula-fd"; DWORD mainthreadId; -bool silent = false; +bool opt_debug = false; /* Imported variables */ extern DWORD g_servicethread; @@ -57,7 +57,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, char *szCmdLine = CmdLine; char *wordPtr, *tempPtr; int i, quote; - DWORD dwCharsWritten; /* Save the application instance and main thread id */ hAppInstance = hInstance; @@ -86,7 +85,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, if (*szCmdLine != '"' && *wordPtr == '"') { szCmdLine = wordPtr + 1; } -// MessageBox(NULL, szCmdLine, "Cmdline", MB_OK); /* Build Unix style argc *argv[] */ @@ -147,10 +145,10 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, /* Now check for command-line arguments */ - /* /silent install quietly -- no prompts */ - if (strnicmp(&szCmdLine[i], BaculaSilent, sizeof(BaculaSilent) - 1) == 0) { - silent = true; - i += sizeof(BaculaSilent) - 1; + /* /debug - enable debugging facilities such as console message window */ + if (strnicmp(&szCmdLine[i], BaculaOptDebug, sizeof(BaculaOptDebug) - 1) == 0) { + opt_debug = true; + i += sizeof(BaculaOptDebug) - 1; continue; } @@ -162,11 +160,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, /* /run (this is the default if no command line arguments) */ if (strnicmp(&szCmdLine[i], BaculaRunAsUserApp, sizeof(BaculaRunAsUserApp) - 1) == 0) { /* Bacula is being run as a user-level program */ - if (!AttachConsole(ATTACH_PARENT_PROCESS)) { - AllocConsole(); - } - WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), "\r\n", 2, &dwCharsWritten, NULL); - return BaculaAppMain(); } /* /install */ @@ -212,12 +205,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, return 1; } - /* If no arguments were given then just run */ - if (!AttachConsole(ATTACH_PARENT_PROCESS)) { - AllocConsole(); - } - WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), "\r\n", 2, &dwCharsWritten, NULL); - return BaculaAppMain(); } @@ -231,7 +218,6 @@ void *Main_Msg_Loop(LPVOID lpwThreadParam) { DWORD old_servicethread = g_servicethread; - pthread_detach(pthread_self()); /* Since we are the only thread with a message loop @@ -286,8 +272,18 @@ int BaculaAppMain() { /* DWORD dwThreadID; */ pthread_t tid; + DWORD dwCharsWritten; InitWinAPIWrapper(); + + /* If no arguments were given then just run */ + if (p_AttachConsole == NULL || !p_AttachConsole(ATTACH_PARENT_PROCESS)) { + if (opt_debug) { + AllocConsole(); + } + } + WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), "\r\n", 2, &dwCharsWritten, NULL); + VSSInit(); WSA_Init(); diff --git a/bacula/src/win32/filed/winservice.cpp b/bacula/src/win32/filed/winservice.cpp index ed5054f4f3..f6ec888c97 100644 --- a/bacula/src/win32/filed/winservice.cpp +++ b/bacula/src/win32/filed/winservice.cpp @@ -52,7 +52,7 @@ void set_service_description(SC_HANDLE hSCManager, SC_HANDLE hService, bacService init; -extern bool silent; +extern bool opt_debug; bacService::bacService() { @@ -369,7 +369,7 @@ bacService::InstallService(const char *pszCmdLine) RegCloseKey(runservices); // We have successfully installed the service! - if (!silent) { + if (opt_debug) { MessageBox(NULL, _("The Bacula File service was successfully installed.\n" "The service may be started by double clicking on the\n" @@ -427,7 +427,7 @@ _("Provides file backup and restore services. Bacula -- the network backup solut CloseServiceHandle(hservice); // Everything went fine - if (!silent) { + if (opt_debug) { MessageBox(NULL, _("The Bacula File service was successfully installed.\n" "The service may be started from the Control Panel and will\n" @@ -485,7 +485,7 @@ bacService::RemoveService() } // We have successfully removed the service! - if (!silent) { + if (opt_debug) { MessageBox(NULL, _("The Bacula service has been removed"), szAppName, MB_ICONINFORMATION | MB_OK); } break; @@ -523,7 +523,7 @@ bacService::RemoveService() // Now remove the service from the SCM if (DeleteService(hservice)) { - if (!silent) { + if (opt_debug) { MessageBox(NULL, _("The Bacula file service has been removed"), szAppName, MB_ICONINFORMATION | MB_OK); } } else { diff --git a/bacula/src/win32/installer/winbacula.nsi b/bacula/src/win32/installer/winbacula.nsi index 8de4b90976..5a80af1e01 100644 --- a/bacula/src/win32/installer/winbacula.nsi +++ b/bacula/src/win32/installer/winbacula.nsi @@ -533,27 +533,21 @@ Section "-Initialize" ${EndIf} ${If} ${FileExists} "$OldInstallDir\bin\bacula-fd.exe" - ${If} $InstallType <> ${MigrateInstall} - nsExec::ExecToLog '"$OldInstallDir\bin\bacula-fd.exe" /silent /kill' ; Shutdown any bacula that could be running - Sleep 3000 - nsExec::ExecToLog '"$OldInstallDir\bin\bacula-fd.exe" /silent /remove' ; Remove existing service - ${Else} - nsExec::ExecToLog '"$OldInstallDir\bin\bacula-fd.exe" /kill' ; Shutdown any bacula that could be running - Sleep 3000 - nsExec::ExecToLog '"$OldInstallDir\bin\bacula-fd.exe" /remove' ; Remove existing service - ${EndIf} + nsExec::ExecToLog '"$OldInstallDir\bin\bacula-fd.exe" /kill' ; Shutdown any bacula that could be running + Sleep 3000 + nsExec::ExecToLog '"$OldInstallDir\bin\bacula-fd.exe" /remove' ; Remove existing service ${EndIf} ${If} ${FileExists} "$OldInstallDir\bin\bacula-sd.exe" - nsExec::ExecToLog '"$OldInstallDir\bin\bacula-sd.exe" /silent /kill' ; Shutdown any bacula that could be running + nsExec::ExecToLog '"$OldInstallDir\bin\bacula-sd.exe" /kill' ; Shutdown any bacula that could be running Sleep 3000 - nsExec::ExecToLog '"$OldInstallDir\bin\bacula-sd.exe" /silent /remove' ; Remove existing service + nsExec::ExecToLog '"$OldInstallDir\bin\bacula-sd.exe" /remove' ; Remove existing service ${EndIf} ${If} ${FileExists} "$OldInstallDir\bin\bacula-dir.exe" - nsExec::ExecToLog '"$OldInstallDir\bin\bacula-dir.exe" /silent /kill' ; Shutdown any bacula that could be running + nsExec::ExecToLog '"$OldInstallDir\bin\bacula-dir.exe" /kill' ; Shutdown any bacula that could be running Sleep 3000 - nsExec::ExecToLog '"$OldInstallDir\bin\bacula-dir.exe" /silent /remove' ; Remove existing service + nsExec::ExecToLog '"$OldInstallDir\bin\bacula-dir.exe" /remove' ; Remove existing service ${EndIf} SectionEnd @@ -865,27 +859,27 @@ UninstallText "This will uninstall Bacula. Hit next to continue." Section "Uninstall" ; Shutdown any baculum that could be running - nsExec::ExecToLog '"$INSTDIR\bin\bacula-fd.exe" /silent /kill' - nsExec::ExecToLog '"$INSTDIR\bin\bacula-sd.exe" /silent /kill' - nsExec::ExecToLog '"$INSTDIR\bin\bacula-dir.exe" /silent /kill' + nsExec::ExecToLog '"$INSTDIR\bin\bacula-fd.exe" /kill' + nsExec::ExecToLog '"$INSTDIR\bin\bacula-sd.exe" /kill' + nsExec::ExecToLog '"$INSTDIR\bin\bacula-dir.exe" /kill' Sleep 3000 ReadRegDWORD $R0 HKLM "Software\Bacula" "Service_Bacula-fd" ${If} $R0 = 1 ; Remove bacula service - nsExec::ExecToLog '"$INSTDIR\bin\bacula-fd.exe" /silent /remove' + nsExec::ExecToLog '"$INSTDIR\bin\bacula-fd.exe" /remove' ${EndIf} ReadRegDWORD $R0 HKLM "Software\Bacula" "Service_Bacula-sd" ${If} $R0 = 1 ; Remove bacula service - nsExec::ExecToLog '"$INSTDIR\bin\bacula-sd.exe" /silent /remove' + nsExec::ExecToLog '"$INSTDIR\bin\bacula-sd.exe" /remove' ${EndIf} ReadRegDWORD $R0 HKLM "Software\Bacula" "Service_Bacula-dir" ${If} $R0 = 1 ; Remove bacula service - nsExec::ExecToLog '"$INSTDIR\bin\bacula-dir.exe" /silent /remove' + nsExec::ExecToLog '"$INSTDIR\bin\bacula-dir.exe" /remove' ${EndIf} ; remove registry keys @@ -930,14 +924,14 @@ Function InstallDaemon WriteRegDWORD HKLM "Software\Bacula" "Service_$0" $2 ${If} $2 = 1 - nsExec::ExecToLog '"$INSTDIR\bin\$0.exe" /silent /install -c "$APPDATA\Bacula\$0.conf"' + nsExec::ExecToLog '"$INSTDIR\bin\$0.exe" /install -c "$APPDATA\Bacula\$0.conf"' ${If} $OsIsNT <> 1 File "Start.bat" File "Stop.bat" ${EndIf} - ; Start the service? (default skipped if silent, use /start to force starting) + ; Start the service? ${If} $3 = 1 ${If} $OsIsNT = 1 diff --git a/bacula/src/win32/libbac/libbac.vcproj b/bacula/src/win32/libbac/libbac.vcproj index 75b52997a1..e9d00418a4 100644 --- a/bacula/src/win32/libbac/libbac.vcproj +++ b/bacula/src/win32/libbac/libbac.vcproj @@ -47,8 +47,8 @@ RuntimeLibrary="3" UsePrecompiledHeader="0" WarningLevel="3" - Detect64BitPortabilityProblems="false" SuppressStartupBanner="true" + Detect64BitPortabilityProblems="false" DebugInformationFormat="4" /> + + diff --git a/bacula/src/win32/libwin32/winbacula.h b/bacula/src/win32/libwin32/winbacula.h index 7968b1da6a..b1674cc662 100644 --- a/bacula/src/win32/libwin32/winbacula.h +++ b/bacula/src/win32/libwin32/winbacula.h @@ -49,7 +49,7 @@ extern int BaculaAppMain(); extern void LogErrorMsg(char *msg); // Standard command-line flag definitions -const char BaculaSilent[] = "/silent"; +const char BaculaOptDebug[] = "/debug"; const char BaculaRunService[] = "/service"; const char BaculaRunAsUserApp[] = "/run"; @@ -64,7 +64,7 @@ const char BaculaShowStatus[] = "/status"; const char BaculaShowHelp[] = "/help"; // Usage string -const char BaculaUsageText[] = "Bacula [/silent] [/service] [/run] [/kill] [/install] [/remove] [/about] [/status] [/help]\n"; +const char BaculaUsageText[] = "Bacula [/debug] [/service] [/run] [/kill] [/install] [/remove] [/about] [/status] [/help]\n"; void LogErrorMsg(char *msg, char *fname, int lineno); #define log_error_message(msg) LogErrorMsg((msg), __FILE__, __LINE__) diff --git a/bacula/src/win32/stored/baculasd/winbacula.h b/bacula/src/win32/stored/baculasd/winbacula.h index 7968b1da6a..b1674cc662 100644 --- a/bacula/src/win32/stored/baculasd/winbacula.h +++ b/bacula/src/win32/stored/baculasd/winbacula.h @@ -49,7 +49,7 @@ extern int BaculaAppMain(); extern void LogErrorMsg(char *msg); // Standard command-line flag definitions -const char BaculaSilent[] = "/silent"; +const char BaculaOptDebug[] = "/debug"; const char BaculaRunService[] = "/service"; const char BaculaRunAsUserApp[] = "/run"; @@ -64,7 +64,7 @@ const char BaculaShowStatus[] = "/status"; const char BaculaShowHelp[] = "/help"; // Usage string -const char BaculaUsageText[] = "Bacula [/silent] [/service] [/run] [/kill] [/install] [/remove] [/about] [/status] [/help]\n"; +const char BaculaUsageText[] = "Bacula [/debug] [/service] [/run] [/kill] [/install] [/remove] [/about] [/status] [/help]\n"; void LogErrorMsg(char *msg, char *fname, int lineno); #define log_error_message(msg) LogErrorMsg((msg), __FILE__, __LINE__) diff --git a/bacula/src/win32/stored/baculasd/winmain.cpp b/bacula/src/win32/stored/baculasd/winmain.cpp index a42e029220..b665df7934 100644 --- a/bacula/src/win32/stored/baculasd/winmain.cpp +++ b/bacula/src/win32/stored/baculasd/winmain.cpp @@ -35,7 +35,7 @@ extern void d_msg(const char *, int, int, const char *, ...); HINSTANCE hAppInstance; const char *szAppName = "Bacula-sd"; DWORD mainthreadId; -bool silent = false; +bool opt_debug = false; /* Imported variables */ extern DWORD g_servicethread; @@ -56,7 +56,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, char *szCmdLine = CmdLine; char *wordPtr, *tempPtr; int i, quote; - DWORD dwCharsWritten; /* Save the application instance and main thread id */ hAppInstance = hInstance; @@ -145,10 +144,10 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, /* Now check for command-line arguments */ - /* /silent install quietly -- no prompts */ - if (strnicmp(&szCmdLine[i], BaculaSilent, sizeof(BaculaSilent) - 1) == 0) { - silent = true; - i += sizeof(BaculaSilent) - 1; + /* /debug install quietly -- no prompts */ + if (strnicmp(&szCmdLine[i], BaculaOptDebug, sizeof(BaculaOptDebug) - 1) == 0) { + opt_debug = true; + i += sizeof(BaculaOptDebug) - 1; continue; } @@ -160,11 +159,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, /* /run (this is the default if no command line arguments) */ if (strnicmp(&szCmdLine[i], BaculaRunAsUserApp, sizeof(BaculaRunAsUserApp) - 1) == 0) { /* Bacula is being run as a user-level program */ - if (!AttachConsole(ATTACH_PARENT_PROCESS)) { - AllocConsole(); - } - WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), "\r\n", 2, &dwCharsWritten, NULL); - return BaculaAppMain(); } /* /install */ @@ -209,12 +203,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, return 1; } - /* If no arguments were given then just run */ - if (!AttachConsole(ATTACH_PARENT_PROCESS)) { - AllocConsole(); - } - WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), "\r\n", 2, &dwCharsWritten, NULL); - return BaculaAppMain(); } @@ -283,11 +271,20 @@ int BaculaAppMain() { /* DWORD dwThreadID; */ pthread_t tid; + DWORD dwCharsWritten; InitWinAPIWrapper(); WSA_Init(); + /* If no arguments were given then just run */ + if (p_AttachConsole == NULL || !p_AttachConsole(ATTACH_PARENT_PROCESS)) { + if (opt_debug) { + AllocConsole(); + } + } + WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), "\r\n", 2, &dwCharsWritten, NULL); + /* Set this process to be the last application to be shut down. */ if (p_SetProcessShutdownParameters) { p_SetProcessShutdownParameters(0x100, 0); diff --git a/bacula/src/win32/stored/baculasd/winservice.cpp b/bacula/src/win32/stored/baculasd/winservice.cpp index 7f3f0cbf57..5e23337fcb 100644 --- a/bacula/src/win32/stored/baculasd/winservice.cpp +++ b/bacula/src/win32/stored/baculasd/winservice.cpp @@ -52,7 +52,7 @@ void set_service_description(SC_HANDLE hSCManager, SC_HANDLE hService, bacService init; -extern bool silent; +extern bool opt_debug; bacService::bacService() { @@ -317,7 +317,7 @@ _("Provides storage services. Bacula -- the network backup solution.")); CloseServiceHandle(hservice); // Everything went fine - if (!silent) { + if (opt_debug) { MessageBox(NULL, _("The Bacula Storage service was successfully installed.\n" "The service may be started from the Control Panel and will\n" @@ -364,7 +364,7 @@ bacService::RemoveService() // Now remove the service from the SCM if(DeleteService(hservice)) { - if (!silent) { + if (opt_debug) { MessageBox(NULL, _("The Bacula Storage service has been removed"), szAppName, MB_ICONINFORMATION | MB_OK); } } else { diff --git a/bacula/src/win32/winapi.h b/bacula/src/win32/winapi.h index fb79e55c4d..5ccc2edba7 100644 --- a/bacula/src/win32/winapi.h +++ b/bacula/src/win32/winapi.h @@ -121,7 +121,9 @@ typedef DWORD (WINAPI * t_GetCurrentDirectoryW) (DWORD, LPWSTR); typedef BOOL (WINAPI * t_GetVolumePathNameW) (LPCWSTR, LPWSTR, DWORD); typedef BOOL (WINAPI * t_GetVolumeNameForVolumeMountPointW) (LPCWSTR, LPWSTR, DWORD); - + +typedef BOOL (WINAPI * t_AttachConsole) (DWORD); + extern t_GetFileAttributesA DLL_IMP_EXP p_GetFileAttributesA; extern t_GetFileAttributesW DLL_IMP_EXP p_GetFileAttributesW; @@ -159,6 +161,8 @@ extern t_GetCurrentDirectoryW DLL_IMP_EXP p_GetCurrentDirectoryW; extern t_GetVolumePathNameW DLL_IMP_EXP p_GetVolumePathNameW; extern t_GetVolumeNameForVolumeMountPointW DLL_IMP_EXP p_GetVolumeNameForVolumeMountPointW; +extern t_AttachConsole DLL_IMP_EXP p_AttachConsole; + void InitWinAPIWrapper(); #endif diff --git a/bacula/src/wx-console/console_thread.cpp b/bacula/src/wx-console/console_thread.cpp index 6adce12512..9d00ef4aa7 100644 --- a/bacula/src/wx-console/console_thread.cpp +++ b/bacula/src/wx-console/console_thread.cpp @@ -216,9 +216,7 @@ wxString console_thread::LoadConfig(wxString configfile) MSGS* msgs = (MSGS *)bmalloc(sizeof(MSGS)); memset(msgs, 0, sizeof(MSGS)); for (int i=1; i<=M_MAX; i++) { -#ifndef HAVE_WIN32 add_msg_dest(msgs, MD_STDOUT, i, NULL, NULL); -#endif // add_msg_dest(msgs, MD_SYSLOG, i, NULL, NULL); add_msg_dest(msgs, MD_CONSOLE, i, NULL, NULL); } diff --git a/bacula/technotes-1.39 b/bacula/technotes-1.39 index 17fdda22a0..f17f9edbf3 100644 --- a/bacula/technotes-1.39 +++ b/bacula/technotes-1.39 @@ -4,6 +4,36 @@ General: 11Oct06 kes Correct mtx-changer bug that I introduced in a recent commit, and pointed out by Robert Nelson -- thanks. +rbn Fix Windows' daemons so that messages print to stdout if not + running as a service. +rbn Add daemon name to trace file name (eg bacula-dir.trace). +rbn Fix environment variable expansion in directory names on Windows. +rbn Fix autochanger support in fill command. +rbn Update SQL scripts to match Unix versions. +rbn Fix daemon usage displays. +rbn Cleanup bacula-dir.conf template. +rbn Install openssl.cnf so that the openssl.exe installed in the + Bacula\bin directory can be used to generate keys and + certificates for TLS and encryption. +rbn Fix cleanup of spool files on Windows. +rbn Remove /silent option from daemons on Windows. The new default + is the same as the old /silent. To enable the message boxes that + previously were suppressed by /silent you must add /debug instead. + NOTE: As a result of this change, the first time you upgrade from + a previous version of 1.39.x you will receive the message + boxes when the remove of the old services succeeds. This + is the same behaviour as when migrating from a version prior + to 1.39.0. + However, going forward, these message boxes will not appear on + upgrades or new installs. +rbn Add new /debug option. This option enables the message boxes that + previously were suppressed by the /silent option. In addition the + daemons running as services will open a console window if this + option is used. +rbn Fix bug with service not being removed on migrated installs. This + should correct those cases where the file daemon install was failing + when upgrading from versions prior to 1.39.x. + 08Oct06 kes Turn on heap reporting in Dir with zero debug level. kes Send a message to the sys log when Bacula forces a SEG FAULT, and @@ -24,6 +54,12 @@ kes Modify the autochanger loaded?, load, and unload commands to print kes Correct a few Win32 errno returns in the VSS code so that hopefully a resonable Win32 error message will be printed. kes Convert a few strcat()... to bstrncat() in the Win32 code. +06Oct06 +rbn Added Windows version of bsmtp. +rbn Fixed path search for Windows so that Bacula\bin is automatically + searched for programs and scripts. +rbn Fixed bugs in mtx-changer.cmd and made template bacula-sd.conf + Windows specific. Version 1.39.24 released: 02Oct06 -- 2.39.5