108 sprintf(m_ServerExeFile, "\"%s%c%s\"", exeDirectory, PATH_DELIMITER, SERVER_PROCESS_NAME); |
108 sprintf(m_ServerExeFile, "\"%s%c%s\"", exeDirectory, PATH_DELIMITER, SERVER_PROCESS_NAME); |
109 |
109 |
110 m_ServerLockFile = new char[MAX_DLLPATHNAME]; |
110 m_ServerLockFile = new char[MAX_DLLPATHNAME]; |
111 sprintf(m_ServerLockFile, "%s%c%s", exeDirectory, PATH_DELIMITER, SERVER_LOCKFILE_NAME); |
111 sprintf(m_ServerLockFile, "%s%c%s", exeDirectory, PATH_DELIMITER, SERVER_LOCKFILE_NAME); |
112 |
112 |
|
113 |
|
114 #ifdef _PSAPI_PRESENT |
|
115 FindOrCreateRunningServer(); |
|
116 #endif |
|
117 |
113 char name[100]; |
118 char name[100]; |
114 sprintf(name, "%s%ld", ERRORMONITORLIST_MUTEX_BASENAME, ::GetCurrentProcessId()); |
119 sprintf(name, "%s%ld", ERRORMONITORLIST_MUTEX_BASENAME, ::GetCurrentProcessId()); |
115 m_ErrorMonitorListMutex.Open(name, ERRORMONITORLIST_MUTEX_TIMEOUT); |
120 m_ErrorMonitorListMutex.Open(name, ERRORMONITORLIST_MUTEX_TIMEOUT); |
116 |
121 |
117 sprintf(name, "%s%ld", INPUTSTREAMLIST_MUTEX_BASENAME, ::GetCurrentProcessId()); |
122 sprintf(name, "%s%ld", INPUTSTREAMLIST_MUTEX_BASENAME, ::GetCurrentProcessId()); |
274 |
279 |
275 if (!foundRunningServer) |
280 if (!foundRunningServer) |
276 { |
281 { |
277 // start the one next to the DLL |
282 // start the one next to the DLL |
278 strncpy(exeDirectory, m_DllLocation, strlen(m_DllLocation) + 1); |
283 strncpy(exeDirectory, m_DllLocation, strlen(m_DllLocation) + 1); |
279 size_t len = strlen(exeDirectory); |
284 } |
280 // remove file |
285 size_t len = strlen(exeDirectory); |
281 for (int i = len-1; i > 0; i--) |
286 // remove file |
282 { |
287 int j; |
283 if (exeDirectory[i] == PATH_DELIMITER) |
288 for (j = len-1; j > 0; j--) |
284 break; |
289 { |
285 } |
290 if (exeDirectory[j] == PATH_DELIMITER) |
286 exeDirectory[i] = NULL; |
291 break; |
287 } |
292 } |
|
293 exeDirectory[j] = NULL; |
288 |
294 |
289 m_ServerExeFile = new char[MAX_DLLPATHNAME]; |
295 m_ServerExeFile = new char[MAX_DLLPATHNAME]; |
290 sprintf(m_ServerExeFile, "\"%s%c%s\"", exeDirectory, PATH_DELIMITER, SERVER_PROCESS_NAME); |
296 sprintf(m_ServerExeFile, "\"%s%c%s\"", exeDirectory, PATH_DELIMITER, SERVER_PROCESS_NAME); |
|
297 TCDEBUGLOGA1("exeFile at %s\n", m_ServerExeFile); |
291 |
298 |
292 m_ServerLockFile = new char[MAX_DLLPATHNAME]; |
299 m_ServerLockFile = new char[MAX_DLLPATHNAME]; |
293 sprintf(m_ServerLockFile, "%s%c%s", exeDirectory, PATH_DELIMITER, SERVER_LOCKFILE_NAME); |
300 sprintf(m_ServerLockFile, "%s%c%s", exeDirectory, PATH_DELIMITER, SERVER_LOCKFILE_NAME); |
|
301 TCDEBUGLOGA1("lockFile at %s\n", m_ServerLockFile); |
|
302 |
|
303 |
294 |
304 |
295 TCDEBUGCLOSE(); |
305 TCDEBUGCLOSE(); |
296 |
306 |
297 } |
307 } |
298 #endif |
308 #endif |
725 void CClientManager::CreateLockFile(DWORD processId) |
735 void CClientManager::CreateLockFile(DWORD processId) |
726 { |
736 { |
727 if (m_ServerLockFile != NULL) |
737 if (m_ServerLockFile != NULL) |
728 { |
738 { |
729 FILE* f = fopen(m_ServerLockFile, "wt"); |
739 FILE* f = fopen(m_ServerLockFile, "wt"); |
730 TCDEBUGLOGA1("CClientManager::CreateLockFile f=%x\n", f); |
740 TCDEBUGLOGA2("CClientManager::CreateLockFile f=%x, lockFile=%s\n", f, m_ServerLockFile); |
731 |
741 |
732 if (f) |
742 if (f) |
733 { |
743 { |
734 DWORD callingProcessId = ::GetCurrentProcessId(); |
744 DWORD callingProcessId = ::GetCurrentProcessId(); |
735 TCDEBUGLOGA2("CClientManager::CreateLockFile callingProcessId=%d processId=%d\n", callingProcessId, processId); |
745 TCDEBUGLOGA2("CClientManager::CreateLockFile callingProcessId=%d processId=%d\n", callingProcessId, processId); |
746 void CClientManager::AppendToLockFile(DWORD processId) |
756 void CClientManager::AppendToLockFile(DWORD processId) |
747 { |
757 { |
748 if (m_ServerLockFile != NULL) |
758 if (m_ServerLockFile != NULL) |
749 { |
759 { |
750 FILE* f = fopen(m_ServerLockFile, "at"); |
760 FILE* f = fopen(m_ServerLockFile, "at"); |
751 TCDEBUGLOGA1("CClientManager::AppendToLockFile f=%x\n", f); |
761 TCDEBUGLOGA2("CClientManager::AppendToLockFile f=%x, lockFile=%s\n", f, m_ServerLockFile); |
752 |
762 |
753 if (f) |
763 if (f) |
754 { |
764 { |
755 DWORD callingProcessId = ::GetCurrentProcessId(); |
765 DWORD callingProcessId = ::GetCurrentProcessId(); |
756 TCDEBUGLOGA2("CClientManager::AppendToLockFile callingProcessId=%d processId=%d\n", callingProcessId, processId); |
766 TCDEBUGLOGA2("CClientManager::AppendToLockFile callingProcessId=%d processId=%d\n", callingProcessId, processId); |
766 } |
776 } |
767 void CClientManager::DeleteLockFile() |
777 void CClientManager::DeleteLockFile() |
768 { |
778 { |
769 if (m_ServerLockFile != NULL) |
779 if (m_ServerLockFile != NULL) |
770 { |
780 { |
771 TCDEBUGLOGS("CClientManager::DeleteLockFile\n"); |
781 TCDEBUGLOGA1("CClientManager::DeleteLockFile lockFile=%s\n", m_ServerLockFile); |
772 ::remove(m_ServerLockFile); |
782 ::remove(m_ServerLockFile); |
773 } |
783 } |
774 } |
784 } |
775 |
785 |
776 void CClientManager::DeleteFromLockFile(DWORD serverProcessId) |
786 void CClientManager::DeleteFromLockFile(DWORD serverProcessId) |
782 DWORD ourProcessId = ::GetCurrentProcessId(); |
792 DWORD ourProcessId = ::GetCurrentProcessId(); |
783 |
793 |
784 if (m_ServerLockFile != NULL) |
794 if (m_ServerLockFile != NULL) |
785 { |
795 { |
786 DWORD attr = ::GetFileAttributes(m_ServerLockFile); |
796 DWORD attr = ::GetFileAttributes(m_ServerLockFile); |
787 TCDEBUGLOGA1("CClientManager::DeleteFromLockFile attr=%x\n", attr); |
797 TCDEBUGLOGA2("CClientManager::DeleteFromLockFile attr=%x, lockFile=%s\n", attr, m_ServerLockFile); |
788 |
798 |
789 if (attr != 0xffffffff) // error |
799 if (attr != 0xffffffff) // error |
790 { |
800 { |
791 // file exists |
801 // file exists |
792 // read the process Ids from it |
802 // read the process Ids from it |