From nobody@FreeBSD.org  Tue Feb  9 13:46:50 2010
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 27231106566C
	for <freebsd-gnats-submit@FreeBSD.org>; Tue,  9 Feb 2010 13:46:50 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id F1A5C8FC15
	for <freebsd-gnats-submit@FreeBSD.org>; Tue,  9 Feb 2010 13:46:49 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o19Dknik006953
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 9 Feb 2010 13:46:49 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o19DknqE006952;
	Tue, 9 Feb 2010 13:46:49 GMT
	(envelope-from nobody)
Message-Id: <201002091346.o19DknqE006952@www.freebsd.org>
Date: Tue, 9 Feb 2010 13:46:49 GMT
From: Ming <symingz@foxmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: pkg_add probably behaving incorrectly
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         143698
>Category:       bin
>Synopsis:       pkg_add(1) probably behaving incorrectly
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    portmgr
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Feb 09 13:50:02 UTC 2010
>Closed-Date:    Wed May 28 14:55:03 UTC 2014
>Last-Modified:  Wed May 28 14:55:03 UTC 2014
>Originator:     Ming
>Release:        8.0-RELEASE-p2
>Organization:
None
>Environment:
FreeBSD freebsd.hello 8.0-RELEASE-p2 FreeBSD 8.0-RELEASE-p2 #0: Tue Feb  9 00:16:31 CST 2010     root@freebsd.hello:/usr/obj/usr/src/sys/MINI  i386
>Description:
I think pkg_add has 2 incorrect behaviors: 
1. When using "pkg_add" or "pkg_add -r"to install a package, the installation 
   will continue even when pkg_add failed to find a dependent package , I think 
   this should only be the case when "-f" is used
2. When using "pkg_add -r" to install a package, the installation will 
   continue even when the fetch and extraction of the package are not 
   error free, and then the installation will only stop if the 
   "half-extracted package" triggers further error. I think installation 
   should stop as soon as an error is detected. Otherwise there is a chance 
   to leave the system in a "dirty state".
>How-To-Repeat:
For 1, just install a package without supplying the dependencies.

For 2, may be try to install a package that is a compressed broken tar (not tested, I think I encountered the problem due to network transfer error).
>Fix:
The fixes are not tested, but I think they might work:

For 1, change src/usr.sbin/pkg_install/add/perform.c, line 320 to:
    for (p = Plist.head; p && code == 0; p = p->next) {

For 2, change src/usr.sbin/pkg_install/lib/url.c as follows:
Insert after line 48: 
    int code = 0;
    int tarstat;

Replace line 152 to line 166 with:
    if (ferror(ftp)) {
	warn("warning: error reading from server");
	code++;
    }
    fclose(ftp);
    if (keep_package) {
	close(pkgfd);
    } 
    close(pfd[1]);
    if (w == -1) {
	warn("warning: error writing to tar");
	code++;
    }
    tpid = waitpid(tpid, &pstat, 0);
    tarstat = WEXITSTATUS(pstat);
    if (!tarstat) {
	warn("warning: error extracting package");
	code++;
    }
    if (Verbose)
	printf("tar command returns %d status\n", tarstat);
    if (code) {
        printf(" End with error.\n");
        return NULL;
    }
    if (rp && (isatty(0) || Verbose))
	printf(" Done.\n");
    return rp;

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-ports-bugs->freebsd-bugs 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Tue Feb 9 21:41:18 UTC 2010 
Responsible-Changed-Why:  
pkg_add(1) lives in src. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=143698 
State-Changed-From-To: open->feedback 
State-Changed-By: linimon 
State-Changed-When: Thu Feb 11 04:19:02 UTC 2010 
State-Changed-Why:  
To submitter: are you writing about the pkg_add in src, or in ports? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=143698 
State-Changed-From-To: feedback->open 
State-Changed-By: linimon 
State-Changed-When: Sun Feb 14 02:39:54 UTC 2010 
State-Changed-Why:  
bin/ is correct category. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=143698 

From: Mark Linimon <linimon@lonesome.com>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/143698: pkg_add(1) probably behaving incorrectly
Date: Sat, 13 Feb 2010 20:41:10 -0600

 ----- Forwarded message from symingz <symingz@foxmail.com> -----
 
 From: symingz <symingz@foxmail.com>
 To: linimon <linimon@FreeBSD.org>, linimon <linimon@FreeBSD.org>,
 	freebsd-bugs <freebsd-bugs@FreeBSD.org>
 Subject: Re: bin/143698: pkg_add(1) probably behaving incorrectly
 
 I'm writing about the pkg_add in src. Sorry for submitting to the wrong place.
 
 ----- End forwarded message -----
Responsible-Changed-From-To: freebsd-bugs->portmgr 
Responsible-Changed-By: flz 
Responsible-Changed-When: Thu Apr 1 17:19:57 UTC 2010 
Responsible-Changed-Why:  
pkg_install is maintained by portmgr. 

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

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