I accidentally missed some things from the last one
thanks john -- How many Bavarian Illuminati does it take to screw in a lightbulb? Three: one to screw it in, and one to confuse the issue.
diff -u -r1.368 ChangeLog --- src/ChangeLog 2001/10/18 16:49:27 1.368 +++ src/ChangeLog 2001/10/19 02:04:30 @@ -1,3 +1,10 @@ +2001-10-19 John Levon <[EMAIL PROTECTED]> + + * lyxserver.h: + * lyxserver.C: + * lyx_main.h: + * lyx_main.C: add emergencyCleanup (remove pipes on crash) + 2001-10-18 Juergen Vigna <[EMAIL PROTECTED]> * text.C (workWidth): new function with added Inset * parameter. diff -u -r1.92 lyx_gui.C --- src/lyx_gui.C 2001/09/27 09:43:31 1.92 +++ src/lyx_gui.C 2001/10/19 02:04:53 @@ -79,9 +79,8 @@ static int LyX_XErrHandler(Display * display, XErrorEvent * xeev) { - // emergency save - if (!bufferlist.empty()) - bufferlist.emergencyWriteAll(); + // emergency cleanup + LyX::emergencyCleanup(); // Get the reason for the crash. char etxt[513]; Index: src/lyx_main.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyx_main.C,v retrieving revision 1.94 diff -u -r1.94 lyx_main.C --- src/lyx_main.C 2001/10/10 16:45:04 1.94 +++ src/lyx_main.C 2001/10/19 02:04:55 @@ -220,7 +220,7 @@ signal(SIGSEGV, SIG_DFL); signal(SIGTERM, SIG_DFL); - bufferlist.emergencyWriteAll(); + LyX::emergencyCleanup(); lyxerr << "Bye." << endl; if (err_sig!= SIGHUP && @@ -556,6 +556,19 @@ } +void LyX::emergencyCleanup() +{ + // what to do about tmpfiles is non-obvious. we would + // like to delete any we find, but our lyxdir might + // contain documents etc. which might be helpful on + // a crash + + bufferlist.emergencyWriteAll(); + if (lyxserver) + lyxserver->emergencyCleanup(); +} + + // LyX can optionally take over the handling of deadkeys void LyX::deadKeyBindings(kb_keymap * kbmap) { Index: src/lyx_main.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyx_main.h,v retrieving revision 1.22 diff -u -r1.22 lyx_main.h --- src/lyx_main.h 2001/06/28 10:25:13 1.22 +++ src/lyx_main.h 2001/10/19 02:04:55 @@ -51,6 +51,9 @@ /// Always is useful a destructor ~LyX(); + /// in the case of failure + static void emergencyCleanup(); + /// LyXGUI * lyxGUI; // should be only one of this private: diff -u -r1.27 lyxserver.C --- src/lyxserver.C 2001/09/09 22:02:11 1.27 +++ src/lyxserver.C 2001/10/19 02:05:03 @@ -110,195 +110,148 @@ if (pipename.empty()) return; - // --- prepare input pipe --------------------------------------- + if ((infd = startPipe(pipename + ".in")) == -1) + return; + + if ((outfd = startPipe(pipename + ".out")) == -1) { + endPipe(infd, pipename + ".in"); + return; + } + + if (fcntl(outfd, F_SETFL, O_NONBLOCK) < 0) { + lyxerr << "LyXComm: Could not set flags on pipe " << pipename << ".out" + << '\n' << strerror(errno) << endl; + return; + } + + // We made it! + ready = true; + lyxerr[Debug::LYXSERVER] << "LyXComm: Connection established" << endl; +} + + +/// Close pipes +void LyXComm::closeConnection() +{ + lyxerr[Debug::LYXSERVER] << "LyXComm: Closing connection" << endl; + + if (pipename.empty()) { + return; + } + + if (!ready) { + lyxerr << "LyXComm: Already disconnected" << endl; + return; + } + + endPipe(infd, pipename + ".in"); + endPipe(outfd, pipename + ".out"); - string tmp = pipename + ".in"; - + ready = false; +} + +int LyXComm::startPipe(string const & filename) +{ + int fd; + #ifdef __EMX__ - HPIPE fd; + HPIPE os2fd; APIRET rc; int errnum; // Try create one instance of named pipe with the mode O_RDONLY|O_NONBLOCK. // The current emx implementation of access() won't work with pipes. - rc = DosCreateNPipe(tmp.c_str(), &fd, NP_ACCESS_INBOUND, + rc = DosCreateNPipe(filename.c_str(), &os2fd, NP_ACCESS_INBOUND, NP_NOWAIT|0x01, 0600, 0600, 0); - if (rc == ERROR_PIPE_BUSY) -#else - if (::access(tmp.c_str(), F_OK) == 0) -#endif - { - lyxerr << "LyXComm: Pipe " << tmp << " already exists.\n" + if (rc == ERROR_PIPE_BUSY) { + lyxerr << "LyXComm: Pipe " << filename << " already exists.\n" << "If no other LyX program is active, please delete" " the pipe by hand and try again." << endl; pipename.erase(); - return; + return -1; } -#ifndef __EMX__ - if (::mkfifo(tmp.c_str(), 0600) < 0) { - lyxerr << "LyXComm: Could not create pipe " << tmp << '\n' - << strerror(errno) << endl; - return; - }; - infd = ::open(tmp.c_str(), O_RDONLY|O_NONBLOCK); -#else + if (rc != NO_ERROR) { errnum = TranslateOS2Error(rc); - lyxerr <<"LyXComm: Could not create pipe " << tmp + lyxerr <<"LyXComm: Could not create pipe " << filename << strerror(errnum) << endl; - return; + return -1; }; // Listen to it. - rc = DosConnectNPipe(fd); + rc = DosConnectNPipe(os2fd); if (rc != NO_ERROR && rc != ERROR_PIPE_NOT_CONNECTED) { errnum = TranslateOS2Error(rc); - lyxerr <<"LyXComm: Could not create pipe " << tmp + lyxerr <<"LyXComm: Could not create pipe " << filename << strerror(errnum) << endl; - return; + return -1; }; // Imported handles can be used both with OS/2 APIs and emx // library functions. - infd = _imphandle(fd); -#endif - if (infd < 0) { - lyxerr << "LyXComm: Could not open pipe " << tmp << '\n' - << strerror(errno) << endl; - return; - } - fl_add_io_callback(infd, FL_READ, C_LyXComm_callback, this); - - // --- prepare output pipe --------------------------------------- - - tmp = pipename + ".out"; - -#ifndef __EMX__ - if (::access(tmp.c_str(), F_OK) == 0) + fd = _imphandle(os2fd); #else - rc = DosCreateNPipe(tmp.c_str(), &fd, NP_ACCESS_DUPLEX, - NP_NOWAIT|0x01, 0600, 0600, 0); - - if (rc == ERROR_PIPE_BUSY) -#endif - { - lyxerr << "LyXComm: Pipe " << tmp << " already exists.\n" + if (::access(filename.c_str(), F_OK) == 0) { + lyxerr << "LyXComm: Pipe " << filename << " already exists.\n" << "If no other LyX program is active, please delete" " the pipe by hand and try again." << endl; pipename.erase(); - return; + return -1; } -#ifndef __EMX__ - if (::mkfifo(tmp.c_str(), 0600) < 0) { - lyxerr << "LyXComm: Could not create pipe " << tmp << '\n' + + if (::mkfifo(filename.c_str(), 0600) < 0) { + lyxerr << "LyXComm: Could not create pipe " << filename << '\n' << strerror(errno) << endl; - return; + return -1; }; - if (::access(tmp.c_str(), F_OK) != 0) { - lyxerr << "LyXComm: Pipe " << tmp - << " does not exist" << endl; - return; - } - outfd = ::open(tmp.c_str(), O_RDWR); -#else - if (rc != NO_ERROR) { - errnum = TranslateOS2Error(rc); - lyxerr << "LyXComm: Could not create pipe " << tmp << '\n' - << strerror(errnum) << endl; - return; - } - rc = DosConnectNPipe(fd); - if (rc == ERROR_BAD_PIPE) { - lyxerr << "LyXComm: Pipe " << tmp - << " does not exist" << endl; - return; - } - if (rc != NO_ERROR && rc != ERROR_PIPE_NOT_CONNECTED) { - errnum = TranslateOS2Error(rc); - lyxerr << "LyXComm: Could not create pipe " << tmp << '\n' - << strerror(errnum) << endl; - return; - } - outfd = _imphandle(fd); + fd = ::open(filename.c_str(), O_RDONLY|O_NONBLOCK); #endif - if (outfd < 0) { - lyxerr << "LyXComm: Could not open pipe " << tmp << '\n' + + if (fd < 0) { + lyxerr << "LyXComm: Could not open pipe " << filename << '\n' << strerror(errno) << endl; - return; + lyx::unlink(filename); + return -1; } - if (fcntl(outfd, F_SETFL, O_NONBLOCK) < 0) { - lyxerr << "LyXComm: Could not set flags on pipe " << tmp - << '\n' << strerror(errno) << endl; - return; - } - // We made it! - ready = true; - lyxerr[Debug::LYXSERVER] << "LyXComm: Connection established" << endl; + fl_add_io_callback(fd, FL_READ, C_LyXComm_callback, this); + return fd; } - -/// Close pipes -void LyXComm::closeConnection() + +void LyXComm::endPipe(int fd, string const & filename) { + if (fd < 0) + return; + #ifdef __EMX__ APIRET rc; int errnum; -#endif - lyxerr[Debug::LYXSERVER] << "LyXComm: Closing connection" << endl; - - if (pipename.empty()) { - return; - } - - if (!ready) { - lyxerr << "LyXComm: Already disconnected" << endl; + + rc = DosDisConnectNPipe(fd); + if (rc != NO_ERROR) { + errnum = TranslateOS2Error(rc); + lyxerr << "LyXComm: Could not disconnect pipe " << filename + << '\n' << strerror(errnum) << endl; return; } - - if (infd > -1) { - fl_remove_io_callback(infd, FL_READ, C_LyXComm_callback); - - string tmp = pipename + ".in"; -#ifdef __EMX__ // Notify the operating system. - rc = DosDisConnectNPipe(infd); - if (rc != NO_ERROR) { - errnum = TranslateOS2Error(rc); - lyxerr << "LyXComm: Could not disconnect pipe " << tmp - << '\n' << strerror(errnum) << endl; - return; - } #endif - if (close(infd) < 0) { - lyxerr << "LyXComm: Could not close pipe " << tmp - << '\n' << strerror(errno) << endl; - } -#ifndef __EMX__ // OS/2 named pipes will be automatically removed. - if (lyx::unlink(tmp) < 0){ - lyxerr << "LyXComm: Could not remove pipe " << tmp - << '\n' << strerror(errno) << endl; - }; -#endif + + if (::close(fd) < 0) { + lyxerr << "LyXComm: Could not close pipe " << filename + << '\n' << strerror(errno) << endl; } - if (outfd > -1) { - string tmp = pipename + ".out"; -#ifdef __EMX__ - rc = DosDisConnectNPipe(outfd); - if (rc != NO_ERROR) { - errnum = TranslateOS2Error(rc); - lyxerr << "LyXComm: Could not disconnect pipe " << tmp - << '\n' << strerror(errnum) << endl; - return; - } -#endif - if (::close(outfd) < 0) { - lyxerr << "LyXComm: Could not close pipe " << tmp - << '\n' << strerror(errno) << endl; - } + +// OS/2 pipes are deleted automatically #ifndef __EMX__ - if (lyx::unlink(tmp) < 0){ - lyxerr << "LyXComm: Could not remove pipe " << tmp - << '\n' << strerror(errno) << endl; - }; + if (lyx::unlink(filename) < 0){ + lyxerr << "LyXComm: Could not remove pipe " << filename + << '\n' << strerror(errno) << endl; + }; #endif - } - ready = false; +} + + +void LyXComm::emergencyCleanup() +{ + endPipe(infd, pipename + ".in"); + endPipe(outfd, pipename + ".out"); } Index: src/lyxserver.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxserver.h,v retrieving revision 1.9 diff -u -r1.9 lyxserver.h --- src/lyxserver.h 2001/05/30 13:53:31 1.9 +++ src/lyxserver.h 2001/10/19 02:05:03 @@ -49,6 +49,9 @@ closeConnection(); } + /// clean up in emergency + void emergencyCleanup(); + /// Send message void send(string const &); @@ -62,6 +65,12 @@ /// Close pipes void closeConnection(); + /// start a pipe + int startPipe(string const &); + + /// finish a pipe + void endPipe(int, string const &); + /// This is -1 if not open int infd; @@ -103,6 +112,12 @@ ~LyXServer(); /// void notifyClient(string const &); + + /// whilst crashing etc. + void emergencyCleanup() { + pipes.emergencyCleanup(); + } + private: /// static void callback(LyXServer *, string const & msg); diff -u -r1.40 ChangeLog --- src/support/ChangeLog 2001/10/12 16:23:26 1.40 +++ src/support/ChangeLog 2001/10/19 02:05:36 @@ -1,3 +1,8 @@ +2001-10-19 John Levon <[EMAIL PROTECTED]> + + * LAssert.h: + * LAssert.C: use new emergencyCleanup() + 2001-10-12 Jean-Marc Lasgouttes <[EMAIL PROTECTED]> * filetools.C (i18nLibFileSearch): check also LANGUAGE and LC_ALL, Index: src/support/LAssert.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/LAssert.C,v retrieving revision 1.3 diff -u -r1.3 LAssert.C --- src/support/LAssert.C 2001/06/04 23:57:32 1.3 +++ src/support/LAssert.C 2001/10/19 02:05:36 @@ -17,20 +17,16 @@ #include "LAssert.h" #ifdef ENABLE_ASSERTIONS -#include "bufferlist.h" +#include "lyx_main.h" -extern BufferList bufferlist; - -void emergencySave() { - static bool didSafe; - if (didSafe) +void emergencyCleanup() { + static bool didCleanup; + if (didCleanup) return; - didSafe = true; + didCleanup = true; - // emergency save - if (!bufferlist.empty()) - bufferlist.emergencyWriteAll(); + LyX::emergencyCleanup(); } #endif Index: src/support/LAssert.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/LAssert.h,v retrieving revision 1.13 diff -u -r1.13 LAssert.h --- src/support/LAssert.h 2001/04/24 15:25:26 1.13 +++ src/support/LAssert.h 2001/10/19 02:05:36 @@ -4,7 +4,7 @@ #include "support/lyxlib.h" -extern void emergencySave(); +extern void emergencyCleanup(); namespace lyx { @@ -12,7 +12,7 @@ /** Live assertion. This is a debug tool to ensure that the assertion holds. If it don't hole - we run #emergencySave()# and then #lyx::abort". + we run #emergencyCleanup()# and then #lyx::abort". @param assertion this should evaluate to true unless you want an abort. */ template<class A> @@ -20,7 +20,7 @@ void Assert(A assertion) { if (!assertion) { - ::emergencySave(); + ::emergencyCleanup(); lyx::abort(); } }