bin/145100: [patch] pkg_add(1) - remove hardcoded versioning data
from add/main.c
Garrett Cooper
gcooper at FreeBSD.org
Sun Mar 28 08:50:04 UTC 2010
>Number: 145100
>Category: bin
>Synopsis: [patch] pkg_add(1) - remove hardcoded versioning data from add/main.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 08:50:02 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:
A keen observation made by bapt@ on #bsdports when submitting the patch for pkg_add, was the fact that the hardcoded versioning information in add/main.c was useless in lieu of (struct uname).release's data.
We'd be losing a small potential feature in the event that ABI breakage was to ever occur (say with the syscons utmp -> utmpx removal), but that shouldn't occur on a regular basis and should only occur on CURRENT (where packages should be built by the end user anyhow IMO..). Besides, if the admin knows enough about the system he / she should be capable enough of determining whether or not he / she should be using FreeBSD version X.Y.Z.
This eases the amount of flux with the folks in re@ and although it could have been circumvented via the environment variable - OSRELDATE - it's just simpler to do things this way (via UNAME_r).
If committed, this item will need an announcement on current and stable beforehand to ensure that all affected parties are aware of the change and update their infrastructures accordingly.
>How-To-Repeat:
>Fix:
Patch attached with submission follows:
==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/add/main.c#3 - /scratch/freebsd/perforce/pkg_install-enhancements/usr.sbin/pkg_install/add/main.c ====
@@ -52,51 +52,6 @@
char *progname = NULL;
-struct {
- int lowver; /* Lowest version number to match */
- int hiver; /* Highest version number to match */
- const char *directory; /* Directory it lives in */
-} releases[] = {
- { 410000, 410000, "/packages-4.1-release" },
- { 420000, 420000, "/packages-4.2-release" },
- { 430000, 430000, "/packages-4.3-release" },
- { 440000, 440000, "/packages-4.4-release" },
- { 450000, 450000, "/packages-4.5-release" },
- { 460000, 460001, "/packages-4.6-release" },
- { 460002, 460099, "/packages-4.6.2-release" },
- { 470000, 470099, "/packages-4.7-release" },
- { 480000, 480099, "/packages-4.8-release" },
- { 490000, 490099, "/packages-4.9-release" },
- { 491000, 491099, "/packages-4.10-release" },
- { 492000, 492099, "/packages-4.11-release" },
- { 500000, 500099, "/packages-5.0-release" },
- { 501000, 501099, "/packages-5.1-release" },
- { 502000, 502009, "/packages-5.2-release" },
- { 502010, 502099, "/packages-5.2.1-release" },
- { 503000, 503099, "/packages-5.3-release" },
- { 504000, 504099, "/packages-5.4-release" },
- { 505000, 505099, "/packages-5.5-release" },
- { 600000, 600099, "/packages-6.0-release" },
- { 601000, 601099, "/packages-6.1-release" },
- { 602000, 602099, "/packages-6.2-release" },
- { 603000, 603099, "/packages-6.3-release" },
- { 604000, 604099, "/packages-6.4-release" },
- { 700000, 700099, "/packages-7.0-release" },
- { 701000, 701099, "/packages-7.1-release" },
- { 702000, 702099, "/packages-7.2-release" },
- { 800000, 800499, "/packages-8.0-release" },
- { 300000, 399000, "/packages-3-stable" },
- { 400000, 499000, "/packages-4-stable" },
- { 502100, 502128, "/packages-5-current" },
- { 503100, 599000, "/packages-5-stable" },
- { 600100, 699000, "/packages-6-stable" },
- { 700100, 799000, "/packages-7-stable" },
- { 800500, 899000, "/packages-8-stable" },
- { 900000, 999000, "/packages-9-current" },
- { 0, 9999999, "/packages-current" },
- { 0, 0, NULL }
-};
-
static char *getpackagesite(void);
int getosreldate(void);
@@ -302,8 +257,8 @@
static char *
getpackagesite(void)
{
- int reldate, i;
static char sitepath[MAXPATHLEN];
+ size_t i;
struct utsname u;
if (getenv("PACKAGESITE")) {
@@ -327,20 +282,22 @@
>= sizeof(sitepath))
return NULL;
- uname(&u);
- if (strlcat(sitepath, u.machine, sizeof(sitepath)) >= sizeof(sitepath))
+ if (uname(&u) == -1) {
+ warn("%s.%s: could not determine uname information", progname,
+ __func__);
+ return NULL;
+ }
+ if (strlcat(sitepath, u.machine, sizeof(sitepath)) >= sizeof(sitepath) ||
+ strlcat(sitepath, "/", sizeof(sitepath)) >= sizeof(sitepath))
return NULL;
- reldate = getosreldate();
- for(i = 0; releases[i].directory != NULL; i++) {
- if (reldate >= releases[i].lowver && reldate <= releases[i].hiver) {
- if (strlcat(sitepath, releases[i].directory, sizeof(sitepath))
- >= sizeof(sitepath))
- return NULL;
- break;
- }
+ for (i = 0; u.release[i] != '\0'; i++) {
+ u.release[i] = tolower(u.release[i]);
}
+ if (strlcat(sitepath, u.release, sizeof(sitepath)) >= sizeof(sitepath))
+ return NULL;
+
if (strlcat(sitepath, "/Latest/", sizeof(sitepath)) >= sizeof(sitepath))
return NULL;
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list