To: vim-dev@vim.org Subject: Patch 6.1.472 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 6.1.472 Problem: When there is an authentication error when connecting to the X server Vim exits. Solution: Use XSetIOErrorHandler() to catch the error and longjmp() to avoid the exit. Also do this in the main loop, so that when the X server exits a Vim running in a console isn't killed. Files: src/globals.h, src/main.c, src/os_unix.c *** ../vim61.471/src/globals.h Thu Apr 10 22:38:13 2003 --- src/globals.h Wed Apr 16 22:19:13 2003 *************** *** 542,547 **** --- 542,552 ---- EXTERN int vr_lines_changed INIT(= 0); /* #Lines changed by "gR" so far */ #endif + #if defined(FEAT_X11) && defined(FEAT_XCLIPBOARD) + /* argument to SETJMP() for handling X IO errors */ + EXTERN JMP_BUF x_jump_env; + #endif + #if defined(HAVE_SETJMP_H) /* * Stuff for setjmp() and longjmp(). *** ../vim61.471/src/main.c Wed Apr 16 20:43:41 2003 --- src/main.c Fri Apr 18 14:23:46 2003 *************** *** 1940,1945 **** --- 1940,1977 ---- { oparg_T oa; /* operator arguments */ + #if defined(FEAT_X11) && defined(FEAT_XCLIPBOARD) + /* Setup to catch a terminating error from the X server. Just ignore + * it, restore the state and continue. This might not always work + * properly, but at least we don't exit unexpectedly when the X server + * exists while Vim is running in a console. */ + if (!cmdwin && SETJMP(x_jump_env)) + { + State = NORMAL; + # ifdef FEAT_VISUAL + VIsual_active = FALSE; + # endif + got_int = TRUE; + need_wait_return = FALSE; + global_busy = FALSE; + exmode_active = 0; + skip_redraw = FALSE; + RedrawingDisabled = 0; + no_wait_return = 0; + # ifdef FEAT_EVAL + emsg_skip = 0; + # endif + emsg_off = 0; + # ifdef FEAT_MOUSE + setmouse(); + # endif + settmode(TMODE_RAW); + starttermcap(); + scroll_start(); + redraw_later_clear(); + } + #endif + clear_oparg(&oa); while (!cmdwin #ifdef FEAT_CMDWIN *** ../vim61.471/src/os_unix.c Wed Apr 16 20:56:52 2003 --- src/os_unix.c Wed Apr 16 22:18:16 2003 *************** *** 751,757 **** * A simplistic version of setjmp() that only allows one level of using. * Don't call twice before calling mch_endjmp()!. * Usage: ! * mch_startjmp() * if (SETJMP(lc_jump_env) != 0) * { * mch_didjmp(); --- 751,757 ---- * A simplistic version of setjmp() that only allows one level of using. * Don't call twice before calling mch_endjmp()!. * Usage: ! * mch_startjmp(); * if (SETJMP(lc_jump_env) != 0) * { * mch_didjmp(); *************** *** 1190,1195 **** --- 1190,1234 ---- return 0; } + #if defined(FEAT_X11) && defined(FEAT_XCLIPBOARD) + # if defined(HAVE_SETJMP_H) + /* + * An X IO Error handler, used to catch error while opening the display. + */ + static int x_IOerror_check __ARGS((Display *dpy)); + + /* ARGSUSED */ + static int + x_IOerror_check(dpy) + Display *dpy; + { + /* This function should not return, it causes exit(). Longjump instead. */ + LONGJMP(lc_jump_env, 1); + /*NOTREACHED*/ + } + # endif + + /* + * An X IO Error handler, used to catch terminal errors. + */ + static int x_IOerror_handler __ARGS((Display *dpy)); + + /* ARGSUSED */ + static int + x_IOerror_handler(dpy) + Display *dpy; + { + xterm_dpy = NULL; + x11_window = 0; + x11_display = NULL; + xterm_Shell = (Widget)0; + + /* This function should not return, it causes exit(). Longjump instead. */ + LONGJMP(x_jump_env, 1); + /*NOTREACHED*/ + } + #endif + /* * Return TRUE when connection to the X server is desired. */ *************** *** 5203,5209 **** --- 5242,5251 ---- */ mch_startjmp(); if (SETJMP(lc_jump_env) != 0) + { success = FALSE; + mch_didjmp(); + } else # endif { *************** *** 5310,5315 **** --- 5352,5360 ---- if (app_context != NULL && xterm_Shell == (Widget)0) { int (*oldhandler)(); + #if defined(HAVE_SETJMP_H) + int (*oldIOhandler)(); + #endif # if defined(HAVE_GETTIMEOFDAY) && defined(HAVE_SYS_TIME_H) struct timeval start_tv; *************** *** 5320,5328 **** /* Ignore X errors while opening the display */ oldhandler = XSetErrorHandler(x_error_check); ! xterm_dpy = XtOpenDisplay(app_context, xterm_display, ! "vim_xterm", "Vim_xterm", NULL, 0, &z, &strp); /* Now handle X errors normally. */ (void)XSetErrorHandler(oldhandler); --- 5365,5393 ---- /* Ignore X errors while opening the display */ oldhandler = XSetErrorHandler(x_error_check); ! #if defined(HAVE_SETJMP_H) ! /* Ignore X IO errors while opening the display */ ! oldIOhandler = XSetIOErrorHandler(x_IOerror_check); ! mch_startjmp(); ! if (SETJMP(lc_jump_env) != 0) ! { ! mch_didjmp(); ! xterm_dpy = NULL; ! } ! else ! #endif ! { ! xterm_dpy = XtOpenDisplay(app_context, xterm_display, ! "vim_xterm", "Vim_xterm", NULL, 0, &z, &strp); ! #if defined(HAVE_SETJMP_H) ! mch_endjmp(); ! #endif ! } + #if defined(HAVE_SETJMP_H) + /* Now handle X IO errors normally. */ + (void)XSetIOErrorHandler(oldIOhandler); + #endif /* Now handle X errors normally. */ (void)XSetErrorHandler(oldhandler); *************** *** 5332,5337 **** --- 5397,5405 ---- MSG(_("Opening the X display failed")); return; } + + /* Catch terminating error of the X server connection. */ + (void)XSetIOErrorHandler(x_IOerror_handler); # if defined(HAVE_GETTIMEOFDAY) && defined(HAVE_SYS_TIME_H) if (p_verbose > 0) *** ../vim61.471/src/version.c Fri Apr 18 12:32:44 2003 --- src/version.c Fri Apr 18 14:30:24 2003 *************** *** 613,614 **** --- 613,616 ---- { /* Add new patch number below this line */ + /**/ + 472, /**/ -- hundred-and-one symptoms of being an internet addict: 20. When looking at a pageful of someone else's links, you notice all of them are already highlighted in purple. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// Creator of Vim - Vi IMproved -- http://www.Vim.org \\\ \\\ Project leader for A-A-P -- http://www.A-A-P.org /// \\\ Help AIDS victims, buy at Amazon -- http://ICCF.nl/click1.html ///