/* * Copyright (c) Microsoft Corporation * * Module Name : * unlo.c * * Shut down and delete functions * Where possible, code has been obtained from BINL server. * * Sadagopan Rajaram -- Oct 14, 1999 * */ #include "tcsrv.h" #include #include "tcsrvc.h" #include "proto.h" NTSTATUS DeleteComPort( LPTSTR device ) /*++ Deletes a Com port from the list --*/ { BOOL ret; NTSTATUS Status; PCOM_PORT_INFO pPrev,pComPortInfo; HANDLE Thread; int index,i; EnterCriticalSection(&GlobalMutex); if(TCGlobalServiceStatus.dwCurrentState == SERVICE_STOP_PENDING){ // Entire Service is shutting down. LeaveCriticalSection(&GlobalMutex); return STATUS_SUCCESS; } // find the device needed to be deleted. pComPortInfo = FindDevice(device,&index); if(!pComPortInfo){ // Bah ! give me an existing device. LeaveCriticalSection(&GlobalMutex); return (STATUS_OBJECT_NAME_NOT_FOUND); } // Set the terminate event on the com port. ret = SetEvent(pComPortInfo->Events[3]); Thread = Threads[index]; LeaveCriticalSection(&GlobalMutex); // wait for the com port thread to finish. Status = NtWaitForSingleObject(Thread, FALSE, NULL); if (Status == WAIT_FAILED) { // catastrophe return Status; } EnterCriticalSection(&GlobalMutex); // do this again as another delete or insert may have // changed the index, though how is beyond me :-) // if we are already shutting down the service. if(TCGlobalServiceStatus.dwCurrentState == SERVICE_STOP_PENDING){ // Entire Service is shutting down. LeaveCriticalSection(&GlobalMutex); return STATUS_SUCCESS; } pComPortInfo = FindDevice(device,&index); if(!pComPortInfo){ LeaveCriticalSection(&GlobalMutex); return (STATUS_OBJECT_NAME_NOT_FOUND); } if(pComPortInfo == ComPortInfo){ ComPortInfo = pComPortInfo->Next; } else{ pPrev = ComPortInfo; while(pPrev->Next != pComPortInfo){// Can never fail pPrev = pPrev->Next; } pPrev->Next = pComPortInfo->Next; } pComPortInfo->Next = NULL; FreeComPortInfo(pComPortInfo); NtClose(Threads[index]); for(i=index;iNext; pTemp->Next = NULL; FreeComPortInfo(pTemp); } TCFree(Threads); NtClose(TerminateService); LeaveCriticalSection(&GlobalMutex); UNINITIALIZE_TRACE_MEMORY //All done, now print status and exit. TCGlobalServiceStatus.dwCurrentState = SERVICE_STOPPED; SetServiceStatus(TCGlobalServiceStatusHandle, &TCGlobalServiceStatus); TCDebugPrint(("Shutdown Status = %lx\n",Status)); return; }