From: Enrico Forestieri Date: Sun, 23 Aug 2009 14:40:26 +0000 (+0000) Subject: Don't start the pipe server if the pipe is already in use. X-Git-Tag: 2.0.0~5600 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=3ab2267014c03cb1a5078f95dd2639543e80230e;p=features.git Don't start the pipe server if the pipe is already in use. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31213 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/Server.cpp b/src/Server.cpp index 9ed5b4ecaf..9837ef7aeb 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -127,7 +127,7 @@ DWORD WINAPI pipeServerWrapper(void * arg) } // namespace anon LyXComm::LyXComm(string const & pip, Server * cli, ClientCallbackfct ccb) - : pipename_(pip), client_(cli), clientcb_(ccb) + : pipename_(pip), client_(cli), clientcb_(ccb), stopserver_(0) { // Ask Qt to notify us on quit. qAddPostRoutine(closing); @@ -147,7 +147,8 @@ void LyXComm::pipeServer() bufsize, 0, 0, NULL); if (outpipe_ == INVALID_HANDLE_VALUE) { lyxerr << "LyXComm: Could not create pipe " - << outPipeName() << '\n' << errormsg() << endl; + << external_path(outPipeName()) << '\n' + << errormsg() << endl; return; } ConnectNamedPipe(outpipe_, NULL); @@ -162,7 +163,8 @@ void LyXComm::pipeServer() 0, bufsize, 0, NULL); if (inpipe == INVALID_HANDLE_VALUE) { lyxerr << "LyXComm: Could not create pipe " - << inPipeName() << '\n' << errormsg() << endl; + << external_path(inPipeName()) << '\n' + << errormsg() << endl; break; } @@ -216,6 +218,16 @@ void LyXComm::openConnection() return; } + // Check whether the pipe is being used by some other program. + if (!stopserver_ && WaitNamedPipe(inPipeName().c_str(), 0)) { + lyxerr << "LyXComm: Pipe " << external_path(inPipeName()) + << " already exists.\nMaybe another instance of LyX" + " is using it." + << endl; + pipename_.erase(); + return; + } + stopserver_ = CreateEvent(NULL, TRUE, FALSE, NULL); DWORD tid; HANDLE thread = CreateThread(NULL, 0, pipeServerWrapper,