LibreOffice Module onlineupdate (master) 1
|
#include <windows.h>
#include <shlwapi.h>
#include <stdio.h>
#include <wchar.h>
#include <shlobj.h>
#include "serviceinstall.hxx"
#include "maintenanceservice.hxx"
#include "servicebase.hxx"
#include "workmonitor.hxx"
#include "uachelper.h"
#include "updatehelper.h"
Go to the source code of this file.
Macros | |
#define | LOGS_TO_KEEP 10 |
Functions | |
BOOL | GetLogDirectoryPath (WCHAR *path) |
Obtains the base path where logs should be stored. More... | |
int | wmain (int argc, WCHAR **argv) |
BOOL | GetBackupLogPath (LPWSTR path, LPCWSTR basePath, int logNumber) |
Calculated a backup path based on the log number. More... | |
void | BackupOldLogs (LPCWSTR basePath, int numLogsToKeep) |
Moves the old log files out of the way before a new one is written. More... | |
DWORD WINAPI | EnsureProcessTerminatedThread (LPVOID) |
Ensures the service is shutdown once all work is complete. More... | |
void | StartTerminationThread () |
void WINAPI | SvcMain (DWORD argc, LPWSTR *argv) |
Main entry point when running as a service. More... | |
void | ReportSvcStatus (DWORD currentState, DWORD exitCode, DWORD waitHint) |
Sets the current service status and reports it to the SCM. More... | |
DWORD WINAPI | StopServiceAndWaitForCommandThread (LPVOID) |
Since the SvcCtrlHandler should only spend at most 30 seconds before returning, this function does the service stop work for the SvcCtrlHandler. More... | |
void WINAPI | SvcCtrlHandler (DWORD dwCtrl) |
Called by SCM whenever a control code is sent to the service using the ControlService function. More... | |
Variables | |
SERVICE_STATUS | gSvcStatus = { 0 } |
SERVICE_STATUS_HANDLE | gSvcStatusHandle = nullptr |
HANDLE | gWorkDoneEvent = nullptr |
HANDLE | gThread = nullptr |
bool | gServiceControlStopping = false |
#define LOGS_TO_KEEP 10 |
Definition at line 29 of file maintenanceservice.cxx.
void BackupOldLogs | ( | LPCWSTR | basePath, |
int | numLogsToKeep | ||
) |
Moves the old log files out of the way before a new one is written.
If you for example keep 3 logs, then this function will do: updater2.log -> updater3.log updater1.log -> updater2.log updater.log -> updater1.log Which clears room for a new updater.log in the basePath directory
basePath | The base directory path where log files are stored |
numLogsToKeep | The number of logs to keep |
Definition at line 208 of file maintenanceservice.cxx.
References GetBackupLogPath(), i, and MAX_PATH.
Referenced by SvcMain().
DWORD WINAPI EnsureProcessTerminatedThread | ( | LPVOID | ) |
Ensures the service is shutdown once all work is complete.
There is an issue on XP SP2 and below where the service can hang in a stop pending state even though the SCM is notified of a stopped state. Control should be returned to StartServiceCtrlDispatcher from the call to SetServiceStatus on a stopped state in the wmain thread. Sometimes this is not the case though. This thread will terminate the process if it has been 5 seconds after all work is done and the process is still not terminated. This thread is only started once a stopped state was sent to the SCM. The stop pending hang can be reproduced intermittently even if you set a stopped state directly and never set a stop pending state. It is safe to forcefully terminate the process ourselves since all work is done once we start this thread.
Definition at line 246 of file maintenanceservice.cxx.
Referenced by StartTerminationThread().
Calculated a backup path based on the log number.
path | The out buffer to store the log path of size MAX_PATH + 1 |
basePath | The base directory where the calculated path should go |
logNumber | The log number, 0 == updater.log |
Definition at line 179 of file maintenanceservice.cxx.
References PathAppendSafe().
Referenced by BackupOldLogs().
BOOL GetLogDirectoryPath | ( | WCHAR * | path | ) |
Obtains the base path where logs should be stored.
path | The out buffer for the backup log path of size MAX_PATH + 1 |
Definition at line 145 of file maintenanceservice.cxx.
References FALSE, hr, PathAppendSafe(), and TRUE.
void ReportSvcStatus | ( | DWORD | currentState, |
DWORD | exitCode, | ||
DWORD | waitHint | ||
) |
Sets the current service status and reports it to the SCM.
currentState | The current state (see SERVICE_STATUS) |
exitCode | The system error code |
waitHint | Estimated time for pending operation in milliseconds |
Definition at line 340 of file maintenanceservice.cxx.
References gSvcStatus, and gSvcStatusHandle.
Referenced by StopServiceAndWaitForCommandThread(), SvcCtrlHandler(), and SvcMain().
void StartTerminationThread | ( | ) |
Definition at line 253 of file maintenanceservice.cxx.
References EnsureProcessTerminatedThread().
Referenced by StopServiceAndWaitForCommandThread(), and SvcMain().
DWORD WINAPI StopServiceAndWaitForCommandThread | ( | LPVOID | ) |
Since the SvcCtrlHandler should only spend at most 30 seconds before returning, this function does the service stop work for the SvcCtrlHandler.
Definition at line 380 of file maintenanceservice.cxx.
References gWorkDoneEvent, NO_ERROR, ReportSvcStatus(), and StartTerminationThread().
Referenced by SvcCtrlHandler().
void WINAPI SvcCtrlHandler | ( | DWORD | dwCtrl | ) |
Called by SCM whenever a control code is sent to the service using the ControlService function.
Definition at line 399 of file maintenanceservice.cxx.
References gServiceControlStopping, NO_ERROR, ReportSvcStatus(), and StopServiceAndWaitForCommandThread().
Referenced by SvcMain().
void WINAPI SvcMain | ( | DWORD | argc, |
LPWSTR * | argv | ||
) |
Main entry point when running as a service.
Definition at line 269 of file maintenanceservice.cxx.
References BackupOldLogs(), UACHelper::DisablePrivileges(), ExecuteServiceCommand(), FALSE, GetLogDirectoryPath(), gServiceControlStopping, gSvcStatus, gSvcStatusHandle, gWorkDoneEvent, LOG_WARN, LogFinish, LogInit, LOGS_TO_KEEP, MAX_PATH, NO_ERROR, ReportSvcStatus(), StartTerminationThread(), SVC_NAME, SvcCtrlHandler(), and TRUE.
Referenced by wmain().
Definition at line 34 of file maintenanceservice.cxx.
References action, ForceInstallSvc, GetLogDirectoryPath(), InstallSvc, LOG, LOG_WARN, LogFinish, LogInit, MAX_PATH, SVC_NAME, SvcInstall(), SvcMain(), SvcUninstall(), and UpgradeSvc.
bool gServiceControlStopping = false |
Definition at line 26 of file maintenanceservice.cxx.
Referenced by SvcCtrlHandler(), and SvcMain().
SERVICE_STATUS gSvcStatus = { 0 } |
Definition at line 22 of file maintenanceservice.cxx.
Referenced by ReportSvcStatus(), and SvcMain().
SERVICE_STATUS_HANDLE gSvcStatusHandle = nullptr |
Definition at line 23 of file maintenanceservice.cxx.
Referenced by ReportSvcStatus(), and SvcMain().
HANDLE gThread = nullptr |
Definition at line 25 of file maintenanceservice.cxx.
HANDLE gWorkDoneEvent = nullptr |
Definition at line 24 of file maintenanceservice.cxx.
Referenced by StopServiceAndWaitForCommandThread(), and SvcMain().