From root@gits.dyndns.org  Mon May  8 23:37:20 2000
Return-Path: <root@gits.dyndns.org>
Received: from racine.cybercable.fr (racine.cybercable.fr [212.198.0.201])
	by hub.freebsd.org (Postfix) with SMTP id EB2FC37BDB9
	for <FreeBSD-gnats-submit@freebsd.org>; Mon,  8 May 2000 23:37:13 -0700 (PDT)
	(envelope-from root@gits.dyndns.org)
Received: (qmail 17776842 invoked from network); 9 May 2000 06:37:11 -0000
Received: from r225m254.cybercable.tm.fr (HELO gits.dyndns.org) ([195.132.225.254]) (envelope-sender <root@gits.dyndns.org>)
          by racine.cybercable.fr (qmail-ldap-1.03) with SMTP
          for <FreeBSD-gnats-submit@freebsd.org>; 9 May 2000 06:37:11 -0000
Received: (from root@localhost)
	by gits.dyndns.org (8.9.3/8.9.3) id IAA05533;
	Tue, 9 May 2000 08:37:10 +0200 (CEST)
	(envelope-from root)
Message-Id: <200005090637.IAA05533@gits.dyndns.org>
Date: Tue, 9 May 2000 08:37:10 +0200 (CEST)
From: clefevre@citeweb.net
Sender: root@gits.dyndns.org
Reply-To: clefevre@citeweb.net
To: FreeBSD-gnats-submit@freebsd.org
Subject: vi.recover misplaced in /var/tmp
X-Send-Pr-Version: 3.2

>Number:         18461
>Category:       conf
>Synopsis:       vi.recover misplaced in /var/tmp
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon May 08 23:40:00 PDT 2000
>Closed-Date:    Sat May 13 05:17:12 PDT 2000
>Last-Modified:  Sat May 13 05:20:01 PDT 2000
>Originator:     Cyrille Lefevre
>Release:        FreeBSD 4.0-STABLE i386
>Organization:
ACME
>Environment:

FreeBSD gits 4.0-STABLE FreeBSD 4.0-STABLE #15: Tue May  9 00:32:14 CEST 2000     root@gits:/disk2/4.0-STABLE/src/sys/compile/CUSTOM  i386

>Description:

	vi.recover should not be in /var/tmp. imagine the case
	where /var/tmp is a memory filesystem. upon reboot,
	everything is lost.

>How-To-Repeat:

	make /var/tmp a memory filesystem in /etc/fstab as :

		swap /var/tmp mfs rw,async,-s65535 0 0

	edit files, left them open, then reboot.
	nothing can be recovered. there all lost.

>Fix:

	first, sets a variable $vi_recover to "/var/tmp/vi.recover"
	in /etc/defaults/rc.conf. in /etc/rc, if that variable in
	not to its default value, update /etc/vi.exrc in consequence.
	in all case, use it to determine where are files to recover.

Index: /usr/src/etc/defaults/rc.conf
===================================================================
RCS file: /home/ncvs/src/etc/defaults/rc.conf,v
retrieving revision 1.53.2.3
diff -u -r1.53.2.3 rc.conf
--- /usr/src/etc/defaults/rc.conf	2000/04/15 11:02:40	1.53.2.3
+++ /usr/src/etc/defaults/rc.conf	2000/05/09 06:25:20
@@ -276,6 +276,7 @@
 svr4_enable="NO"	# SysVR4 emulation loaded at startup (or NO).
 osf1_enable="NO"	# Alpha OSF/1 emulation loaded at startup (or NO).
 rand_irqs="NO"		# Stir the entropy pool (like "5 11" or NO).
+vi_recover="/var/tmp/vi.recover" # The directory where recovery files are stored.
 clear_tmp_enable="NO"	# Clear /tmp at startup.
 ldconfig_paths="/usr/lib/compat /usr/X11R6/lib /usr/local/lib"
 			# shared library search paths
Index: /usr/src/etc/rc
===================================================================
RCS file: /home/ncvs/src/etc/rc,v
retrieving revision 1.212
diff -u -r1.212 rc
--- /usr/src/etc/rc	2000/02/28 19:54:06	1.212
+++ /usr/src/etc/rc	2000/05/09 06:32:00
@@ -413,11 +413,26 @@
 echo '.'
 
 # Recover vi editor files.
