From owner-freebsd-bugs@FreeBSD.ORG Sun Mar 28 10:00:12 2010 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4D7B1106567C for ; Sun, 28 Mar 2010 10:00:12 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 21C098FC15 for ; Sun, 28 Mar 2010 10:00:12 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id o2SA0BK1097711 for ; Sun, 28 Mar 2010 10:00:11 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id o2SA0BkY097709; Sun, 28 Mar 2010 10:00:11 GMT (envelope-from gnats) Resent-Date: Sun, 28 Mar 2010 10:00:11 GMT Resent-Message-Id: <201003281000.o2SA0BkY097709@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Garrett Cooper Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 16043106566B for ; 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 ; 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 ; 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 To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: bin/145101: [patch] pkg_version(1) - remove hardcoded INDEX filename versioning checks from lib.h and version/perform.c X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 28 Mar 2010 10:00:12 -0000 >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: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sun Mar 28 10:00:11 UTC 2010 >Closed-Date: >Last-Modified: >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 #include #include +#include #include #include #include @@ -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: >Unformatted: