]> git.lyx.org Git - features.git/commitdiff
Don't start the pipe server if the pipe is already in use.
authorEnrico Forestieri <forenr@lyx.org>
Sun, 23 Aug 2009 14:40:26 +0000 (14:40 +0000)
committerEnrico Forestieri <forenr@lyx.org>
Sun, 23 Aug 2009 14:40:26 +0000 (14:40 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31213 a592a061-630c-0410-9148-cb99ea01b6c8

src/Server.cpp

index 9ed5b4ecaffea1d8f2150c4b3d3efb743e10c078..9837ef7aebd44ecb2dc0ed097ca7e59fc586f2bb 100644 (file)
@@ -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,