svn commit: r235722 - in stable/7/usr.sbin/pkg_install: add delete
info lib updating version
Baptiste Daroussin
bapt at FreeBSD.org
Mon May 21 13:07:13 UTC 2012
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, "");
More information about the svn-src-stable-7
mailing list