From aecolley@ois.ie  Thu Oct 30 09:45:27 1997
Received: from ios.internet-ireland.ie (ios.internet-ireland.ie [195.17.130.2])
          by hub.freebsd.org (8.8.7/8.8.7) with SMTP id JAA25359
          for <FreeBSD-gnats-submit@freebsd.org>; Thu, 30 Oct 1997 09:45:23 -0800 (PST)
          (envelope-from aecolley@ois.ie)
Received: from gate.ois.ie (oisgw.ois.ie [195.17.130.66]) by ios.internet-ireland.ie (8.6.12/8.6.12) with ESMTP id RAA03484 for <FreeBSD-gnats-submit@freebsd.org>; Thu, 30 Oct 1997 17:45:06 GMT
Received: from faust.ois.ie (faust.ois.ie [192.168.0.254]) by gate.ois.ie (8.8.7/8.6.12) with SMTP id RAA27667 for <FreeBSD-gnats-submit@freebsd.org>; Thu, 30 Oct 1997 17:44:44 GMT
Received: from aecolley by faust.ois.ie with local (Exim 1.70 #1)
	id 0xQyeC-0000Wn-00; Thu, 30 Oct 1997 17:44:44 +0000
Message-Id: <E0xQyeC-0000Wn-00@faust.ois.ie>
Date: Thu, 30 Oct 1997 17:44:44 +0000
From: aecolley@ois.ie
Reply-To: aecolley@ois.ie
To: FreeBSD-gnats-submit@freebsd.org
Subject: pkg_delete ignores @cwd because pkg_create removes it
X-Send-Pr-Version: 3.2

>Number:         4894
>Category:       bin
>Synopsis:       pkg_delete ignores @cwd because pkg_create removes it
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Oct 30 09:50:00 PST 1997
>Closed-Date:    Thu Nov 13 03:50:03 PST 1997
>Last-Modified:  Thu Nov 13 03:50:16 PST 1997
>Originator:     Adrian Colley
>Release:        FreeBSD 2.2.5-STABLE i386
>Organization:
Office Integrated Solutions
>Environment:

	Last update via CTM to src-2.2.0486.
	RCS ID in usr.sbin/pkg_install/create/perform.c is:
	  Id: perform.c,v 1.32.2.4 1997/10/13 15:06:11 jkh Exp

>Description:

	When a port's pkg/PLIST contains an @cwd line followed by an @unexec
	line which includes %D, it is expected that %D will be replaced by
	the current directory name set by @cwd.

	However, when pkg_create is used to make PLIST into
	/var/db/pkg/(package)/+CONTENTS, the @cwds are stripped and replaced
	with a single @cwd $PREFIX.

	Consequently, if the package is later removed with pkg_delete, @unexec
	commands in +CONTENTS may fail because %D is replaced with the wrong
	value, or because the command is sensitive to its working directory.

>How-To-Repeat:

	Install comms/mgetty+sendfax from the ports collection (install with
	make -DBATCH install to avoid the questionnaire).  Then pkg_delete
	mgetty-1.0.0.  The pkg_delete will complain about /usr/local/fax being
	nonexistent.

	The pkg/PLIST of mgetty+sendfax includes the lines:
	@cd /var/spool
	@exec mkdir -p %D/fax/incoming
	@exec mkdir -p %D/fax/outgoing
	@exec chmod -R 775 %D/fax
	@unexec rm -r %D/fax

	After make install, /var/db/pkg/mgetty-1.0.0/+CONTENTS can be seen to have
	lost the @cd, which causes the @unexec to expand as "rm -r /usr/local/fax"
	instead of "rm -r /var/spool/fax"

>Fix:
	
	/usr/src/usr.sbin/pkg_install/create/perform.c, lines 99-103 contain the
	perpetrating code:

	/* Prefix should override the packing list */
	if (Prefix) {
	    delete_plist(&plist, FALSE, PLIST_CWD, NULL);
	    add_plist_top(&plist, PLIST_CWD, Prefix);
	}

	Perhaps there's a reason for the delete_plist call here, but I can't think
	what it is.  If the packing list contains @cwds which should be removed,
	then they should be removed from the actual packing lists.  If a packing
	list has a good reason to use @cwd, this should be respected.

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: jkh 
State-Changed-When: Thu Nov 13 03:50:03 PST 1997 
State-Changed-Why:  
Suggested fix applied, thanks! 
>Unformatted:
