From nobody@FreeBSD.org  Sun Mar 21 01:25:37 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 D4E6E1065670
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 21 Mar 2010 01:25:37 +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 C46518FC1B
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 21 Mar 2010 01:25:37 +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 o2L1PbeY063857
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 21 Mar 2010 01:25:37 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o2L1Pah4063856;
	Sun, 21 Mar 2010 01:25:36 GMT
	(envelope-from nobody)
Message-Id: <201003210125.o2L1Pah4063856@www.freebsd.org>
Date: Sun, 21 Mar 2010 01:25:36 GMT
From: Garrett Cooper <yaneurabeya@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] [pkg_install] Remove partially downloaded file on fetch failure
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         144919
>Category:       bin
>Synopsis:       [patch] pkg_add(1): Remove partially downloaded file on fetch failure
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    portmgr
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Mar 21 01:30:01 UTC 2010
>Closed-Date:    Mon May 21 13:09:23 UTC 2012
>Last-Modified:  Sun Feb 03 22:28:21 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:
An annoyance I've had to deal with over the past week is that pkg_add -Kr
on DNS resolution failure retains dummy 0 byte packages instead of
deleting them on fetch failure.

This patch removes the file when the fetch fails.
>How-To-Repeat:
pkg_add -Kr a_package_that_does_not_exist.tbz
>Fix:
See patch.

Patch attached with submission follows:

==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/lib/url.c#1 - /scratch/freebsd/perforce/pkg_install-enhancements/usr.sbin/pkg_install/lib/url.c ====
@@ -108,6 +108,10 @@
     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;
     }
 


>Release-Note:
>Audit-Trail:

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/144919: commit references a PR
Date: Thu,  1 Apr 2010 14:27:40 +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:06:49 UTC 2010 
State-Changed-Why:  
Committed to HEAD. Will MFC in a few weeks. 

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

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

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/144919: commit references a PR
Date: Mon, 21 May 2012 13:05:54 +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/144919: commit references a PR
Date: Mon, 21 May 2012 13:07:24 +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:
