From 3273d1bc8b5ad769448ba2944cb6cf47097f24f5 Mon Sep 17 00:00:00 2001 From: seb Date: Mon, 24 Mar 2003 21:44:45 +0000 Subject: [PATCH] Consistently check findmatchingname() return value for error condition. Among other this fixes 'pkg_info -e whateverpkg' exit status when /var/db/pkg is missing: it is now 1 and not 0. --- usr.sbin/pkg_install/admin/main.c | 6 +++--- usr.sbin/pkg_install/info/main.c | 6 +++--- usr.sbin/pkg_install/info/perform.c | 14 +++++++++----- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/usr.sbin/pkg_install/admin/main.c b/usr.sbin/pkg_install/admin/main.c index 00a3808eadce..797d8ce75f65 100644 --- a/usr.sbin/pkg_install/admin/main.c +++ b/usr.sbin/pkg_install/admin/main.c @@ -1,8 +1,8 @@ -/* $NetBSD: main.c,v 1.33 2003/03/15 20:49:25 agc Exp $ */ +/* $NetBSD: main.c,v 1.34 2003/03/24 21:44:45 seb Exp $ */ #include #ifndef lint -__RCSID("$NetBSD: main.c,v 1.33 2003/03/15 20:49:25 agc Exp $"); +__RCSID("$NetBSD: main.c,v 1.34 2003/03/24 21:44:45 seb Exp $"); #endif /* @@ -390,7 +390,7 @@ main(int argc, char *argv[]) while (*argv != NULL) { if (ispkgpattern(*argv)) { - if (findmatchingname(_pkgdb_getPKGDB_DIR(), *argv, checkpattern_fn, NULL) == 0) + if (findmatchingname(_pkgdb_getPKGDB_DIR(), *argv, checkpattern_fn, NULL) <= 0) errx(EXIT_FAILURE, "No matching pkg for %s.", *argv); } else { rc = chdir(*argv); diff --git a/usr.sbin/pkg_install/info/main.c b/usr.sbin/pkg_install/info/main.c index ae075ce96235..e59de1b9e76e 100644 --- a/usr.sbin/pkg_install/info/main.c +++ b/usr.sbin/pkg_install/info/main.c @@ -1,11 +1,11 @@ -/* $NetBSD: main.c,v 1.33 2003/01/05 21:49:56 agc Exp $ */ +/* $NetBSD: main.c,v 1.34 2003/03/24 21:44:45 seb Exp $ */ #include #ifndef lint #if 0 static char *rcsid = "from FreeBSD Id: main.c,v 1.14 1997/10/08 07:47:26 charnier Exp"; #else -__RCSID("$NetBSD: main.c,v 1.33 2003/01/05 21:49:56 agc Exp $"); +__RCSID("$NetBSD: main.c,v 1.34 2003/03/24 21:44:45 seb Exp $"); #endif #endif @@ -238,7 +238,7 @@ main(int argc, char **argv) errx(EXIT_FAILURE, "No matching pkg for %s.", *argv); } else { if (ispkgpattern(*argv)) { - if (findmatchingname(_pkgdb_getPKGDB_DIR(), *argv, add_to_list_fn, &pkgs) == 0) + if (findmatchingname(_pkgdb_getPKGDB_DIR(), *argv, add_to_list_fn, &pkgs) <= 0) errx(EXIT_FAILURE, "No matching pkg for %s.", *argv); } else { lpp = alloc_lpkg(*argv); diff --git a/usr.sbin/pkg_install/info/perform.c b/usr.sbin/pkg_install/info/perform.c index b0ec72de946f..d78e9cf2a7b1 100644 --- a/usr.sbin/pkg_install/info/perform.c +++ b/usr.sbin/pkg_install/info/perform.c @@ -1,11 +1,11 @@ -/* $NetBSD: perform.c,v 1.44 2003/03/15 20:49:26 agc Exp $ */ +/* $NetBSD: perform.c,v 1.45 2003/03/24 21:44:46 seb Exp $ */ #include #ifndef lint #if 0 static const char *rcsid = "from FreeBSD Id: perform.c,v 1.23 1997/10/13 15:03:53 jkh Exp"; #else -__RCSID("$NetBSD: perform.c,v 1.44 2003/03/15 20:49:26 agc Exp $"); +__RCSID("$NetBSD: perform.c,v 1.45 2003/03/24 21:44:46 seb Exp $"); #endif #endif @@ -130,7 +130,7 @@ pkg_do(char *pkg) char try[FILENAME_MAX]; snprintf(try, FILENAME_MAX, "%s-[0-9]*", pkg); if (findmatchingname(_pkgdb_getPKGDB_DIR(), try, - add_to_list_fn, &pkgs) != 0) { + add_to_list_fn, &pkgs) > 0) { return 0; /* we've just appended some names to the pkgs list, * they will be processed after this package. */ } @@ -278,7 +278,11 @@ CheckForPkg(char *pkgspec, char *dbdir) if (strpbrk(pkgspec, "<>[]?*{")) { /* expensive (pattern) match */ - return !findmatchingname(dbdir, pkgspec, foundpkg, dbdir); + error = findmatchingname(dbdir, pkgspec, foundpkg, dbdir); + if (error == -1) + return 1; + else + return !error; } /* simple match */ (void) snprintf(buf, sizeof(buf), "%s/%s", dbdir, pkgspec); @@ -291,7 +295,7 @@ CheckForPkg(char *pkgspec, char *dbdir) char try[FILENAME_MAX]; snprintf(try, FILENAME_MAX, "%s-[0-9]*", pkgspec); - if (findmatchingname(dbdir, try, foundpkg, dbdir) != 0) { + if (findmatchingname(dbdir, try, foundpkg, dbdir) > 0) { error = 0; } }