From nobody@FreeBSD.org  Sun Mar 28 09:52:12 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 16043106566B
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 28 Mar 2010 09:52:12 +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 0409F8FC08
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 28 Mar 2010 09:52:12 +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 o2S9qB4D069449
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 28 Mar 2010 09:52:11 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o2S9qBu6069448;
	Sun, 28 Mar 2010 09:52:11 GMT
	(envelope-from nobody)
Message-Id: <201003280952.o2S9qBu6069448@www.freebsd.org>
Date: Sun, 28 Mar 2010 09:52:11 GMT
From: Garrett Cooper <yaneurabeya@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] pkg_version(1) - remove hardcoded INDEX filename versioning checks from lib.h and version/perform.c
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         145101
>Category:       bin
>Synopsis:       [patch] pkg_version(1) - remove hardcoded INDEX filename versioning checks from lib.h and version/perform.c
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    portmgr
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Mar 28 10:00:11 UTC 2010
>Closed-Date:    Mon May 21 13:07:52 UTC 2012
>Last-Modified:  Sun Feb 03 22:28:27 UTC 2013
>Originator:     Garrett Cooper
>Release:        9-CURRENT
>Organization:
Cisco Systems, Inc.
>Environment:
FreeBSD bayonetta.local 9.0-CURRENT FreeBSD 9.0-CURRENT #5 r205310: Sat Mar 20 01:32:51 PDT 2010     gcooper@bayonetta.local:/usr/obj/usr/src/sys/BAYONETTA  amd64

>Description:
Similar to bin/145100, the hardcoded versioning information for the INDEX filename can be yanked provided that proper scanning of the (struct uname).release field is done.

This was based off another keen observation made by bapt@ on #bsdports when submitting the patch for pkg_version.

All of the basic criteria for bin/145100 apply to this patch as well at this time, w.r.t. the progname item, etc.
>How-To-Repeat:

>Fix:


Patch attached with submission follows:

==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/lib/lib.h#2 - /scratch/freebsd/perforce/pkg_install-enhancements/usr.sbin/pkg_install/lib/lib.h ====
@@ -28,6 +28,7 @@
 #include <sys/file.h>
 #include <sys/stat.h>
 #include <sys/queue.h>
+#include <sys/utsname.h>
 #include <ctype.h>
 #include <dirent.h>
 #include <err.h>
@@ -86,18 +87,6 @@
 #define DISPLAY_FNAME		"+DISPLAY"
 #define MTREE_FNAME		"+MTREE_DIRS"
 
-#if defined(__FreeBSD_version) && __FreeBSD_version >= 900000
-#define INDEX_FNAME		"INDEX-9"
-#elif defined(__FreeBSD_version) && __FreeBSD_version >= 800000
-#define INDEX_FNAME		"INDEX-8"
-#elif defined(__FreeBSD_version) && __FreeBSD_version >= 700000
-#define INDEX_FNAME		"INDEX-7"
-#elif defined(__FreeBSD_version) && __FreeBSD_version >= 600000
-#define INDEX_FNAME		"INDEX-6"
-#else
-#define INDEX_FNAME		"INDEX"
-#endif
-
 #define CMD_CHAR		'@'	/* prefix for extended PLIST cmd */
 
 /* The name of the "prefix" environment variable given to scripts */
