style(sonar): fix cpp:S4962 (#4140)
This commit is contained in:
parent
dbe80d0f92
commit
fc7b9e30c8
20 changed files with 119 additions and 119 deletions
|
|
@ -52,9 +52,9 @@ DWORD WINAPI HandlerEx(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, L
|
|||
}
|
||||
|
||||
HANDLE CreateJobObjectForChildProcess() {
|
||||
HANDLE job_handle = CreateJobObjectW(NULL, NULL);
|
||||
HANDLE job_handle = CreateJobObjectW(nullptr, nullptr);
|
||||
if (!job_handle) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
JOBOBJECT_EXTENDED_LIMIT_INFORMATION job_limit_info = {};
|
||||
|
|
@ -69,7 +69,7 @@ HANDLE CreateJobObjectForChildProcess() {
|
|||
|
||||
if (!SetInformationJobObject(job_handle, JobObjectExtendedLimitInformation, &job_limit_info, sizeof(job_limit_info))) {
|
||||
CloseHandle(job_handle);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return job_handle;
|
||||
|
|
@ -77,16 +77,16 @@ HANDLE CreateJobObjectForChildProcess() {
|
|||
|
||||
LPPROC_THREAD_ATTRIBUTE_LIST AllocateProcThreadAttributeList(DWORD attribute_count) {
|
||||
SIZE_T size;
|
||||
InitializeProcThreadAttributeList(NULL, attribute_count, 0, &size);
|
||||
InitializeProcThreadAttributeList(nullptr, attribute_count, 0, &size);
|
||||
|
||||
auto list = (LPPROC_THREAD_ATTRIBUTE_LIST) HeapAlloc(GetProcessHeap(), 0, size);
|
||||
if (list == NULL) {
|
||||
return NULL;
|
||||
if (list == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!InitializeProcThreadAttributeList(list, attribute_count, 0, &size)) {
|
||||
HeapFree(GetProcessHeap(), 0, list);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return list;
|
||||
|
|
@ -95,14 +95,14 @@ LPPROC_THREAD_ATTRIBUTE_LIST AllocateProcThreadAttributeList(DWORD attribute_cou
|
|||
HANDLE DuplicateTokenForSession(DWORD console_session_id) {
|
||||
HANDLE current_token;
|
||||
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_DUPLICATE, ¤t_token)) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Duplicate our own LocalSystem token
|
||||
HANDLE new_token;
|
||||
if (!DuplicateTokenEx(current_token, TOKEN_ALL_ACCESS, NULL, SecurityImpersonation, TokenPrimary, &new_token)) {
|
||||
if (!DuplicateTokenEx(current_token, TOKEN_ALL_ACCESS, nullptr, SecurityImpersonation, TokenPrimary, &new_token)) {
|
||||
CloseHandle(current_token);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CloseHandle(current_token);
|
||||
|
|
@ -110,7 +110,7 @@ HANDLE DuplicateTokenForSession(DWORD console_session_id) {
|
|||
// Change the duplicated token to the console session ID
|
||||
if (!SetTokenInformation(new_token, TokenSessionId, &console_session_id, sizeof(console_session_id))) {
|
||||
CloseHandle(new_token);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return new_token;
|
||||
|
|
@ -124,15 +124,15 @@ HANDLE OpenLogFileHandle() {
|
|||
wcscat_s(log_file_name, L"sunshine.log");
|
||||
|
||||
// The file handle must be inheritable for our child process to use it
|
||||
SECURITY_ATTRIBUTES security_attributes = {sizeof(security_attributes), NULL, TRUE};
|
||||
SECURITY_ATTRIBUTES security_attributes = {sizeof(security_attributes), nullptr, TRUE};
|
||||
|
||||
// Overwrite the old sunshine.log
|
||||
return CreateFileW(log_file_name, GENERIC_WRITE, FILE_SHARE_READ, &security_attributes, CREATE_ALWAYS, 0, NULL);
|
||||
return CreateFileW(log_file_name, GENERIC_WRITE, FILE_SHARE_READ, &security_attributes, CREATE_ALWAYS, 0, nullptr);
|
||||
}
|
||||
|
||||
bool RunTerminationHelper(HANDLE console_token, DWORD pid) {
|
||||
WCHAR module_path[MAX_PATH];
|
||||
GetModuleFileNameW(NULL, module_path, _countof(module_path));
|
||||
GetModuleFileNameW(nullptr, module_path, _countof(module_path));
|
||||
std::wstring command;
|
||||
|
||||
command += L'"';
|
||||
|
|
@ -147,7 +147,7 @@ bool RunTerminationHelper(HANDLE console_token, DWORD pid) {
|
|||
// Execute ourselves as a detached process in the user session with the --terminate argument.
|
||||
// This will allow us to attach to Sunshine's console and send it a Ctrl-C event.
|
||||
PROCESS_INFORMATION process_info;
|
||||
if (!CreateProcessAsUserW(console_token, module_path, (LPWSTR) command.c_str(), NULL, NULL, FALSE, CREATE_UNICODE_ENVIRONMENT | DETACHED_PROCESS, NULL, NULL, &startup_info, &process_info)) {
|
||||
if (!CreateProcessAsUserW(console_token, module_path, (LPWSTR) command.c_str(), nullptr, nullptr, FALSE, CREATE_UNICODE_ENVIRONMENT | DETACHED_PROCESS, nullptr, nullptr, &startup_info, &process_info)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -167,8 +167,8 @@ bool RunTerminationHelper(HANDLE console_token, DWORD pid) {
|
|||
}
|
||||
|
||||
VOID WINAPI ServiceMain(DWORD dwArgc, LPTSTR *lpszArgv) {
|
||||
service_status_handle = RegisterServiceCtrlHandlerEx(SERVICE_NAME, HandlerEx, NULL);
|
||||
if (service_status_handle == NULL) {
|
||||
service_status_handle = RegisterServiceCtrlHandlerEx(SERVICE_NAME, HandlerEx, nullptr);
|
||||
if (service_status_handle == nullptr) {
|
||||
// Nothing we can really do here but terminate ourselves
|
||||
ExitProcess(GetLastError());
|
||||
return;
|
||||
|
|
@ -185,8 +185,8 @@ VOID WINAPI ServiceMain(DWORD dwArgc, LPTSTR *lpszArgv) {
|
|||
SetServiceStatus(service_status_handle, &service_status);
|
||||
|
||||
// Create a manual-reset stop event
|
||||
stop_event = CreateEventA(NULL, TRUE, FALSE, NULL);
|
||||
if (stop_event == NULL) {
|
||||
stop_event = CreateEventA(nullptr, TRUE, FALSE, nullptr);
|
||||
if (stop_event == nullptr) {
|
||||
// Tell SCM we failed to start
|
||||
service_status.dwWin32ExitCode = GetLastError();
|
||||
service_status.dwCurrentState = SERVICE_STOPPED;
|
||||
|
|
@ -195,8 +195,8 @@ VOID WINAPI ServiceMain(DWORD dwArgc, LPTSTR *lpszArgv) {
|
|||
}
|
||||
|
||||
// Create an auto-reset session change event
|
||||
session_change_event = CreateEventA(NULL, FALSE, FALSE, NULL);
|
||||
if (session_change_event == NULL) {
|
||||
session_change_event = CreateEventA(nullptr, FALSE, FALSE, nullptr);
|
||||
if (session_change_event == nullptr) {
|
||||
// Tell SCM we failed to start
|
||||
service_status.dwWin32ExitCode = GetLastError();
|
||||
service_status.dwCurrentState = SERVICE_STOPPED;
|
||||
|
|
@ -218,13 +218,13 @@ VOID WINAPI ServiceMain(DWORD dwArgc, LPTSTR *lpszArgv) {
|
|||
startup_info.StartupInfo.cb = sizeof(startup_info);
|
||||
startup_info.StartupInfo.lpDesktop = (LPWSTR) L"winsta0\\default";
|
||||
startup_info.StartupInfo.dwFlags = STARTF_USESTDHANDLES;
|
||||
startup_info.StartupInfo.hStdInput = NULL;
|
||||
startup_info.StartupInfo.hStdInput = nullptr;
|
||||
startup_info.StartupInfo.hStdOutput = log_file_handle;
|
||||
startup_info.StartupInfo.hStdError = log_file_handle;
|
||||
|
||||
// Allocate an attribute list with space for 2 entries
|
||||
startup_info.lpAttributeList = AllocateProcThreadAttributeList(2);
|
||||
if (startup_info.lpAttributeList == NULL) {
|
||||
if (startup_info.lpAttributeList == nullptr) {
|
||||
// Tell SCM we failed to start
|
||||
service_status.dwWin32ExitCode = GetLastError();
|
||||
service_status.dwCurrentState = SERVICE_STOPPED;
|
||||
|
|
@ -233,7 +233,7 @@ VOID WINAPI ServiceMain(DWORD dwArgc, LPTSTR *lpszArgv) {
|
|||
}
|
||||
|
||||
// Only allow Sunshine.exe to inherit the log file handle, not all inheritable handles
|
||||
UpdateProcThreadAttribute(startup_info.lpAttributeList, 0, PROC_THREAD_ATTRIBUTE_HANDLE_LIST, &log_file_handle, sizeof(log_file_handle), NULL, NULL);
|
||||
UpdateProcThreadAttribute(startup_info.lpAttributeList, 0, PROC_THREAD_ATTRIBUTE_HANDLE_LIST, &log_file_handle, sizeof(log_file_handle), nullptr, nullptr);
|
||||
|
||||
// Tell SCM we're running (and stoppable now)
|
||||
service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_PRESHUTDOWN | SERVICE_ACCEPT_SESSIONCHANGE;
|
||||
|
|
@ -249,22 +249,22 @@ VOID WINAPI ServiceMain(DWORD dwArgc, LPTSTR *lpszArgv) {
|
|||
}
|
||||
|
||||
auto console_token = DuplicateTokenForSession(console_session_id);
|
||||
if (console_token == NULL) {
|
||||
if (console_token == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Job objects cannot span sessions, so we must create one for each process
|
||||
auto job_handle = CreateJobObjectForChildProcess();
|
||||
if (job_handle == NULL) {
|
||||
if (job_handle == nullptr) {
|
||||
CloseHandle(console_token);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Start Sunshine.exe inside our job object
|
||||
UpdateProcThreadAttribute(startup_info.lpAttributeList, 0, PROC_THREAD_ATTRIBUTE_JOB_LIST, &job_handle, sizeof(job_handle), NULL, NULL);
|
||||
UpdateProcThreadAttribute(startup_info.lpAttributeList, 0, PROC_THREAD_ATTRIBUTE_JOB_LIST, &job_handle, sizeof(job_handle), nullptr, nullptr);
|
||||
|
||||
PROCESS_INFORMATION process_info;
|
||||
if (!CreateProcessAsUserW(console_token, L"Sunshine.exe", NULL, NULL, NULL, TRUE, CREATE_UNICODE_ENVIRONMENT | CREATE_NO_WINDOW | EXTENDED_STARTUPINFO_PRESENT, NULL, NULL, (LPSTARTUPINFOW) &startup_info, &process_info)) {
|
||||
if (!CreateProcessAsUserW(console_token, L"Sunshine.exe", nullptr, nullptr, nullptr, TRUE, CREATE_UNICODE_ENVIRONMENT | CREATE_NO_WINDOW | EXTENDED_STARTUPINFO_PRESENT, nullptr, nullptr, (LPSTARTUPINFOW) &startup_info, &process_info)) {
|
||||
CloseHandle(console_token);
|
||||
CloseHandle(job_handle);
|
||||
continue;
|
||||
|
|
@ -327,7 +327,7 @@ int DoGracefulTermination(DWORD pid) {
|
|||
}
|
||||
|
||||
// Disable our own Ctrl-C handling
|
||||
SetConsoleCtrlHandler(NULL, TRUE);
|
||||
SetConsoleCtrlHandler(nullptr, TRUE);
|
||||
|
||||
// Send a Ctrl-C event to Sunshine
|
||||
if (!GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0)) {
|
||||
|
|
@ -340,7 +340,7 @@ int DoGracefulTermination(DWORD pid) {
|
|||
int main(int argc, char *argv[]) {
|
||||
static const SERVICE_TABLE_ENTRY service_table[] = {
|
||||
{(LPSTR) SERVICE_NAME, ServiceMain},
|
||||
{NULL, NULL}
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
|
||||
// Check if this is a reinvocation of ourselves to send Ctrl-C to Sunshine.exe
|
||||
|
|
@ -352,7 +352,7 @@ int main(int argc, char *argv[]) {
|
|||
// We want to use the directory where Sunshine.exe is located instead of system32.
|
||||
// This requires stripping off 2 path components: the file name and the last folder
|
||||
WCHAR module_path[MAX_PATH];
|
||||
GetModuleFileNameW(NULL, module_path, _countof(module_path));
|
||||
GetModuleFileNameW(nullptr, module_path, _countof(module_path));
|
||||
for (auto i = 0; i < 2; i++) {
|
||||
auto last_sep = wcsrchr(module_path, '\\');
|
||||
if (last_sep) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue