From owner-freebsd-bugs@FreeBSD.ORG Tue Feb 12 18:10:02 2008 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E9A1616A41A for ; Tue, 12 Feb 2008 18:10:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id D8A2613C4D9 for ; Tue, 12 Feb 2008 18:10:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.2/8.14.2) with ESMTP id m1CIA2Qd061640 for ; Tue, 12 Feb 2008 18:10:02 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.2/8.14.1/Submit) id m1CIA2Am061639; Tue, 12 Feb 2008 18:10:02 GMT (envelope-from gnats) Date: Tue, 12 Feb 2008 18:10:02 GMT Message-Id: <200802121810.m1CIA2Am061639@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Jaakko Heinonen Cc: Subject: Re: bin/21089: vi silently corrupt open file on SIGINT when entering :wq in command mode X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Jaakko Heinonen List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Feb 2008 18:10:03 -0000 The following reply was made to PR bin/21089; it has been noted by GNATS. From: Jaakko Heinonen To: Yar Tikhiy Cc: bug-followup@freebsd.org Subject: Re: bin/21089: vi silently corrupt open file on SIGINT when entering :wq in command mode Date: Tue, 12 Feb 2008 20:02:25 +0200 --pf9I7BMVVzbSWLtt Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, On 2008-02-10, Yar Tikhiy wrote: > I think that you looked in the right direction but applied the fix > at a wrong level. In fact, we shouldn't put a test for INTERRUPTED(sp) > into each ex command's implementation. Agreed. [thanks for good analysis of the problem] > What perhaps is needed is a clear indication from v_txt() to its > caller that a special event ended text input, so that it can be up > to the caller to decide how to handle the event. What do you think about the attached patch? It sets a global state flag when a resize event occurs. I am not sure if it's a good way to do it. > But for now the ^C bug can be fixed quickly as shown in the attached > patch. Looks much better than my original patch. -- Jaakko --pf9I7BMVVzbSWLtt Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="nvi-SIGINT.diff" Index: common/gs.h =================================================================== RCS file: /home/ncvs/src/contrib/nvi/common/gs.h,v retrieving revision 1.1.1.1 diff -p -u -r1.1.1.1 gs.h --- common/gs.h 1 Nov 1996 06:45:37 -0000 1.1.1.1 +++ common/gs.h 12 Feb 2008 17:55:35 -0000 @@ -144,6 +144,7 @@ struct _gs { #define G_SNAPSHOT 0x0040 /* Always snapshot files. */ #define G_SRESTART 0x0080 /* Screen restarted. */ #define G_TMP_INUSE 0x0100 /* Temporary buffer in use. */ +#define G_RESIZE 0x0200 /* Resize requested. */ u_int32_t flags; /* Screen interface functions. */ Index: common/key.c =================================================================== RCS file: /home/ncvs/src/contrib/nvi/common/key.c,v retrieving revision 1.1.1.1 diff -p -u -r1.1.1.1 key.c --- common/key.c 1 Nov 1996 06:45:37 -0000 1.1.1.1 +++ common/key.c 12 Feb 2008 17:55:35 -0000 @@ -591,6 +591,10 @@ loop: if (gp->scr_event(sp, argp, if (LF_ISSET(EC_INTERRUPT)) return (0); goto append; + case E_WRESIZE: + /* Set the global resize flag. */ + F_SET(sp->gp, G_RESIZE); + goto append; default: append: if (v_event_append(sp, argp)) return (1); Index: vi/v_txt.c =================================================================== RCS file: /home/ncvs/src/contrib/nvi/vi/v_txt.c,v retrieving revision 1.1.1.1 diff -p -u -r1.1.1.1 v_txt.c --- vi/v_txt.c 1 Nov 1996 06:45:33 -0000 1.1.1.1 +++ vi/v_txt.c 12 Feb 2008 17:55:36 -0000 @@ -92,6 +92,8 @@ v_tcmd(sp, vp, prompt, flags) if (O_ISSET(sp, O_TTYWERASE)) LF_SET(TXT_TTYWERASE); + F_CLR(sp->gp, G_RESIZE); + /* Do the input thing. */ if (v_txt(sp, vp, NULL, NULL, 0, prompt, 0, 1, flags)) return (1); @@ -109,6 +111,10 @@ v_tcmd(sp, vp, prompt, flags) /* Set the cursor to the resulting position. */ sp->lno = vp->m_final.lno; sp->cno = vp->m_final.cno; + + /* Abort the command on interrupt or window resize. */ + if (INTERRUPTED(sp) || F_ISSET(sp->gp, G_RESIZE)) + return (1); return (0); } --pf9I7BMVVzbSWLtt--