From jhein@timing.com  Mon May 14 23:30:09 2007
Return-Path: <jhein@timing.com>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 8364B16A400
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 14 May 2007 23:30:09 +0000 (UTC)
	(envelope-from jhein@timing.com)
Received: from Daffy.timing.com (w.timing.com [206.168.13.218])
	by mx1.freebsd.org (Postfix) with ESMTP id 44A4C13C45E
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 14 May 2007 23:30:09 +0000 (UTC)
	(envelope-from jhein@timing.com)
Received: from gromit.timing.com (gromit.timing.com [206.168.13.209])
	by Daffy.timing.com (8.13.1/8.13.1) with ESMTP id l4ENU69o080255
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 14 May 2007 17:30:06 -0600 (MDT)
	(envelope-from jhein@timing.com)
Received: from gromit.timing.com (localhost [127.0.0.1])
	by gromit.timing.com (8.13.8/8.13.8) with ESMTP id l4ENU3xr037187;
	Mon, 14 May 2007 17:30:03 -0600 (MDT)
	(envelope-from jhein@gromit.timing.com)
Received: (from jhein@localhost)
	by gromit.timing.com (8.13.8/8.13.8/Submit) id l4ENU3qr037186;
	Mon, 14 May 2007 17:30:03 -0600 (MDT)
	(envelope-from jhein)
Message-Id: <200705142330.l4ENU3qr037186@gromit.timing.com>
Date: Mon, 14 May 2007 17:30:03 -0600 (MDT)
From: "John E. Hein" <jhein@timing.com>
To: FreeBSD-gnats-submit@freebsd.org
Subject: [patch] pkg_add -S leaks the temp dir
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         112673
>Category:       bin
>Synopsis:       [patch] pkg_add(1): pkg_add -S leaks the temp dir
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    portmgr
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon May 14 23:40:04 GMT 2007
>Closed-Date:    Wed May 28 15:05:18 UTC 2014
>Last-Modified:  Wed May 28 15:05:18 UTC 2014
>Originator:     John E. Hein
>Release:        FreeBSD 6.2-STABLE i386
>Organization:
Symmetricom, Inc.
>Environment:
System: FreeBSD gromit.timing.com 6.2-STABLE FreeBSD 6.2-STABLE #2: Wed Mar 21 09:48:47 MDT 2007 jhein@gromit.timing.com:/usr/obj/usr/src/sys/GROMIT i386


7-current has the same problem.

>Description:

pkg_add -S doesn't clean up the temp dir created by pkg_add -M.

I found this because pkg_add -p was not working because of a package
that had multiple @cwd's - and plenty of packages do have these days
due to USE_RC_SUBR.  But that's another bug for another day.

>How-To-Repeat:

ls /var/tmp/instmp.*
pkg_add -v -M pkg.tbz | pkg_add -v -S
ls /var/tmp/instmp.*

Note temp dir left uncleaned.

>Fix:

This patch works fine, but I'm not that pleased with it.  But that's
mostly because I wanted to rewrite more of pkg_* as I dug into the
code.

Rather than do that (which someone else may be undertaking
already for SoC?), I figured a simple patch would do the trick for
now.  Alternate suggestions welcome.


Index: src/usr.sbin/pkg_install/add/perform.c
===================================================================
RCS file: /base/FreeBSD-CVS/src/usr.sbin/pkg_install/add/perform.c,v
retrieving revision 1.80
diff -u -p -r1.80 perform.c
--- src/usr.sbin/pkg_install/add/perform.c	9 Mar 2006 14:49:19 -0000	1.80
+++ src/usr.sbin/pkg_install/add/perform.c	14 May 2007 23:20:15 -0000
@@ -91,6 +91,7 @@ pkg_do(char *pkg)
     if (!pkg) {
 	fgets(playpen, FILENAME_MAX, stdin);
 	playpen[strlen(playpen) - 1] = '\0'; /* pesky newline! */
+	note_playpen(playpen);
 	if (chdir(playpen) == FAIL) {
 	    warnx("pkg_add in SLAVE mode can't chdir to %s", playpen);
 	    return 1;
Index: src/usr.sbin/pkg_install/lib/lib.h
===================================================================
RCS file: /base/FreeBSD-CVS/src/usr.sbin/pkg_install/lib/lib.h,v
retrieving revision 1.60
diff -u -p -r1.60 lib.h
--- src/usr.sbin/pkg_install/lib/lib.h	28 Mar 2007 05:33:52 -0000	1.60
+++ src/usr.sbin/pkg_install/lib/lib.h	14 May 2007 23:20:15 -0000
@@ -152,6 +152,7 @@ char		*vpipe(const char *, ...);
 void		cleanup(int);
 char		*make_playpen(char *, off_t);
 char		*where_playpen(void);
+void		note_playpen(const char *);
 void		leave_playpen(void);
 off_t		min_free(const char *);
 
Index: src/usr.sbin/pkg_install/lib/pen.c
===================================================================
RCS file: /base/FreeBSD-CVS/src/usr.sbin/pkg_install/lib/pen.c,v
retrieving revision 1.42
diff -u -p -r1.42 pen.c
--- src/usr.sbin/pkg_install/lib/pen.c	28 Jul 2004 16:03:13 -0000	1.42
+++ src/usr.sbin/pkg_install/lib/pen.c	14 May 2007 23:20:15 -0000
@@ -140,6 +140,17 @@ make_playpen(char *pen, off_t sz)
     return Previous;
 }
 
+/*
+ * Just record an already created playpen, so we can clean it later.
+ */
+void
+note_playpen(const char *pen)
+{
+    if (PenLocation[0])
+	pushPen(PenLocation);
+    strcpy(PenLocation, pen);
+}
+
 /* Convenience routine for getting out of playpen */
 void
 leave_playpen()
>Release-Note:
>Audit-Trail:

From: Garrett Cooper <yanegomi@gmail.com>
To: bug-followup@FreeBSD.org, jhein@timing.com
Cc:  
Subject: Re: bin/112673: [patch] pkg_add(1): pkg_add -S leaks the temp dir
Date: Tue, 23 Mar 2010 23:33:30 -0700

 Hi John,
     (No one has replied to this PR yet in the past 3 years, so I
 figure I should).
     Yes, I've noted the same as well with my toying around with
 pkg_install over the past couple of days. Something's rotten in terms
 of how the directories are pushed and popped, in fact because many
 times it's not properly pushing and popping the directories in the
 correct / respective order.
     Your patch may resolve this issue, but I'm concerned about the
 case where a tainted directory hasn't been properly cleaned up and
 thus you get some of the contents of package A along with the contents
 of package B in the same directory, instead of properly resolving the
 root cause.
      I'll keep this bug in mind and look at proposing a solution
 sometime in the next couple of weeks.
      And the rewrite isn't completely off -- it's just been put on
 hold until this stuff is fixed :).
 Thanks,
 -Garrett
Responsible-Changed-From-To: freebsd-bugs->portmgr 
Responsible-Changed-By: flz 
Responsible-Changed-When: Thu Apr 1 17:20:54 UTC 2010 
Responsible-Changed-Why:  
pkg_install is maintained by portmgr. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=112673 
State-Changed-From-To: open->closed 
State-Changed-By: bapt 
State-Changed-When: Wed May 28 15:05:17 UTC 2014 
State-Changed-Why:  
pkg_install is not being worked on anymore 

http://www.freebsd.org/cgi/query-pr.cgi?pr=112673 
>Unformatted:
