- pkg_info: flag -r: (show packages this packages depends on (documentation change))

- pkg_info: new flag -j (show the requirements script)

- pkg_info: fix verbose output when used on packages

- better handling of corrupt entries in /var/db/pkg

- differ between corrupt entires and packages not installed

- various small fixes

PR:		56989, 57016, 57029, 26468
This commit is contained in:
eik 2004-06-29 18:59:19 +00:00
parent ffbd0ede95
commit 7a7a88ae41
13 changed files with 110 additions and 81 deletions

View File

@ -85,7 +85,7 @@ rollback(const char *name, const char *home, PackingList start, PackingList stop
++(pos); \ ++(pos); \
} while (0) } while (0)
int static int
add_arg(char *buf, int len, const char *str) add_arg(char *buf, int len, const char *str)
{ {
int i = 0; int i = 0;

View File

@ -71,7 +71,7 @@ pkg_do(char *pkg)
int code; int code;
PackingList p; PackingList p;
struct stat sb; struct stat sb;
int inPlace, conflictsfound, i, errcode; int inPlace, conflictsfound, errcode;
/* support for separate pre/post install scripts */ /* support for separate pre/post install scripts */
int new_m = 0; int new_m = 0;
char pre_script[FILENAME_MAX] = INSTALL_FNAME; char pre_script[FILENAME_MAX] = INSTALL_FNAME;
@ -243,7 +243,7 @@ pkg_do(char *pkg)
* See if we're already registered either with the same name (the same * See if we're already registered either with the same name (the same
* version) or some other version with the same origin. * version) or some other version with the same origin.
*/ */
if ((isinstalledpkg(Plist.name) || if ((isinstalledpkg(Plist.name) > 0 ||
matchbyorigin(Plist.origin, NULL) != NULL) && !Force) { matchbyorigin(Plist.origin, NULL) != NULL) && !Force) {
warnx("package '%s' or its older version already installed", warnx("package '%s' or its older version already installed",
Plist.name); Plist.name);
@ -254,13 +254,14 @@ pkg_do(char *pkg)
/* Now check the packing list for conflicts */ /* Now check the packing list for conflicts */
for (p = Plist.head; p != NULL; p = p->next) { for (p = Plist.head; p != NULL; p = p->next) {
if (p->type == PLIST_CONFLICTS) { if (p->type == PLIST_CONFLICTS) {
int i;
conflict[0] = strdup(p->name); conflict[0] = strdup(p->name);
conflict[1] = NULL; conflict[1] = NULL;
matched = matchinstalled(MATCH_GLOB, conflict, &errcode); matched = matchinstalled(MATCH_GLOB, conflict, &errcode);
free(conflict[0]); free(conflict[0]);
if (errcode == 0 && matched != NULL) if (errcode == 0 && matched != NULL)
for (i = 0; matched[i] != NULL; i++) for (i = 0; matched[i] != NULL; i++)
if (isinstalledpkg(matched[i])) { if (isinstalledpkg(matched[i]) > 0) {
warnx("package '%s' conflicts with %s", Plist.name, warnx("package '%s' conflicts with %s", Plist.name,
matched[i]); matched[i]);
conflictsfound = 1; conflictsfound = 1;
@ -291,7 +292,7 @@ pkg_do(char *pkg)
printf(" with '%s' origin", deporigin); printf(" with '%s' origin", deporigin);
printf(".\n"); printf(".\n");
} }
if (!isinstalledpkg(p->name) && if (isinstalledpkg(p->name) <= 0 &&
!(deporigin != NULL && matchbyorigin(deporigin, NULL) != NULL)) { !(deporigin != NULL && matchbyorigin(deporigin, NULL) != NULL)) {
char path[FILENAME_MAX], *cp = NULL; char path[FILENAME_MAX], *cp = NULL;

View File

@ -125,6 +125,7 @@ pkg_do(char *pkg)
char *deporigin, **depnames, home[FILENAME_MAX]; char *deporigin, **depnames, home[FILENAME_MAX];
PackingList p; PackingList p;
int i, len; int i, len;
int isinstalled;
/* support for separate pre/post install scripts */ /* support for separate pre/post install scripts */
int new_m = 0; int new_m = 0;
const char *pre_script = DEINSTALL_FNAME; const char *pre_script = DEINSTALL_FNAME;
@ -141,9 +142,26 @@ pkg_do(char *pkg)
if (Plist.head) if (Plist.head)
free_plist(&Plist); free_plist(&Plist);
if (!isinstalledpkg(pkg)) { sprintf(LogDir, "%s/%s", LOG_DIR, pkg);
isinstalled = isinstalledpkg(pkg);
if (isinstalled == 0) {
warnx("no such package '%s' installed", pkg); warnx("no such package '%s' installed", pkg);
return 1; return 1;
} else if (isinstalled < 0) {
warnx("the package info for package '%s' is corrupt%s",
pkg, Force ? " (but I'll delete it anyway)" : " (use -f to force removal)");
if (!Force)
return 1;
if (!Fake) {
if (vsystem("%s -rf %s", REMOVE_CMD, LogDir)) {
warnx("couldn't remove log entry in %s, deinstall failed", LogDir);
} else {
warnx("couldn't completely deinstall package '%s',\n"
"only the log entry in %s was removed", pkg, LogDir);
}
}
return 0;
} }
if (!getcwd(home, FILENAME_MAX)) { if (!getcwd(home, FILENAME_MAX)) {
@ -151,8 +169,6 @@ pkg_do(char *pkg)
errx(2, "%s: unable to get current working directory!", __func__); errx(2, "%s: unable to get current working directory!", __func__);
} }
sprintf(LogDir, "%s/%s", LOG_DIR, pkg);
if (chdir(LogDir) == FAIL) { if (chdir(LogDir) == FAIL) {
warnx("unable to change directory to %s! deinstall failed", LogDir); warnx("unable to change directory to %s! deinstall failed", LogDir);
return 1; return 1;
@ -247,6 +263,30 @@ pkg_do(char *pkg)
} }
} }
for (p = Plist.head; p ; p = p->next) {
if (p->type != PLIST_PKGDEP)
continue;
deporigin = (p->next->type == PLIST_DEPORIGIN) ? p->next->name :
NULL;
if (Verbose) {
printf("Trying to remove dependency on package '%s'", p->name);
if (deporigin != NULL)
printf(" with '%s' origin", deporigin);
printf(".\n");
}
if (!Fake) {
depnames = (deporigin != NULL) ? matchbyorigin(deporigin, NULL) :
NULL;
if (depnames == NULL) {
depnames = alloca(sizeof(*depnames) * 2);
depnames[0] = p->name;
depnames[1] = NULL;
}
for (i = 0; depnames[i] != NULL; i++)
undepend(depnames[i], pkg);
}
}
if (chdir(home) == FAIL) { if (chdir(home) == FAIL) {
cleanup(0); cleanup(0);
errx(2, "%s: unable to return to working directory %s!", __func__, errx(2, "%s: unable to return to working directory %s!", __func__,
@ -293,30 +333,6 @@ pkg_do(char *pkg)
return 1; return 1;
} }
} }
for (p = Plist.head; p ; p = p->next) {
if (p->type != PLIST_PKGDEP)
continue;
deporigin = (p->next->type == PLIST_DEPORIGIN) ? p->next->name :
NULL;
if (Verbose) {
printf("Trying to remove dependency on package '%s'", p->name);
if (deporigin != NULL)
printf(" with '%s' origin", deporigin);
printf(".\n");
}
if (!Fake) {
depnames = (deporigin != NULL) ? matchbyorigin(deporigin, NULL) :
NULL;
if (depnames == NULL) {
depnames = alloca(sizeof(*depnames) * 2);
depnames[0] = p->name;
depnames[1] = NULL;
}
for (i = 0; depnames[i] != NULL; i++)
undepend(depnames[i], pkg);
}
}
return 0; return 0;
} }

View File

@ -26,7 +26,7 @@ __FBSDID("$FreeBSD$");
#include "info.h" #include "info.h"
#include <err.h> #include <err.h>
static char Options[] = "abcdDe:EfgGhiIkl:LmoO:pPqQrRst:vVW:xX"; static char Options[] = "abcdDe:EfgGhiIjkl:LmoO:pPqQrRst:vVW:xX";
int Flags = 0; int Flags = 0;
match_t MatchType = MATCH_GLOB; match_t MatchType = MATCH_GLOB;
@ -115,12 +115,16 @@ main(int argc, char **argv)
Flags |= SHOW_INSTALL; Flags |= SHOW_INSTALL;
break; break;
case 'j':
Flags |= SHOW_REQUIRE;
break;
case 'k': case 'k':
Flags |= SHOW_DEINSTALL; Flags |= SHOW_DEINSTALL;
break; break;
case 'r': case 'r':
Flags |= SHOW_REQUIRE; Flags |= SHOW_DEPEND;
break; break;
case 'R': case 'R':
@ -258,7 +262,7 @@ static void
usage() usage()
{ {
fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n", fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
"usage: pkg_info [-bcdDEfgGiIjLmopPqQrRsvVxX] [-e package] [-l prefix]", "usage: pkg_info [-bcdDEfgGiIjkLmopPqQrRsvVxX] [-e package] [-l prefix]",
" [-t template] -a | pkg-name ...", " [-t template] -a | pkg-name ...",
" pkg_info [-qQ] -W filename", " pkg_info [-qQ] -W filename",
" pkg_info [-qQ] -O origin", " pkg_info [-qQ] -O origin",

View File

@ -46,7 +46,7 @@ pkg_perform(char **pkgs)
if (Flags & SHOW_PKGNAME) { if (Flags & SHOW_PKGNAME) {
return matched_packages(pkgs); return matched_packages(pkgs);
} else if (CheckPkg) { } else if (CheckPkg) {
return isinstalledpkg(CheckPkg) == TRUE ? 0 : 1; return isinstalledpkg(CheckPkg) > 0 ? 0 : 1;
/* Not reached */ /* Not reached */
} else if (!TAILQ_EMPTY(whead)) { } else if (!TAILQ_EMPTY(whead)) {
return find_pkg(whead); return find_pkg(whead);
@ -92,7 +92,7 @@ pkg_do(char *pkg)
{ {
Boolean installed = FALSE, isTMP = FALSE; Boolean installed = FALSE, isTMP = FALSE;
char log_dir[FILENAME_MAX]; char log_dir[FILENAME_MAX];
char fname[FILENAME_MAX], extrlist[FILENAME_MAX]; char fname[FILENAME_MAX];
Package plist; Package plist;
FILE *fp; FILE *fp;
struct stat sb; struct stat sb;
@ -135,29 +135,19 @@ pkg_do(char *pkg)
goto bail; goto bail;
} }
Home = make_playpen(PlayPen, sb.st_size / 2); Home = make_playpen(PlayPen, sb.st_size / 2);
snprintf(extrlist, sizeof(extrlist), "--fast-read %s %s %s", if (unpack(fname, "'+*'")) {
CONTENTS_FNAME, COMMENT_FNAME, DESC_FNAME);
if (Flags & SHOW_DISPLAY)
snprintf(extrlist, sizeof(extrlist), "%s %s", extrlist,
DISPLAY_FNAME);
if (Flags & SHOW_INSTALL)
snprintf(extrlist, sizeof(extrlist), "%s %s %s", extrlist,
INSTALL_FNAME, POST_INSTALL_FNAME);
if (Flags & SHOW_DEINSTALL)
snprintf(extrlist, sizeof(extrlist), "%s %s %s", extrlist,
DEINSTALL_FNAME, POST_DEINSTALL_FNAME);
if (Flags & SHOW_MTREE)
snprintf(extrlist, sizeof(extrlist), "%s %s", extrlist,
MTREE_FNAME);
if (unpack(fname, extrlist)) {
warnx("error during unpacking, no info for '%s' available", pkg); warnx("error during unpacking, no info for '%s' available", pkg);
code = 1; code = 1;
goto bail; goto bail;
} }
} }
/* It's not an ininstalled package, try and find it among the installed */ /* It's not an uninstalled package, try and find it among the installed */
else { else {
if (!isinstalledpkg(pkg)) { int isinstalled = isinstalledpkg(pkg);
if (isinstalled < 0) {
warnx("the package info for package '%s' is corrupt", pkg);
return 1;
} else if (isinstalled == 0) {
warnx("can't find package '%s' installed or in a file!", pkg); warnx("can't find package '%s' installed or in a file!", pkg);
return 1; return 1;
} }
@ -199,7 +189,7 @@ pkg_do(char *pkg)
printf("%s%s:", InfoPrefix, pkg); printf("%s%s:", InfoPrefix, pkg);
if (Flags & SHOW_COMMENT) if (Flags & SHOW_COMMENT)
show_file("Comment:\n", COMMENT_FNAME); show_file("Comment:\n", COMMENT_FNAME);
if (Flags & SHOW_REQUIRE) if (Flags & SHOW_DEPEND)
show_plist("Depends on:\n", &plist, PLIST_PKGDEP, FALSE); show_plist("Depends on:\n", &plist, PLIST_PKGDEP, FALSE);
if ((Flags & SHOW_REQBY) && !isemptyfile(REQUIRED_BY_FNAME)) if ((Flags & SHOW_REQBY) && !isemptyfile(REQUIRED_BY_FNAME))
show_file("Required by:\n", REQUIRED_BY_FNAME); show_file("Required by:\n", REQUIRED_BY_FNAME);
@ -209,6 +199,8 @@ pkg_do(char *pkg)
show_file("Install notice:\n", DISPLAY_FNAME); show_file("Install notice:\n", DISPLAY_FNAME);
if (Flags & SHOW_PLIST) if (Flags & SHOW_PLIST)
show_plist("Packing list:\n", &plist, (plist_t)0, TRUE); show_plist("Packing list:\n", &plist, (plist_t)0, TRUE);
if (Flags & SHOW_REQUIRE && fexists(REQUIRE_FNAME))
show_file("Requirements script:\n", REQUIRE_FNAME);
if ((Flags & SHOW_INSTALL) && fexists(INSTALL_FNAME)) if ((Flags & SHOW_INSTALL) && fexists(INSTALL_FNAME))
show_file("Install script:\n", INSTALL_FNAME); show_file("Install script:\n", INSTALL_FNAME);
if ((Flags & SHOW_INSTALL) && fexists(POST_INSTALL_FNAME)) if ((Flags & SHOW_INSTALL) && fexists(POST_INSTALL_FNAME))

View File

@ -17,7 +17,7 @@
.\" @(#)pkg_info.1 .\" @(#)pkg_info.1
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd February 8, 2001 .Dd June 29, 2004
.Dt PKG_INFO 1 .Dt PKG_INFO 1
.Os .Os
.Sh NAME .Sh NAME
@ -25,7 +25,7 @@
.Nd a utility for displaying information on software packages .Nd a utility for displaying information on software packages
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl bcdDEfgGiIkLmopPqQrRsvVxX .Op Fl bcdDEfgGijIkLmopPqQrRsvVxX
.Op Fl e Ar package .Op Fl e Ar package
.Op Fl l Ar prefix .Op Fl l Ar prefix
.Op Fl t Ar template .Op Fl t Ar template
@ -99,10 +99,12 @@ Show the install script (if any) for each package.
.It Fl I .It Fl I
Show an index line for each package. This option takes Show an index line for each package. This option takes
precedence over all other package formatting options. precedence over all other package formatting options.
.It Fl j
Show the requirements script (if any) for each package.
.It Fl k .It Fl k
Show the de-install script (if any) for each package. Show the de-install script (if any) for each package.
.It Fl r .It Fl r
Show the requirements script (if any) for each package. Show the list of packages on which each package depends.
.It Fl R .It Fl R
Show the list of installed packages which require each package. Show the list of installed packages which require each package.
.It Fl m .It Fl m

View File

@ -97,7 +97,7 @@ chkifdepends(const char *pkgname1, const char *pkgname2)
errcode = 0; errcode = 0;
/* Check that pkgname2 is actually installed */ /* Check that pkgname2 is actually installed */
if (!isinstalledpkg(pkgname2)) if (isinstalledpkg(pkgname2) <= 0)
goto exit; goto exit;
errcode = requiredby(pkgname2, &rb_list, FALSE, TRUE); errcode = requiredby(pkgname2, &rb_list, FALSE, TRUE);
@ -153,7 +153,7 @@ requiredby(const char *pkgname, struct reqr_by_head **list, Boolean strict, Bool
free(rb_entry); free(rb_entry);
} }
if (!isinstalledpkg(pkgname)) { if (isinstalledpkg(pkgname) <= 0) {
if (strict == TRUE) if (strict == TRUE)
warnx("no such package '%s' installed", pkgname); warnx("no such package '%s' installed", pkgname);
return -1; return -1;
@ -173,7 +173,7 @@ requiredby(const char *pkgname, struct reqr_by_head **list, Boolean strict, Bool
while (fgets(fbuf, sizeof(fbuf), fp) != NULL) { while (fgets(fbuf, sizeof(fbuf), fp) != NULL) {
if (fbuf[strlen(fbuf) - 1] == '\n') if (fbuf[strlen(fbuf) - 1] == '\n')
fbuf[strlen(fbuf) - 1] = '\0'; fbuf[strlen(fbuf) - 1] = '\0';
if (filter == TRUE && !isinstalledpkg(fbuf)) { if (filter == TRUE && isinstalledpkg(fbuf) <= 0) {
if (strict == TRUE) if (strict == TRUE)
warnx("package '%s' is recorded in the '%s' but isn't " warnx("package '%s' is recorded in the '%s' but isn't "
"actually installed", fbuf, fname); "actually installed", fbuf, fname);

View File

@ -126,7 +126,8 @@ isURL(const char *fname)
return FALSE; return FALSE;
while (isspace(*fname)) while (isspace(*fname))
++fname; ++fname;
if (!strncmp(fname, "ftp://", 6) || !strncmp(fname, "http://", 7)) if (!strncmp(fname, "ftp://", 6) || !strncmp(fname, "http://", 7) ||
!strncmp(fname, "https://", 8) || !strncmp(fname, "file://", 7))
return TRUE; return TRUE;
return FALSE; return FALSE;
} }
@ -328,7 +329,8 @@ copy_hierarchy(const char *dir, const char *fname, Boolean to)
int int
unpack(const char *pkg, const char *flist) unpack(const char *pkg, const char *flist)
{ {
char *comp, suff[80], *cp; const char *comp, *cp;
char suff[80];
comp = ""; comp = "";
/* /*

View File

@ -122,8 +122,8 @@ typedef struct _plist *PackingList;
struct _pack { struct _pack {
struct _plist *head, *tail; struct _plist *head, *tail;
char *name; const char *name;
char *origin; const char *origin;
int fmtver_maj, fmtver_mnr; int fmtver_maj, fmtver_mnr;
}; };
typedef struct _pack Package; typedef struct _pack Package;

View File

@ -307,8 +307,9 @@ matchbyorigin(const char *origin, int *retval)
} }
/* /*
* Return TRUE if the specified package is installed, *
* or FALSE otherwise. * Return 1 if the specified package is installed,
* 0 if not, and -1 if an error occured.
*/ */
int int
isinstalledpkg(const char *name) isinstalledpkg(const char *name)
@ -318,13 +319,13 @@ isinstalledpkg(const char *name)
snprintf(buf, sizeof(buf), "%s/%s", LOG_DIR, name); snprintf(buf, sizeof(buf), "%s/%s", LOG_DIR, name);
if (!isdir(buf) || access(buf, R_OK) == FAIL) if (!isdir(buf) || access(buf, R_OK) == FAIL)
return FALSE; return 0;
snprintf(buf2, sizeof(buf2), "%s/%s", buf, CONTENTS_FNAME); snprintf(buf2, sizeof(buf2), "%s/%s", buf, CONTENTS_FNAME);
if (!isfile(buf2) || access(buf2, R_OK) == FAIL) if (!isfile(buf2) || access(buf2, R_OK) == FAIL)
return FALSE; return -1;
return TRUE; return 1;
} }
/* /*

View File

@ -7,9 +7,13 @@ MLINKS= pkg_sign.1 pkg_check.1
SRCS= main.c check.c common.c gzip.c pgp_check.c pgp_sign.c \ SRCS= main.c check.c common.c gzip.c pgp_check.c pgp_sign.c \
sha1.c sign.c stand.c x509.c sha1.c sign.c stand.c x509.c
CFLAGS+= ${DEBUG} -I${.CURDIR}/../lib
WARNS?= 0
DISTRIBUTION= crypto DISTRIBUTION= crypto
DPADD= ${LIBINSTALL} ${LIBCRYPTO} DPADD= ${LIBINSTALL} ${LIBMD} ${LIBCRYPTO}
LDADD= ${LIBINSTALL} -lcrypto LDADD= ${LIBINSTALL} -lmd -lcrypto
.include <bsd.prog.mk> .include <bsd.prog.mk>

View File

@ -34,9 +34,10 @@ __FBSDID("$FreeBSD$");
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <stdio.h> #include <stdio.h>
#include <assert.h> #include <assert.h>
#include <openssl/sha.h> #include <sha.h>
#include "stand.h" #include "stand.h"
#include "gzip.h" #include "gzip.h"
#include "extern.h" #include "extern.h"
@ -66,9 +67,9 @@ sha1_build_checksum(result, n)
{ {
size_t length; size_t length;
sprintf(result, "SHA1 (%s) = ", n->id); snprintf(result, BUFSIZE-2*SHA_DIGEST_LENGTH-1, SHA1_TEMPLATE, n->id);
length = strlen(result); length = strlen(result);
SHA1_Final(result + length, &n->context); SHA1_End(&n->context, result + length);
strcat(result, "\n"); strcat(result, "\n");
free(n); free(n);
return length; return length;
@ -167,7 +168,7 @@ retrieve_sha1_marker(filename, sign, userid)
FILE *f; FILE *f;
char buffer[1024]; char buffer[1024];
char result[BUFSIZE]; char result[BUFSIZE];
ssize_t length; ssize_t length = -1;
struct sha1_checker *checker; struct sha1_checker *checker;
struct signature *old; struct signature *old;
@ -181,8 +182,13 @@ retrieve_sha1_marker(filename, sign, userid)
n = malloc(sizeof *n); n = malloc(sizeof *n);
if (n == NULL) if (n == NULL)
return 0; return 0;
n->data = (char *)userid; n->length = strlen(userid)+1;
n->length = strlen(n->data)+1; n->data = malloc(n->length);
if (n->data == NULL) {
free(n);
return 0;
}
memcpy(n->data, userid, n->length);
n->type = TAG_SHA1; n->type = TAG_SHA1;
memcpy(n->tag, sha1tag, sizeof sha1tag); memcpy(n->tag, sha1tag, sizeof sha1tag);
sign_fill_tag(n); sign_fill_tag(n);
@ -208,8 +214,9 @@ retrieve_sha1_marker(filename, sign, userid)
* Calculate the SHA1 of the remaining data and write it to stderr. * Calculate the SHA1 of the remaining data and write it to stderr.
*/ */
checker = new_sha1_checker(&h, *sign, NULL, NULL, filename); checker = new_sha1_checker(&h, *sign, NULL, NULL, filename);
while ((length = fread(buffer, 1, sizeof buffer, f)) > 0) if (checker)
sha1_add(checker, buffer, length); while ((length = fread(buffer, 1, sizeof buffer, f)) > 0)
sha1_add(checker, buffer, length);
if (fclose(f) != 0 || length == -1) { if (fclose(f) != 0 || length == -1) {
warn("Problem checksumming %s", filename); warn("Problem checksumming %s", filename);
*sign = n->next; *sign = n->next;

View File

@ -132,7 +132,7 @@ pkg_do(char *pkg)
snprintf(tmp, PATH_MAX, "%s/%s/%s", LOG_DIR, pkg, CONTENTS_FNAME); snprintf(tmp, PATH_MAX, "%s/%s/%s", LOG_DIR, pkg, CONTENTS_FNAME);
fp = fopen(tmp, "r"); fp = fopen(tmp, "r");
if (!fp) { if (!fp) {
warnx("unable to open %s file", CONTENTS_FNAME); warnx("the package info for package '%s' is corrupt", pkg);
return 1; return 1;
} }
read_plist(&plist, fp); read_plist(&plist, fp);