diff options
author | jschauma <jschauma@pkgsrc.org> | 2003-01-06 04:34:15 +0000 |
---|---|---|
committer | jschauma <jschauma@pkgsrc.org> | 2003-01-06 04:34:15 +0000 |
commit | 588eb561c11d1e286eb9f53adb95d0835ba3ecd0 (patch) | |
tree | 47922a126964577f4de990bbc9ed7e6b489cf026 /pkgtools | |
parent | 0e29f29c69028a0b688eeb13d50b64c4e0f83682 (diff) | |
download | pkgsrc-588eb561c11d1e286eb9f53adb95d0835ba3ecd0.tar.gz |
Synch with basesrc:
Use EXIT_FAILURE, rather than hardcoding a value of '1' in err(3) and
errx(3).
Plug a memory leak by modifying the signature of
_pkgdb_getPKGDB_FILE() to take a buffer and its size, and fill in that
buffer and return it.
Add an enumerated type which is used in pkgdb_open() to specify
read-only or read-write mode.
Modify the return value of pkgdb_open() to have a more logical boolean
value.
Diffstat (limited to 'pkgtools')
-rw-r--r-- | pkgtools/pkg_install/files/add/extract.c | 8 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/add/perform.c | 8 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/admin/main.c | 61 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/create/pl.c | 8 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/delete/main.c | 21 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/delete/perform.c | 10 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/info/main.c | 18 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/info/perform.c | 10 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/lib/file.c | 12 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/lib/ftpio.c | 16 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/lib/lib.h.in | 9 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/lib/lpkg.c | 6 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/lib/path.c | 18 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/lib/pen.c | 8 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/lib/pkgdb.c | 31 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/lib/plist.c | 8 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/lib/str.c | 16 |
17 files changed, 135 insertions, 133 deletions
diff --git a/pkgtools/pkg_install/files/add/extract.c b/pkgtools/pkg_install/files/add/extract.c index 911dd696ae0..6df4ee92b11 100644 --- a/pkgtools/pkg_install/files/add/extract.c +++ b/pkgtools/pkg_install/files/add/extract.c @@ -1,4 +1,4 @@ -/* $NetBSD: extract.c,v 1.1.1.1 2002/12/20 18:13:55 schmonz Exp $ */ +/* $NetBSD: extract.c,v 1.2 2003/01/06 04:34:15 jschauma Exp $ */ #if 0 #include <sys/cdefs.h> @@ -6,7 +6,7 @@ #if 0 static const char *rcsid = "FreeBSD - Id: extract.c,v 1.17 1997/10/08 07:45:35 charnier Exp"; #else -__RCSID("$NetBSD: extract.c,v 1.1.1.1 2002/12/20 18:13:55 schmonz Exp $"); +__RCSID("$NetBSD: extract.c,v 1.2 2003/01/06 04:34:15 jschauma Exp $"); #endif #endif #endif @@ -153,9 +153,9 @@ extract_plist(char *home, package_t *pkg) Directory = home; /* Open Package Database for writing */ - if (pkgdb_open(0) == -1) { + if (!pkgdb_open(ReadWrite)) { cleanup(0); - err(1, "can't open pkgdb"); + err(EXIT_FAILURE, "can't open pkgdb"); } /* Do it */ while (p) { diff --git a/pkgtools/pkg_install/files/add/perform.c b/pkgtools/pkg_install/files/add/perform.c index 2d3b9ccd62c..ddab188ca57 100644 --- a/pkgtools/pkg_install/files/add/perform.c +++ b/pkgtools/pkg_install/files/add/perform.c @@ -1,4 +1,4 @@ -/* $NetBSD: perform.c,v 1.1.1.1 2002/12/20 18:13:56 schmonz Exp $ */ +/* $NetBSD: perform.c,v 1.2 2003/01/06 04:34:15 jschauma Exp $ */ #if 0 #include <sys/cdefs.h> @@ -6,7 +6,7 @@ #if 0 static const char *rcsid = "from FreeBSD Id: perform.c,v 1.44 1997/10/13 15:03:46 jkh Exp"; #else -__RCSID("$NetBSD: perform.c,v 1.1.1.1 2002/12/20 18:13:56 schmonz Exp $"); +__RCSID("$NetBSD: perform.c,v 1.2 2003/01/06 04:34:15 jschauma Exp $"); #endif #endif #endif @@ -142,7 +142,7 @@ pkg_do(const char *pkg) /* make sure dbdir actually exists! */ if (!(isdir(dbdir) || islinktodir(dbdir))) { if (vsystem("%s -p -m 755 %s", MKDIR, dbdir)) { - errx(1, "Database-dir %s cannot be generated, aborting.", + errx(EXIT_FAILURE, "Database-dir %s cannot be generated, aborting.", dbdir); } } @@ -630,7 +630,7 @@ pkg_do(const char *pkg) strcpy(t + 1, s); free(s); } else { - errx(1, "Where did our dependency go?!"); + errx(EXIT_FAILURE, "Where did our dependency go?!"); /* this shouldn't happen... X-) */ } } diff --git a/pkgtools/pkg_install/files/admin/main.c b/pkgtools/pkg_install/files/admin/main.c index 14e5a886ea0..2ff9d2d66f4 100644 --- a/pkgtools/pkg_install/files/admin/main.c +++ b/pkgtools/pkg_install/files/admin/main.c @@ -1,9 +1,9 @@ -/* $NetBSD: main.c,v 1.1.1.1 2002/12/20 18:13:53 schmonz Exp $ */ +/* $NetBSD: main.c,v 1.2 2003/01/06 04:34:16 jschauma Exp $ */ #if 0 #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: main.c,v 1.1.1.1 2002/12/20 18:13:53 schmonz Exp $"); +__RCSID("$NetBSD: main.c,v 1.2 2003/01/06 04:34:16 jschauma Exp $"); #endif #endif @@ -98,13 +98,13 @@ check1pkg(const char *pkgdir) f = fopen(CONTENTS_FNAME, "r"); if (f == NULL) - err(1, "can't open %s/%s/%s", _pkgdb_getPKGDB_DIR(), pkgdir, CONTENTS_FNAME); + err(EXIT_FAILURE, "can't open %s/%s/%s", _pkgdb_getPKGDB_DIR(), pkgdir, CONTENTS_FNAME); Plist.head = Plist.tail = NULL; read_plist(&Plist, f); p = find_plist(&Plist, PLIST_NAME); if (p == NULL) - errx(1, "Package %s has no @name, aborting.", + errx(EXIT_FAILURE, "Package %s has no @name, aborting.", pkgdir); PkgName = p->name; for (p = Plist.head; p; p = p->next) { @@ -184,15 +184,16 @@ rebuild(void) plist_t *p; char *PkgName, dir[FILENAME_MAX], *dirp = NULL; char *PkgDBDir = NULL, file[FILENAME_MAX]; + char cachename[FILENAME_MAX]; pkgcnt = 0; filecnt = 0; - if (unlink(_pkgdb_getPKGDB_FILE()) != 0 && errno != ENOENT) - err(1, "unlink %s", _pkgdb_getPKGDB_FILE()); + if (unlink(_pkgdb_getPKGDB_FILE(cachename, sizeof(cachename))) != 0 && errno != ENOENT) + err(EXIT_FAILURE, "unlink %s", cachename); - if (pkgdb_open(0) == -1) - err(1, "cannot open pkgdb"); + if (!pkgdb_open(ReadWrite)) + err(EXIT_FAILURE, "cannot open pkgdb"); setbuf(stdout, NULL); PkgDBDir = _pkgdb_getPKGDB_DIR(); @@ -202,7 +203,7 @@ rebuild(void) #endif dp = opendir("."); if (dp == NULL) - err(1, "opendir failed"); + err(EXIT_FAILURE, "opendir failed"); while ((de = readdir(dp))) { package_t Plist; @@ -223,13 +224,13 @@ rebuild(void) f = fopen(CONTENTS_FNAME, "r"); if (f == NULL) - err(1, "can't open %s/%s", de->d_name, CONTENTS_FNAME); + err(EXIT_FAILURE, "can't open %s/%s", de->d_name, CONTENTS_FNAME); Plist.head = Plist.tail = NULL; read_plist(&Plist, f); p = find_plist(&Plist, PLIST_NAME); if (p == NULL) - errx(1, "Package %s has no @name, aborting.", + errx(EXIT_FAILURE, "Package %s has no @name, aborting.", de->d_name); PkgName = p->name; for (p = Plist.head; p; p = p->next) { @@ -294,7 +295,7 @@ rebuild(void) printf("Stored %d file%s from %d package%s in %s.\n", filecnt, filecnt == 1 ? "" : "s", pkgcnt, pkgcnt == 1 ? "" : "s", - _pkgdb_getPKGDB_FILE()); + cachename); } static void @@ -311,7 +312,7 @@ checkall(void) dp = opendir("."); if (dp == NULL) - err(1, "opendir failed"); + err(EXIT_FAILURE, "opendir failed"); while ((de = readdir(dp))) { if (!isdir(de->d_name)) continue; @@ -344,7 +345,7 @@ checkpattern_fn(const char *pkg, void *vp) rc = chdir(pkg); if (rc == -1) - err(1, "Cannot chdir to %s/%s", _pkgdb_getPKGDB_DIR(), pkg); + err(EXIT_FAILURE, "Cannot chdir to %s/%s", _pkgdb_getPKGDB_DIR(), pkg); check1pkg(pkg); printf("."); @@ -416,12 +417,12 @@ main(int argc, char *argv[]) rc = chdir(_pkgdb_getPKGDB_DIR()); if (rc == -1) - err(1, "Cannot chdir to %s", _pkgdb_getPKGDB_DIR()); + err(EXIT_FAILURE, "Cannot chdir to %s", _pkgdb_getPKGDB_DIR()); while (*argv != NULL) { if (ispkgpattern(*argv)) { if (findmatchingname(_pkgdb_getPKGDB_DIR(), *argv, checkpattern_fn, NULL) == 0) - errx(1, "No matching pkg for %s.", *argv); + errx(EXIT_FAILURE, "No matching pkg for %s.", *argv); } else { rc = chdir(*argv); if (rc == -1) { @@ -432,7 +433,7 @@ main(int argc, char *argv[]) if (findmatchingname(_pkgdb_getPKGDB_DIR(), try, checkpattern_fn, NULL) <= 0) { - errx(1, "cannot find package %s", *argv); + errx(EXIT_FAILURE, "cannot find package %s", *argv); } else { /* nothing to do - all the work is/was * done in checkpattern_fn() */ @@ -466,7 +467,7 @@ main(int argc, char *argv[]) /* preserve cwd */ saved_wd=open(".", O_RDONLY); if (saved_wd == -1) - err(1, "Cannot save working dir"); + err(EXIT_FAILURE, "Cannot save working dir"); while (*argv != NULL) { /* args specified */ @@ -482,11 +483,11 @@ main(int argc, char *argv[]) fchdir(saved_wd); rc = chdir(dir); if (rc == -1) - err(1, "Cannot chdir to %s", _pkgdb_getPKGDB_DIR()); + err(EXIT_FAILURE, "Cannot chdir to %s", _pkgdb_getPKGDB_DIR()); cwd = getcwd(NULL, 0); if (findmatchingname(cwd, base, lspattern_fn, cwd) == -1) - errx(1, "Error in findmatchingname(\"%s\", \"%s\", ...)", + errx(EXIT_FAILURE, "Error in findmatchingname(\"%s\", \"%s\", ...)", cwd, base); free(cwd); @@ -504,7 +505,7 @@ main(int argc, char *argv[]) /* preserve cwd */ saved_wd=open(".", O_RDONLY); if (saved_wd == -1) - err(1, "Cannot save working dir"); + err(EXIT_FAILURE, "Cannot save working dir"); while (*argv != NULL) { /* args specified */ @@ -521,7 +522,7 @@ main(int argc, char *argv[]) fchdir(saved_wd); rc = chdir(dir); if (rc == -1) - err(1, "Cannot chdir to %s", _pkgdb_getPKGDB_DIR()); + err(EXIT_FAILURE, "Cannot chdir to %s", _pkgdb_getPKGDB_DIR()); cwd = getcwd(NULL, 0); p = findbestmatchingname(cwd, base); @@ -540,11 +541,13 @@ main(int argc, char *argv[]) strcasecmp(argv[1], "dump") == 0) { char *key, *val; + char cachename[FILENAME_MAX]; - printf("Dumping pkgdb %s:\n", _pkgdb_getPKGDB_FILE()); - if (pkgdb_open(1) == -1) { - err(1, "cannot open %s", _pkgdb_getPKGDB_FILE()); + printf("Dumping pkgdb %s:\n", _pkgdb_getPKGDB_FILE(cachename, sizeof(cachename))); + + if (!pkgdb_open(ReadOnly)) { + err(EXIT_FAILURE, "cannot open %s", cachename); } while ((key = pkgdb_iter())) { val = pkgdb_retrieve(key); @@ -560,8 +563,8 @@ main(int argc, char *argv[]) int rc; - if (pkgdb_open(0) == -1) - err(1, "cannot open pkgdb"); + if (!pkgdb_open(ReadWrite)) + err(EXIT_FAILURE, "cannot open pkgdb"); rc = pkgdb_remove(argv[2]); if (rc) { @@ -577,8 +580,8 @@ main(int argc, char *argv[]) int rc; - if (pkgdb_open(0) == -1) { - err(1, "cannot open pkgdb"); + if (!pkgdb_open(ReadWrite)) { + err(EXIT_FAILURE, "cannot open pkgdb"); } rc = pkgdb_store(argv[2], argv[3]); diff --git a/pkgtools/pkg_install/files/create/pl.c b/pkgtools/pkg_install/files/create/pl.c index 54b763d3337..73ea88a73cd 100644 --- a/pkgtools/pkg_install/files/create/pl.c +++ b/pkgtools/pkg_install/files/create/pl.c @@ -1,4 +1,4 @@ -/* $NetBSD: pl.c,v 1.1.1.1 2002/12/20 18:14:11 schmonz Exp $ */ +/* $NetBSD: pl.c,v 1.2 2003/01/06 04:34:16 jschauma Exp $ */ #if 0 #include <sys/cdefs.h> @@ -6,7 +6,7 @@ #if 0 static const char *rcsid = "from FreeBSD Id: pl.c,v 1.11 1997/10/08 07:46:35 charnier Exp"; #else -__RCSID("$NetBSD: pl.c,v 1.1.1.1 2002/12/20 18:14:11 schmonz Exp $"); +__RCSID("$NetBSD: pl.c,v 1.2 2003/01/06 04:34:16 jschauma Exp $"); #endif #endif #endif @@ -132,9 +132,9 @@ check_list(char *home, package_t *pkg, const char *PkgName) int dirc; /* Open Package Database for writing */ - if (update_pkgdb && pkgdb_open(0) == -1) { + if (update_pkgdb && !pkgdb_open(ReadWrite)) { cleanup(0); - err(1, "can't open pkgdb"); + err(EXIT_FAILURE, "can't open pkgdb"); } for (dirc = 0, p = pkg->head; p; p = p->next) { diff --git a/pkgtools/pkg_install/files/delete/main.c b/pkgtools/pkg_install/files/delete/main.c index 32dacc7e3e4..ad69dd98d51 100644 --- a/pkgtools/pkg_install/files/delete/main.c +++ b/pkgtools/pkg_install/files/delete/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.1.1.1 2002/12/20 18:14:09 schmonz Exp $ */ +/* $NetBSD: main.c,v 1.2 2003/01/06 04:34:16 jschauma Exp $ */ #if 0 #include <sys/cdefs.h> @@ -6,7 +6,7 @@ #if 0 static char *rcsid = "from FreeBSD Id: main.c,v 1.11 1997/10/08 07:46:48 charnier Exp"; #else -__RCSID("$NetBSD: main.c,v 1.1.1.1 2002/12/20 18:14:09 schmonz Exp $"); +__RCSID("$NetBSD: main.c,v 1.2 2003/01/06 04:34:16 jschauma Exp $"); #endif #endif #endif @@ -133,8 +133,8 @@ main(int argc, char **argv) /* Get all the remaining package names, if any */ if (File2Pkg) - if (pkgdb_open(1) == -1) { - err(1, "cannot open pkgdb"); + if (!pkgdb_open(ReadOnly)) { + err(EXIT_FAILURE, "cannot open pkgdb"); } /* Get all the remaining package names, if any */ while (*argv) { @@ -150,15 +150,15 @@ main(int argc, char **argv) lpp = alloc_lpkg(s); TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link); } else - errx(1, "No matching pkg for %s in pkgdb.", *argv); + errx(EXIT_FAILURE, "No matching pkg for %s in pkgdb.", *argv); } else { if (ispkgpattern(*argv)) { int rc; rc = findmatchingname(_pkgdb_getPKGDB_DIR(), *argv, add_to_list_fn, &pkgs); if (rc == 0) - errx(1, "No matching pkg for %s.", *argv); + errx(EXIT_FAILURE, "No matching pkg for %s.", *argv); else if (rc == -1) - errx(1, "error expanding '%s' ('%s' nonexistant?)", *argv, _pkgdb_getPKGDB_DIR()); + errx(EXIT_FAILURE, "error expanding '%s' ('%s' nonexistant?)", *argv, _pkgdb_getPKGDB_DIR()); } else { lpp = alloc_lpkg(*argv); TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link); @@ -174,15 +174,16 @@ main(int argc, char **argv) if (TAILQ_FIRST(&pkgs) == NULL) warnx("missing package name(s)"), usage(); if (!Fake && getuid() != 0) - errx(1, "you must be root to delete packages"); + errx(EXIT_FAILURE, "you must be root to delete packages"); if (OnlyDeleteFromPkgDB) { /* Only delete the given packages' files from pkgdb, do not * touch the pkg itself. Used by "make reinstall" in * bsd.pkg.mk */ char *key, *val; + char cachename[FILENAME_MAX]; - if (pkgdb_open(0) == -1) { - err(1, "cannot open %s", _pkgdb_getPKGDB_FILE()); + if (!pkgdb_open(ReadWrite)) { + err(EXIT_FAILURE, "cannot open %s", _pkgdb_getPKGDB_FILE(cachename, sizeof(cachename))); } error = 0; diff --git a/pkgtools/pkg_install/files/delete/perform.c b/pkgtools/pkg_install/files/delete/perform.c index cb7bfa04d70..3ee3ecf001c 100644 --- a/pkgtools/pkg_install/files/delete/perform.c +++ b/pkgtools/pkg_install/files/delete/perform.c @@ -1,4 +1,4 @@ -/* $NetBSD: perform.c,v 1.1.1.1 2002/12/20 18:14:08 schmonz Exp $ */ +/* $NetBSD: perform.c,v 1.2 2003/01/06 04:34:16 jschauma Exp $ */ #if 0 #include <sys/cdefs.h> @@ -6,7 +6,7 @@ #if 0 static const char *rcsid = "from FreeBSD Id: perform.c,v 1.15 1997/10/13 15:03:52 jkh Exp"; #else -__RCSID("$NetBSD: perform.c,v 1.1.1.1 2002/12/20 18:14:08 schmonz Exp $"); +__RCSID("$NetBSD: perform.c,v 1.2 2003/01/06 04:34:16 jschauma Exp $"); #endif #endif #endif @@ -191,7 +191,7 @@ require_delete(char *home, int tryall) /* save cwd */ oldcwd = open(".", O_RDONLY, 0); if (oldcwd == -1) - err(1, "cannot open \".\""); + err(EXIT_FAILURE, "cannot open \".\""); (void) snprintf(pkgdir, sizeof(pkgdir), "%s", (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR); @@ -683,14 +683,14 @@ pkg_perform(lpkg_head_t *pkghead) /* save cwd */ oldcwd = open(".", O_RDONLY, 0); if (oldcwd == -1) - err(1, "cannot open \".\""); + err(EXIT_FAILURE, "cannot open \".\""); while ((lpp = TAILQ_FIRST(pkghead))) { err_cnt += pkg_do(lpp->lp_name); TAILQ_REMOVE(pkghead, lpp, lp_link); free_lpkg(lpp); if (fchdir(oldcwd) == FAIL) - err(1, "unable to change to previous directory"); + err(EXIT_FAILURE, "unable to change to previous directory"); } close(oldcwd); return err_cnt; diff --git a/pkgtools/pkg_install/files/info/main.c b/pkgtools/pkg_install/files/info/main.c index 27e17085533..e34e9a4d230 100644 --- a/pkgtools/pkg_install/files/info/main.c +++ b/pkgtools/pkg_install/files/info/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.1.1.1 2002/12/20 18:14:12 schmonz Exp $ */ +/* $NetBSD: main.c,v 1.2 2003/01/06 04:34:16 jschauma Exp $ */ #if 0 #include <sys/cdefs.h> @@ -6,7 +6,7 @@ #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.1.1.1 2002/12/20 18:14:12 schmonz Exp $"); +__RCSID("$NetBSD: main.c,v 1.2 2003/01/06 04:34:16 jschauma Exp $"); #endif #endif #endif @@ -216,15 +216,15 @@ main(int argc, char **argv) if (CheckPkg && File2Pkg) { char *s; - if (pkgdb_open(1) == -1) - err(1, "cannot open pkgdb"); + if (pkgdb_open(ReadOnly) == -1) + err(EXIT_FAILURE, "cannot open pkgdb"); s = pkgdb_retrieve(CheckPkg); if (s) { CheckPkg = strdup(s); } else { - errx(1, "No matching pkg for %s.", CheckPkg); + errx(EXIT_FAILURE, "No matching pkg for %s.", CheckPkg); } pkgdb_close(); @@ -234,8 +234,8 @@ main(int argc, char **argv) /* Get all the remaining package names, if any */ if (File2Pkg && !AllInstalled) - if (pkgdb_open(1) == -1) { - err(1, "cannot open pkgdb"); + if (pkgdb_open(ReadOnly) == -1) { + err(EXIT_FAILURE, "cannot open pkgdb"); } while (*argv) { /* pkgdb: if -F flag given, don't add pkgnames to the "pkgs" @@ -250,11 +250,11 @@ main(int argc, char **argv) lpp = alloc_lpkg(s); TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link); } else - errx(1, "No matching pkg for %s.", *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) - errx(1, "No matching pkg for %s.", *argv); + errx(EXIT_FAILURE, "No matching pkg for %s.", *argv); } else { lpp = alloc_lpkg(*argv); TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link); diff --git a/pkgtools/pkg_install/files/info/perform.c b/pkgtools/pkg_install/files/info/perform.c index c8dddc7b3b2..61fed767765 100644 --- a/pkgtools/pkg_install/files/info/perform.c +++ b/pkgtools/pkg_install/files/info/perform.c @@ -1,4 +1,4 @@ -/* $NetBSD: perform.c,v 1.1.1.1 2002/12/20 18:14:13 schmonz Exp $ */ +/* $NetBSD: perform.c,v 1.2 2003/01/06 04:34:16 jschauma Exp $ */ #if 0 #include <sys/cdefs.h> @@ -6,7 +6,7 @@ #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.1.1.1 2002/12/20 18:14:13 schmonz Exp $"); +__RCSID("$NetBSD: perform.c,v 1.2 2003/01/06 04:34:16 jschauma Exp $"); #endif #endif #endif @@ -78,7 +78,7 @@ pkg_do(char *pkg) if (*pkg != '/') { if (!getcwd(fname, FILENAME_MAX)) { cleanup(0); - err(1, "fatal error during execution: getcwd"); + err(EXIT_FAILURE, "fatal error during execution: getcwd"); } len = strlen(fname); (void) snprintf(&fname[len], sizeof(fname) - len, "/%s", pkg); @@ -338,8 +338,8 @@ pkg_perform(lpkg_head_t *pkghead) char *file, *pkg; /* pkg_info -Fa => Dump pkgdb */ - if (pkgdb_open(1) == -1) { - err(1, "cannot open pkgdb"); + if (!pkgdb_open(ReadOnly)) { + err(EXIT_FAILURE, "cannot open pkgdb"); } while ((file = pkgdb_iter())) { pkg = pkgdb_retrieve(file); diff --git a/pkgtools/pkg_install/files/lib/file.c b/pkgtools/pkg_install/files/lib/file.c index 96a71b4b376..faf268887f5 100644 --- a/pkgtools/pkg_install/files/lib/file.c +++ b/pkgtools/pkg_install/files/lib/file.c @@ -1,4 +1,4 @@ -/* $NetBSD: file.c,v 1.1.1.1 2002/12/20 18:14:00 schmonz Exp $ */ +/* $NetBSD: file.c,v 1.2 2003/01/06 04:34:17 jschauma Exp $ */ #if 0 #include <sys/cdefs.h> @@ -6,7 +6,7 @@ #if 0 static const char *rcsid = "from FreeBSD Id: file.c,v 1.29 1997/10/08 07:47:54 charnier Exp"; #else -__RCSID("$NetBSD: file.c,v 1.1.1.1 2002/12/20 18:14:00 schmonz Exp $"); +__RCSID("$NetBSD: file.c,v 1.2 2003/01/06 04:34:17 jschauma Exp $"); #endif #endif #endif @@ -205,7 +205,7 @@ fileURLHost(const char *fname, char *where, int max) assert(max > 0); if ((i = URLlength(fname)) < 0) { /* invalid URL? */ - errx(1, "fileURLhost called with a bad URL: `%s'", fname); + errx(EXIT_FAILURE, "fileURLhost called with a bad URL: `%s'", fname); } fname += i; /* Do we have a place to stick our work? */ @@ -230,7 +230,7 @@ fileURLFilename(const char *fname, char *where, int max) assert(max > 0); if ((i = URLlength(fname)) < 0) { /* invalid URL? */ - errx(1, "fileURLFilename called with a bad URL: `%s'", fname); + errx(EXIT_FAILURE, "fileURLFilename called with a bad URL: `%s'", fname); } fname += i; /* Do we have a place to stick our work? */ @@ -261,7 +261,7 @@ fileGetURL(const char *spec) rp = NULL; if (!IS_URL(spec)) { - errx(1, "fileGetURL was called with non-url arg '%s'", spec); + errx(EXIT_FAILURE, "fileGetURL was called with non-url arg '%s'", spec); } /* Some sanity checks on the URL */ @@ -399,7 +399,7 @@ fileFindByPath(const char *fname) else { char cwdtmp[MAXPATHLEN]; if (getcwd(cwdtmp, sizeof(cwdtmp)) == NULL) - errx(1, "getcwd"); + errx(EXIT_FAILURE, "getcwd"); snprintf(tmp, sizeof(tmp), "%s/%s/%s", cwdtmp, cp2, fname); } cp = resolvepattern(tmp); diff --git a/pkgtools/pkg_install/files/lib/ftpio.c b/pkgtools/pkg_install/files/lib/ftpio.c index 02e6339ee9f..5a5e631fe5c 100644 --- a/pkgtools/pkg_install/files/lib/ftpio.c +++ b/pkgtools/pkg_install/files/lib/ftpio.c @@ -1,9 +1,9 @@ -/* $NetBSD: ftpio.c,v 1.1.1.1 2002/12/20 18:14:01 schmonz Exp $ */ +/* $NetBSD: ftpio.c,v 1.2 2003/01/06 04:34:17 jschauma Exp $ */ #if 0 #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: ftpio.c,v 1.1.1.1 2002/12/20 18:14:01 schmonz Exp $"); +__RCSID("$NetBSD: ftpio.c,v 1.2 2003/01/06 04:34:17 jschauma Exp $"); #endif #endif @@ -147,12 +147,12 @@ expect(int fd, const char *str, int *ftprc) #if EXPECT_DEBUG vstr=malloc(2*sizeof(buf)); if (vstr == NULL) - err(1, "expect: malloc() failed"); + err(EXIT_FAILURE, "expect: malloc() failed"); strvis(vstr, str, VIS_NL|VIS_SAFE|VIS_CSTYLE); #endif /* EXPECT_DEBUG */ if (regcomp(&rstr, str, REG_EXTENDED) != 0) - err(1, "expect: regcomp() failed"); + err(EXIT_FAILURE, "expect: regcomp() failed"); #if EXPECT_DEBUG if (expect_debug) @@ -326,14 +326,14 @@ setupCoproc(const char *base) (void) close(command_pipe[1]); rc1 = dup2(command_pipe[0], 0); if (rc1 == -1) { - err(1, "setupCoproc: dup2 failed (command_pipe[0])"); + err(EXIT_FAILURE, "setupCoproc: dup2 failed (command_pipe[0])"); } (void) close(command_pipe[0]); (void) close(answer_pipe[0]); rc1 = dup2(answer_pipe[1], 1); if (rc1 == -1) { - err(1, "setupCoproc: dup2 failed (answer_pipe[1])"); + err(EXIT_FAILURE, "setupCoproc: dup2 failed (answer_pipe[1])"); } (void) close(answer_pipe[1]); @@ -468,7 +468,7 @@ ftp_start(char *base) fileURLHost(base, newHost, sizeof(newHost)); urllen = URLlength(base); if (urllen < 0 || !(newDir = strchr(base + URLlength(base), '/'))) - errx(1, "ftp_start: bad URL '%s'", base); + errx(EXIT_FAILURE, "ftp_start: bad URL '%s'", base); newDir++; if (currentHost && currentDir @@ -883,7 +883,7 @@ miscstuff(const char *url) static void usage(void) { - errx(1, "Usage: foo [-v] ftp://-pattern"); + errx(EXIT_FAILURE, "Usage: foo [-v] ftp://-pattern"); } diff --git a/pkgtools/pkg_install/files/lib/lib.h.in b/pkgtools/pkg_install/files/lib/lib.h.in index 69b9fd50579..82ab40f50f1 100644 --- a/pkgtools/pkg_install/files/lib/lib.h.in +++ b/pkgtools/pkg_install/files/lib/lib.h.in @@ -1,4 +1,4 @@ -/* $NetBSD: lib.h.in,v 1.1.1.1 2002/12/20 18:14:02 schmonz Exp $ */ +/* $NetBSD: lib.h.in,v 1.2 2003/01/06 04:34:17 jschauma Exp $ */ /* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */ @@ -118,6 +118,11 @@ #define HAVE_TAR__FAST_READ 1 #endif +enum { + ReadWrite, + ReadOnly +}; + /* Where we put logging information by default, else ${PKG_DBDIR} if set */ #ifndef DEF_LOG_DIR @@ -426,7 +431,7 @@ int pkgdb_store(const char *, const char *); char *pkgdb_retrieve(const char *); int pkgdb_remove(const char *); char *pkgdb_iter(void); -char *_pkgdb_getPKGDB_FILE(void); +char *_pkgdb_getPKGDB_FILE(char *, unsigned); char *_pkgdb_getPKGDB_DIR(void); /* List of packages functions */ diff --git a/pkgtools/pkg_install/files/lib/lpkg.c b/pkgtools/pkg_install/files/lib/lpkg.c index ff759c24405..6aad8c01b49 100644 --- a/pkgtools/pkg_install/files/lib/lpkg.c +++ b/pkgtools/pkg_install/files/lib/lpkg.c @@ -1,4 +1,4 @@ -/* $NetBSD: lpkg.c,v 1.1.1.1 2002/12/20 18:14:02 schmonz Exp $ */ +/* $NetBSD: lpkg.c,v 1.2 2003/01/06 04:34:17 jschauma Exp $ */ /* * Copyright (c) 1999 Christian E. Hopps @@ -47,9 +47,9 @@ alloc_lpkg(const char *pkgname) lpkg_t *lpp; if ((lpp = malloc(sizeof(*lpp))) == 0) - err(1, "cannot allocate recursion data"); + err(EXIT_FAILURE, "cannot allocate recursion data"); if ((lpp->lp_name = strdup(pkgname)) == 0) - err(1, "cannot allocate recursion data"); + err(EXIT_FAILURE, "cannot allocate recursion data"); return (lpp); } diff --git a/pkgtools/pkg_install/files/lib/path.c b/pkgtools/pkg_install/files/lib/path.c index abb84ae798b..1ef24c5f064 100644 --- a/pkgtools/pkg_install/files/lib/path.c +++ b/pkgtools/pkg_install/files/lib/path.c @@ -1,4 +1,4 @@ -/* $NetBSD: path.c,v 1.1.1.1 2002/12/20 18:14:06 schmonz Exp $ */ +/* $NetBSD: path.c,v 1.2 2003/01/06 04:34:17 jschauma Exp $ */ /*- * Copyright (c)2002 YAMAMOTO Takashi, @@ -29,7 +29,7 @@ #if 0 #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: path.c,v 1.1.1.1 2002/12/20 18:14:06 schmonz Exp $"); +__RCSID("$NetBSD: path.c,v 1.2 2003/01/06 04:34:17 jschauma Exp $"); #endif #endif @@ -115,7 +115,7 @@ path_new_entry(const char *cp, size_t len) new = malloc(sizeof(*new)); if (new == NULL) - err(1, "path_create"); + err(EXIT_FAILURE, "path_create"); if (!IS_FULLPATH(cp) && !IS_URL(cp)) { /* this is a relative path */ @@ -124,18 +124,18 @@ path_new_entry(const char *cp, size_t len) size_t cwdlen; if (getcwd(cwd, sizeof(cwd)) == NULL) - err(1, "getcwd"); + err(EXIT_FAILURE, "getcwd"); cwdlen = strlen(cwd); total = cwdlen + 1 + len + 1; new->pl_path = malloc(total); if (new->pl_path == NULL) - err(1, "path_create"); + err(EXIT_FAILURE, "path_create"); snprintf(new->pl_path, total, "%s/%*.*s", cwd, (int)len, (int)len, cp); } else { new->pl_path = malloc(len + 1); if (new->pl_path == NULL) - err(1, "path_create"); + err(EXIT_FAILURE, "path_create"); memcpy(new->pl_path, cp, len); new->pl_path[len] = '\0'; } @@ -185,7 +185,7 @@ path_setenv(const char *envname) env = malloc(len); if (env == NULL) - err(1, "path_setenv"); + err(EXIT_FAILURE, "path_setenv"); env0 = env; envend = env + len; @@ -195,7 +195,7 @@ path_setenv(const char *envname) r = snprintf(env, envend - env, "%s%s", sep, p->pl_path); if (r < 0 || r >= envend - env) - err(1, "snprintf"); + err(EXIT_FAILURE, "snprintf"); env += r; sep = ";"; } @@ -203,6 +203,6 @@ path_setenv(const char *envname) if (Verbose) printf("%s = %s\n", envname, env0); if (setenv(envname, env0, 1) != 0) - err(1, "setenv"); + err(EXIT_FAILURE, "setenv"); free(env0); } diff --git a/pkgtools/pkg_install/files/lib/pen.c b/pkgtools/pkg_install/files/lib/pen.c index 9d8f3e64d12..051a5bb4cfa 100644 --- a/pkgtools/pkg_install/files/lib/pen.c +++ b/pkgtools/pkg_install/files/lib/pen.c @@ -1,4 +1,4 @@ -/* $NetBSD: pen.c,v 1.2 2002/12/28 21:44:00 jschauma Exp $ */ +/* $NetBSD: pen.c,v 1.3 2003/01/06 04:34:17 jschauma Exp $ */ #if 0 #include <sys/cdefs.h> @@ -6,7 +6,7 @@ #if 0 static const char *rcsid = "from FreeBSD Id: pen.c,v 1.25 1997/10/08 07:48:12 charnier Exp"; #else -__RCSID("$NetBSD: pen.c,v 1.2 2002/12/28 21:44:00 jschauma Exp $"); +__RCSID("$NetBSD: pen.c,v 1.3 2003/01/06 04:34:17 jschauma Exp $"); #endif #endif #endif @@ -181,7 +181,7 @@ make_playpen(char *pen, size_t pensize, size_t sz) strcpy(Previous, Current); else if (!getcwd(Previous, FILENAME_MAX)) { cleanup(0); - err(1, "fatal error during execution: getcwd"); + err(EXIT_FAILURE, "fatal error during execution: getcwd"); } if (chdir(pen) == FAIL) { cleanup(0); @@ -228,7 +228,7 @@ leave_playpen(char *save) * in libc on 2.7 and 2.8, but not in 2.9) */ #if !defined(HAVE_STATFS) || (defined(HAVE_STATFS) && defined(HAVE_STATVFS) && !defined(__linux__)) -/* $NetBSD: pen.c,v 1.2 2002/12/28 21:44:00 jschauma Exp $ */ +/* $NetBSD: pen.c,v 1.3 2003/01/06 04:34:17 jschauma Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. diff --git a/pkgtools/pkg_install/files/lib/pkgdb.c b/pkgtools/pkg_install/files/lib/pkgdb.c index 1ae6d622307..b81d2718857 100644 --- a/pkgtools/pkg_install/files/lib/pkgdb.c +++ b/pkgtools/pkg_install/files/lib/pkgdb.c @@ -1,9 +1,9 @@ -/* $NetBSD: pkgdb.c,v 1.1.1.1 2002/12/20 18:14:03 schmonz Exp $ */ +/* $NetBSD: pkgdb.c,v 1.2 2003/01/06 04:34:17 jschauma Exp $ */ #if 0 #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: pkgdb.c,v 1.1.1.1 2002/12/20 18:14:03 schmonz Exp $"); +__RCSID("$NetBSD: pkgdb.c,v 1.2 2003/01/06 04:34:17 jschauma Exp $"); #endif #endif @@ -75,10 +75,11 @@ static int pkgdb_iter_flag; * -1: error, see errno */ int -pkgdb_open(int ro) +pkgdb_open(int mode) { #if defined(HAVE_DBOPEN) BTREEINFO info; + char cachename[FILENAME_MAX]; pkgdb_iter_flag = 0; /* used in pkgdb_iter() */ @@ -91,8 +92,8 @@ pkgdb_open(int ro) info.compare = NULL; info.prefix = NULL; info.lorder = 0; - pkgdbp = (DB *) dbopen(_pkgdb_getPKGDB_FILE(), - ro ? O_RDONLY : O_RDWR | O_CREAT, + pkgdbp = (DB *) dbopen(_pkgdb_getPKGDB_FILE(cachename, sizeof(cachename)), + (mode == ReadOnly) ? O_RDONLY : O_RDWR | O_CREAT, 0644, DB_BTREE, (void *) &info); return (pkgdbp == NULL) ? -1 : 0; #else @@ -244,32 +245,24 @@ pkgdb_iter(void) } /* - * Return filename as string that can be passed to free(3) + * Return name of cache file in the buffer that was passed. */ -char * -_pkgdb_getPKGDB_FILE(void) +char * +_pkgdb_getPKGDB_FILE(char *buf, unsigned size) { - char *tmp; - - tmp = malloc(FILENAME_MAX); - if (tmp == NULL) - errx(1, "_pkgdb_getPKGDB_FILE: out of memory"); - snprintf(tmp, FILENAME_MAX, "%s/%s", _pkgdb_getPKGDB_DIR(), PKGDB_FILE); - return tmp; + (void) snprintf(buf, size, "%s/%s", _pkgdb_getPKGDB_DIR(), PKGDB_FILE); + return buf; } /* * Return directory where pkgdb is stored - * as string that can be passed to free(3) */ -char * +char * _pkgdb_getPKGDB_DIR(void) { char *tmp; static char *cache = NULL; - if (cache == NULL) cache = (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR; - return cache; } diff --git a/pkgtools/pkg_install/files/lib/plist.c b/pkgtools/pkg_install/files/lib/plist.c index c0466cc4d4d..fe8baaf82a8 100644 --- a/pkgtools/pkg_install/files/lib/plist.c +++ b/pkgtools/pkg_install/files/lib/plist.c @@ -1,4 +1,4 @@ -/* $NetBSD: plist.c,v 1.1.1.1 2002/12/20 18:14:04 schmonz Exp $ */ +/* $NetBSD: plist.c,v 1.2 2003/01/06 04:34:17 jschauma Exp $ */ #if 0 #include <sys/cdefs.h> @@ -6,7 +6,7 @@ #if 0 static const char *rcsid = "from FreeBSD Id: plist.c,v 1.24 1997/10/08 07:48:15 charnier Exp"; #else -__RCSID("$NetBSD: plist.c,v 1.1.1.1 2002/12/20 18:14:04 schmonz Exp $"); +__RCSID("$NetBSD: plist.c,v 1.2 2003/01/06 04:34:17 jschauma Exp $"); #endif #endif #endif @@ -343,8 +343,8 @@ delete_package(Boolean ign_err, Boolean nukedirs, package_t *pkg) Boolean preserve; char tmp[FILENAME_MAX], *name = NULL; - if (pkgdb_open(0) == -1) { - err(1, "cannot open pkgdb"); + if (!pkgdb_open(ReadWrite)) { + err(EXIT_FAILURE, "cannot open pkgdb"); } preserve = find_plist_option(pkg, "preserve") ? TRUE : FALSE; diff --git a/pkgtools/pkg_install/files/lib/str.c b/pkgtools/pkg_install/files/lib/str.c index a994728892f..63c8a34fbc8 100644 --- a/pkgtools/pkg_install/files/lib/str.c +++ b/pkgtools/pkg_install/files/lib/str.c @@ -1,4 +1,4 @@ -/* $NetBSD: str.c,v 1.1.1.1 2002/12/20 18:14:05 schmonz Exp $ */ +/* $NetBSD: str.c,v 1.2 2003/01/06 04:34:17 jschauma Exp $ */ #if 0 #include <sys/cdefs.h> @@ -6,7 +6,7 @@ #if 0 static const char *rcsid = "Id: str.c,v 1.5 1997/10/08 07:48:21 charnier Exp"; #else -__RCSID("$NetBSD: str.c,v 1.1.1.1 2002/12/20 18:14:05 schmonz Exp $"); +__RCSID("$NetBSD: str.c,v 1.2 2003/01/06 04:34:17 jschauma Exp $"); #endif #endif #endif @@ -93,7 +93,7 @@ dirname_of(const char *path) } cc = (size_t) (s - path); if (cc >= sizeof(buf)) - errx(1, "dirname_of: too long dirname: '%s'", path); + errx(EXIT_FAILURE, "dirname_of: too long dirname: '%s'", path); (void) memcpy(buf, path, cc); buf[cc] = 0; return buf; @@ -335,7 +335,7 @@ alternate_match(const char *pattern, const char *pkg) int found; if ((sep = strchr(pattern, '{')) == (char *) NULL) { - errx(1, "alternate_match(): '{' expected in `%s'", pattern); + errx(EXIT_FAILURE, "alternate_match(): '{' expected in `%s'", pattern); } (void) strncpy(buf, pattern, (size_t) (sep - pattern)); alt = &buf[sep - pattern]; @@ -348,7 +348,7 @@ alternate_match(const char *pattern, const char *pkg) } } if (cnt != 0) { - errx(1, "Malformed alternate `%s'", pattern); + errx(EXIT_FAILURE, "Malformed alternate `%s'", pattern); } for (found = 0, cp = sep + 1; *sep != '}'; cp = sep + 1) { for (cnt = 0, sep = cp; cnt > 0 || (cnt == 0 && *sep != '}' && *sep != ','); sep++) { @@ -381,7 +381,7 @@ dewey_match(const char *pattern, const char *pkg) int n; if ((sep = strpbrk(pattern, "<>")) == NULL) { - errx(1, "dewey_match(): '<' or '>' expected in `%s'", pattern); + errx(EXIT_FAILURE, "dewey_match(): '<' or '>' expected in `%s'", pattern); } (void) snprintf(name, sizeof(name), "%.*s", (int) (sep - pattern), pattern); if ((n = mktest(&op, sep)) < 0) { @@ -458,7 +458,7 @@ findmatchingname(const char *dir, const char *pattern, matchfn match, void *data char pat_sfx[PKG_SUFFIX_MAX], file_sfx[PKG_SUFFIX_MAX]; /* suffixes */ if (strlen(pattern) >= PKG_PATTERN_MAX) - errx(1, "too long pattern '%s'", pattern); + errx(EXIT_FAILURE, "too long pattern '%s'", pattern); found = 0; if ((dirp = opendir(dir)) == (DIR *) NULL) { @@ -625,7 +625,7 @@ strip_txz(char *buf, char *sfx, const char *fname) buf[len - suffixlen] = 0; if (sfx) { if (suffixlen >= PKG_SUFFIX_MAX) - errx(1, "too long suffix '%s'", fname); + errx(EXIT_FAILURE, "too long suffix '%s'", fname); memcpy(sfx, *suffixp, suffixlen+1); return; } |