-find /var/tmp/vi.recover ! -type f -a ! -type d -delete
-vibackup=`echo /var/tmp/vi.recover/vi.*`
-if [ "${vibackup}" != '/var/tmp/vi.recover/vi.*' ]; then
+if [ -n "$vi_recover" ]; then
+	if [ "$vi_recover" != /var/tmp/vi.recover ]; then
+		if [ -s /etc/vi.exrc ]; then
+			# be conservative
+			sed -e 's/recdir=[^ 	]*[ 	]*//' \
+			    -e '/^[ 	]*set[ 	]*$/d' \
+				/etc/vi.exrc > /tmp/vi.exrc.$$ &&
+			cp /tmp/vi.exrc.$$ /etc/vi.exrc &&
+			rm /tmp/vi.exrc.$$
+		fi
+		echo set recdir=$vi_recover >> /etc/vi.exrc
+	fi
+else
+	vi_recover=/var/tmp/vi.recover # just in case
+fi
+find $vi_recover ! -type f -a ! -type d -delete
+vibackup=`echo $vi_recover/vi.*`
+if [ "${vibackup}" != '$vi_recover/vi.*' ]; then
 	echo 'Recovering vi editor sessions'
-	for i in /var/tmp/vi.recover/vi.*; do
+	for i in $vi_recover/vi.*; do
 		# Only test files that are readable.
 		if [ ! -r "${i}" ]; then
 			continue
@@ -432,9 +447,9 @@
 
 	# It is possible to get incomplete recovery files, if the editor
 	# crashes at the right time.
-	virecovery=`echo /var/tmp/vi.recover/recover.*`
-	if [ "${virecovery}" != "/var/tmp/vi.recover/recover.*" ]; then
-		for i in /var/tmp/vi.recover/recover.*; do
+	virecovery=`echo $vi_recover/recover.*`
+	if [ "${virecovery}" != "$vi_recover/recover.*" ]; then
+		for i in $vi_recover/recover.*; do
 			# Only test files that are readable.
 			if [ ! -r "${i}" ]; then
 				continue
@@ -452,6 +467,7 @@
 		done
 	fi
 fi
+mkdir -m 1777 -p $vi_recover
 
 # Make a bounds file for msgs(1) if there isn't one already
 # "Delete important files with symlink" security hole?

>Release-Note:
>Audit-Trail:

From: Gregory Bond <gnb@itga.com.au>
To: clefevre@citeweb.net
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: conf/18461: vi.recover misplaced in /var/tmp 
Date: Tue, 09 May 2000 17:36:14 +1000

 > 	vi.recover should not be in /var/tmp. imagine the case
 > 	where /var/tmp is a memory filesystem. upon reboot,
 > 	everything is lost.
 
 On the contrary, /var/tmp is exactly the right spot for vi.recover, because 
 /var/tmp is -explicitly documented- to remain over reboots.  See "man hier".
 
 Anyone who uses mfs for /var/tmp is just plain wrong.
 
 
 
State-Changed-From-To: open->closed 
State-Changed-By: asmodai 
State-Changed-When: Sat May 13 05:17:12 PDT 2000 
State-Changed-Why:  
/var/tmp is supposed to be preserved over reboots.  it is /tmp 
that is commonly mounted on MFS systems.  See mail from me 
on this subject. 

From: Jeroen Ruigrok/Asmodai <asmodai@wxs.nl>
To: Gregory Bond <gnb@itga.com.au>
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: conf/18461: vi.recover misplaced in /var/tmp
Date: Sat, 13 May 2000 14:07:23 +0200

 -On [20000509 12:01], Gregory Bond (gnb@itga.com.au) wrote:
 >
 >From: Gregory Bond <gnb@itga.com.au>
 >
 > > 	vi.recover should not be in /var/tmp. imagine the case
 > > 	where /var/tmp is a memory filesystem. upon reboot,
 > > 	everything is lost.
 > 
 > On the contrary, /var/tmp is exactly the right spot for vi.recover, because 
 > /var/tmp is -explicitly documented- to remain over reboots.  See "man hier".
 > 
 > Anyone who uses mfs for /var/tmp is just plain wrong.
 
 I agree with the above sentiment, from hier(7):
 
      /tmp/    temporary files, usually a mfs(8) memory-based filesystem (the
               contents of /tmp are usually NOT preserved across a system re-
               boot)
 
      /var/    multi-purpose log, temporary, transient, and spool files
               tmp/       temporary files that are kept between system reboots
                          vi.recover/
                                      the directory where recovery files are
                                      stored
 
 This is also why there is a clear_tmp_enable directive in the rc.conf.
 
 -- 
 Jeroen Ruigrok vd Werven/Asmodai    asmodai@[wxs.nl|bart.nl|freebsd.org]
 Documentation nutter/C-rated Coder BSD: Technical excellence at its best  
 The BSD Programmer's Documentation Project <http://home.wxs.nl/~asmodai>
 And every word upon your spiralling cross is but a misled sun, a bitter
  loss...
 
>Unformatted:
