From 84c68fb31c2503b7b2cffeaa2e96638b3f06ccdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Fri, 1 Jan 2010 22:19:09 +0000 Subject: [PATCH] fix attach/detach --- library/DFProcess-linux-SHM.cpp | 17 +++++++++++++---- tools/attachtest.cpp | 4 ++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/library/DFProcess-linux-SHM.cpp b/library/DFProcess-linux-SHM.cpp index 01d8a3c59..6fc83241e 100644 --- a/library/DFProcess-linux-SHM.cpp +++ b/library/DFProcess-linux-SHM.cpp @@ -393,7 +393,7 @@ bool SHMProcess::resume() bool SHMProcess::attach() { int status; - if(g_pProcess != NULL) + if(g_pProcess != 0) { cerr << "there's already a different process attached" << endl; return false; @@ -412,6 +412,7 @@ bool SHMProcess::attach() } d->attached = false; cerr << "unable to suspend" << endl; + // FIXME: detach sehment here return false; } cerr << "unable to attach" << endl; @@ -428,9 +429,17 @@ bool SHMProcess::detach() { resume(); } - d->attached = false; - d->suspended = false; - return true; + // detach segment + if(shmdt(d->my_shm) != -1) + { + d->attached = false; + d->suspended = false; + g_pProcess = 0; + return true; + } + // fail if we can't detach + perror("failed to detach shared segment"); + return false; } diff --git a/tools/attachtest.cpp b/tools/attachtest.cpp index a17966475..f02f7b019 100644 --- a/tools/attachtest.cpp +++ b/tools/attachtest.cpp @@ -68,8 +68,8 @@ int main (void) for (int i = 0; i < 1000000; i++) { DF.Suspend(); - if(i%10000 == 0) - cout << i / 10000 << "%" << endl; + if(i%10000 == 0) + cout << i / 10000 << "%" << endl; DF.Resume(); } time(&end);