<commit_before>/**
 * FreeRDS: FreeRDP Remote Desktop Services (RDS)
 * X11 Server Module
 *
 * Copyright 2013 <NAME> <<EMAIL>>
 * Copyright 2013 Thincast Technologies GmbH
 * Copyright 2013 DI (FH) <NAME> <<EMAIL>>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#ifndef WIN32
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#endif

#include <winpr/pipe.h>
#include <winpr/path.h>
#include <winpr/synch.h>
#include <winpr/thread.h>
#include <winpr/wlog.h>
#include <winpr/environment.h>

#include <freerds/backend.h>
#include <limits.h>

#include "x11_module.h"
#include "../common/module_helper.h"

RDS_MODULE_CONFIG_CALLBACKS gConfig;
RDS_MODULE_STATUS_CALLBACKS gStatus;

#define X11_DISPLAY_OFFSET 10
#define X11_LOCKFILE_FORMAT "/tmp/.X%d-lock"
#define X11_UNIX_SOCKET_FORMAT "/tmp/.X11-unix/X%d"
#define X11_DISPLAY_MAX 1024

static wLog *gModuleLog;

struct rds_module_x11
{
	RDS_MODULE_COMMON commonModule;

	STARTUPINFO X11StartupInfo;
	PROCESS_INFORMATION X11ProcessInformation;

	HANDLE monitorThread;
	HANDLE monitorStopEvent;
	STARTUPINFO WMStartupInfo;
	PROCESS_INFORMATION WMProcessInformation;
	unsigned int displayNum;
};

typedef struct rds_module_x11 rdsModuleX11;

void x11_rds_module_reset_process_informations(STARTUPINFO *si, PROCESS_INFORMATION *pi)
{
	ZeroMemory(si, sizeof(STARTUPINFO));
	si->cb = sizeof(STARTUPINFO);
	ZeroMemory(pi, sizeof(PROCESS_INFORMATION));
}

int clean_up_process(PROCESS_INFORMATION *pi)
{
	DWORD ret = 0;
	GetExitCodeProcess(pi->hProcess, &ret);
	CloseHandle(pi->hProcess);
	CloseHandle(pi->hThread);
	return ret;<commit_msg>Added coded to prevent the process and thread handles from being closed twice on cleanup.<commit_after>/**
 * FreeRDS: FreeRDP Remote Desktop Services (RDS)
 * X11 Server Module
 *
 * Copyright 2013 <NAME> <<EMAIL>>
 * Copyright 2013 Thincast Technologies GmbH
 * Copyright 2013 DI (FH) <NAME> <<EMAIL>>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#ifndef WIN32
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#endif

#include <winpr/pipe.h>
#include <winpr/path.h>
#include <winpr/synch.h>
#include <winpr/thread.h>
#include <winpr/wlog.h>
#include <winpr/environment.h>

#include <freerds/backend.h>
#include <limits.h>

#include "x11_module.h"
#include "../common/module_helper.h"

RDS_MODULE_CONFIG_CALLBACKS gConfig;
RDS_MODULE_STATUS_CALLBACKS gStatus;

#define X11_DISPLAY_OFFSET 10
#define X11_LOCKFILE_FORMAT "/tmp/.X%d-lock"
#define X11_UNIX_SOCKET_FORMAT "/tmp/.X11-unix/X%d"
#define X11_DISPLAY_MAX 1024

static wLog *gModuleLog;

struct rds_module_x11
{
	RDS_MODULE_COMMON commonModule;

	STARTUPINFO X11StartupInfo;
	PROCESS_INFORMATION X11ProcessInformation;

	HANDLE monitorThread;
	HANDLE monitorStopEvent;
	STARTUPINFO WMStartupInfo;
	PROCESS_INFORMATION WMProcessInformation;
	unsigned int displayNum;
};

typedef struct rds_module_x11 rdsModuleX11;

void x11_rds_module_reset_process_informations(STARTUPINFO *si, PROCESS_INFORMATION *pi)
{
	ZeroMemory(si, sizeof(STARTUPINFO));
	si->cb = sizeof(STARTUPINFO);
	ZeroMemory(pi, sizeof(PROCESS_INFORMATION));
}

int clean_up_process(PROCESS_INFORMATION *pi)
{
	DWORD ret = 0;
	if (pi->hProcess)
	{
		GetExitCodeProcess(pi->hProcess, &ret);
		CloseHandle(pi->hProcess);
		pi->hProcess = NULL;
	}
	if (pi->hThread)
	{
		CloseHandle(pi->hThread);
		pi->hThread = NULL;
	}
	return ret;
{'fraction_non_alphanumeric': 0.108839190628328, 'fraction_numerical': 0.021725239616613417, 'mean_word_length': 5.286479250334672, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7575334', 'n_tokens_mistral': 1717, 'n_tokens_neox': 1607, 'n_words': 445}