Date: Sun, 28 Mar 2010 03:07:15 -0700 From: Garrett Cooper <gcooper@FreeBSD.org> To: FreeBSD-gnats-submit@freebsd.org, freebsd-bugs@freebsd.org Subject: Re: bin/145101: [patch] pkg_version(1) - remove hardcoded INDEX filename versioning checks from lib.h and version/perform.c Message-ID: <364299f41003280307i3d5c1307na94a7a0028a902e0@mail.gmail.com> In-Reply-To: <201003281000.o2SA0BjB097677@freefall.freebsd.org> References: <201003280952.o2S9qBu6069448@www.freebsd.org> <201003281000.o2SA0BjB097677@freefall.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
[-- Attachment #1 --] 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=145101 > >>Category: bin >>Responsible: freebsd-bugs >>Synopsis: [patch] pkg_version(1) - remove hardcoded INDEX filename versioning checks from lib.h and version/perform.c >>Arrival-Date: 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 [-- Attachment #2 --] ==== //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,44 @@ 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) { + warnx("%s.%s: bad release version specified: %s", progname, __func__, + u.release); + return 1; + } + /* * 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, "");
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?364299f41003280307i3d5c1307na94a7a0028a902e0>
