modify how we determine if the TCFServer process creator is still alive - this will help in killing orphan TCFServer processes on startup
authorChad Peckham <chad.peckham@nokia.com>
Mon, 21 Sep 2009 17:03:45 -0500
changeset 505 6de8d9cfdda1
parent 501 c39dede7ad37
child 506 44dbbc3220b8
modify how we determine if the TCFServer process creator is still alive - this will help in killing orphan TCFServer processes on startup
connectivity/com.nokia.tcf/native/TCFNative/TCFClient/ClientManager.cpp
--- a/connectivity/com.nokia.tcf/native/TCFNative/TCFClient/ClientManager.cpp	Mon Sep 21 08:14:15 2009 -0500
+++ b/connectivity/com.nokia.tcf/native/TCFNative/TCFClient/ClientManager.cpp	Mon Sep 21 17:03:45 2009 -0500
@@ -640,8 +640,8 @@
 
 void CClientManager::DeleteFromLockFile(DWORD serverProcessId)
 {
-	DWORD callingId[10];
-	DWORD serverId[10];
+	DWORD creatorIds[10];
+	DWORD serverIds[10];
 	int numIds = 0;
 
 	DWORD ourProcessId = ::GetCurrentProcessId();
@@ -663,16 +663,16 @@
 				BOOL done = FALSE;
 				while (!done)
 				{
-					DWORD cId = 0xffffffff;
-					DWORD sId = 0xffffffff;
-					int n = fscanf(f, "%ld %ld\n", &cId, &sId);
+					DWORD creatorId = 0xffffffff;
+					DWORD serverId = 0xffffffff;
+					int n = fscanf(f, "%ld %ld\n", &creatorId, &serverId);
 					if (n == 2)
 					{
-						TCDEBUGLOGA3("CClientManager::DeleteFromLockFile numIds=%d sId=%d pId=%d\n", numIds, cId, sId);
-						if (cId != ourProcessId || sId != serverProcessId)
+						TCDEBUGLOGA3("CClientManager::DeleteFromLockFile numIds=%d creatorId=%d serverId=%d\n", numIds, creatorId, serverId);
+						if (creatorId != ourProcessId || serverId != serverProcessId)
 						{
-							callingId[numIds] = cId;
-							serverId[numIds] = sId;
+							creatorIds[numIds] = creatorId;
+							serverIds[numIds] = serverId;
 							numIds++;
 							if (numIds > 9)
 								done = TRUE;
@@ -695,7 +695,7 @@
 				{
 					for (int i = 0; i < numIds; i++)
 					{
-						fprintf(f, "%ld %ld\n", callingId[i], serverId[i]);
+						fprintf(f, "%ld %ld\n", creatorIds[i], serverIds[i]);
 					}
 					fclose(f);
 				}
@@ -708,8 +708,8 @@
 // we should not have more than a few Carbide processes connecting to the same TCFServer
 void CClientManager::TerminateServerThroughLockFile(pServerProcessData pData)
 {
-	DWORD callingId[10];
-	DWORD serverId[10];
+	DWORD creatorIds[10];
+	DWORD serverIds[10];
 	BOOL liveCaller[10];
 	int numIds = 0;
 	if (m_ServerLockFile != NULL)
@@ -729,14 +729,14 @@
 				BOOL done = FALSE;
 				while (!done)
 				{
-					DWORD cId = 0xffffffff;
-					DWORD sId = 0xffffffff;
-					int n = fscanf(f, "%ld %ld\n", &cId, &sId);
+					DWORD creatorId = 0xffffffff;
+					DWORD serverId = 0xffffffff;
+					int n = fscanf(f, "%ld %ld\n", &creatorId, &serverId);
 					if (n == 2)
 					{
-						TCDEBUGLOGA3("CClientManager::TerminateServerThroughLockFile n=%d sId=%d pId=%d\n", n, cId, sId);
-						callingId[numIds] = cId;
-						serverId[numIds] = sId;
+						TCDEBUGLOGA3("CClientManager::TerminateServerThroughLockFile n=%d creatorId=%d serverId=%d\n", n, creatorId, serverId);
+						creatorIds[numIds] = creatorId;
+						serverIds[numIds] = serverId;
 						numIds++;
 						if (numIds > 9)
 							done = TRUE;
@@ -751,20 +751,31 @@
 				int numDeadCallers = 0;
 				for (int i = 0; i < numIds; i++)
 				{
-					HANDLE h = ::OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, callingId[i]);
+					HANDLE h = ::OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, creatorIds[i]);
 					if (h)
 					{
 						// calling process is still alive
 						liveCaller[i] = TRUE;
+						DWORD exitCode = -5;
+						BOOL exitCall = ::GetExitCodeProcess(h, &exitCode);
+						DWORD id = ::GetCurrentProcessId();
 						::CloseHandle(h);
-						TCDEBUGLOGA1("CClientManager::TerminateServerThroughLockFile %d alive\n", callingId[i]);
+						TCDEBUGLOGA3("CClientManager::TerminateServerThroughLockFile %d alive exitCall=%d currentId=%d\n", creatorIds[i], exitCall, id);
+						if (exitCall == TRUE && exitCode != STILL_ACTIVE)
+						{
+							liveCaller[i] = FALSE;
+							numDeadCallers++;
+						}
+						{
+							TCDEBUGLOGA2("CClientManager::TerminateServerThroughLockFile exitCode=%d still_active=%d\n", exitCode, STILL_ACTIVE);
+						}
 					}
 					else
 					{
 						liveCaller[i] = FALSE;
 						numDeadCallers++;
 						DWORD err = ::GetLastError();
-						TCDEBUGLOGA3("CClientManager::TerminateServerThroughLockFile %d dead err=%d:%s\n", callingId[i], err, GetErrorText(err));
+						TCDEBUGLOGA3("CClientManager::TerminateServerThroughLockFile %d dead err=%d:%s\n", creatorIds[i], err, GetErrorText(err));
 					}
 				}
 				if (numDeadCallers == numIds)
@@ -772,7 +783,7 @@
 					// terminate the TCFServer, and delete lock file
 					pData->numRefs = 0;
 					::remove(m_ServerLockFile);
-					HANDLE h = ::OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE, serverId[0]);
+					HANDLE h = ::OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE, serverIds[0]);
 					if (h)
 					{
 						BOOL ret = ::TerminateProcess(h, -1);
@@ -795,7 +806,7 @@
 						{
 							if (liveCaller[i])
 							{
-								fprintf(f, "%ld %ld\n", callingId[i], serverId[i]);
+								fprintf(f, "%ld %ld\n", creatorIds[i], serverIds[i]);
 							}
 						}
 						fclose(f);