mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-26 19:25:39 +00:00
Fix bug 641 (Detect stale lyxpipes after crash)
http://bugzilla.lyx.org/show_bug.cgi?id=641 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@27708 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
c2bdcc6b63
commit
077baded5c
@ -178,13 +178,40 @@ void LyXComm::closeConnection()
|
|||||||
|
|
||||||
int LyXComm::startPipe(string const & file, bool write)
|
int LyXComm::startPipe(string const & file, bool write)
|
||||||
{
|
{
|
||||||
|
static bool stalepipe = false;
|
||||||
FileName const filename(file);
|
FileName const filename(file);
|
||||||
if (::access(filename.toFilesystemEncoding().c_str(), F_OK) == 0) {
|
if (filename.exists()) {
|
||||||
lyxerr << "LyXComm: Pipe " << filename << " already exists.\n"
|
if (!write) {
|
||||||
<< "If no other LyX program is active, please delete"
|
// Let's see whether we have a stale pipe.
|
||||||
" the pipe by hand and try again." << endl;
|
errno = 0;
|
||||||
pipename_.erase();
|
int fd = ::open(filename.toFilesystemEncoding().c_str(),
|
||||||
return -1;
|
O_WRONLY | O_NONBLOCK);
|
||||||
|
if (fd >= 0) {
|
||||||
|
// Another LyX instance is using it.
|
||||||
|
close(fd);
|
||||||
|
} else if (errno == ENXIO) {
|
||||||
|
// No process is reading from the other end.
|
||||||
|
stalepipe = true;
|
||||||
|
LYXERR(Debug::LYXSERVER,
|
||||||
|
"LyXComm: trying to remove "
|
||||||
|
<< filename);
|
||||||
|
filename.removeFile();
|
||||||
|
}
|
||||||
|
} else if (stalepipe) {
|
||||||
|
LYXERR(Debug::LYXSERVER, "LyXComm: trying to remove "
|
||||||
|
<< filename);
|
||||||
|
filename.removeFile();
|
||||||
|
stalepipe = false;
|
||||||
|
}
|
||||||
|
if (filename.exists()) {
|
||||||
|
lyxerr << "LyXComm: Pipe " << filename
|
||||||
|
<< " already exists.\nIf no other LyX program"
|
||||||
|
" is active, please delete the pipe by hand"
|
||||||
|
" and try again."
|
||||||
|
<< endl;
|
||||||
|
pipename_.erase();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (::mkfifo(filename.toFilesystemEncoding().c_str(), 0600) < 0) {
|
if (::mkfifo(filename.toFilesystemEncoding().c_str(), 0600) < 0) {
|
||||||
|
@ -556,6 +556,7 @@ unsigned long FileName::checksum() const
|
|||||||
bool FileName::removeFile() const
|
bool FileName::removeFile() const
|
||||||
{
|
{
|
||||||
bool const success = QFile::remove(d->fi.absoluteFilePath());
|
bool const success = QFile::remove(d->fi.absoluteFilePath());
|
||||||
|
d->refresh();
|
||||||
if (!success && exists())
|
if (!success && exists())
|
||||||
LYXERR0("Could not delete file " << *this);
|
LYXERR0("Could not delete file " << *this);
|
||||||
return success;
|
return success;
|
||||||
|
Loading…
Reference in New Issue
Block a user