bin/21089: vi silently corrupt open file on SIGINT when entering :wq in command mode

Jaakko Heinonen jh at saunalahti.fi
Tue Feb 12 18:10:03 UTC 2008


The following reply was made to PR bin/21089; it has been noted by GNATS.

From: Jaakko Heinonen <jh at saunalahti.fi>
To: Yar Tikhiy <yar at comp.chem.msu.su>
Cc: bug-followup at 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--


More information about the freebsd-bugs mailing list