From 9d7574dafe2da7b93131996a667c583243f9e7c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 9 Mar 2010 03:30:22 +0100 Subject: [PATCH] DF disappeared exception --- library/DFError.h | 11 +++++++++++ library/DFProcess-linux-SHM.cpp | 10 ++++++++-- library/DFProcess-windows-SHM.cpp | 3 ++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/library/DFError.h b/library/DFError.h index 3e905b491..a3a0a036c 100644 --- a/library/DFError.h +++ b/library/DFError.h @@ -208,6 +208,17 @@ namespace DFHack return s.str().c_str(); } }; + + class DFHACK_EXPORT SHMServerDisappeared : public std::exception + { + public: + SHMServerDisappeared(){} + virtual ~SHMServerDisappeared() throw(){}; + virtual const char* what() const throw() + { + return "The server process has disappeared"; + } + }; } } diff --git a/library/DFProcess-linux-SHM.cpp b/library/DFProcess-linux-SHM.cpp index 766e1e3f9..581635e5e 100644 --- a/library/DFProcess-linux-SHM.cpp +++ b/library/DFProcess-linux-SHM.cpp @@ -96,10 +96,16 @@ bool Process::Private::waitWhile (uint32_t state) { shmctl(my_shmid, IPC_STAT, &descriptor); - if(descriptor.shm_nattch == 1)// DF crashed? + if(descriptor.shm_nattch == 1)// DF crashed or exited - no way to tell? { - SHMCMD = CORE_RUNNING; + //detach the shared memory + shmdt(my_shm); attached = suspended = false; + + // we aren't the current process anymore + g_pProcess = NULL; + + throw Error::SHMServerDisappeared(); return false; } else diff --git a/library/DFProcess-windows-SHM.cpp b/library/DFProcess-windows-SHM.cpp index 1fcd34fb0..a8ccdf431 100644 --- a/library/DFProcess-windows-SHM.cpp +++ b/library/DFProcess-windows-SHM.cpp @@ -118,9 +118,10 @@ bool Process::Private::waitWhile (uint32_t state) { if(!isValidSV())// DF not there anymore? { - SHMCMD = CORE_RUNNING; attached = suspended = false; ReleaseMutex(DFCLMutex); + UnmapViewOfFile(my_shm); + throw Error::SHMServerDisappeared(); return false; } else