Fixed crash on drive hotplug shutdown.
This commit is contained in:
parent
4dac07667c
commit
598ece4ae7
@ -135,7 +135,8 @@ BOOL check_path(char* path)
|
||||
{
|
||||
UINT type = GetDriveTypeA(path);
|
||||
|
||||
if (!(type == DRIVE_FIXED ||type == DRIVE_REMOVABLE || type == DRIVE_CDROM || type == DRIVE_REMOTE))
|
||||
if (!(type == DRIVE_FIXED || type == DRIVE_REMOVABLE || type == DRIVE_CDROM ||
|
||||
type == DRIVE_REMOTE))
|
||||
return FALSE;
|
||||
|
||||
return GetVolumeInformationA(path, NULL, 0, NULL, NULL, NULL, NULL, 0);
|
||||
@ -592,33 +593,6 @@ static DWORD WINAPI drive_hotplug_thread_func(LPVOID arg)
|
||||
return CHANNEL_RC_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function description
|
||||
*
|
||||
* @return 0 on success, otherwise a Win32 error code
|
||||
*/
|
||||
static UINT drive_hotplug_thread_terminate(rdpdrPlugin* rdpdr)
|
||||
{
|
||||
UINT error;
|
||||
|
||||
if (rdpdr->hotplugThread)
|
||||
{
|
||||
CFRunLoopStop(rdpdr->runLoop);
|
||||
|
||||
if (WaitForSingleObject(rdpdr->hotplugThread, INFINITE) == WAIT_FAILED)
|
||||
{
|
||||
error = GetLastError();
|
||||
WLog_ERR(TAG, "WaitForSingleObject failed with error %"PRIu32"!", error);
|
||||
return error;
|
||||
}
|
||||
|
||||
rdpdr->hotplugThread = NULL;
|
||||
}
|
||||
|
||||
return CHANNEL_RC_OK;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#define MAX_USB_DEVICES 100
|
||||
@ -948,14 +922,6 @@ static DWORD WINAPI drive_hotplug_thread_func(LPVOID arg)
|
||||
UINT error = 0;
|
||||
DWORD status;
|
||||
rdpdr = (rdpdrPlugin*) arg;
|
||||
|
||||
if (!(rdpdr->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL)))
|
||||
{
|
||||
WLog_ERR(TAG, "CreateEvent failed!");
|
||||
error = ERROR_INTERNAL_ERROR;
|
||||
goto out;
|
||||
}
|
||||
|
||||
mfd = open("/proc/mounts", O_RDONLY, 0);
|
||||
|
||||
if (mfd < 0)
|
||||
@ -1008,11 +974,13 @@ out:
|
||||
setChannelError(rdpdr->rdpcontext, error,
|
||||
"drive_hotplug_thread_func reported an error");
|
||||
|
||||
CloseHandle(rdpdr->stopEvent);
|
||||
ExitThread(error);
|
||||
return error;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
/**
|
||||
* Function description
|
||||
*
|
||||
@ -1024,8 +992,10 @@ static UINT drive_hotplug_thread_terminate(rdpdrPlugin* rdpdr)
|
||||
|
||||
if (rdpdr->hotplugThread)
|
||||
{
|
||||
if (rdpdr->stopEvent)
|
||||
SetEvent(rdpdr->stopEvent);
|
||||
SetEvent(rdpdr->stopEvent);
|
||||
#ifdef __MACOSX__
|
||||
CFRunLoopStop(rdpdr->runLoop);
|
||||
#endif
|
||||
|
||||
if (WaitForSingleObject(rdpdr->hotplugThread, INFINITE) == WAIT_FAILED)
|
||||
{
|
||||
@ -1034,6 +1004,9 @@ static UINT drive_hotplug_thread_terminate(rdpdrPlugin* rdpdr)
|
||||
return error;
|
||||
}
|
||||
|
||||
CloseHandle(rdpdr->hotplugThread);
|
||||
CloseHandle(rdpdr->stopEvent);
|
||||
rdpdr->stopEvent = NULL;
|
||||
rdpdr->hotplugThread = NULL;
|
||||
}
|
||||
|
||||
@ -1082,11 +1055,24 @@ static UINT rdpdr_process_connect(rdpdrPlugin* rdpdr)
|
||||
if (drive->Path && (strcmp(drive->Path, "*") == 0))
|
||||
{
|
||||
first_hotplug(rdpdr);
|
||||
#ifndef _WIN32
|
||||
|
||||
if (!(rdpdr->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL)))
|
||||
{
|
||||
WLog_ERR(TAG, "CreateEvent failed!");
|
||||
return ERROR_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if (!(rdpdr->hotplugThread = CreateThread(NULL, 0,
|
||||
drive_hotplug_thread_func, rdpdr, 0, NULL)))
|
||||
{
|
||||
WLog_ERR(TAG, "CreateThread failed!");
|
||||
#ifndef _WIN32
|
||||
CloseHandle(rdpdr->stopEvent);
|
||||
rdpdr->stopEvent = NULL;
|
||||
#endif
|
||||
return ERROR_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
|
@ -70,9 +70,11 @@ struct rdpdr_plugin
|
||||
HANDLE hotplugThread;
|
||||
#ifdef _WIN32
|
||||
HWND hotplug_wnd;
|
||||
#elif __MACOSX__
|
||||
#endif
|
||||
#ifdef __MACOSX__
|
||||
CFRunLoopRef runLoop;
|
||||
#else
|
||||
#endif
|
||||
#ifndef _WIN32
|
||||
HANDLE stopEvent;
|
||||
#endif
|
||||
rdpContext* rdpcontext;
|
||||
|
Loading…
Reference in New Issue
Block a user