==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/version/perform.c#1 - /scratch/freebsd/perforce/pkg_install-enhancements/usr.sbin/pkg_install/version/perform.c ====
@@ -35,28 +35,42 @@
 static void show_version(Package, const char *, const char *);
 
 /*
- * This is the traditional pkg_perform, except that the argument is _not_
- * a list of packages. It is the index file from the command line.
+ * This is the traditional pkg_perform, except that the argument is _not_ a
+ * list of packages. It is the index file from the command line.
+ *
+ * We loop over the installed packages, matching them with the -s flag if
+ * needed and calling pkg_do(). Beforehand we set up a few things, and after
+ * we tear them down...
  *
- * We loop over the installed packages, matching them with the -s flag
- * if needed and calling pkg_do(). Before hand we set up a few things,
- * and after we tear them down...
+ * Returns 0 on success, non-zero on failure, corresponding to the number of
+ * failed attempts to access the INDEX.
  */
 int
 pkg_perform(char **indexarg)
 {
     char **pkgs, *pat[2], **patterns;
     struct index_entry *ie;
-    int i, err_cnt = 0;
+    int i, err_cnt = 0, rel_major_ver;
     int MatchType;
 
+    struct utsname u;
+
+    if (uname(&u) == -1) {
+	warn("%s.%s: failed to determine uname information", progname,
+	    __func__);
+	return 1;
+    } else if ((rel_major_ver = (int) strtol(u.release, NULL, 10)) <= 0) {
+
+    }
+
     /*
      * Try to find and open the INDEX. We only check IndexFile != NULL
      * later, if we actually need the INDEX.
      */
-    if (*indexarg == NULL)
-	snprintf(IndexPath, sizeof(IndexPath), "%s/%s", PORTS_DIR, INDEX_FNAME);
-    else
+    if (*indexarg == NULL) {
+	snprintf(IndexPath, sizeof(IndexPath), "%s/INDEX-%d", PORTS_DIR,
+	    rel_major_ver);
+    } else
 	strlcpy(IndexPath, *indexarg, sizeof(IndexPath));
     if (isURL(IndexPath))
 	IndexFile = fetchGetURL(IndexPath, "");


>Release-Note:
>Audit-Trail:

From: Garrett Cooper <yaneurabeya@gmail.com>
To: FreeBSD-gnats-submit@freebsd.org, freebsd-bugs@freebsd.org
Cc:  
Subject: Re: bin/145101: [patch] pkg_version(1) - remove hardcoded INDEX 
	filename versioning checks from lib.h and version/perform.c
Date: Sun, 28 Mar 2010 03:07:15 -0700

 --001485f90dfe9f37af0482d98fe9
 Content-Type: text/plain; charset=ISO-8859-1
 Content-Transfer-Encoding: quoted-printable
 
 On Sun, Mar 28, 2010 at 3:00 AM,  <FreeBSD-gnats-submit@freebsd.org> wrote:
 > Thank you very much for your problem report.
 > It has the internal identification `bin/145101'.
 > The individual assigned to look at your
 > report is: freebsd-bugs.
 >
 > You can access the state of your problem report at any time
 > via this link:
 >
 > http://www.freebsd.org/cgi/query-pr.cgi?pr=3D145101
 >
 >>Category: =A0 =A0 =A0 bin
 >>Responsible: =A0 =A0freebsd-bugs
 >>Synopsis: =A0 =A0 =A0 [patch] pkg_version(1) - remove hardcoded INDEX fil=
 ename versioning checks from lib.h and version/perform.c
 >>Arrival-Date: =A0 Sun Mar 28 10:00:11 UTC 2010
 
     Here's a better version that detects debunk UNAME_r version info
 and deals with it in a proper manner.
 Thanks,
 -Garrett
 
 --001485f90dfe9f37af0482d98fe9
 Content-Type: text/plain; charset=US-ASCII; 
 	name="simplify-pkg_version-index-versioning.diff.txt"
 Content-Disposition: attachment; 
 	filename="simplify-pkg_version-index-versioning.diff.txt"
 Content-Transfer-Encoding: base64
 X-Attachment-Id: f_g7bopxuv0
 
 PT09PSAvL2RlcG90L3Byb2plY3RzL3NvYzIwMDcvZ2Nvb3Blci1wa2dfaW5zdGFsbC1lbmhhbmNl
 bWVudHMtc2ltcGxpZmllZC91c3Iuc2Jpbi9wa2dfaW5zdGFsbC9saWIvbGliLmgjMiAtIC9zY3Jh
 dGNoL2ZyZWVic2QvcGVyZm9yY2UvcGtnX2luc3RhbGwtZW5oYW5jZW1lbnRzL3Vzci5zYmluL3Br
 Z19pbnN0YWxsL2xpYi9saWIuaCA9PT09CkBAIC0yOCw2ICsyOCw3IEBACiAjaW5jbHVkZSA8c3lz
 L2ZpbGUuaD4KICNpbmNsdWRlIDxzeXMvc3RhdC5oPgogI2luY2x1ZGUgPHN5cy9xdWV1ZS5oPgor
 I2luY2x1ZGUgPHN5cy91dHNuYW1lLmg+CiAjaW5jbHVkZSA8Y3R5cGUuaD4KICNpbmNsdWRlIDxk
 aXJlbnQuaD4KICNpbmNsdWRlIDxlcnIuaD4KQEAgLTg2LDE4ICs4Nyw2IEBACiAjZGVmaW5lIERJ
 U1BMQVlfRk5BTUUJCSIrRElTUExBWSIKICNkZWZpbmUgTVRSRUVfRk5BTUUJCSIrTVRSRUVfRElS
 UyIKIAotI2lmIGRlZmluZWQoX19GcmVlQlNEX3ZlcnNpb24pICYmIF9fRnJlZUJTRF92ZXJzaW9u
 ID49IDkwMDAwMAotI2RlZmluZSBJTkRFWF9GTkFNRQkJIklOREVYLTkiCi0jZWxpZiBkZWZpbmVk
 KF9fRnJlZUJTRF92ZXJzaW9uKSAmJiBfX0ZyZWVCU0RfdmVyc2lvbiA+PSA4MDAwMDAKLSNkZWZp
 bmUgSU5ERVhfRk5BTUUJCSJJTkRFWC04IgotI2VsaWYgZGVmaW5lZChfX0ZyZWVCU0RfdmVyc2lv
 bikgJiYgX19GcmVlQlNEX3ZlcnNpb24gPj0gNzAwMDAwCi0jZGVmaW5lIElOREVYX0ZOQU1FCQki
 SU5ERVgtNyIKLSNlbGlmIGRlZmluZWQoX19GcmVlQlNEX3ZlcnNpb24pICYmIF9fRnJlZUJTRF92
 ZXJzaW9uID49IDYwMDAwMAotI2RlZmluZSBJTkRFWF9GTkFNRQkJIklOREVYLTYiCi0jZWxzZQot
 I2RlZmluZSBJTkRFWF9GTkFNRQkJIklOREVYIgotI2VuZGlmCi0KICNkZWZpbmUgQ01EX0NIQVIJ
 CSdAJwkvKiBwcmVmaXggZm9yIGV4dGVuZGVkIFBMSVNUIGNtZCAqLwogCiAvKiBUaGUgbmFtZSBv
 ZiB0aGUgInByZWZpeCIgZW52aXJvbm1lbnQgdmFyaWFibGUgZ2l2ZW4gdG8gc2NyaXB0cyAqLwo9
 PT09IC8vZGVwb3QvcHJvamVjdHMvc29jMjAwNy9nY29vcGVyLXBrZ19pbnN0YWxsLWVuaGFuY2Vt
 ZW50cy1zaW1wbGlmaWVkL3Vzci5zYmluL3BrZ19pbnN0YWxsL3ZlcnNpb24vcGVyZm9ybS5jIzEg
 LSAvc2NyYXRjaC9mcmVlYnNkL3BlcmZvcmNlL3BrZ19pbnN0YWxsLWVuaGFuY2VtZW50cy91c3Iu
 c2Jpbi9wa2dfaW5zdGFsbC92ZXJzaW9uL3BlcmZvcm0uYyA9PT09CkBAIC0zNSwyOCArMzUsNDQg
 QEAKIHN0YXRpYyB2b2lkIHNob3dfdmVyc2lvbihQYWNrYWdlLCBjb25zdCBjaGFyICosIGNvbnN0
 IGNoYXIgKik7CiAKIC8qCi0gKiBUaGlzIGlzIHRoZSB0cmFkaXRpb25hbCBwa2dfcGVyZm9ybSwg
 ZXhjZXB0IHRoYXQgdGhlIGFyZ3VtZW50IGlzIF9ub3RfCi0gKiBhIGxpc3Qgb2YgcGFja2FnZXMu
 IEl0IGlzIHRoZSBpbmRleCBmaWxlIGZyb20gdGhlIGNvbW1hbmQgbGluZS4KKyAqIFRoaXMgaXMg
 dGhlIHRyYWRpdGlvbmFsIHBrZ19wZXJmb3JtLCBleGNlcHQgdGhhdCB0aGUgYXJndW1lbnQgaXMg
 X25vdF8gYQorICogbGlzdCBvZiBwYWNrYWdlcy4gSXQgaXMgdGhlIGluZGV4IGZpbGUgZnJvbSB0
 aGUgY29tbWFuZCBsaW5lLgorICoKKyAqIFdlIGxvb3Agb3ZlciB0aGUgaW5zdGFsbGVkIHBhY2th
 Z2VzLCBtYXRjaGluZyB0aGVtIHdpdGggdGhlIC1zIGZsYWcgaWYKKyAqIG5lZWRlZCBhbmQgY2Fs
 bGluZyBwa2dfZG8oKS4gQmVmb3JlaGFuZCB3ZSBzZXQgdXAgYSBmZXcgdGhpbmdzLCBhbmQgYWZ0
 ZXIKKyAqIHdlIHRlYXIgdGhlbSBkb3duLi4uCiAgKgotICogV2UgbG9vcCBvdmVyIHRoZSBpbnN0
 YWxsZWQgcGFja2FnZXMsIG1hdGNoaW5nIHRoZW0gd2l0aCB0aGUgLXMgZmxhZwotICogaWYgbmVl
 ZGVkIGFuZCBjYWxsaW5nIHBrZ19kbygpLiBCZWZvcmUgaGFuZCB3ZSBzZXQgdXAgYSBmZXcgdGhp
 bmdzLAotICogYW5kIGFmdGVyIHdlIHRlYXIgdGhlbSBkb3duLi4uCisgKiBSZXR1cm5zIDAgb24g
 c3VjY2Vzcywgbm9uLXplcm8gb24gZmFpbHVyZSwgY29ycmVzcG9uZGluZyB0byB0aGUgbnVtYmVy
 IG9mCisgKiBmYWlsZWQgYXR0ZW1wdHMgdG8gYWNjZXNzIHRoZSBJTkRFWC4KICAqLwogaW50CiBw
 a2dfcGVyZm9ybShjaGFyICoqaW5kZXhhcmcpCiB7CiAgICAgY2hhciAqKnBrZ3MsICpwYXRbMl0s
 ICoqcGF0dGVybnM7CiAgICAgc3RydWN0IGluZGV4X2VudHJ5ICppZTsKLSAgICBpbnQgaSwgZXJy
 X2NudCA9IDA7CisgICAgaW50IGksIGVycl9jbnQgPSAwLCByZWxfbWFqb3JfdmVyOwogICAgIGlu
 dCBNYXRjaFR5cGU7CiAKKyAgICBzdHJ1Y3QgdXRzbmFtZSB1OworCisgICAgaWYgKHVuYW1lKCZ1
 KSA9PSAtMSkgeworCXdhcm4oIiVzLiVzOiBmYWlsZWQgdG8gZGV0ZXJtaW5lIHVuYW1lIGluZm9y
 bWF0aW9uIiwgcHJvZ25hbWUsCisJICAgIF9fZnVuY19fKTsKKwlyZXR1cm4gMTsKKyAgICB9IGVs
 c2UgaWYgKChyZWxfbWFqb3JfdmVyID0gKGludCkgc3RydG9sKHUucmVsZWFzZSwgTlVMTCwgMTAp
 KSA8PSAwKSB7CisJd2FybngoIiVzLiVzOiBiYWQgcmVsZWFzZSB2ZXJzaW9uIHNwZWNpZmllZDog
 JXMiLCBwcm9nbmFtZSwgX19mdW5jX18sCisJICAgIHUucmVsZWFzZSk7CisJcmV0dXJuIDE7Cisg
 ICAgfQorCiAgICAgLyoKICAgICAgKiBUcnkgdG8gZmluZCBhbmQgb3BlbiB0aGUgSU5ERVguIFdl
 IG9ubHkgY2hlY2sgSW5kZXhGaWxlICE9IE5VTEwKICAgICAgKiBsYXRlciwgaWYgd2UgYWN0dWFs
 bHkgbmVlZCB0aGUgSU5ERVguCiAgICAgICovCi0gICAgaWYgKCppbmRleGFyZyA9PSBOVUxMKQot
 CXNucHJpbnRmKEluZGV4UGF0aCwgc2l6ZW9mKEluZGV4UGF0aCksICIlcy8lcyIsIFBPUlRTX0RJ
 UiwgSU5ERVhfRk5BTUUpOwotICAgIGVsc2UKKyAgICBpZiAoKmluZGV4YXJnID09IE5VTEwpIHsK
 KwlzbnByaW50ZihJbmRleFBhdGgsIHNpemVvZihJbmRleFBhdGgpLCAiJXMvSU5ERVgtJWQiLCBQ
 T1JUU19ESVIsCisJICAgIHJlbF9tYWpvcl92ZXIpOworICAgIH0gZWxzZQogCXN0cmxjcHkoSW5k
 ZXhQYXRoLCAqaW5kZXhhcmcsIHNpemVvZihJbmRleFBhdGgpKTsKICAgICBpZiAoaXNVUkwoSW5k
 ZXhQYXRoKSkKIAlJbmRleEZpbGUgPSBmZXRjaEdldFVSTChJbmRleFBhdGgsICIiKTsK
 --001485f90dfe9f37af0482d98fe9--

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/145101: commit references a PR
Date: Thu,  1 Apr 2010 14:27:39 +0000 (UTC)

 Author: flz
 Date: Thu Apr  1 14:27:29 2010
 New Revision: 206043
 URL: http://svn.freebsd.org/changeset/base/206043
 
 Log:
   Various fixes.
   
   - Replace hardcoded INDEX version. [1]
   - Fix a buffer overlap. [2]
   - Remove empty package when fetching fails and -K is used. [3]
   - Remove useless chmod2() after mkdtemp(3). [4]
   - Replace mkdir(1) call with mkdir(2). [5]
   - Get rid of some vsystem() calls.
   - Switch from lstat(2) to open(2) in fexists().
   - Try rename(2) in move_file() first.
   - Bump PKG_INSTALL_VERSION to 20100401.
   
   PR:		bin/145101 [1], bin/139492 [2], bin/144919 [3]
   		bin/144920 [4], bin/144921 [5]
   Submitted by:	gcooper [1,2,3,4,5]
 
 Modified:
   head/usr.sbin/pkg_install/add/futil.c
   head/usr.sbin/pkg_install/add/perform.c
   head/usr.sbin/pkg_install/delete/perform.c
   head/usr.sbin/pkg_install/lib/file.c
   head/usr.sbin/pkg_install/lib/lib.h
   head/usr.sbin/pkg_install/lib/match.c
   head/usr.sbin/pkg_install/lib/pen.c
   head/usr.sbin/pkg_install/lib/url.c
   head/usr.sbin/pkg_install/version/perform.c
 
 Modified: head/usr.sbin/pkg_install/add/futil.c
 ==============================================================================
 --- head/usr.sbin/pkg_install/add/futil.c	Thu Apr  1 13:27:27 2010	(r206042)
 +++ head/usr.sbin/pkg_install/add/futil.c	Thu Apr  1 14:27:29 2010	(r206043)
 @@ -50,7 +50,7 @@ make_hierarchy(char *dir)
  	    }
  	}
  	else {
 -	    if (vsystem("/bin/mkdir %s", dir)) {
 +	    if (mkdir(dir, 0777) < 0) {
  		if (cp2)
  		    *cp2 = '/';
  		return FAIL;
 
 Modified: head/usr.sbin/pkg_install/add/perform.c
 ==============================================================================
 --- head/usr.sbin/pkg_install/add/perform.c	Thu Apr  1 13:27:27 2010	(r206042)
 +++ head/usr.sbin/pkg_install/add/perform.c	Thu Apr  1 14:27:29 2010	(r206043)
 @@ -78,6 +78,7 @@ pkg_do(char *pkg)
      char pre_arg[FILENAME_MAX], post_arg[FILENAME_MAX];
      char *conflict[2];
      char **matched;
 +    int fd;
  
      conflictsfound = 0;
      code = 0;
 @@ -408,8 +409,10 @@ pkg_do(char *pkg)
  	goto bomb;
  
      /* Look for the requirements file */
 -    if (fexists(REQUIRE_FNAME)) {
 -	vsystem("/bin/chmod +x %s", REQUIRE_FNAME);	/* be sure */
 +    if ((fd = open(REQUIRE_FNAME, O_RDWR)) != -1) {
 +	fstat(fd, &sb);
 +	fchmod(fd, sb.st_mode | S_IXALL);	/* be sure, chmod a+x */
 +	close(fd);
  	if (Verbose)
  	    printf("Running requirements file first for %s..\n", Plist.name);
  	if (!Fake && vsystem("./%s %s INSTALL", REQUIRE_FNAME, Plist.name)) {
 @@ -441,8 +444,10 @@ pkg_do(char *pkg)
      }
  
      /* If we're really installing, and have an installation file, run it */
 -    if (!NoInstall && fexists(pre_script)) {
 -	vsystem("/bin/chmod +x %s", pre_script);	/* make sure */
 +    if (!NoInstall && (fd = open(pre_script, O_RDWR)) != -1) {
 +	fstat(fd, &sb);
 +	fchmod(fd, sb.st_mode | S_IXALL);	/* be sure, chmod a+x */
 +	close(fd);
  	if (Verbose)
  	    printf("Running pre-install for %s..\n", Plist.name);
  	if (!Fake && vsystem("./%s %s %s", pre_script, Plist.name, pre_arg)) {
 @@ -470,8 +475,10 @@ pkg_do(char *pkg)
      }
  
      /* Run the installation script one last time? */
 -    if (!NoInstall && fexists(post_script)) {
 -	vsystem("/bin/chmod +x %s", post_script);	/* make sure */
 +    if (!NoInstall && (fd = open(post_script, O_RDWR)) != -1) {
 +	fstat(fd, &sb);
 +	fchmod(fd, sb.st_mode | S_IXALL);	/* be sure, chmod a+x */
 +	close(fd);
  	if (Verbose)
  	    printf("Running post-install for %s..\n", Plist.name);
  	if (!Fake && vsystem("./%s %s %s", post_script, Plist.name, post_arg)) {
 @@ -503,7 +510,10 @@ pkg_do(char *pkg)
  	    goto success;	/* close enough for government work */
  	}
  	/* Make sure pkg_info can read the entry */
 -	vsystem("/bin/chmod a+rx %s", LogDir);
 +	fd = open(LogDir, O_RDWR);
 +	fstat(fd, &sb);
 +	fchmod(fd, sb.st_mode | S_IRALL | S_IXALL);	/* be sure, chmod a+rx */
 +	close(fd);
  	move_file(".", DESC_FNAME, LogDir);
  	move_file(".", COMMENT_FNAME, LogDir);
  	if (fexists(INSTALL_FNAME))
 
 Modified: head/usr.sbin/pkg_install/delete/perform.c
 ==============================================================================
 --- head/usr.sbin/pkg_install/delete/perform.c	Thu Apr  1 13:27:27 2010	(r206042)
 +++ head/usr.sbin/pkg_install/delete/perform.c	Thu Apr  1 14:27:29 2010	(r206043)
 @@ -132,6 +132,8 @@ pkg_do(char *pkg)
      const char *post_script, *pre_arg, *post_arg;
      struct reqr_by_entry *rb_entry;
      struct reqr_by_head *rb_list;
 +    int fd;
 +    struct stat sb;
  
      if (!pkg || !(len = strlen(pkg)))
  	return 1;
 @@ -221,10 +223,12 @@ pkg_do(char *pkg)
  
      setenv(PKG_PREFIX_VNAME, p->name, 1);
  
 -    if (fexists(REQUIRE_FNAME)) {
 +    if ((fd = open(REQUIRE_FNAME, O_RDWR)) != -1) {
 +	fstat(fd, &sb);
 +	fchmod(fd, sb.st_mode | S_IXALL);       /* be sure, chmod a+x */
 +	close(fd);
  	if (Verbose)
  	    printf("Executing 'require' script.\n");
 -	vsystem("/bin/chmod +x %s", REQUIRE_FNAME);	/* be sure */
  	if (vsystem("./%s %s DEINSTALL", REQUIRE_FNAME, pkg)) {
  	    warnx("package %s fails requirements %s", pkg,
  		   Force ? "" : "- not deleted");
 @@ -250,11 +254,13 @@ pkg_do(char *pkg)
  	post_script = pre_arg = post_arg = NULL;
      }
  
 -    if (!NoDeInstall && pre_script != NULL && fexists(pre_script)) {
 +    if (!NoDeInstall && pre_script != NULL && (fd = open(pre_script, O_RDWR)) != -1) {
  	if (Fake)
  	    printf("Would execute de-install script at this point.\n");
  	else {
 -	    vsystem("/bin/chmod +x %s", pre_script);	/* make sure */
 +	    fstat(fd, &sb);
 +	    fchmod(fd, sb.st_mode | S_IXALL);       /* be sure, chmod a+x */
 +	    close(fd);
  	    if (vsystem("./%s %s %s", pre_script, pkg, pre_arg)) {
  		warnx("deinstall script returned error status");
  		if (!Force)
 @@ -326,11 +332,13 @@ pkg_do(char *pkg)
   	return 1;
      }
  
 -    if (!NoDeInstall && post_script != NULL && fexists(post_script)) {
 +    if (!NoDeInstall && post_script != NULL && (fd = open(post_script, O_RDWR)) != -1) {
   	if (Fake)
   	    printf("Would execute post-deinstall script at this point.\n");
   	else {
 - 	    vsystem("/bin/chmod +x %s", post_script);	/* make sure */
 +	    fstat(fd, &sb);
 +	    fchmod(fd, sb.st_mode | S_IXALL);       /* be sure, chmod a+x */
 +	    close(fd);
   	    if (vsystem("./%s %s %s", post_script, pkg, post_arg)) {
   		warnx("post-deinstall script returned error status");
   		if (!Force)
 
 Modified: head/usr.sbin/pkg_install/lib/file.c
 ==============================================================================
 --- head/usr.sbin/pkg_install/lib/file.c	Thu Apr  1 13:27:27 2010	(r206042)
 +++ head/usr.sbin/pkg_install/lib/file.c	Thu Apr  1 14:27:29 2010	(r206043)
 @@ -31,10 +31,13 @@ __FBSDID("$FreeBSD$");
  Boolean
  fexists(const char *fname)
  {
 -    struct stat dummy;
 -    if (!lstat(fname, &dummy))
 -	return TRUE;
 -    return FALSE;
 +    int fd;
 +
 +    if ((fd = open(fname, O_RDONLY)) == -1)
 +	return FALSE;
 +
 +    close(fd);
 +    return TRUE;
  }
  
  /* Quick check to see if something is a directory or symlink to a directory */
 @@ -279,17 +282,23 @@ copy_file(const char *dir, const char *f
  }
  
  void
 -move_file(const char *dir, const char *fname, const char *to)
 +move_file(const char *dir, const char *fname, const char *tdir)
  {
 -    char cmd[FILENAME_MAX];
 +    char from[FILENAME_MAX];
 +    char to[FILENAME_MAX];
  
      if (fname[0] == '/')
 -	snprintf(cmd, FILENAME_MAX, "/bin/mv %s %s", fname, to);
 +	strncpy(from, fname, FILENAME_MAX);
      else
 -	snprintf(cmd, FILENAME_MAX, "/bin/mv %s/%s %s", dir, fname, to);
 -    if (vsystem(cmd)) {
 -	cleanup(0);
 -	errx(2, "%s: could not perform '%s'", __func__, cmd);
 +	snprintf(from, FILENAME_MAX, "%s/%s", dir, fname);
 +
 +    snprintf(to, FILENAME_MAX, "%s/%s", tdir, fname);
 +
 +    if (rename(from, to) == -1) {
 +        if (vsystem("/bin/mv %s %s", from, to)) {
 +	    cleanup(0);
 +	    errx(2, "%s: could not move '%s' to '%s'", __func__, from, to);
 +	}
      }
  }
  
 
 Modified: head/usr.sbin/pkg_install/lib/lib.h
 ==============================================================================
 --- head/usr.sbin/pkg_install/lib/lib.h	Thu Apr  1 13:27:27 2010	(r206042)
 +++ head/usr.sbin/pkg_install/lib/lib.h	Thu Apr  1 14:27:29 2010	(r206043)
 @@ -28,6 +28,7 @@
  #include <sys/file.h>
  #include <sys/stat.h>
  #include <sys/queue.h>
 +#include <sys/utsname.h>
  #include <ctype.h>
  #include <dirent.h>
  #include <stdarg.h>
 @@ -51,6 +52,11 @@
  #define YES		2
  #define NO		1
  
 +/* Some more stat macros. */
 +#define S_IRALL		0000444
 +#define S_IWALL		0000222
 +#define S_IXALL		0000111
 +
  /* Usually "rm", but often "echo" during debugging! */
  #define REMOVE_CMD	"/bin/rm"
  
 @@ -84,18 +90,6 @@
  #define DISPLAY_FNAME		"+DISPLAY"
  #define MTREE_FNAME		"+MTREE_DIRS"
  
 -#if defined(__FreeBSD_version) && __FreeBSD_version >= 900000
 -#define INDEX_FNAME		"INDEX-9"
 -#elif defined(__FreeBSD_version) && __FreeBSD_version >= 800000
 -#define INDEX_FNAME		"INDEX-8"
 -#elif defined(__FreeBSD_version) && __FreeBSD_version >= 700000
 -#define INDEX_FNAME		"INDEX-7"
 -#elif defined(__FreeBSD_version) && __FreeBSD_version >= 600000
 -#define INDEX_FNAME		"INDEX-6"
 -#else
 -#define INDEX_FNAME		"INDEX"
 -#endif
 -
  #define CMD_CHAR		'@'	/* prefix for extended PLIST cmd */
  
  /* The name of the "prefix" environment variable given to scripts */
 @@ -105,7 +99,7 @@
   * Version of the package tools - increase whenever you make a change
   * in the code that is not cosmetic only.
   */
 -#define PKG_INSTALL_VERSION	20100122
 +#define PKG_INSTALL_VERSION	20100401
  
  #define PKG_WRAPCONF_FNAME	"/var/db/pkg_install.conf"
  #define main(argc, argv)	real_main(argc, argv)
 
 Modified: head/usr.sbin/pkg_install/lib/match.c
 ==============================================================================
 --- head/usr.sbin/pkg_install/lib/match.c	Thu Apr  1 13:27:27 2010	(r206042)
 +++ head/usr.sbin/pkg_install/lib/match.c	Thu Apr  1 14:27:29 2010	(r206043)
 @@ -267,7 +267,7 @@ matchallbyorigin(const char **origins, i
  	 */
  	if (isemptydir(tmp))
  	    continue;
 -	snprintf(tmp, PATH_MAX, "%s/%s", tmp, CONTENTS_FNAME);
 +	strncat(tmp, "/" CONTENTS_FNAME, PATH_MAX);
  	fp = fopen(tmp, "r");
  	if (fp == NULL) {
  	    warnx("the package info for package '%s' is corrupt", installed[i]);
 
 Modified: head/usr.sbin/pkg_install/lib/pen.c
 ==============================================================================
 --- head/usr.sbin/pkg_install/lib/pen.c	Thu Apr  1 13:27:27 2010	(r206042)
 +++ head/usr.sbin/pkg_install/lib/pen.c	Thu Apr  1 14:27:29 2010	(r206043)
 @@ -113,10 +113,6 @@ make_playpen(char *pen, off_t sz)
  	cleanup(0);
  	errx(2, "%s: can't mktemp '%s'", __func__, pen);
      }
 -    if (chmod(pen, 0700) == FAIL) {
 -	cleanup(0);
 -	errx(2, "%s: can't mkdir '%s'", __func__, pen);
 -    }
  
      if (Verbose) {
  	if (sz) {
 
 Modified: head/usr.sbin/pkg_install/lib/url.c
 ==============================================================================
 --- head/usr.sbin/pkg_install/lib/url.c	Thu Apr  1 13:27:27 2010	(r206042)
 +++ head/usr.sbin/pkg_install/lib/url.c	Thu Apr  1 14:27:29 2010	(r206043)
 @@ -108,6 +108,10 @@ fileGetURL(const char *base, const char 
      if ((ftp = fetchGetURL(fname, Verbose ? "v" : NULL)) == NULL) {
  	printf("Error: Unable to get %s: %s\n",
  	       fname, fetchLastErrString);
 +	/* If the fetch fails, yank the package. */
 +	if (keep_package && unlink(pkg) < 0 && Verbose) {
 +	    warnx("failed to remove partially fetched package: %s", pkg);
 +	}
  	return NULL;
      }
  
 
 Modified: head/usr.sbin/pkg_install/version/perform.c
 ==============================================================================
 --- head/usr.sbin/pkg_install/version/perform.c	Thu Apr  1 13:27:27 2010	(r206042)
 +++ head/usr.sbin/pkg_install/version/perform.c	Thu Apr  1 14:27:29 2010	(r206043)
 @@ -35,28 +35,41 @@ static int pkg_do(char *);
  static void show_version(Package, const char *, const char *);
  
  /*
 - * This is the traditional pkg_perform, except that the argument is _not_
 - * a list of packages. It is the index file from the command line.
 + * This is the traditional pkg_perform, except that the argument is _not_ a
 + * list of packages. It is the index file from the command line.
   *
 - * We loop over the installed packages, matching them with the -s flag
 - * if needed and calling pkg_do(). Before hand we set up a few things,
 - * and after we tear them down...
 + * We loop over the installed packages, matching them with the -s flag if
 + * needed and calling pkg_do(). Beforehand we set up a few things, and after
 + * we tear them down...
 + *
 + * Returns 0 on success, non-zero on failure, corresponding to the number of
 + * failed attempts to access the INDEX.
   */
  int
  pkg_perform(char **indexarg)
  {
      char **pkgs, *pat[2], **patterns;
      struct index_entry *ie;
 -    int i, err_cnt = 0;
 +    int i, err_cnt = 0, rel_major_ver;
      int MatchType;
  
 +    struct utsname u;
 +
 +    if (uname(&u) == -1) {
 +	warn("%s(): failed to determine uname information", __func__);
 +	return 1;
 +    } else if ((rel_major_ver = (int) strtol(u.release, NULL, 10)) <= 0) {
 +
 +    }
 +
      /*
       * Try to find and open the INDEX. We only check IndexFile != NULL
       * later, if we actually need the INDEX.
       */
 -    if (*indexarg == NULL)
 -	snprintf(IndexPath, sizeof(IndexPath), "%s/%s", PORTS_DIR, INDEX_FNAME);
 -    else
 +    if (*indexarg == NULL) {
 +	snprintf(IndexPath, sizeof(IndexPath), "%s/INDEX-%d", PORTS_DIR,
 +	    rel_major_ver);
 +    } else
  	strlcpy(IndexPath, *indexarg, sizeof(IndexPath));
      if (isURL(IndexPath))
  	IndexFile = fetchGetURL(IndexPath, "");
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: flz 
State-Changed-When: Thu Apr 1 17:05:40 UTC 2010 
State-Changed-Why:  
Committed to HEAD. Will MFC in a few weeks. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=145101 
Responsible-Changed-From-To: freebsd-bugs->portmgr 
Responsible-Changed-By: flz 
Responsible-Changed-When: Thu Apr 1 17:18:54 UTC 2010 
Responsible-Changed-Why:  
pkg_install is maintained by portmgr. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=145101 
State-Changed-From-To: patched->closed 
State-Changed-By: bapt 
State-Changed-When: Mon May 21 13:07:52 UTC 2012 
State-Changed-Why:  
Committed and MFCed. Thanks! 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/145101: commit references a PR
Date: Mon, 21 May 2012 13:05:53 +0000 (UTC)

 Author: bapt
 Date: Mon May 21 13:05:41 2012
 New Revision: 235721
 URL: http://svn.freebsd.org/changeset/base/235721
 
 Log:
   MFC: r201226, r202844, r206043, r206132, r206133, r212029, r225610, r226708,
   r228670
   
   - Add support for UPDATING remote fetching.
   - Reorganize EXAMPLES section in pkg_updating(1).
   - Style fixes.
   - Replace hardcoded INDEX version. [1]
   - Fix a buffer overlap. [2]
   - Remove empty package when fetching fails and -K is used. [3]
   - Remove useless chmod2() after mkdtemp(3). [4]
   - Replace mkdir(1) call with mkdir(2). [5]
   - Get rid of some vsystem() calls.
   - Switch from lstat(2) to open(2) in fexists().
   - Try rename(2) in move_file() first.
   - Fix pkg_delete, check if the file we're trying to delete is a
   symlink before complaining that it doesn't exist. Typical case
   would be a leftover library symlink that's left over after the
   actual library has been removed.
   - Print the package name on deletion errors.
   - Staticify elide_root()
   - In usr.sbin/pkg_install/updating/main.c, use the size of the destination
   buffer as size argument to strlcpy(), not the length of the source
   
   PR:		bin/145101 [1], bin/139492 [2], bin/144919 [3]
   		bin/144920 [4], bin/144921 [5]
   Submitted by:	gcooper [1,2,3,4,5]
   Approved by:	des (mentor)
 
 Modified:
   stable/8/usr.sbin/pkg_install/add/futil.c
   stable/8/usr.sbin/pkg_install/add/main.c
   stable/8/usr.sbin/pkg_install/add/perform.c
   stable/8/usr.sbin/pkg_install/delete/perform.c
   stable/8/usr.sbin/pkg_install/lib/file.c
   stable/8/usr.sbin/pkg_install/lib/lib.h
   stable/8/usr.sbin/pkg_install/lib/match.c
   stable/8/usr.sbin/pkg_install/lib/pen.c
   stable/8/usr.sbin/pkg_install/lib/plist.c
   stable/8/usr.sbin/pkg_install/lib/url.c
   stable/8/usr.sbin/pkg_install/updating/main.c
   stable/8/usr.sbin/pkg_install/updating/pkg_updating.1
   stable/8/usr.sbin/pkg_install/version/perform.c
 Directory Properties:
   stable/8/usr.sbin/   (props changed)
   stable/8/usr.sbin/pkg_install/   (props changed)
   stable/8/usr.sbin/pkg_install/add/   (props changed)
   stable/8/usr.sbin/pkg_install/info/   (props changed)
 
 Modified: stable/8/usr.sbin/pkg_install/add/futil.c
 ==============================================================================
 --- stable/8/usr.sbin/pkg_install/add/futil.c	Mon May 21 08:10:42 2012	(r235720)
 +++ stable/8/usr.sbin/pkg_install/add/futil.c	Mon May 21 13:05:41 2012	(r235721)
 @@ -50,7 +50,7 @@ make_hierarchy(char *dir)
  	    }
  	}
  	else {
 -	    if (vsystem("/bin/mkdir %s", dir)) {
 +	    if (mkdir(dir, 0777) < 0) {
  		if (cp2)
  		    *cp2 = '/';
  		return FAIL;
 
 Modified: stable/8/usr.sbin/pkg_install/add/main.c
 ==============================================================================
 --- stable/8/usr.sbin/pkg_install/add/main.c	Mon May 21 08:10:42 2012	(r235720)
 +++ stable/8/usr.sbin/pkg_install/add/main.c	Mon May 21 13:05:41 2012	(r235721)
 @@ -22,7 +22,7 @@
  __FBSDID("$FreeBSD$");
  
  #include <sys/param.h>
 -#include <sys/utsname.h>
 +#include <sys/sysctl.h>
  #include <err.h>
  #include <getopt.h>
  
 @@ -306,7 +306,9 @@ getpackagesite(void)
  {
      int reldate, i;
      static char sitepath[MAXPATHLEN];
 -    struct utsname u;
 +    int archmib[] = { CTL_HW, HW_MACHINE_ARCH };
 +    char arch[64];
 +    size_t archlen = sizeof(arch);
  
      if (getenv("PACKAGESITE")) {
  	if (strlcpy(sitepath, getenv("PACKAGESITE"), sizeof(sitepath))
 @@ -329,8 +331,10 @@ getpackagesite(void)
  	>= sizeof(sitepath))
  	return NULL;
  
 -    uname(&u);
 -    if (strlcat(sitepath, u.machine, sizeof(sitepath)) >= sizeof(sitepath))
 +    if (sysctl(archmib, 2, arch, &archlen, NULL, 0) == -1)
 +	return NULL;
 +    arch[archlen-1] = 0;
 +    if (strlcat(sitepath, arch, sizeof(sitepath)) >= sizeof(sitepath))
  	return NULL;
  
      reldate = getosreldate();
 
 Modified: stable/8/usr.sbin/pkg_install/add/perform.c
 ==============================================================================
 --- stable/8/usr.sbin/pkg_install/add/perform.c	Mon May 21 08:10:42 2012	(r235720)
 +++ stable/8/usr.sbin/pkg_install/add/perform.c	Mon May 21 13:05:41 2012	(r235721)
 @@ -78,6 +78,7 @@ pkg_do(char *pkg)
      char pre_arg[FILENAME_MAX], post_arg[FILENAME_MAX];
      char *conflict[2];
      char **matched;
 +    int fd;
  
      conflictsfound = 0;
      code = 0;
 @@ -408,8 +409,10 @@ pkg_do(char *pkg)
  	goto bomb;
  
      /* Look for the requirements file */
 -    if (fexists(REQUIRE_FNAME)) {
 -	vsystem("/bin/chmod +x %s", REQUIRE_FNAME);	/* be sure */
 +    if ((fd = open(REQUIRE_FNAME, O_RDWR)) != -1) {
 +	fstat(fd, &sb);
 +	fchmod(fd, sb.st_mode | S_IXALL);	/* be sure, chmod a+x */
 +	close(fd);
  	if (Verbose)
  	    printf("Running requirements file first for %s..\n", Plist.name);
  	if (!Fake && vsystem("./%s %s INSTALL", REQUIRE_FNAME, Plist.name)) {
 @@ -441,8 +444,10 @@ pkg_do(char *pkg)
      }
  
      /* If we're really installing, and have an installation file, run it */
 -    if (!NoInstall && fexists(pre_script)) {
 -	vsystem("/bin/chmod +x %s", pre_script);	/* make sure */
 +    if (!NoInstall && (fd = open(pre_script, O_RDWR)) != -1) {
 +	fstat(fd, &sb);
 +	fchmod(fd, sb.st_mode | S_IXALL);	/* be sure, chmod a+x */
 +	close(fd);
  	if (Verbose)
  	    printf("Running pre-install for %s..\n", Plist.name);
  	if (!Fake && vsystem("./%s %s %s", pre_script, Plist.name, pre_arg)) {
 @@ -470,8 +475,10 @@ pkg_do(char *pkg)
      }
  
      /* Run the installation script one last time? */
 -    if (!NoInstall && fexists(post_script)) {
 -	vsystem("/bin/chmod +x %s", post_script);	/* make sure */
 +    if (!NoInstall && (fd = open(post_script, O_RDWR)) != -1) {
 +	fstat(fd, &sb);
 +	fchmod(fd, sb.st_mode | S_IXALL);	/* be sure, chmod a+x */
 +	close(fd);
  	if (Verbose)
  	    printf("Running post-install for %s..\n", Plist.name);
  	if (!Fake && vsystem("./%s %s %s", post_script, Plist.name, post_arg)) {
 @@ -503,7 +510,10 @@ pkg_do(char *pkg)
  	    goto success;	/* close enough for government work */
  	}
  	/* Make sure pkg_info can read the entry */
 -	vsystem("/bin/chmod a+rx %s", LogDir);
 +	fd = open(LogDir, O_RDWR);
 +	fstat(fd, &sb);
 +	fchmod(fd, sb.st_mode | S_IRALL | S_IXALL);	/* be sure, chmod a+rx */
 +	close(fd);
  	move_file(".", DESC_FNAME, LogDir);
  	move_file(".", COMMENT_FNAME, LogDir);
  	if (fexists(INSTALL_FNAME))
 
 Modified: stable/8/usr.sbin/pkg_install/delete/perform.c
 ==============================================================================
 --- stable/8/usr.sbin/pkg_install/delete/perform.c	Mon May 21 08:10:42 2012	(r235720)
 +++ stable/8/usr.sbin/pkg_install/delete/perform.c	Mon May 21 13:05:41 2012	(r235721)
 @@ -132,6 +132,8 @@ pkg_do(char *pkg)
      const char *post_script, *pre_arg, *post_arg;
      struct reqr_by_entry *rb_entry;
      struct reqr_by_head *rb_list;
 +    int fd;
 +    struct stat sb;
  
      if (!pkg || !(len = strlen(pkg)))
  	return 1;
 @@ -221,10 +223,12 @@ pkg_do(char *pkg)
  
      setenv(PKG_PREFIX_VNAME, p->name, 1);
  
 -    if (fexists(REQUIRE_FNAME)) {
 +    if ((fd = open(REQUIRE_FNAME, O_RDWR)) != -1) {
 +	fstat(fd, &sb);
 +	fchmod(fd, sb.st_mode | S_IXALL);       /* be sure, chmod a+x */
 +	close(fd);
  	if (Verbose)
  	    printf("Executing 'require' script.\n");
 -	vsystem("/bin/chmod +x %s", REQUIRE_FNAME);	/* be sure */
  	if (vsystem("./%s %s DEINSTALL", REQUIRE_FNAME, pkg)) {
  	    warnx("package %s fails requirements %s", pkg,
  		   Force ? "" : "- not deleted");
 @@ -250,11 +254,13 @@ pkg_do(char *pkg)
  	post_script = pre_arg = post_arg = NULL;
      }
  
 -    if (!NoDeInstall && pre_script != NULL && fexists(pre_script)) {
 +    if (!NoDeInstall && pre_script != NULL && (fd = open(pre_script, O_RDWR)) != -1) {
  	if (Fake)
  	    printf("Would execute de-install script at this point.\n");
  	else {
 -	    vsystem("/bin/chmod +x %s", pre_script);	/* make sure */
 +	    fstat(fd, &sb);
 +	    fchmod(fd, sb.st_mode | S_IXALL);       /* be sure, chmod a+x */
 +	    close(fd);
  	    if (vsystem("./%s %s %s", pre_script, pkg, pre_arg)) {
  		warnx("deinstall script returned error status");
  		if (!Force)
 @@ -326,11 +332,13 @@ pkg_do(char *pkg)
   	return 1;
      }
  
 -    if (!NoDeInstall && post_script != NULL && fexists(post_script)) {
 +    if (!NoDeInstall && post_script != NULL && (fd = open(post_script, O_RDWR)) != -1) {
   	if (Fake)
   	    printf("Would execute post-deinstall script at this point.\n");
   	else {
 - 	    vsystem("/bin/chmod +x %s", post_script);	/* make sure */
 +	    fstat(fd, &sb);
 +	    fchmod(fd, sb.st_mode | S_IXALL);       /* be sure, chmod a+x */
 +	    close(fd);
   	    if (vsystem("./%s %s %s", post_script, pkg, post_arg)) {
   		warnx("post-deinstall script returned error status");
   		if (!Force)
 
 Modified: stable/8/usr.sbin/pkg_install/lib/file.c
 ==============================================================================
 --- stable/8/usr.sbin/pkg_install/lib/file.c	Mon May 21 08:10:42 2012	(r235720)
 +++ stable/8/usr.sbin/pkg_install/lib/file.c	Mon May 21 13:05:41 2012	(r235721)
 @@ -31,10 +31,13 @@ __FBSDID("$FreeBSD$");
  Boolean
  fexists(const char *fname)
  {
 -    struct stat dummy;
 -    if (!lstat(fname, &dummy))
 -	return TRUE;
 -    return FALSE;
 +    int fd;
 +
 +    if ((fd = open(fname, O_RDONLY)) == -1)
 +	return FALSE;
 +
 +    close(fd);
 +    return TRUE;
  }
  
  /* Quick check to see if something is a directory or symlink to a directory */
 @@ -279,17 +282,23 @@ copy_file(const char *dir, const char *f
  }
  
  void
 -move_file(const char *dir, const char *fname, const char *to)
 +move_file(const char *dir, const char *fname, const char *tdir)
  {
 -    char cmd[FILENAME_MAX];
 +    char from[FILENAME_MAX];
 +    char to[FILENAME_MAX];
  
      if (fname[0] == '/')
 -	snprintf(cmd, FILENAME_MAX, "/bin/mv %s %s", fname, to);
 +	strncpy(from, fname, FILENAME_MAX);
      else
 -	snprintf(cmd, FILENAME_MAX, "/bin/mv %s/%s %s", dir, fname, to);
 -    if (vsystem(cmd)) {
 -	cleanup(0);
 -	errx(2, "%s: could not perform '%s'", __func__, cmd);
 +	snprintf(from, FILENAME_MAX, "%s/%s", dir, fname);
 +
 +    snprintf(to, FILENAME_MAX, "%s/%s", tdir, fname);
 +
 +    if (rename(from, to) == -1) {
 +        if (vsystem("/bin/mv %s %s", from, to)) {
 +	    cleanup(0);
 +	    errx(2, "%s: could not move '%s' to '%s'", __func__, from, to);
 +	}
      }
  }
  
 
 Modified: stable/8/usr.sbin/pkg_install/lib/lib.h
 ==============================================================================
 --- stable/8/usr.sbin/pkg_install/lib/lib.h	Mon May 21 08:10:42 2012	(r235720)
 +++ stable/8/usr.sbin/pkg_install/lib/lib.h	Mon May 21 13:05:41 2012	(r235721)
 @@ -28,6 +28,7 @@
  #include <sys/file.h>
  #include <sys/stat.h>
  #include <sys/queue.h>
 +#include <sys/utsname.h>
  #include <ctype.h>
  #include <dirent.h>
  #include <stdarg.h>
 @@ -51,6 +52,11 @@
  #define YES		2
  #define NO		1
  
 +/* Some more stat macros. */
 +#define S_IRALL		0000444
 +#define S_IWALL		0000222
 +#define S_IXALL		0000111
 +
  /* Usually "rm", but often "echo" during debugging! */
  #define REMOVE_CMD	"/bin/rm"
  
 @@ -84,18 +90,6 @@
  #define DISPLAY_FNAME		"+DISPLAY"
  #define MTREE_FNAME		"+MTREE_DIRS"
  
 -#if defined(__FreeBSD_version) && __FreeBSD_version >= 900000
 -#define INDEX_FNAME		"INDEX-9"
 -#elif defined(__FreeBSD_version) && __FreeBSD_version >= 800000
 -#define INDEX_FNAME		"INDEX-8"
 -#elif defined(__FreeBSD_version) && __FreeBSD_version >= 700000
 -#define INDEX_FNAME		"INDEX-7"
 -#elif defined(__FreeBSD_version) && __FreeBSD_version >= 600000
 -#define INDEX_FNAME		"INDEX-6"
 -#else
 -#define INDEX_FNAME		"INDEX"
 -#endif
 -
  #define CMD_CHAR		'@'	/* prefix for extended PLIST cmd */
  
  /* The name of the "prefix" environment variable given to scripts */
 @@ -105,7 +99,7 @@
   * Version of the package tools - increase whenever you make a change
   * in the code that is not cosmetic only.
   */
 -#define PKG_INSTALL_VERSION	20101002
 +#define PKG_INSTALL_VERSION	20100403
  
  #define PKG_WRAPCONF_FNAME	"/var/db/pkg_install.conf"
  #define main(argc, argv)	real_main(argc, argv)
 
 Modified: stable/8/usr.sbin/pkg_install/lib/match.c
 ==============================================================================
 --- stable/8/usr.sbin/pkg_install/lib/match.c	Mon May 21 08:10:42 2012	(r235720)
 +++ stable/8/usr.sbin/pkg_install/lib/match.c	Mon May 21 13:05:41 2012	(r235721)
 @@ -267,7 +267,7 @@ matchallbyorigin(const char **origins, i
  	 */
  	if (isemptydir(tmp))
  	    continue;
 -	snprintf(tmp, PATH_MAX, "%s/%s", tmp, CONTENTS_FNAME);
 +	strncat(tmp, "/" CONTENTS_FNAME, PATH_MAX);
  	fp = fopen(tmp, "r");
  	if (fp == NULL) {
  	    warnx("the package info for package '%s' is corrupt", installed[i]);
 
 Modified: stable/8/usr.sbin/pkg_install/lib/pen.c
 ==============================================================================
 --- stable/8/usr.sbin/pkg_install/lib/pen.c	Mon May 21 08:10:42 2012	(r235720)
 +++ stable/8/usr.sbin/pkg_install/lib/pen.c	Mon May 21 13:05:41 2012	(r235721)
 @@ -113,10 +113,6 @@ make_playpen(char *pen, off_t sz)
  	cleanup(0);
  	errx(2, "%s: can't mktemp '%s'", __func__, pen);
      }
 -    if (chmod(pen, 0700) == FAIL) {
 -	cleanup(0);
 -	errx(2, "%s: can't mkdir '%s'", __func__, pen);
 -    }
  
      if (Verbose) {
  	if (sz) {
 
 Modified: stable/8/usr.sbin/pkg_install/lib/plist.c
 ==============================================================================
 --- stable/8/usr.sbin/pkg_install/lib/plist.c	Mon May 21 08:10:42 2012	(r235720)
 +++ stable/8/usr.sbin/pkg_install/lib/plist.c	Mon May 21 13:05:41 2012	(r235721)
 @@ -551,7 +551,7 @@ delete_hierarchy(const char *dir, Boolea
      char *cp1, *cp2;
  
      cp1 = cp2 = strdup(dir);
 -    if (!fexists(dir)) {
 +    if (!fexists(dir) && !issymlink(dir)) {
  	if (!ign_err)
  	    warnx("%s '%s' doesn't exist",
  		isdir(dir) ? "directory" : "file", dir);
 
 Modified: stable/8/usr.sbin/pkg_install/lib/url.c
 ==============================================================================
 --- stable/8/usr.sbin/pkg_install/lib/url.c	Mon May 21 08:10:42 2012	(r235720)
 +++ stable/8/usr.sbin/pkg_install/lib/url.c	Mon May 21 13:05:41 2012	(r235721)
 @@ -108,6 +108,10 @@ fileGetURL(const char *base, const char 
      if ((ftp = fetchGetURL(fname, Verbose ? "v" : NULL)) == NULL) {
  	printf("Error: Unable to get %s: %s\n",
  	       fname, fetchLastErrString);
 +	/* If the fetch fails, yank the package. */
 +	if (keep_package && unlink(pkg) < 0 && Verbose) {
 +	    warnx("failed to remove partially fetched package: %s", pkg);
 +	}
  	return NULL;
      }
  
 
 Modified: stable/8/usr.sbin/pkg_install/updating/main.c
 ==============================================================================
 --- stable/8/usr.sbin/pkg_install/updating/main.c	Mon May 21 08:10:42 2012	(r235720)
 +++ stable/8/usr.sbin/pkg_install/updating/main.c	Mon May 21 13:05:41 2012	(r235721)
 @@ -10,7 +10,11 @@
  #include <sys/cdefs.h>
  __FBSDID("$FreeBSD$");
  
 +
 +#include <sys/param.h>
 +#include <stdio.h>
  #include <errno.h>
 +#include <fetch.h>
  #include <limits.h>
  #include <sysexits.h>
  #include <getopt.h>
 @@ -115,10 +119,10 @@ main(int argc, char *argv[])
  	if (argc != 0) {
  		pflag = 1;
  		while (*argv) {
 -			if((curr = (INSTALLEDPORT *)
 +			if ((curr = (INSTALLEDPORT *)
  				malloc(sizeof(INSTALLEDPORT))) == NULL)
  				(void)exit(EXIT_FAILURE);
 -			strlcpy (curr->name, *argv, strlen(*argv) + 1);
 +			strlcpy(curr->name, *argv, strlen(*argv) + 1);
  			curr->next = head;
  			head = curr;
  			(void)*argv++;
 @@ -131,22 +135,22 @@ main(int argc, char *argv[])
  	 */
  	if (pflag == 0) {
  		/* Open /var/db/pkg and search for all installed ports. */
 -		if((dir = opendir(pkgdbpath)) != NULL) {
 +		if ((dir = opendir(pkgdbpath)) != NULL) {
  			while ((pkgdbdir = readdir(dir)) != NULL) {
  				if (strcmp(pkgdbdir->d_name, ".") != 0 && 
 -					strcmp(pkgdbdir->d_name, "..") !=0) {
 +					strcmp(pkgdbdir->d_name, "..") != 0) {
  
  					/* Create path to +CONTENTS file for each installed port */
 -					n = strlcpy(tmp_file, pkgdbpath, strlen(pkgdbpath)+1);
 +					n = strlcpy(tmp_file, pkgdbpath, sizeof(tmp_file));
  					n = strlcpy(tmp_file + n, "/", sizeof(tmp_file) - n);
  					n = strlcat(tmp_file + n, pkgdbdir->d_name,
  						sizeof(tmp_file) - n);
 -					if(stat(tmp_file, &attribute) == -1) {
 +					if (stat(tmp_file, &attribute) == -1) {
  						fprintf(stderr, "can't open %s: %s\n",
  							tmp_file, strerror(errno));
  						return EXIT_FAILURE;
  					}
 -					if(attribute.st_mode & S_IFREG)
 +					if (attribute.st_mode & S_IFREG)
  						continue;
  					(void)strlcat(tmp_file + n, "/",
  						sizeof(tmp_file) - n);
 @@ -155,7 +159,7 @@ main(int argc, char *argv[])
  
  					/* Open +CONTENT file */
  					fd = fopen(tmp_file, "r");
 -					if(fd == NULL) {
 +					if (fd == NULL) {
  						fprintf(stderr, "warning: can't open %s: %s\n",
  						tmp_file, strerror(errno));
  						continue;
 @@ -165,25 +169,25 @@ main(int argc, char *argv[])
  					 * Parses +CONTENT for ORIGIN line and
  					 * put element into linked list.
  					 */
 -					while(fgets(originline, maxcharperline, fd) != NULL) {
 +					while (fgets(originline, maxcharperline, fd) != NULL) {
  						tmpline1 = strstr(originline, origin);
 -						if( tmpline1 != NULL ) {
 +						if (tmpline1 != NULL) {
  							/* Tmp variable to store port name. */
  							char *pname;
  							pname = strrchr(originline, (int)':');
  							pname++;
 -							if((curr = (INSTALLEDPORT *)
 +							if ((curr = (INSTALLEDPORT *)
  								malloc(sizeof(INSTALLEDPORT))) == NULL)
  								(void)exit(EXIT_FAILURE);
  							if (pname[strlen(pname) - 1] == '\n')
  								pname[strlen(pname) - 1] = '\0';
 -							strlcpy (curr->name, pname, strlen(pname)+1);
 +							strlcpy (curr->name, pname, sizeof(curr->name));
  							curr->next = head;
  							head = curr;
  						}
  					}
  					
 -					if(ferror(fd)) {
 +					if (ferror(fd)) {
  						fprintf(stderr, "error reading input\n");
  						exit(EX_IOERR);
  					}
 @@ -195,32 +199,41 @@ main(int argc, char *argv[])
  		} 
  	}
  
 -	/* Open UPDATING file */
 -	fd = fopen(updatingfile, "r");
 -	if(fd == NULL) {
 +	/* Fetch UPDATING file if needed and open file */
 +	if (isURL(updatingfile)) {
 +		if ((fd = fetchGetURL(updatingfile, "")) == NULL) {
 +			fprintf(stderr, "Error: Unable to get %s: %s\n",
 +				updatingfile, fetchLastErrString);
 +			exit(EX_UNAVAILABLE);
 +		}
 +	}
 +	else {
 +		fd = fopen(updatingfile, "r");
 +	}
 +	if (fd == NULL) {
  		fprintf(stderr, "can't open %s: %s\n",
 -		updatingfile, strerror(errno));
 +			updatingfile, strerror(errno));
  		exit(EX_UNAVAILABLE);
  	}
  
  	/* Parse opened UPDATING file. */
 -	while(fgets(updatingline, maxcharperline, fd) != NULL) {
 +	while (fgets(updatingline, maxcharperline, fd) != NULL) {
  		/* No entry is found so far */
  		if (found == 0) {
  			/* Search for AFFECTS line to parse the portname. */
  			tmpline1 = strstr(updatingline, affects);
  
 -			if( tmpline1 != NULL ) {
 +			if (tmpline1 != NULL) {
  				curr = head; 
 -				while(curr != NULL) {
 +				while (curr != NULL) {
  					tmpline2 = strstr(updatingline, curr->name);
 -					if( tmpline2 != NULL )
 +					if (tmpline2 != NULL)
  						break;
  					curr = curr->next;
  				}
 -				if( tmpline2 != NULL ) {
 +				if (tmpline2 != NULL) {
  					/* If -d is set, check if entry is newer than the date. */
 -					if ( (dflag == 1) && (strncmp(dateline, date, 8) < 0))
 +					if ((dflag == 1) && (strncmp(dateline, date, 8) < 0))
  						continue;
  					printf("%s", dateline);
  					printf("%s", updatingline);
 @@ -231,7 +244,7 @@ main(int argc, char *argv[])
  		/* Search for the end of an entry, if not found print the line. */
  		else {
  			tmpline1 = strstr(updatingline, end);
 -			if( tmpline1 == NULL )
 +			if (tmpline1 == NULL)
  				printf("%s", updatingline);
  			else {
  				linelength = strlen(updatingline);
 @@ -245,7 +258,7 @@ main(int argc, char *argv[])
  		dateline = strdup(updatingline);
  	}
  
 -	if(ferror(fd)) {
 +	if (ferror(fd)) {
  		fprintf(stderr, "error reading input\n");
  		exit(EX_IOERR);
  	}
 
 Modified: stable/8/usr.sbin/pkg_install/updating/pkg_updating.1
 ==============================================================================
 --- stable/8/usr.sbin/pkg_install/updating/pkg_updating.1	Mon May 21 08:10:42 2012	(r235720)
 +++ stable/8/usr.sbin/pkg_install/updating/pkg_updating.1	Mon May 21 13:05:41 2012	(r235721)
 @@ -45,26 +45,31 @@ Print help message.
  .El
  .Sh EXAMPLES
  .Bl -tag -width indent
 -.Dl pkg_updating
 +Shows all entries of all installed ports:
  .Pp
 -Shows all entries of all installed ports.
 +.Dl % pkg_updating
  .Pp
 -.Dl pkg_updating -d 20070101
 +Shows all entries of all installed ports since 2007-01-01:
  .Pp
 -Shows all entries of all installed ports since 2007-01-01.
 +.Dl % pkg_updating -d 20070101
  .Pp
 -.Dl pkg_updating apache mysql
 +Shows all entries for all apache and mysql ports:
  .Pp
 -Shows all entries for all apache and mysql ports.
 +.Dl % pkg_updating apache mysql
  .Pp
 -.Dl pkg_updating -d 20060101 apache
 +Shows all apache entries since 2006-01-01:
  .Pp
 -Shows all apache entries since 2006-01-01.
 -.Pp
 -.Dl pkg_updating -f /tmp/UPDATING
 +.Dl % pkg_updating -d 20060101 apache
  .Pp
  Defines that the UPDATING file is in /tmp and shows all entries of all
 -installed ports
 +installed ports:
 +.Pp
 +.Dl % pkg_updating -f /tmp/UPDATING
 +.Pp
 +Fetch UPDATING file from ftp mirror and show all entries of all
 +installed ports:
 +.Pp
 +.Dl % pkg_updating -f ftp://ftp.freebsd.org/pub/FreeBSD/ports/packages/UPDATING
  .Pp
  .El
  .Sh ENVIRONMENT
 
 Modified: stable/8/usr.sbin/pkg_install/version/perform.c
 ==============================================================================
 --- stable/8/usr.sbin/pkg_install/version/perform.c	Mon May 21 08:10:42 2012	(r235720)
 +++ stable/8/usr.sbin/pkg_install/version/perform.c	Mon May 21 13:05:41 2012	(r235721)
 @@ -35,28 +35,41 @@ static int pkg_do(char *);
  static void show_version(Package, const char *, const char *);
  
  /*
 - * This is the traditional pkg_perform, except that the argument is _not_
 - * a list of packages. It is the index file from the command line.
 + * This is the traditional pkg_perform, except that the argument is _not_ a
 + * list of packages. It is the index file from the command line.
   *
 - * We loop over the installed packages, matching them with the -s flag
 - * if needed and calling pkg_do(). Before hand we set up a few things,
 - * and after we tear them down...
 + * We loop over the installed packages, matching them with the -s flag if
 + * needed and calling pkg_do(). Beforehand we set up a few things, and after
 + * we tear them down...
 + *
 + * Returns 0 on success, non-zero on failure, corresponding to the number of
 + * failed attempts to access the INDEX.
   */
  int
  pkg_perform(char **indexarg)
  {
      char **pkgs, *pat[2], **patterns;
      struct index_entry *ie;
 -    int i, err_cnt = 0;
 +    int i, err_cnt = 0, rel_major_ver;
      int MatchType;
  
 +    struct utsname u;
 +
 +    if (uname(&u) == -1) {
 +	warn("%s(): failed to determine uname information", __func__);
 +	return 1;
 +    } else if ((rel_major_ver = (int) strtol(u.release, NULL, 10)) <= 0) {
 +
 +    }
 +
      /*
       * Try to find and open the INDEX. We only check IndexFile != NULL
       * later, if we actually need the INDEX.
       */
 -    if (*indexarg == NULL)
 -	snprintf(IndexPath, sizeof(IndexPath), "%s/%s", PORTS_DIR, INDEX_FNAME);
 -    else
 +    if (*indexarg == NULL) {
 +	snprintf(IndexPath, sizeof(IndexPath), "%s/INDEX-%d", PORTS_DIR,
 +	    rel_major_ver);
 +    } else
  	strlcpy(IndexPath, *indexarg, sizeof(IndexPath));
      if (isURL(IndexPath))
  	IndexFile = fetchGetURL(IndexPath, "");
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/145101: commit references a PR
Date: Mon, 21 May 2012 13:07:23 +0000 (UTC)

 Author: bapt
 Date: Mon May 21 13:07:12 2012
 New Revision: 235722
 URL: http://svn.freebsd.org/changeset/base/235722
 
 Log:
   MFC: r201226, r202844, r206043, r206132, r206133, r212029, r225610, r226708,
   r228670
   
   - Add support for UPDATING remote fetching.
   - Reorganize EXAMPLES section in pkg_updating(1).
   - Style fixes.
   - Replace hardcoded INDEX version. [1]
   - Fix a buffer overlap. [2]
   - Remove empty package when fetching fails and -K is used. [3]
   - Remove useless chmod2() after mkdtemp(3). [4]
   - Replace mkdir(1) call with mkdir(2). [5]
   - Get rid of some vsystem() calls.
   - Switch from lstat(2) to open(2) in fexists().
   - Try rename(2) in move_file() first.
   - Fix pkg_delete, check if the file we're trying to delete is a
   symlink before complaining that it doesn't exist. Typical case
   would be a leftover library symlink that's left over after the
   actual library has been removed.
   - Print the package name on deletion errors.
   - Staticify elide_root()
   - In usr.sbin/pkg_install/updating/main.c, use the size of the destination
   buffer as size argument to strlcpy(), not the length of the source
   
   PR:		bin/145101 [1], bin/139492 [2], bin/144919 [3]
   		bin/144920 [4], bin/144921 [5]
   Submitted by:	gcooper [1,2,3,4,5]
   Approved by:	des (mentor)
 
 Modified:
   stable/7/usr.sbin/pkg_install/add/futil.c
   stable/7/usr.sbin/pkg_install/add/main.c
   stable/7/usr.sbin/pkg_install/add/perform.c
   stable/7/usr.sbin/pkg_install/delete/perform.c
   stable/7/usr.sbin/pkg_install/info/show.c
   stable/7/usr.sbin/pkg_install/lib/file.c
   stable/7/usr.sbin/pkg_install/lib/lib.h
   stable/7/usr.sbin/pkg_install/lib/match.c
   stable/7/usr.sbin/pkg_install/lib/pen.c
   stable/7/usr.sbin/pkg_install/lib/plist.c
   stable/7/usr.sbin/pkg_install/lib/url.c
   stable/7/usr.sbin/pkg_install/updating/main.c
   stable/7/usr.sbin/pkg_install/updating/pkg_updating.1
   stable/7/usr.sbin/pkg_install/version/perform.c
 Directory Properties:
   stable/7/usr.sbin/   (props changed)
   stable/7/usr.sbin/pkg_install/   (props changed)
 
 Modified: stable/7/usr.sbin/pkg_install/add/futil.c
 ==============================================================================
 --- stable/7/usr.sbin/pkg_install/add/futil.c	Mon May 21 13:05:41 2012	(r235721)
 +++ stable/7/usr.sbin/pkg_install/add/futil.c	Mon May 21 13:07:12 2012	(r235722)
 @@ -50,7 +50,7 @@ make_hierarchy(char *dir)
  	    }
  	}
  	else {
 -	    if (vsystem("/bin/mkdir %s", dir)) {
 +	    if (mkdir(dir, 0777) < 0) {
  		if (cp2)
  		    *cp2 = '/';
  		return FAIL;
 
 Modified: stable/7/usr.sbin/pkg_install/add/main.c
 ==============================================================================
 --- stable/7/usr.sbin/pkg_install/add/main.c	Mon May 21 13:05:41 2012	(r235721)
 +++ stable/7/usr.sbin/pkg_install/add/main.c	Mon May 21 13:07:12 2012	(r235722)
 @@ -22,7 +22,7 @@
  __FBSDID("$FreeBSD$");
  
  #include <sys/param.h>
 -#include <sys/utsname.h>
 +#include <sys/sysctl.h>
  #include <err.h>
  #include <getopt.h>
  
 @@ -303,7 +303,9 @@ getpackagesite(void)
  {
      int reldate, i;
      static char sitepath[MAXPATHLEN];
 -    struct utsname u;
 +    int archmib[] = { CTL_HW, HW_MACHINE_ARCH };
 +    char arch[64];
 +    size_t archlen = sizeof(arch);
  
      if (getenv("PACKAGESITE")) {
  	if (strlcpy(sitepath, getenv("PACKAGESITE"), sizeof(sitepath))
 @@ -326,8 +328,10 @@ getpackagesite(void)
  	>= sizeof(sitepath))
  	return NULL;
  
 -    uname(&u);
 -    if (strlcat(sitepath, u.machine, sizeof(sitepath)) >= sizeof(sitepath))
 +    if (sysctl(archmib, 2, arch, &archlen, NULL, 0) == -1)
 +	return NULL;
 +    arch[archlen-1] = 0;
 +    if (strlcat(sitepath, arch, sizeof(sitepath)) >= sizeof(sitepath))
  	return NULL;
  
      reldate = getosreldate();
 
 Modified: stable/7/usr.sbin/pkg_install/add/perform.c
 ==============================================================================
 --- stable/7/usr.sbin/pkg_install/add/perform.c	Mon May 21 13:05:41 2012	(r235721)
 +++ stable/7/usr.sbin/pkg_install/add/perform.c	Mon May 21 13:07:12 2012	(r235722)
 @@ -78,6 +78,7 @@ pkg_do(char *pkg)
      char pre_arg[FILENAME_MAX], post_arg[FILENAME_MAX];
      char *conflict[2];
      char **matched;
 +    int fd;
  
      conflictsfound = 0;
      code = 0;
 @@ -408,8 +409,10 @@ pkg_do(char *pkg)
  	goto bomb;
  
      /* Look for the requirements file */
 -    if (fexists(REQUIRE_FNAME)) {
 -	vsystem("/bin/chmod +x %s", REQUIRE_FNAME);	/* be sure */
 +    if ((fd = open(REQUIRE_FNAME, O_RDWR)) != -1) {
 +	fstat(fd, &sb);
 +	fchmod(fd, sb.st_mode | S_IXALL);	/* be sure, chmod a+x */
 +	close(fd);
  	if (Verbose)
  	    printf("Running requirements file first for %s..\n", Plist.name);
  	if (!Fake && vsystem("./%s %s INSTALL", REQUIRE_FNAME, Plist.name)) {
 @@ -441,8 +444,10 @@ pkg_do(char *pkg)
      }
  
      /* If we're really installing, and have an installation file, run it */
 -    if (!NoInstall && fexists(pre_script)) {
 -	vsystem("/bin/chmod +x %s", pre_script);	/* make sure */
 +    if (!NoInstall && (fd = open(pre_script, O_RDWR)) != -1) {
 +	fstat(fd, &sb);
 +	fchmod(fd, sb.st_mode | S_IXALL);	/* be sure, chmod a+x */
 +	close(fd);
  	if (Verbose)
  	    printf("Running pre-install for %s..\n", Plist.name);
  	if (!Fake && vsystem("./%s %s %s", pre_script, Plist.name, pre_arg)) {
 @@ -470,8 +475,10 @@ pkg_do(char *pkg)
      }
  
      /* Run the installation script one last time? */
 -    if (!NoInstall && fexists(post_script)) {
 -	vsystem("/bin/chmod +x %s", post_script);	/* make sure */
 +    if (!NoInstall && (fd = open(post_script, O_RDWR)) != -1) {
 +	fstat(fd, &sb);
 +	fchmod(fd, sb.st_mode | S_IXALL);	/* be sure, chmod a+x */
 +	close(fd);
  	if (Verbose)
  	    printf("Running post-install for %s..\n", Plist.name);
  	if (!Fake && vsystem("./%s %s %s", post_script, Plist.name, post_arg)) {
 @@ -503,7 +510,10 @@ pkg_do(char *pkg)
  	    goto success;	/* close enough for government work */
  	}
  	/* Make sure pkg_info can read the entry */
 -	vsystem("/bin/chmod a+rx %s", LogDir);
 +	fd = open(LogDir, O_RDWR);
 +	fstat(fd, &sb);
 +	fchmod(fd, sb.st_mode | S_IRALL | S_IXALL);	/* be sure, chmod a+rx */
 +	close(fd);
  	move_file(".", DESC_FNAME, LogDir);
  	move_file(".", COMMENT_FNAME, LogDir);
  	if (fexists(INSTALL_FNAME))
 
 Modified: stable/7/usr.sbin/pkg_install/delete/perform.c
 ==============================================================================
 --- stable/7/usr.sbin/pkg_install/delete/perform.c	Mon May 21 13:05:41 2012	(r235721)
 +++ stable/7/usr.sbin/pkg_install/delete/perform.c	Mon May 21 13:07:12 2012	(r235722)
 @@ -132,6 +132,8 @@ pkg_do(char *pkg)
      const char *post_script, *pre_arg, *post_arg;
      struct reqr_by_entry *rb_entry;
      struct reqr_by_head *rb_list;
 +    int fd;
 +    struct stat sb;
  
      if (!pkg || !(len = strlen(pkg)))
  	return 1;
 @@ -221,10 +223,12 @@ pkg_do(char *pkg)
  
      setenv(PKG_PREFIX_VNAME, p->name, 1);
  
 -    if (fexists(REQUIRE_FNAME)) {
 +    if ((fd = open(REQUIRE_FNAME, O_RDWR)) != -1) {
 +	fstat(fd, &sb);
 +	fchmod(fd, sb.st_mode | S_IXALL);       /* be sure, chmod a+x */
 +	close(fd);
  	if (Verbose)
  	    printf("Executing 'require' script.\n");
 -	vsystem("/bin/chmod +x %s", REQUIRE_FNAME);	/* be sure */
  	if (vsystem("./%s %s DEINSTALL", REQUIRE_FNAME, pkg)) {
  	    warnx("package %s fails requirements %s", pkg,
  		   Force ? "" : "- not deleted");
 @@ -250,11 +254,13 @@ pkg_do(char *pkg)
  	post_script = pre_arg = post_arg = NULL;
      }
  
 -    if (!NoDeInstall && pre_script != NULL && fexists(pre_script)) {
 +    if (!NoDeInstall && pre_script != NULL && (fd = open(pre_script, O_RDWR)) != -1) {
  	if (Fake)
  	    printf("Would execute de-install script at this point.\n");
  	else {
 -	    vsystem("/bin/chmod +x %s", pre_script);	/* make sure */
 +	    fstat(fd, &sb);
 +	    fchmod(fd, sb.st_mode | S_IXALL);       /* be sure, chmod a+x */
 +	    close(fd);
  	    if (vsystem("./%s %s %s", pre_script, pkg, pre_arg)) {
  		warnx("deinstall script returned error status");
  		if (!Force)
 @@ -318,19 +324,21 @@ pkg_do(char *pkg)
       */
      if (delete_package(FALSE, CleanDirs, &Plist) == FAIL)
  	warnx(
 -	"couldn't entirely delete package (perhaps the packing list is\n"
 -	"incorrectly specified?)");
 +	"couldn't entirely delete package `%s'\n"
 +	"(perhaps the packing list is incorrectly specified?)", pkg);
  
      if (chdir(LogDir) == FAIL) {
   	warnx("unable to change directory to %s! deinstall failed", LogDir);
   	return 1;
      }
  
 -    if (!NoDeInstall && post_script != NULL && fexists(post_script)) {
 +    if (!NoDeInstall && post_script != NULL && (fd = open(post_script, O_RDWR)) != -1) {
   	if (Fake)
   	    printf("Would execute post-deinstall script at this point.\n");
   	else {
 - 	    vsystem("/bin/chmod +x %s", post_script);	/* make sure */
 +	    fstat(fd, &sb);
 +	    fchmod(fd, sb.st_mode | S_IXALL);       /* be sure, chmod a+x */
 +	    close(fd);
   	    if (vsystem("./%s %s %s", post_script, pkg, post_arg)) {
   		warnx("post-deinstall script returned error status");
   		if (!Force)
 
 Modified: stable/7/usr.sbin/pkg_install/info/show.c
 ==============================================================================
 --- stable/7/usr.sbin/pkg_install/info/show.c	Mon May 21 13:05:41 2012	(r235721)
 +++ stable/7/usr.sbin/pkg_install/info/show.c	Mon May 21 13:07:12 2012	(r235722)
 @@ -207,6 +207,14 @@ show_plist(const char *title, Package *p
      }
  }
  
 +static const char *
 +elide_root(const char *dir)
 +{
 +    if (strcmp(dir, "/") == 0)
 +	return "";
 +    return dir;
 +}
 +
  /* Show all files in the packing list (except ignored ones) */
  void
  show_files(const char *title, Package *plist)
 @@ -223,7 +231,7 @@ show_files(const char *title, Package *p
  	switch(p->type) {
  	case PLIST_FILE:
  	    if (!ign)
 -		printf("%s/%s\n", dir, p->name);
 +		printf("%s/%s\n", elide_root(dir), p->name);
  	    ign = FALSE;
  	    break;
  
 @@ -270,7 +278,7 @@ show_size(const char *title, Package *pl
  	switch (p->type) {
  	case PLIST_FILE:
  	    if (!ign) {
 -		snprintf(tmp, FILENAME_MAX, "%s/%s", dir, p->name);
 +		snprintf(tmp, FILENAME_MAX, "%s/%s", elide_root(dir), p->name);
  		if (!lstat(tmp, &sb)) {
  		    size += sb.st_size;
  		    if (Verbose)
 @@ -328,7 +336,7 @@ show_cksum(const char *title, Package *p
  	    else
  		dir = p->name;
  	} else if (p->type == PLIST_FILE) {
 -	    snprintf(tmp, FILENAME_MAX, "%s/%s", dir, p->name);
 +	    snprintf(tmp, FILENAME_MAX, "%s/%s", elide_root(dir), p->name);
  	    if (!fexists(tmp))
  		warnx("%s doesn't exist", tmp);
  	    else if (p->next && p->next->type == PLIST_COMMENT &&
 
 Modified: stable/7/usr.sbin/pkg_install/lib/file.c
 ==============================================================================
 --- stable/7/usr.sbin/pkg_install/lib/file.c	Mon May 21 13:05:41 2012	(r235721)
 +++ stable/7/usr.sbin/pkg_install/lib/file.c	Mon May 21 13:07:12 2012	(r235722)
 @@ -31,10 +31,13 @@ __FBSDID("$FreeBSD$");
  Boolean
  fexists(const char *fname)
  {
 -    struct stat dummy;
 -    if (!lstat(fname, &dummy))
 -	return TRUE;
 -    return FALSE;
 +    int fd;
 +
 +    if ((fd = open(fname, O_RDONLY)) == -1)
 +	return FALSE;
 +
 +    close(fd);
 +    return TRUE;
  }
  
  /* Quick check to see if something is a directory or symlink to a directory */
 @@ -279,17 +282,23 @@ copy_file(const char *dir, const char *f
  }
  
  void
 -move_file(const char *dir, const char *fname, const char *to)
 +move_file(const char *dir, const char *fname, const char *tdir)
  {
 -    char cmd[FILENAME_MAX];
 +    char from[FILENAME_MAX];
 +    char to[FILENAME_MAX];
  
      if (fname[0] == '/')
 -	snprintf(cmd, FILENAME_MAX, "/bin/mv %s %s", fname, to);
 +	strncpy(from, fname, FILENAME_MAX);
      else
 -	snprintf(cmd, FILENAME_MAX, "/bin/mv %s/%s %s", dir, fname, to);
 -    if (vsystem(cmd)) {
 -	cleanup(0);
 -	errx(2, "%s: could not perform '%s'", __func__, cmd);
 +	snprintf(from, FILENAME_MAX, "%s/%s", dir, fname);
 +
 +    snprintf(to, FILENAME_MAX, "%s/%s", tdir, fname);
 +
 +    if (rename(from, to) == -1) {
 +        if (vsystem("/bin/mv %s %s", from, to)) {
 +	    cleanup(0);
 +	    errx(2, "%s: could not move '%s' to '%s'", __func__, from, to);
 +	}
      }
  }
  
 
 Modified: stable/7/usr.sbin/pkg_install/lib/lib.h
 ==============================================================================
 --- stable/7/usr.sbin/pkg_install/lib/lib.h	Mon May 21 13:05:41 2012	(r235721)
 +++ stable/7/usr.sbin/pkg_install/lib/lib.h	Mon May 21 13:07:12 2012	(r235722)
 @@ -28,6 +28,7 @@
  #include <sys/file.h>
  #include <sys/stat.h>
  #include <sys/queue.h>
 +#include <sys/utsname.h>
  #include <ctype.h>
  #include <dirent.h>
  #include <stdarg.h>
 @@ -51,6 +52,11 @@
  #define YES		2
  #define NO		1
  
 +/* Some more stat macros. */
 +#define S_IRALL		0000444
 +#define S_IWALL		0000222
 +#define S_IXALL		0000111
 +
  /* Usually "rm", but often "echo" during debugging! */
  #define REMOVE_CMD	"/bin/rm"
  
 @@ -84,18 +90,6 @@
  #define DISPLAY_FNAME		"+DISPLAY"
  #define MTREE_FNAME		"+MTREE_DIRS"
  
 -#if defined(__FreeBSD_version) && __FreeBSD_version >= 900000
 -#define INDEX_FNAME		"INDEX-9"
 -#elif defined(__FreeBSD_version) && __FreeBSD_version >= 800000
 -#define INDEX_FNAME		"INDEX-8"
 -#elif defined(__FreeBSD_version) && __FreeBSD_version >= 700000
 -#define INDEX_FNAME		"INDEX-7"
 -#elif defined(__FreeBSD_version) && __FreeBSD_version >= 600000
 -#define INDEX_FNAME		"INDEX-6"
 -#else
 -#define INDEX_FNAME		"INDEX"
 -#endif
 -
  #define CMD_CHAR		'@'	/* prefix for extended PLIST cmd */
  
  /* The name of the "prefix" environment variable given to scripts */
 @@ -105,7 +99,7 @@
   * Version of the package tools - increase whenever you make a change
   * in the code that is not cosmetic only.
   */
 -#define PKG_INSTALL_VERSION	20090902
 +#define PKG_INSTALL_VERSION	20100403
  
  #define PKG_WRAPCONF_FNAME	"/var/db/pkg_install.conf"
  #define main(argc, argv)	real_main(argc, argv)
 
 Modified: stable/7/usr.sbin/pkg_install/lib/match.c
 ==============================================================================
 --- stable/7/usr.sbin/pkg_install/lib/match.c	Mon May 21 13:05:41 2012	(r235721)
 +++ stable/7/usr.sbin/pkg_install/lib/match.c	Mon May 21 13:07:12 2012	(r235722)
 @@ -267,7 +267,7 @@ matchallbyorigin(const char **origins, i
  	 */
  	if (isemptydir(tmp))
  	    continue;
 -	snprintf(tmp, PATH_MAX, "%s/%s", tmp, CONTENTS_FNAME);
 +	strncat(tmp, "/" CONTENTS_FNAME, PATH_MAX);
  	fp = fopen(tmp, "r");
  	if (fp == NULL) {
  	    warnx("the package info for package '%s' is corrupt", installed[i]);
 
 Modified: stable/7/usr.sbin/pkg_install/lib/pen.c
 ==============================================================================
 --- stable/7/usr.sbin/pkg_install/lib/pen.c	Mon May 21 13:05:41 2012	(r235721)
 +++ stable/7/usr.sbin/pkg_install/lib/pen.c	Mon May 21 13:07:12 2012	(r235722)
 @@ -113,10 +113,6 @@ make_playpen(char *pen, off_t sz)
  	cleanup(0);
  	errx(2, "%s: can't mktemp '%s'", __func__, pen);
      }
 -    if (chmod(pen, 0700) == FAIL) {
 -	cleanup(0);
 -	errx(2, "%s: can't mkdir '%s'", __func__, pen);
 -    }
  
      if (Verbose) {
  	if (sz) {
 
 Modified: stable/7/usr.sbin/pkg_install/lib/plist.c
 ==============================================================================
 --- stable/7/usr.sbin/pkg_install/lib/plist.c	Mon May 21 13:05:41 2012	(r235721)
 +++ stable/7/usr.sbin/pkg_install/lib/plist.c	Mon May 21 13:07:12 2012	(r235722)
 @@ -551,7 +551,7 @@ delete_hierarchy(const char *dir, Boolea
      char *cp1, *cp2;
  
      cp1 = cp2 = strdup(dir);
 -    if (!fexists(dir)) {
 +    if (!fexists(dir) && !issymlink(dir)) {
  	if (!ign_err)
  	    warnx("%s '%s' doesn't exist",
  		isdir(dir) ? "directory" : "file", dir);
 
 Modified: stable/7/usr.sbin/pkg_install/lib/url.c
 ==============================================================================
 --- stable/7/usr.sbin/pkg_install/lib/url.c	Mon May 21 13:05:41 2012	(r235721)
 +++ stable/7/usr.sbin/pkg_install/lib/url.c	Mon May 21 13:07:12 2012	(r235722)
 @@ -108,6 +108,10 @@ fileGetURL(const char *base, const char 
      if ((ftp = fetchGetURL(fname, Verbose ? "v" : NULL)) == NULL) {
  	printf("Error: Unable to get %s: %s\n",
  	       fname, fetchLastErrString);
 +	/* If the fetch fails, yank the package. */
 +	if (keep_package && unlink(pkg) < 0 && Verbose) {
 +	    warnx("failed to remove partially fetched package: %s", pkg);
 +	}
  	return NULL;
      }
  
 
 Modified: stable/7/usr.sbin/pkg_install/updating/main.c
 ==============================================================================
 --- stable/7/usr.sbin/pkg_install/updating/main.c	Mon May 21 13:05:41 2012	(r235721)
 +++ stable/7/usr.sbin/pkg_install/updating/main.c	Mon May 21 13:07:12 2012	(r235722)
 @@ -10,7 +10,11 @@
  #include <sys/cdefs.h>
  __FBSDID("$FreeBSD$");
  
 +
 +#include <sys/param.h>
 +#include <stdio.h>
  #include <errno.h>
 +#include <fetch.h>
  #include <limits.h>
  #include <sysexits.h>
  #include <getopt.h>
 @@ -115,10 +119,10 @@ main(int argc, char *argv[])
  	if (argc != 0) {
  		pflag = 1;
  		while (*argv) {
 -			if((curr = (INSTALLEDPORT *)
 +			if ((curr = (INSTALLEDPORT *)
  				malloc(sizeof(INSTALLEDPORT))) == NULL)
  				(void)exit(EXIT_FAILURE);
 -			strlcpy (curr->name, *argv, strlen(*argv) + 1);
 +			strlcpy(curr->name, *argv, strlen(*argv) + 1);
  			curr->next = head;
  			head = curr;
  			(void)*argv++;
 @@ -131,22 +135,22 @@ main(int argc, char *argv[])
  	 */
  	if (pflag == 0) {
  		/* Open /var/db/pkg and search for all installed ports. */
 -		if((dir = opendir(pkgdbpath)) != NULL) {
 +		if ((dir = opendir(pkgdbpath)) != NULL) {
  			while ((pkgdbdir = readdir(dir)) != NULL) {
  				if (strcmp(pkgdbdir->d_name, ".") != 0 && 
 -					strcmp(pkgdbdir->d_name, "..") !=0) {
 +					strcmp(pkgdbdir->d_name, "..") != 0) {
  
  					/* Create path to +CONTENTS file for each installed port */
 -					n = strlcpy(tmp_file, pkgdbpath, strlen(pkgdbpath)+1);
 +					n = strlcpy(tmp_file, pkgdbpath, sizeof(tmp_file));
  					n = strlcpy(tmp_file + n, "/", sizeof(tmp_file) - n);
  					n = strlcat(tmp_file + n, pkgdbdir->d_name,
  						sizeof(tmp_file) - n);
 -					if(stat(tmp_file, &attribute) == -1) {
 +					if (stat(tmp_file, &attribute) == -1) {
  						fprintf(stderr, "can't open %s: %s\n",
  							tmp_file, strerror(errno));
  						return EXIT_FAILURE;
  					}
 -					if(attribute.st_mode & S_IFREG)
 +					if (attribute.st_mode & S_IFREG)
  						continue;
  					(void)strlcat(tmp_file + n, "/",
  						sizeof(tmp_file) - n);
 @@ -155,7 +159,7 @@ main(int argc, char *argv[])
  
  					/* Open +CONTENT file */
  					fd = fopen(tmp_file, "r");
 -					if(fd == NULL) {
 +					if (fd == NULL) {
  						fprintf(stderr, "warning: can't open %s: %s\n",
  						tmp_file, strerror(errno));
  						continue;
 @@ -165,25 +169,25 @@ main(int argc, char *argv[])
  					 * Parses +CONTENT for ORIGIN line and
  					 * put element into linked list.
  					 */
 -					while(fgets(originline, maxcharperline, fd) != NULL) {
 +					while (fgets(originline, maxcharperline, fd) != NULL) {
  						tmpline1 = strstr(originline, origin);
 -						if( tmpline1 != NULL ) {
 +						if (tmpline1 != NULL) {
  							/* Tmp variable to store port name. */
  							char *pname;
  							pname = strrchr(originline, (int)':');
  							pname++;
 -							if((curr = (INSTALLEDPORT *)
 +							if ((curr = (INSTALLEDPORT *)
  								malloc(sizeof(INSTALLEDPORT))) == NULL)
  								(void)exit(EXIT_FAILURE);
  							if (pname[strlen(pname) - 1] == '\n')
  								pname[strlen(pname) - 1] = '\0';
 -							strlcpy (curr->name, pname, strlen(pname)+1);
 +							strlcpy (curr->name, pname, sizeof(curr->name));
  							curr->next = head;
  							head = curr;
  						}
  					}
  					
 -					if(ferror(fd)) {
 +					if (ferror(fd)) {
  						fprintf(stderr, "error reading input\n");
  						exit(EX_IOERR);
  					}
 @@ -195,32 +199,41 @@ main(int argc, char *argv[])
  		} 
  	}
  
 -	/* Open UPDATING file */
 -	fd = fopen(updatingfile, "r");
 -	if(fd == NULL) {
 +	/* Fetch UPDATING file if needed and open file */
 +	if (isURL(updatingfile)) {
 +		if ((fd = fetchGetURL(updatingfile, "")) == NULL) {
 +			fprintf(stderr, "Error: Unable to get %s: %s\n",
 +				updatingfile, fetchLastErrString);
 +			exit(EX_UNAVAILABLE);
 +		}
 +	}
 +	else {
 +		fd = fopen(updatingfile, "r");
 +	}
 +	if (fd == NULL) {
  		fprintf(stderr, "can't open %s: %s\n",
 -		updatingfile, strerror(errno));
 +			updatingfile, strerror(errno));
  		exit(EX_UNAVAILABLE);
  	}
  
  	/* Parse opened UPDATING file. */
 -	while(fgets(updatingline, maxcharperline, fd) != NULL) {
 +	while (fgets(updatingline, maxcharperline, fd) != NULL) {
  		/* No entry is found so far */
  		if (found == 0) {
  			/* Search for AFFECTS line to parse the portname. */
  			tmpline1 = strstr(updatingline, affects);
  
 -			if( tmpline1 != NULL ) {
 +			if (tmpline1 != NULL) {
  				curr = head; 
 -				while(curr != NULL) {
 +				while (curr != NULL) {
  					tmpline2 = strstr(updatingline, curr->name);
 -					if( tmpline2 != NULL )
 +					if (tmpline2 != NULL)
  						break;
  					curr = curr->next;
  				}
 -				if( tmpline2 != NULL ) {
 +				if (tmpline2 != NULL) {
  					/* If -d is set, check if entry is newer than the date. */
 -					if ( (dflag == 1) && (strncmp(dateline, date, 8) < 0))
 +					if ((dflag == 1) && (strncmp(dateline, date, 8) < 0))
  						continue;
  					printf("%s", dateline);
  					printf("%s", updatingline);
 @@ -231,7 +244,7 @@ main(int argc, char *argv[])
  		/* Search for the end of an entry, if not found print the line. */
  		else {
  			tmpline1 = strstr(updatingline, end);
 -			if( tmpline1 == NULL )
 +			if (tmpline1 == NULL)
  				printf("%s", updatingline);
  			else {
  				linelength = strlen(updatingline);
 @@ -245,7 +258,7 @@ main(int argc, char *argv[])
  		dateline = strdup(updatingline);
  	}
  
 -	if(ferror(fd)) {
 +	if (ferror(fd)) {
  		fprintf(stderr, "error reading input\n");
  		exit(EX_IOERR);
  	}
 
 Modified: stable/7/usr.sbin/pkg_install/updating/pkg_updating.1
 ==============================================================================
 --- stable/7/usr.sbin/pkg_install/updating/pkg_updating.1	Mon May 21 13:05:41 2012	(r235721)
 +++ stable/7/usr.sbin/pkg_install/updating/pkg_updating.1	Mon May 21 13:07:12 2012	(r235722)
 @@ -45,26 +45,31 @@ Print help message.
  .El
  .Sh EXAMPLES
  .Bl -tag -width indent
 -.Dl pkg_updating
 +Shows all entries of all installed ports:
  .Pp
 -Shows all entries of all installed ports.
 +.Dl % pkg_updating
  .Pp
 -.Dl pkg_updating -d 20070101
 +Shows all entries of all installed ports since 2007-01-01:
  .Pp
 -Shows all entries of all installed ports since 2007-01-01.
 +.Dl % pkg_updating -d 20070101
  .Pp
 -.Dl pkg_updating apache mysql
 +Shows all entries for all apache and mysql ports:
  .Pp
 -Shows all entries for all apache and mysql ports.
 +.Dl % pkg_updating apache mysql
  .Pp
 -.Dl pkg_updating -d 20060101 apache
 +Shows all apache entries since 2006-01-01:
  .Pp
 -Shows all apache entries since 2006-01-01.
 -.Pp
 -.Dl pkg_updating -f /tmp/UPDATING
 +.Dl % pkg_updating -d 20060101 apache
  .Pp
  Defines that the UPDATING file is in /tmp and shows all entries of all
 -installed ports
 +installed ports:
 +.Pp
 +.Dl % pkg_updating -f /tmp/UPDATING
 +.Pp
 +Fetch UPDATING file from ftp mirror and show all entries of all
 +installed ports:
 +.Pp
 +.Dl % pkg_updating -f ftp://ftp.freebsd.org/pub/FreeBSD/ports/packages/UPDATING
  .Pp
  .El
  .Sh ENVIRONMENT
 
 Modified: stable/7/usr.sbin/pkg_install/version/perform.c
 ==============================================================================
 --- stable/7/usr.sbin/pkg_install/version/perform.c	Mon May 21 13:05:41 2012	(r235721)
 +++ stable/7/usr.sbin/pkg_install/version/perform.c	Mon May 21 13:07:12 2012	(r235722)
 @@ -35,28 +35,41 @@ static int pkg_do(char *);
  static void show_version(Package, const char *, const char *);
  
  /*
 - * This is the traditional pkg_perform, except that the argument is _not_
 - * a list of packages. It is the index file from the command line.
 + * This is the traditional pkg_perform, except that the argument is _not_ a
 + * list of packages. It is the index file from the command line.
   *
 - * We loop over the installed packages, matching them with the -s flag
 - * if needed and calling pkg_do(). Before hand we set up a few things,
 - * and after we tear them down...
 + * We loop over the installed packages, matching them with the -s flag if
 + * needed and calling pkg_do(). Beforehand we set up a few things, and after
 + * we tear them down...
 + *
 + * Returns 0 on success, non-zero on failure, corresponding to the number of
 + * failed attempts to access the INDEX.
   */
  int
  pkg_perform(char **indexarg)
  {
      char **pkgs, *pat[2], **patterns;
      struct index_entry *ie;
 -    int i, err_cnt = 0;
 +    int i, err_cnt = 0, rel_major_ver;
      int MatchType;
  
 +    struct utsname u;
 +
 +    if (uname(&u) == -1) {
 +	warn("%s(): failed to determine uname information", __func__);
 +	return 1;
 +    } else if ((rel_major_ver = (int) strtol(u.release, NULL, 10)) <= 0) {
 +
 +    }
 +
      /*
       * Try to find and open the INDEX. We only check IndexFile != NULL
       * later, if we actually need the INDEX.
       */
 -    if (*indexarg == NULL)
 -	snprintf(IndexPath, sizeof(IndexPath), "%s/%s", PORTS_DIR, INDEX_FNAME);
 -    else
 +    if (*indexarg == NULL) {
 +	snprintf(IndexPath, sizeof(IndexPath), "%s/INDEX-%d", PORTS_DIR,
 +	    rel_major_ver);
 +    } else
  	strlcpy(IndexPath, *indexarg, sizeof(IndexPath));
      if (isURL(IndexPath))
  	IndexFile = fetchGetURL(IndexPath, "");
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
