From: Jean-Marc Lasgouttes Date: Fri, 19 Oct 2001 15:13:49 +0000 (+0000) Subject: lyxserver cleanup patch + andre's small patches X-Git-Tag: 1.6.10~20462 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=8488e475a67fe5ba76730bca213230ba9a75b9a5;p=features.git lyxserver cleanup patch + andre's small patches git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2901 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index c52616df71..891c94dea9 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -2914,6 +2914,10 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) mathDispatchMathMode(bv_, argument); break; + case LFUN_GREEK: // Insert a single greek letter + mathDispatchGreek(bv_, argument); + break; + case LFUN_CITATION_INSERT: { InsetCommandParams p; diff --git a/src/ChangeLog b/src/ChangeLog index d6a6ecf05d..3bd2010c01 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2001-10-19 John Levon + + * lyxserver.h: + * lyxserver.C: + * lyx_main.h: + * lyx_main.C: add emergencyCleanup (remove pipes on crash) + 2001-10-19 Jean-Marc Lasgouttes * text.C (workWidth): do not search for the exact row when diff --git a/src/commandtags.h b/src/commandtags.h index 6fc1a29757..5445872c06 100644 --- a/src/commandtags.h +++ b/src/commandtags.h @@ -27,12 +27,12 @@ enum kb_action { LFUN_WRITEAS, LFUN_MENUPRINT, LFUN_MENUSENDTO, - LFUN_BUILDPROG, + LFUN_BUILDPROG, LFUN_TOCVIEW, // 10 LFUN_PREVIEW, LFUN_CLOSEBUFFER, - LFUN_BUFFER_PRINT, // ARRae 20000313 - LFUN_PRINTER_PARAMS_GET, // ARRae 20000313 + LFUN_BUFFER_PRINT, // ARRae 20000313 + LFUN_PRINTER_PARAMS_GET, // ARRae 20000313 LFUN_QUIT, LFUN_AUTOSAVE, LFUN_UNDO, @@ -68,7 +68,7 @@ enum kb_action { LFUN_HOME, LFUN_END, LFUN_TAB, - LFUN_SHIFT_TAB, // Jug 20000522 + LFUN_SHIFT_TAB, // Jug 20000522 LFUN_WORDRIGHT, LFUN_WORDLEFT, // 50 LFUN_BEGINNINGBUF, @@ -110,7 +110,7 @@ enum kb_action { LFUN_UMLAUT, LFUN_DOT, LFUN_OGONEK, - LFUN_VECTOR, // Alejandro 040696 // 90 + LFUN_VECTOR, // 90 // Alejandro 040696 LFUN_SELFINSERT, LFUN_GETBUFNAME, LFUN_GETXY, @@ -121,7 +121,7 @@ enum kb_action { LFUN_GETFONT, LFUN_GETNAME, // 100 LFUN_NOTIFY, - LFUN_GOTOFILEROW, // Edmar 12/23/98 + LFUN_GOTOFILEROW, // Edmar 12/23/98 LFUN_INSERT_NOTE, LFUN_KMAP_OFF, LFUN_KMAP_PRIM, @@ -132,25 +132,25 @@ enum kb_action { LFUN_GREEK, // 110 LFUN_MATH_LIMITS, LFUN_GREEK_TOGGLE, - LFUN_MATH_DELIM, // Alejandro 180696 - LFUN_MATH_DISPLAY, // was INSERT_EQUATION Alejandro 180696 - LFUN_MATH_MODE, // Alejandro 040696 - LFUN_MATH_NUMBER, // Alejandro 040696 - LFUN_MATH_NONUMBER, // Alejandro 180696 - LFUN_MATH_SIZE, // Alejandro 150896 - LFUN_MATH_MACRO, // ale970510 - LFUN_MATH_MACROARG, // ale970510 // 120 - LFUN_MATH_EXTERN, // Andre' 20010424 - LFUN_MATH_PANEL, // Andre' 20010522 - LFUN_MATH_VALIGN, // Andre' 20010522 - LFUN_MATH_HALIGN, // Andre' 20010522 - LFUN_MATH_ROW_INSERT, // Andre' 20010522 - LFUN_MATH_ROW_DELETE, // Andre' 20010522 - LFUN_MATH_COLUMN_INSERT, // Andre' 20010522 - LFUN_MATH_COLUMN_DELETE, // Andre' 20010522 - LFUN_MATH_MUTATE, // Andre' 20010523 - LFUN_MATH_IMPORT_SELECTION, // Andre' 20010704 - LFUN_MATH_SPACE, // Andre' 20010725 + LFUN_MATH_DELIM, // Alejandro 180696 + LFUN_MATH_DISPLAY, // was INSERT_EQUATION Alejandro 180696 + LFUN_MATH_MODE, // Alejandro 040696 + LFUN_MATH_NUMBER, // Alejandro 040696 + LFUN_MATH_NONUMBER, // Alejandro 180696 + LFUN_MATH_SIZE, // Alejandro 150896 + LFUN_MATH_MACRO, // ale970510 + LFUN_MATH_MACROARG, // 120 // ale970510 + LFUN_MATH_EXTERN, // Andre' 20010424 + LFUN_MATH_PANEL, // Andre' 20010522 + LFUN_MATH_VALIGN, // Andre' 20010522 + LFUN_MATH_HALIGN, // Andre' 20010522 + LFUN_MATH_ROW_INSERT, // Andre' 20010522 + LFUN_MATH_ROW_DELETE, // Andre' 20010522 + LFUN_MATH_COLUMN_INSERT, // Andre' 20010522 + LFUN_MATH_COLUMN_DELETE, // Andre' 20010522 + LFUN_MATH_MUTATE, // Andre' 20010523 + LFUN_MATH_IMPORT_SELECTION, // Andre' 20010704 + LFUN_MATH_SPACE, // Andre' 20010725 LFUN_FIGURE, LFUN_DELETE_WORD_FORWARD, LFUN_DELETE_WORD_BACKWARD, @@ -158,12 +158,12 @@ enum kb_action { LFUN_MARK_OFF, LFUN_MARK_ON, LFUN_LAYOUT, - LFUN_LAYOUTNO, // Lgb 97-06-10 // 130 + LFUN_LAYOUTNO, // 130 // Lgb 97-06-10 LFUN_LAYOUT_CHARACTER, LFUN_LAYOUT_PARAGRAPH, LFUN_LAYOUT_DOCUMENT, LFUN_LAYOUT_PREAMBLE, - LFUN_LAYOUT_SAVE_DEFAULT, + LFUN_LAYOUT_SAVE_DEFAULT, LFUN_DROP_LAYOUTS_CHOICE, LFUN_CODE, LFUN_SANS, @@ -178,12 +178,12 @@ enum kb_action { LFUN_REF_INSERT, LFUN_PUSH_TOOLBAR, LFUN_ADD_TO_TOOLBAR, - LFUN_DEPTH_MIN, // 150 // RVDK_PATCH_5 - LFUN_DEPTH_PLUS, // RVDK_PATCH_5 - LFUN_MENU_OPEN_BY_NAME, // RVDK_PATCH_5 - LFUN_SPELLCHECK, // RVDK_PATCH_5 - LFUN_CANCEL, // RVDK_PATCH_5 - LFUN_META_FAKE, // RVDK_PATCH_5 + LFUN_DEPTH_MIN, // 150 // RVDK_PATCH_5 + LFUN_DEPTH_PLUS, // RVDK_PATCH_5 + LFUN_MENU_OPEN_BY_NAME, // RVDK_PATCH_5 + LFUN_SPELLCHECK, // RVDK_PATCH_5 + LFUN_CANCEL, // RVDK_PATCH_5 + LFUN_META_FAKE, // RVDK_PATCH_5 LFUN_EXEC_COMMAND, LFUN_FILE_INSERT, LFUN_FILE_INSERT_ASCII, // CFO-G 1997-11-19 @@ -191,26 +191,26 @@ enum kb_action { LFUN_FILE_NEW, LFUN_FILE_OPEN, // 160 LFUN_UP_PARAGRAPH, // Asger 1996-10-01 - LFUN_UP_PARAGRAPHSEL, // Asger 1996-10-01 - LFUN_DOWN_PARAGRAPH, // Asger 1996-10-01 - LFUN_DOWN_PARAGRAPHSEL, // Asger 1996-10-01 + LFUN_UP_PARAGRAPHSEL, // Asger 1996-10-01 + LFUN_DOWN_PARAGRAPH, // Asger 1996-10-01 + LFUN_DOWN_PARAGRAPHSEL, // Asger 1996-10-01 LFUN_BREAKPARAGRAPH_SKIP, LFUN_BACKSPACE_SKIP, LFUN_DELETE_SKIP, - LFUN_MENUNEWTMPLT, // Asger 1997-02-02 - LFUN_MENURELOAD, // Asger 1997-02-02 - LFUN_RECONFIGURE, // 170 // Asger 1997-02-14 + LFUN_MENUNEWTMPLT, // Asger 1997-02-02 + LFUN_MENURELOAD, // Asger 1997-02-02 + LFUN_RECONFIGURE, // 170 // Asger 1997-02-14 LFUN_CITATION_INSERT, // AAS 97-02-23 LFUN_INSERT_BIBTEX, // AAS 97-02-23 LFUN_INDEX_CREATE, // Lgb 97-02-27 - LFUN_INDEX_INSERT_LAST, // Reh 98-09-17 + LFUN_INDEX_INSERT_LAST, // Reh 98-09-17 LFUN_INDEX_PRINT, // Lgb 97-02-27 LFUN_APROPOS, // Asger 1997-02-27 LFUN_LATEX_LOG, // Lgb 97-04-05 - LFUN_LAYOUT_COPY, // Asger 1997-05-04 - LFUN_LAYOUT_PASTE, // Asger 1997-05-04 + LFUN_LAYOUT_COPY, // Asger 1997-05-04 + LFUN_LAYOUT_PASTE, // Asger 1997-05-04 LFUN_TABINSERT, // 180 // Ale 970515 - LFUN_CHILD_INSERT, // Ale 970521 + LFUN_CHILD_INSERT, // Ale 970521 LFUN_CHILDOPEN, // Ale 970528 LFUN_TOC_INSERT, // Lgb 97-05-27 LFUN_FLOAT_LIST, // Lgb 20010503 @@ -231,37 +231,37 @@ enum kb_action { // schedule for deletion #endif LFUN_REF_GOTO, // 200 // Ale 970806 - //LFUN_REF_BACK, // Ale 970806 - LFUN_PARENTINSERT, // Ale 970813 + //LFUN_REF_BACK, // Ale 970806 + LFUN_PARENTINSERT, // Ale 970813 LFUN_REMOVEERRORS, // Asger 970906 LFUN_LDOTS, // Asger 970929 - LFUN_END_OF_SENTENCE, // Asger 970929 - LFUN_RUNCHKTEX, // Asger 971030 + LFUN_END_OF_SENTENCE, // Asger 970929 + LFUN_RUNCHKTEX, // Asger 971030 LFUN_TOGGLECURSORFOLLOW, // ARRae 971202 LFUN_HTMLURL, // CFO-G 971121 LFUN_URL, // CFO-G 971121 - LFUN_WORDFINDFORWARD, // 210 // Etienne 980216 - LFUN_WORDFINDBACKWARD, // Etienne 980220 + LFUN_WORDFINDFORWARD, // 210 // Etienne 980216 + LFUN_WORDFINDBACKWARD, // Etienne 980220 LFUN_APPENDIX, // ettrich 980505 - LFUN_IMPORT, // Asger 980724 + LFUN_IMPORT, // Asger 980724 LFUN_MENU_SEPARATOR, // Asger 990220 LFUN_SEQUENCE, // Andre' 991111 - LFUN_DIALOG_PREFERENCES, // ARRae 20000726 + LFUN_DIALOG_PREFERENCES, // ARRae 20000726 LFUN_SAVEPREFERENCES, // Lgb 991127 - LFUN_HELP_OPEN, // 220 // Jug 990627 - LFUN_DATE_INSERT, // jdblair 20000131 + LFUN_HELP_OPEN, // 220 // Jug 990627 + LFUN_DATE_INSERT, // jdblair 20000131 LFUN_LANGUAGE, // Dekel 20000203 - LFUN_INSET_TEXT, // Jug 20000214 - LFUN_INSET_ERT, // Jug 20000218 + LFUN_INSET_TEXT, // Jug 20000214 + LFUN_INSET_ERT, // Jug 20000218 LFUN_INSET_GRAPHICS, // Lgb 20000226 LFUN_INSET_FOOTNOTE, // Jug 20000307 LFUN_PARAGRAPH_SPACING, // Lgb 20000411 - LFUN_INSET_TABULAR, // Jug 20000412 - LFUN_LOFVIEW, // 230 // Dekel 20000519 - LFUN_LOTVIEW, // Dekel 20000519 - LFUN_LOAVIEW, // Dekel 20000519 - LFUN_SET_COLOR, // SLior 20000611 - LFUN_INSET_EXTERNAL, // Alstrup 20000609 + LFUN_INSET_TABULAR, // Jug 20000412 + LFUN_LOFVIEW, // 230 // Dekel 20000519 + LFUN_LOTVIEW, // Dekel 20000519 + LFUN_LOAVIEW, // Dekel 20000519 + LFUN_SET_COLOR, // SLior 20000611 + LFUN_INSET_EXTERNAL, // Alstrup 20000609 LFUN_INSET_MARGINAL, // Lgb 20000626 LFUN_INSET_MINIPAGE, // Lgb 20000627 LFUN_INSET_FLOAT, // Lgb 20000627 @@ -273,28 +273,28 @@ enum kb_action { #endif LFUN_CITATION_CREATE, // 240 // Angus 20000705 LFUN_INSET_CAPTION, // Lgb 20000718 - LFUN_SWITCHBUFFER, // and where is this comming from? + LFUN_SWITCHBUFFER, // and where is this coming from? LFUN_INSERT_URL, // Angus 20000726 LFUN_TABULAR_FEATURE, // Jug 20000728 LFUN_LAYOUT_TABULAR, // Jug 20000731 LFUN_SCROLL_INSET, // Jug 20000801 LFUN_UPDATE, // Dekel 20000805 LFUN_INDEX_INSERT, // Angus 20000803 - LFUN_SCREEN_FONT_UPDATE, // ARRae 20000813 + LFUN_SCREEN_FONT_UPDATE, // ARRae 20000813 LFUN_DIALOG_TABULAR_INSERT, // 250 // Jug 20000825 (old table-insert) - LFUN_GOTO_PARAGRAPH, // Dekel 20000826 - LFUN_REFERENCE_GOTO, // Dekel 20010114 - LFUN_BOOKMARK_SAVE, // Dekel 20010127 - LFUN_BOOKMARK_GOTO, // Dekel 20010127 - LFUN_SELECT_FILE_SYNC, // Levon 20010214 + LFUN_GOTO_PARAGRAPH, // Dekel 20000826 + LFUN_REFERENCE_GOTO, // Dekel 20010114 + LFUN_BOOKMARK_SAVE, // Dekel 20010127 + LFUN_BOOKMARK_GOTO, // Dekel 20010127 + LFUN_SELECT_FILE_SYNC, // Levon 20010214 LFUN_MESSAGE, // Lgb 20010408 LFUN_MESSAGE_PUSH, // Lgb 20010410 LFUN_MESSAGE_POP, // Lgb 20010410 LFUN_TRANSPOSE_CHARS, // Lgb 20010425 LFUN_ESCAPE, // 260 // Lgb 20010517 LFUN_HELP_ABOUTLYX, // Edwin 20010712 - LFUN_THESAURUS_ENTRY, // Levon 20010720 - LFUN_HELP_TEXINFO, // Herbert 20011001 + LFUN_THESAURUS_ENTRY, // Levon 20010720 + LFUN_HELP_TEXINFO, // Herbert 20011001 LFUN_LASTACTION /* this marks the end of the table */ }; diff --git a/src/lyx_gui.C b/src/lyx_gui.C index a9c516d8aa..991486b18f 100644 --- a/src/lyx_gui.C +++ b/src/lyx_gui.C @@ -79,9 +79,8 @@ extern "C" { 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]; diff --git a/src/lyx_main.C b/src/lyx_main.C index c07c19c064..b085903939 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -220,7 +220,7 @@ void error_handler(int err_sig) 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::defaultKeyBindings(kb_keymap * kbmap) } +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) { diff --git a/src/lyx_main.h b/src/lyx_main.h index d2b0fb9bea..fa48772a78 100644 --- a/src/lyx_main.h +++ b/src/lyx_main.h @@ -51,6 +51,9 @@ public: /// Always is useful a destructor ~LyX(); + /// in the case of failure + static void emergencyCleanup(); + /// LyXGUI * lyxGUI; // should be only one of this private: diff --git a/src/lyxserver.C b/src/lyxserver.C index 0133d1abc3..fa0294c5dd 100644 --- a/src/lyxserver.C +++ b/src/lyxserver.C @@ -110,195 +110,148 @@ void LyXComm::openConnection() 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"); + + ready = false; +} + +int LyXComm::startPipe(string const & filename) +{ + int fd; - string tmp = pipename + ".in"; - #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"); } diff --git a/src/lyxserver.h b/src/lyxserver.h index 05db4ea338..4311aba232 100644 --- a/src/lyxserver.h +++ b/src/lyxserver.h @@ -49,6 +49,9 @@ public: closeConnection(); } + /// clean up in emergency + void emergencyCleanup(); + /// Send message void send(string const &); @@ -62,6 +65,12 @@ private: /// 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 @@ public: ~LyXServer(); /// void notifyClient(string const &); + + /// whilst crashing etc. + void emergencyCleanup() { + pipes.emergencyCleanup(); + } + private: /// static void callback(LyXServer *, string const & msg); diff --git a/src/support/ChangeLog b/src/support/ChangeLog index 6a75ee1f86..bfab4ca167 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,8 @@ +2001-10-19 John Levon + + * LAssert.h: + * LAssert.C: use new emergencyCleanup() + 2001-10-12 Jean-Marc Lasgouttes * filetools.C (i18nLibFileSearch): check also LANGUAGE and LC_ALL, diff --git a/src/support/LAssert.C b/src/support/LAssert.C index b878f26d47..41d69602e5 100644 --- a/src/support/LAssert.C +++ b/src/support/LAssert.C @@ -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 diff --git a/src/support/LAssert.h b/src/support/LAssert.h index d424d93063..6a93726602 100644 --- a/src/support/LAssert.h +++ b/src/support/LAssert.h @@ -4,7 +4,7 @@ #include "support/lyxlib.h" -extern void emergencySave(); +extern void emergencyCleanup(); namespace lyx { @@ -12,7 +12,7 @@ namespace lyx { /** 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 @@ -20,7 +20,7 @@ inline void Assert(A assertion) { if (!assertion) { - ::emergencySave(); + ::emergencyCleanup(); lyx::abort(); } }