bin/145101: [patch] pkg_version(1) - remove hardcoded INDEX filename versioning checks from lib.h and version/perform.c

Garrett Cooper gcooper at FreeBSD.org
Sun Mar 28 10:00:12 UTC 2010


>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 at 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:
>Unformatted:


More information about the freebsd-bugs mailing list