diff options
| author | hubertf <hubertf@NetBSD.org> | 1999-03-22 05:02:39 +0000 |
|---|---|---|
| committer | hubertf <hubertf@NetBSD.org> | 1999-03-22 05:02:39 +0000 |
| commit | 04417da1663ee41a9933b1e6bdb0efa1f8896470 (patch) | |
| tree | 4ee9164b79dff77224ff535089e2be208c0e207d | |
| parent | 6c70403fe8d4617944779e3d9dc3ffd2985dd131 (diff) | |
Replace static array of packages given to pkg_perform() with linear
list, using chopss' list functions (moved to lib/lpkg.c and
lib/lib.h).
Properly handle wildcards in arguments to "pkg_info", "pkg_delete" and
"pkg_admin check".
Some other minor cleanups.
| -rw-r--r-- | usr.sbin/pkg_install/add/main.c | 49 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/add/perform.c | 16 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/add/pkg_add.1 | 3 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/admin/main.c | 59 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/admin/pkg_admin.1 | 8 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/create/create.h | 3 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/create/main.c | 29 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/create/perform.c | 12 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/create/pkg_create.1 | 3 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/delete/main.c | 77 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/delete/perform.c | 211 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/delete/pkg_delete.1 | 7 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/info/main.c | 53 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/info/perform.c | 17 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/info/pkg_info.1 | 12 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/lib/Makefile | 4 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/lib/lib.h | 25 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/lib/lpkg.c | 64 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/lib/str.c | 5 |
19 files changed, 396 insertions, 261 deletions
diff --git a/usr.sbin/pkg_install/add/main.c b/usr.sbin/pkg_install/add/main.c index 6cd6213654a..7d2a3f4c637 100644 --- a/usr.sbin/pkg_install/add/main.c +++ b/usr.sbin/pkg_install/add/main.c @@ -1,11 +1,11 @@ -/* $NetBSD: main.c,v 1.8 1999/01/19 17:01:57 hubertf Exp $ */ +/* $NetBSD: main.c,v 1.9 1999/03/22 05:02:39 hubertf Exp $ */ #include <sys/cdefs.h> #ifndef lint #if 0 static char *rcsid = "from FreeBSD Id: main.c,v 1.16 1997/10/08 07:45:43 charnier Exp"; #else -__RCSID("$NetBSD: main.c,v 1.8 1999/01/19 17:01:57 hubertf Exp $"); +__RCSID("$NetBSD: main.c,v 1.9 1999/03/22 05:02:39 hubertf Exp $"); #endif #endif @@ -49,10 +49,6 @@ char *Directory = NULL; char FirstPen[FILENAME_MAX]; add_mode_t AddMode = NORMAL; -#define MAX_PKGS 20 -char pkgnames[MAX_PKGS][MAXPATHLEN]; -char *pkgs[MAX_PKGS]; - static void usage(void) { @@ -66,10 +62,11 @@ int main(int argc, char **argv) { int ch, error; - char **start; + lpkg_head_t pkgs; + lpkg_t *lpp; char *cp; + char pkgname[MAXPATHLEN]; - start = argv; while ((ch = getopt(argc, argv, Options)) != -1) { switch(ch) { case 'v': @@ -119,40 +116,38 @@ main(int argc, char **argv) argc -= optind; argv += optind; - if (argc > MAX_PKGS) { - warnx("too many packages (max %d)", MAX_PKGS); - return(1); - } - + TAILQ_INIT(&pkgs); + if (AddMode != SLAVE) { - for (ch = 0; ch < MAX_PKGS; pkgs[ch++] = NULL) ; - /* Get all the remaining package names, if any */ for (ch = 0; *argv; ch++, argv++) { if (!strcmp(*argv, "-")) /* stdin? */ - pkgs[ch] = "-"; + lpp = alloc_lpkg("-"); else if (isURL(*argv)) /* preserve URLs */ - pkgs[ch] = strcpy(pkgnames[ch], *argv); + lpp = alloc_lpkg(*argv); else { /* expand all pathnames to fullnames */ char *s; - if (fexists(*argv)) /* refers to a file directly */ - pkgs[ch] = realpath(*argv, pkgnames[ch]); - else if (ispkgpattern(*argv) + if (fexists(*argv)) { /* refers to a file directly */ + lpp = alloc_lpkg(realpath(*argv, pkgname)); + } else if (ispkgpattern(*argv) && (s=findbestmatchingname(dirname_of(*argv), - basename_of(*argv))) > 0) { + basename_of(*argv))) != NULL) { if (Verbose) printf("Using %s for %s\n",s, *argv); - - pkgs[ch] = realpath(s, pkgnames[ch]); + + lpp = alloc_lpkg(realpath(s, pkgname)); } else { /* look for the file(pattern) in the expected places */ - if (!(cp = fileFindByPath(NULL, *argv))) + if (!(cp = fileFindByPath(NULL, *argv))) { + lpp = NULL; warnx("can't find package '%s'", *argv); - else - pkgs[ch] = strcpy(pkgnames[ch], cp); + } else + lpp = alloc_lpkg(cp); } } + if (lpp) + TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link); } } /* If no packages, yelp */ @@ -161,7 +156,7 @@ main(int argc, char **argv) else if (ch > 1 && AddMode == MASTER) warnx("only one package name may be specified with master mode"), usage(); - if ((error = pkg_perform(pkgs)) != 0) { + if ((error = pkg_perform(&pkgs)) != 0) { if (Verbose) warnx("%d package addition(s) failed", error); return error; diff --git a/usr.sbin/pkg_install/add/perform.c b/usr.sbin/pkg_install/add/perform.c index c17a0a171ee..76040e7e33c 100644 --- a/usr.sbin/pkg_install/add/perform.c +++ b/usr.sbin/pkg_install/add/perform.c @@ -1,11 +1,11 @@ -/* $NetBSD: perform.c,v 1.28 1998/11/07 23:16:50 hubertf Exp $ */ +/* $NetBSD: perform.c,v 1.29 1999/03/22 05:02:40 hubertf Exp $ */ #include <sys/cdefs.h> #ifndef lint #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.28 1998/11/07 23:16:50 hubertf Exp $"); +__RCSID("$NetBSD: perform.c,v 1.29 1999/03/22 05:02:40 hubertf Exp $"); #endif #endif @@ -602,9 +602,10 @@ cleanup(int signo) } int -pkg_perform(char **pkgs) +pkg_perform(lpkg_head_t *pkgs) { - int i, err_cnt = 0; + int err_cnt = 0; + lpkg_t *lpp; signal(SIGINT, cleanup); signal(SIGHUP, cleanup); @@ -612,8 +613,11 @@ pkg_perform(char **pkgs) if (AddMode == SLAVE) err_cnt = pkg_do(NULL); else { - for (i = 0; pkgs[i]; i++) - err_cnt += pkg_do(pkgs[i]); + while ((lpp = TAILQ_FIRST(pkgs))) { + err_cnt += pkg_do(lpp->lp_name); + TAILQ_REMOVE(pkgs, lpp, lp_link); + free_lpkg(lpp); + } } return err_cnt; } diff --git a/usr.sbin/pkg_install/add/pkg_add.1 b/usr.sbin/pkg_install/add/pkg_add.1 index 8d7a1874b4b..63956ef7990 100644 --- a/usr.sbin/pkg_install/add/pkg_add.1 +++ b/usr.sbin/pkg_install/add/pkg_add.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: pkg_add.1,v 1.12 1999/03/07 11:58:27 mycroft Exp $ +.\" $NetBSD: pkg_add.1,v 1.13 1999/03/22 05:02:40 hubertf Exp $ .\" .\" FreeBSD install - a package for the installation and maintainance .\" of non-core utilities. @@ -364,6 +364,7 @@ period. Where to register packages instead of .Pa /var/db/pkg . .Sh SEE ALSO +.Xr pkg_admin 1 , .Xr pkg_create 1 , .Xr pkg_delete 1 , .Xr pkg_info 1 , diff --git a/usr.sbin/pkg_install/admin/main.c b/usr.sbin/pkg_install/admin/main.c index 9eadafb930e..490fc3d9557 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.2 1999/03/03 00:35:16 hubertf Exp $ */ +/* $NetBSD: main.c,v 1.3 1999/03/22 05:02:40 hubertf Exp $ */ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: main.c,v 1.2 1999/03/03 00:35:16 hubertf Exp $"); +__RCSID("$NetBSD: main.c,v 1.3 1999/03/22 05:02:40 hubertf Exp $"); #endif /* @@ -51,10 +51,12 @@ void usage(void); extern const char *__progname; /* from crt0.o */ +int filecnt; + /* * assumes CWD is in /var/db/pkg/<pkg>! */ -static void check1pkg(const char *pkgdir, int *filecnt) +static void check1pkg(const char *pkgdir) { FILE *f; plist_t *p; @@ -103,7 +105,7 @@ static void check1pkg(const char *pkgdir, int *filecnt) } } - (*filecnt)++; + filecnt++; } break; case PLIST_CWD: @@ -150,7 +152,9 @@ static void rebuild(void) plist_t *p; char *PkgName, dir[FILENAME_MAX], *dirp=NULL; char *PkgDBDir=NULL, file[FILENAME_MAX]; - int filecnt=0, pkgcnt=0; + int pkgcnt=0; + + filecnt=0; if (unlink(_pkgdb_getPKGDB_FILE()) != 0 && errno!=ENOENT) err(1, "unlink %s", _pkgdb_getPKGDB_FILE()); @@ -268,8 +272,10 @@ static void checkall(void) { DIR *dp; struct dirent *de; - int filecnt=0, pkgcnt=0; + int pkgcnt=0; + filecnt = 0; + setbuf(stdout, NULL); chdir(_pkgdb_getPKGDB_DIR()); @@ -286,7 +292,7 @@ static void checkall(void) chdir(de->d_name); - check1pkg(de->d_name, &filecnt); + check1pkg(de->d_name); printf("."); chdir(".."); @@ -303,6 +309,22 @@ static void checkall(void) pkgcnt, (pkgcnt==1)?"":"s"); } +static int +checkpattern_fn(const char *pkg, char *data) +{ + int rc; + + rc = chdir(pkg); + if (rc == -1) + err(1, "Cannot chdir to %s/%s", _pkgdb_getPKGDB_DIR(), pkg); + + check1pkg(pkg); + printf("."); + + chdir(".."); + + return 0; +} int main(int argc, char *argv[]) { @@ -320,9 +342,11 @@ int main(int argc, char *argv[]) if (*argv != NULL) { /* args specified */ - int filecnt=0, pkgcnt=0; + int pkgcnt=0; int rc; - + + filecnt = 0; + setbuf(stdout, NULL); rc = chdir(_pkgdb_getPKGDB_DIR()); @@ -330,14 +354,19 @@ int main(int argc, char *argv[]) err(1, "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); + }else { rc = chdir(*argv); - if (rc == -1) - err(1, "Cannot chdir to %s/%s", _pkgdb_getPKGDB_DIR(), *argv); - - check1pkg(*argv, &filecnt); - printf("."); + if (rc == -1) + err(1, "Cannot chdir to %s/%s", _pkgdb_getPKGDB_DIR(), *argv); - chdir(".."); + check1pkg(*argv); + printf("."); + + chdir(".."); + } pkgcnt++; argv++; diff --git a/usr.sbin/pkg_install/admin/pkg_admin.1 b/usr.sbin/pkg_install/admin/pkg_admin.1 index 7d0f757386d..3ef1fd492e9 100644 --- a/usr.sbin/pkg_install/admin/pkg_admin.1 +++ b/usr.sbin/pkg_install/admin/pkg_admin.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: pkg_admin.1,v 1.3 1999/03/10 08:20:26 erh Exp $ +.\" $NetBSD: pkg_admin.1,v 1.4 1999/03/22 05:02:40 hubertf Exp $ .\" .\" Copyright (c) 1999 Hubert Feyrer. All rights reserved. .\" @@ -66,9 +66,11 @@ Use this command to check the files belonging to some or all of the packages installed on the local machine against their MD5 checksum noted in their +CONTENTS files. If no additional argument is given, the files of all installed packages are installed, else only the named -packages will be ckecked. +packages will be ckecked (wildcards can be used here, see +.Xr pkg_info 1 +). .Pp -The named packages' +CONTENTS files will be parsed and the MD5 +The packages' +CONTENTS files will be parsed and the MD5 checksum will be checked for every file found. A warning message is printed if the expected checksum differs from the checksum of the file on disk. diff --git a/usr.sbin/pkg_install/create/create.h b/usr.sbin/pkg_install/create/create.h index 6d3b21aa2bb..3d2e26757cb 100644 --- a/usr.sbin/pkg_install/create/create.h +++ b/usr.sbin/pkg_install/create/create.h @@ -1,4 +1,4 @@ -/* $NetBSD: create.h,v 1.10 1999/01/19 17:01:59 hubertf Exp $ */ +/* $NetBSD: create.h,v 1.11 1999/03/22 05:02:40 hubertf Exp $ */ /* from FreeBSD Id: create.h,v 1.13 1997/10/08 07:46:19 charnier Exp */ @@ -48,7 +48,6 @@ extern int RelativeLinks; extern int ReorderDirs; void check_list(char *, package_t *, const char *); -int pkg_perform(char **); void copy_plist(char *, package_t *); #endif /* _INST_CREATE_H_INCLUDE */ diff --git a/usr.sbin/pkg_install/create/main.c b/usr.sbin/pkg_install/create/main.c index d0924cc401a..534422fa66f 100644 --- a/usr.sbin/pkg_install/create/main.c +++ b/usr.sbin/pkg_install/create/main.c @@ -1,11 +1,11 @@ -/* $NetBSD: main.c,v 1.12 1999/01/19 17:01:59 hubertf Exp $ */ +/* $NetBSD: main.c,v 1.13 1999/03/22 05:02:40 hubertf Exp $ */ #include <sys/cdefs.h> #ifndef lint #if 0 static const char *rcsid = "from FreeBSD Id: main.c,v 1.17 1997/10/08 07:46:23 charnier Exp"; #else -__RCSID("$NetBSD: main.c,v 1.12 1999/01/19 17:01:59 hubertf Exp $"); +__RCSID("$NetBSD: main.c,v 1.13 1999/03/22 05:02:40 hubertf Exp $"); #endif #endif @@ -65,9 +65,9 @@ int main(int argc, char **argv) { int ch; - char **pkgs, **start; + lpkg_head_t pkgs; + lpkg_t *lpp; - pkgs = start = argv; while ((ch = getopt(argc, argv, Options)) != -1) switch(ch) { case 'v': @@ -163,18 +163,25 @@ main(int argc, char **argv) argc -= optind; argv += optind; + TAILQ_INIT(&pkgs); + /* Get all the remaining package names, if any */ - while (*argv) - *pkgs++ = *argv++; + while (*argv) { + lpp = alloc_lpkg(*argv); + TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link); + argv++; + } /* If no packages, yelp */ - if (pkgs == start) + lpp = TAILQ_FIRST(&pkgs); + if (lpp == NULL) warnx("missing package name"), usage(); - *pkgs = NULL; - if (start[1]) - warnx("only one package name allowed ('%s' extraneous)", start[1]), + lpp = TAILQ_NEXT(lpp, lp_link); + if (lpp != NULL) + warnx("only one package name allowed ('%s' extraneous)", + lpp->lp_name), usage(); - if (!pkg_perform(start)) { + if (!pkg_perform(&pkgs)) { if (Verbose) warnx("package creation failed"); return 1; diff --git a/usr.sbin/pkg_install/create/perform.c b/usr.sbin/pkg_install/create/perform.c index 724145bb2fd..0d7a3705959 100644 --- a/usr.sbin/pkg_install/create/perform.c +++ b/usr.sbin/pkg_install/create/perform.c @@ -1,11 +1,11 @@ -/* $NetBSD: perform.c,v 1.16 1999/03/09 11:10:40 agc Exp $ */ +/* $NetBSD: perform.c,v 1.17 1999/03/22 05:02:40 hubertf Exp $ */ #include <sys/cdefs.h> #ifndef lint #if 0 static const char *rcsid = "from FreeBSD Id: perform.c,v 1.38 1997/10/13 15:03:51 jkh Exp"; #else -__RCSID("$NetBSD: perform.c,v 1.16 1999/03/09 11:10:40 agc Exp $"); +__RCSID("$NetBSD: perform.c,v 1.17 1999/03/22 05:02:40 hubertf Exp $"); #endif #endif @@ -187,13 +187,17 @@ cleanup(int sig) } int -pkg_perform(char **pkgs) +pkg_perform(lpkg_head_t *pkgs) { - char *pkg = *pkgs; /* Only one arg to create */ + char *pkg; char *cp; FILE *pkg_in, *fp; package_t plist; char *suffix; /* What we tack on to the end of the finished package */ + lpkg_t *lpp; + + lpp = TAILQ_FIRST(pkgs); + pkg = lpp->lp_name; /* Only one arg to create */ /* Preliminary setup */ sanity_check(); diff --git a/usr.sbin/pkg_install/create/pkg_create.1 b/usr.sbin/pkg_install/create/pkg_create.1 index 4a438ac602e..42e48dd11e5 100644 --- a/usr.sbin/pkg_install/create/pkg_create.1 +++ b/usr.sbin/pkg_install/create/pkg_create.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: pkg_create.1,v 1.14 1999/03/07 11:58:28 mycroft Exp $ +.\" $NetBSD: pkg_create.1,v 1.15 1999/03/22 05:02:40 hubertf Exp $ .\" .\" FreeBSD install - a package for the installation and maintainance .\" of non-core utilities. @@ -430,6 +430,7 @@ and so cannot co-exist on the same system. .El .Sh SEE ALSO .Xr pkg_add 1 , +.Xr pkg_admin 1 , .Xr pkg_delete 1 , .Xr pkg_info 1 , .Xr sysconf 3 . diff --git a/usr.sbin/pkg_install/delete/main.c b/usr.sbin/pkg_install/delete/main.c index f5b8c445834..cc1308bb51f 100644 --- a/usr.sbin/pkg_install/delete/main.c +++ b/usr.sbin/pkg_install/delete/main.c @@ -1,11 +1,11 @@ -/* $NetBSD: main.c,v 1.10 1999/03/08 00:20:21 hubertf Exp $ */ +/* $NetBSD: main.c,v 1.11 1999/03/22 05:02:40 hubertf Exp $ */ #include <sys/cdefs.h> #ifndef lint #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.10 1999/03/08 00:20:21 hubertf Exp $"); +__RCSID("$NetBSD: main.c,v 1.11 1999/03/22 05:02:40 hubertf Exp $"); #endif #endif @@ -45,6 +45,7 @@ Boolean File2Pkg = FALSE; Boolean Recurse_up = FALSE; Boolean Recurse_down = FALSE; Boolean OnlyDeleteFromPkgDB = FALSE; +lpkg_head_t pkgs; static void usage(void) @@ -53,15 +54,25 @@ usage(void) exit(1); } +static int +find_fn(const char *pkg, char *data) +{ + lpkg_t *lpp; + + lpp=alloc_lpkg(pkg); + TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link); + + return 0; +} + int main(int argc, char **argv) { int ch, error; - char **pkgs, **start; + lpkg_t *lpp; ProgramPath = argv[0]; - pkgs = start = argv; while ((ch = getopt(argc, argv, Options)) != -1) switch(ch) { case 'v': @@ -115,6 +126,8 @@ main(int argc, char **argv) argc -= optind; argv += optind; + TAILQ_INIT(&pkgs); + /* Get all the remaining package names, if any */ if (File2Pkg) if (pkgdb_open(1)==-1) { @@ -122,7 +135,7 @@ main(int argc, char **argv) } /* Get all the remaining package names, if any */ while (*argv) { - /* pkgdb: if -F flag given, don't add pkgnames to *pkgs but + /* pkgdb: if -F flag given, don't add pkgnames to pkgs but * rather resolve the given filenames to pkgnames using * pkgdb_retrieve, then add them. */ @@ -131,12 +144,19 @@ main(int argc, char **argv) s = pkgdb_retrieve(*argv); - if (s) - *pkgs++ = s; - else - warnx("No matching pkg for %s.", *argv); + if (s) { + lpp = alloc_lpkg(s); + TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link); + } else + errx(1, "No matching pkg for %s in pkgdb.", *argv); } else { - *pkgs++ = *argv; + if (ispkgpattern(*argv)) { + if (findmatchingname(_pkgdb_getPKGDB_DIR(), *argv, find_fn, NULL) == 0) + errx(1, "No matching pkg for %s.", *argv); + }else { + lpp = alloc_lpkg(*argv); + TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link); + } } argv++; } @@ -145,9 +165,8 @@ main(int argc, char **argv) pkgdb_close(); /* If no packages, yelp */ - if (pkgs == start) + if (TAILQ_FIRST(&pkgs) == NULL) warnx("missing package name(s)"), usage(); - *pkgs = NULL; if (!Fake && getuid() != 0) errx(1, "you must be root to delete packages"); if (OnlyDeleteFromPkgDB) { @@ -155,7 +174,6 @@ main(int argc, char **argv) * the pkg itself. Used by "make reinstall" in bsd.pkg.mk */ char *key, *val; - char **s; if (pkgdb_open(0)==-1) { err(1, "cannot open %s", _pkgdb_getPKGDB_FILE()); @@ -165,27 +183,32 @@ main(int argc, char **argv) while ((key=pkgdb_iter())) { val=pkgdb_retrieve(key); - for (s=start; *s; s++) { - if (strcmp(val, *s) == 0) { - if (Verbose) - printf("Removing file %s from pkgdb\n", key); - - errno=0; - if (pkgdb_remove(key)) { - if (errno) - printf("Error removing %s from pkgdb: %s\n", key, strerror(errno)); - else - printf("Key %s not present in pkgdb?!\n", key); - error = 1; + lpp = TAILQ_FIRST(&pkgs); + if (lpp != NULL) { + do { + if (strcmp(val, lpp->lp_name) == 0) { + if (Verbose) + printf("Removing file %s from pkgdb\n", key); + + errno=0; + if (pkgdb_remove(key)) { + if (errno) + printf("Error removing %s from pkgdb: %s\n", key, strerror(errno)); + else + printf("Key %s not present in pkgdb?!\n", key); + error = 1; + } } - } + + lpp = TAILQ_NEXT(lpp, lp_link); + } while(lpp != NULL); } } pkgdb_close(); return error; - } else if ((error = pkg_perform(start)) != 0) { + } else if ((error = pkg_perform(&pkgs)) != 0) { if (Verbose) warnx("%d package deletion(s) failed", error); return error; diff --git a/usr.sbin/pkg_install/delete/perform.c b/usr.sbin/pkg_install/delete/perform.c index ea0c2e4fc5c..5e7a01a8319 100644 --- a/usr.sbin/pkg_install/delete/perform.c +++ b/usr.sbin/pkg_install/delete/perform.c @@ -1,11 +1,11 @@ -/* $NetBSD: perform.c,v 1.21 1999/03/22 03:24:04 abs Exp $ */ +/* $NetBSD: perform.c,v 1.22 1999/03/22 05:02:40 hubertf Exp $ */ #include <sys/cdefs.h> #ifndef lint #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.21 1999/03/22 03:24:04 abs Exp $"); +__RCSID("$NetBSD: perform.c,v 1.22 1999/03/22 05:02:40 hubertf Exp $"); #endif #endif @@ -57,37 +57,19 @@ __RCSID("$NetBSD: perform.c,v 1.21 1999/03/22 03:24:04 abs Exp $"); * Added the require find and require delete code */ -#include <sys/queue.h> #include <err.h> #include <fcntl.h> #include "lib.h" #include "delete.h" -/* This should only happen on 1.3 and 1.3.1, not 1.3.2 and up */ -#ifndef TAILQ_FIRST -#define TAILQ_FIRST(head) ((head)->tqh_first) -#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) -#endif - - -typedef struct _rec_del_t { - TAILQ_ENTRY(_rec_del_t) rd_link; - char *rd_name; -} rec_del_t; - -TAILQ_HEAD(_rec_del_head_t, _rec_del_t); -typedef struct _rec_del_head_t rec_del_head_t; /* In which direction to search in require_find() */ typedef enum { FIND_UP, FIND_DOWN } rec_find_t; -static rec_del_t *alloc_rec_del(const char *); -static rec_del_t *find_on_queue(rec_del_head_t *, const char *); -static void free_rec_del(rec_del_t *); -static int require_find_recursive_up(rec_del_t *); -static int require_find_recursive_down(rec_del_t *, package_t *); +static int require_find_recursive_up(lpkg_t *); +static int require_find_recursive_down(lpkg_t *, package_t *); static int require_find(char *, rec_find_t); static int require_delete(char *, int); static void require_print(void); @@ -99,8 +81,8 @@ static char pkgdir[FILENAME_MAX]; static package_t Plist; -static rec_del_head_t rdfindq; -static rec_del_head_t rddelq; +static lpkg_head_t lpfindq; +static lpkg_head_t lpdelq; static void sanity_check(char *pkg) @@ -180,44 +162,12 @@ undepend(const char *deppkgname, char *pkg2delname) return 0; } -/* add a package to the recursive delete list */ -rec_del_t * -alloc_rec_del(const char *pkgname) -{ - rec_del_t *rdp; - - if ((rdp = malloc(sizeof(*rdp))) == 0) - err(1, "cannot allocate recursion data"); - if ((rdp->rd_name = strdup(pkgname)) == 0) - err(1, "cannot allocate recursion data"); - return (rdp); -} - -void -free_rec_del(rec_del_t *rdp) -{ - free(rdp->rd_name); - free(rdp); -} - -rec_del_t * -find_on_queue(rec_del_head_t *qp, const char *name) -{ - rec_del_t *rdp; - - for (rdp = TAILQ_FIRST(qp); rdp; rdp = TAILQ_NEXT(rdp, rd_link)) - if (!strcmp(name, rdp->rd_name)) - return (rdp); - return (0); -} - - -/* delete from directory 'home' all packages on rec_del_list +/* delete from directory 'home' all packages on lpkg_list * if tryall is set, ignore errors from pkg_delete */ int require_delete(char *home, int tryall) { - rec_del_t *rdp; + lpkg_t *lpp; int rv, fail; char *tmp; int oldcwd; @@ -232,8 +182,8 @@ require_delete(char *home, int tryall) /* walk list of things to delete */ fail = 0; - rdp = TAILQ_FIRST(&rddelq); - for (; rdp; rdp = TAILQ_NEXT(rdp, rd_link)) { + lpp = TAILQ_FIRST(&lpdelq); + for (; lpp; lpp = TAILQ_NEXT(lpp, lp_link)) { /* go to the db dir */ if (chdir(pkgdir) == FAIL) { warnx("unable to change directory to %s, deinstall failed (1)", @@ -243,8 +193,8 @@ require_delete(char *home, int tryall) } /* look to see if package was already deleted */ - if (!fexists(rdp->rd_name)) { - warnx("%s appears to have been deleted", rdp->rd_name); + if (!fexists(lpp->lp_name)) { + warnx("%s appears to have been deleted", lpp->lp_name); continue; } @@ -256,7 +206,7 @@ require_delete(char *home, int tryall) } if (Verbose) - printf("deinstalling %s\n", rdp->rd_name); + printf("deinstalling %s\n", lpp->lp_name); /* delete the package */ if (Fake) @@ -270,12 +220,12 @@ require_delete(char *home, int tryall) NoDeInstall ? "-D" : "", CleanDirs ? "-d" : "", Fake ? "-n" : "", - rdp->rd_name); + lpp->lp_name); /* check for delete failure */ if (rv && !tryall) { fail = 1; - warnx("had problem removing %s%s", rdp->rd_name, + warnx("had problem removing %s%s", lpp->lp_name, Force ? ", continuing" : ""); if (!Force) break; @@ -283,9 +233,9 @@ require_delete(char *home, int tryall) } /* cleanup list */ - while ((rdp = TAILQ_FIRST(&rddelq))) { - TAILQ_REMOVE(&rddelq, rdp, rd_link); - free_rec_del(rdp); + while ((lpp = TAILQ_FIRST(&lpdelq))) { + TAILQ_REMOVE(&lpdelq, lpp, lp_link); + free_lpkg(lpp); } /* return to the log dir */ @@ -300,23 +250,23 @@ require_delete(char *home, int tryall) /* recursively find all packages "up" the tree (follow +REQUIRED_BY) * return 1 on errors */ int -require_find_recursive_up(rec_del_t *thisrdp) +require_find_recursive_up(lpkg_t *thislpp) { - rec_del_head_t reqq; - rec_del_t *rdp = NULL; + lpkg_head_t reqq; + lpkg_t *lpp = NULL; FILE *cfile; char *nl, *tmp; /* see if we are on the find queue -- circular dependency */ - if ((rdp = find_on_queue(&rdfindq, thisrdp->rd_name))) { - warnx("circular dependency found for pkg %s", rdp->rd_name); + if ((lpp = find_on_queue(&lpfindq, thislpp->lp_name))) { + warnx("circular dependency found for pkg %s", lpp->lp_name); return (1); } TAILQ_INIT(&reqq); (void)snprintf(pkgdir, sizeof(pkgdir), "%s/%s", - (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR, thisrdp->rd_name); + (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR, thislpp->lp_name); /* change to package's dir */ if (chdir(pkgdir) == FAIL) { @@ -337,39 +287,39 @@ require_find_recursive_up(rec_del_t *thisrdp) while (fgets(linebuf, sizeof(linebuf), cfile)) { if ((nl = strrchr(linebuf, '\n'))) *nl = 0; - rdp = alloc_rec_del(linebuf); - TAILQ_INSERT_TAIL(&reqq, rdp, rd_link); + lpp = alloc_lpkg(linebuf); + TAILQ_INSERT_TAIL(&reqq, lpp, lp_link); } fclose(cfile); /* put ourselves on the top of the find queue */ - TAILQ_INSERT_HEAD(&rdfindq, thisrdp, rd_link); + TAILQ_INSERT_HEAD(&lpfindq, thislpp, lp_link); - while ((rdp = TAILQ_FIRST(&reqq))) { + while ((lpp = TAILQ_FIRST(&reqq))) { /* remove a direct req from our queue */ - TAILQ_REMOVE(&reqq, rdp, rd_link); + TAILQ_REMOVE(&reqq, lpp, lp_link); /* find direct required requires */ - if (require_find_recursive_up(rdp)) + if (require_find_recursive_up(lpp)) goto fail; /* all requires taken care of, add to tail of delete queue * if not already there */ - if (find_on_queue(&rddelq, rdp->rd_name)) - free_rec_del(rdp); + if (find_on_queue(&lpdelq, lpp->lp_name)) + free_lpkg(lpp); else - TAILQ_INSERT_TAIL(&rddelq, rdp, rd_link); + TAILQ_INSERT_TAIL(&lpdelq, lpp, lp_link); } /* take ourselves off the find queue */ - TAILQ_REMOVE(&rdfindq, thisrdp, rd_link); + TAILQ_REMOVE(&lpfindq, thislpp, lp_link); return (0); fail: - while ((rdp = TAILQ_FIRST(&reqq))) { - TAILQ_REMOVE(&reqq, rdp, rd_link); - free_rec_del(rdp); + while ((lpp = TAILQ_FIRST(&reqq))) { + TAILQ_REMOVE(&reqq, lpp, lp_link); + free_lpkg(lpp); } return (1); } @@ -377,35 +327,35 @@ fail: /* recursively find all packages "down" the tree (follow @pkgdep) * return 1 on errors */ int -require_find_recursive_down(rec_del_t *thisrdp, package_t *plist) +require_find_recursive_down(lpkg_t *thislpp, package_t *plist) { plist_t *p; - rec_del_t *rdp, *rdp2; - rec_del_head_t reqq; + lpkg_t *lpp, *lpp2; + lpkg_head_t reqq; int rc, fail=0; /* see if we are on the find queue -- circular dependency */ - if ((rdp = find_on_queue(&rdfindq, thisrdp->rd_name))) { - warnx("circular dependency found for pkg %s", rdp->rd_name); + if ((lpp = find_on_queue(&lpfindq, thislpp->lp_name))) { + warnx("circular dependency found for pkg %s", lpp->lp_name); return (1); } TAILQ_INIT(&reqq); /* width-first scan */ - /* first enqueue all @pkgdep's to rddelq, then (further below) + /* first enqueue all @pkgdep's to lpdelq, then (further below) * go in recursively */ for (p = plist->head; p ; p = p->next) { switch(p->type) { case PLIST_PKGDEP: - rdp = alloc_rec_del(p->name); - TAILQ_INSERT_TAIL(&reqq, rdp, rd_link); - - rdp2 = find_on_queue(&rddelq, p->name); - if (rdp2) - TAILQ_REMOVE(&rddelq, rdp2, rd_link); - rdp = alloc_rec_del(p->name); - TAILQ_INSERT_TAIL(&rddelq, rdp, rd_link); + lpp = alloc_lpkg(p->name); + TAILQ_INSERT_TAIL(&reqq, lpp, lp_link); + + lpp2 = find_on_queue(&lpdelq, p->name); + if (lpp2) + TAILQ_REMOVE(&lpdelq, lpp2, lp_link); + lpp = alloc_lpkg(p->name); + TAILQ_INSERT_TAIL(&lpdelq, lpp, lp_link); break; default: @@ -413,14 +363,14 @@ require_find_recursive_down(rec_del_t *thisrdp, package_t *plist) } } - while ((rdp = TAILQ_FIRST(&reqq))) { + while ((lpp = TAILQ_FIRST(&reqq))) { FILE *cfile; package_t rPlist; char *tmp; plist_t *p; /* remove a direct req from our queue */ - TAILQ_REMOVE(&reqq, rdp, rd_link); + TAILQ_REMOVE(&reqq, lpp, lp_link); /* Reset some state */ rPlist.head = NULL; @@ -428,8 +378,8 @@ require_find_recursive_down(rec_del_t *thisrdp, package_t *plist) /* prepare for recursion */ chdir((tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR); - chdir(rdp->rd_name); - sanity_check(rdp->rd_name); + chdir(lpp->lp_name); + sanity_check(lpp->lp_name); cfile = fopen(CONTENTS_FNAME, "r"); if (!cfile) { @@ -444,30 +394,30 @@ require_find_recursive_down(rec_del_t *thisrdp, package_t *plist) fclose(cfile); p = find_plist(&rPlist, PLIST_CWD); if (!p) { - warnx("package '%s' doesn't have a prefix", rdp->rd_name); + warnx("package '%s' doesn't have a prefix", lpp->lp_name); fail=1; goto fail; } /* put ourselves on the top of the find queue */ - TAILQ_INSERT_HEAD(&rdfindq, thisrdp, rd_link); + TAILQ_INSERT_HEAD(&lpfindq, thislpp, lp_link); - rc=require_find_recursive_down(rdp, &rPlist); + rc=require_find_recursive_down(lpp, &rPlist); if (rc) { fail=1; goto fail; } /* take ourselves off the find queue */ - TAILQ_REMOVE(&rdfindq, thisrdp, rd_link); - free_rec_del(rdp); + TAILQ_REMOVE(&lpfindq, thislpp, lp_link); + free_lpkg(lpp); } fail: /* Clean out reqq */ - while ((rdp = TAILQ_FIRST(&reqq))) { - TAILQ_REMOVE(&reqq, rdp, rd_link); - free_rec_del(rdp); + while ((lpp = TAILQ_FIRST(&reqq))) { + TAILQ_REMOVE(&reqq, lpp, lp_link); + free_lpkg(lpp); } return fail; @@ -476,22 +426,22 @@ require_find_recursive_down(rec_del_t *thisrdp, package_t *plist) int require_find(char *pkg, rec_find_t updown) { - rec_del_t *rdp; + lpkg_t *lpp; int rv=0; - TAILQ_INIT(&rdfindq); - TAILQ_INIT(&rddelq); + TAILQ_INIT(&lpfindq); + TAILQ_INIT(&lpdelq); - rdp = alloc_rec_del(pkg); + lpp = alloc_lpkg(pkg); switch (updown) { case FIND_UP: - rv = require_find_recursive_up(rdp); + rv = require_find_recursive_up(lpp); break; case FIND_DOWN: - rv = require_find_recursive_down(rdp, &Plist); + rv = require_find_recursive_down(lpp, &Plist); break; } - free_rec_del(rdp); + free_lpkg(lpp); return (rv); } @@ -499,13 +449,13 @@ require_find(char *pkg, rec_find_t updown) void require_print(void) { - rec_del_t *rdp; + lpkg_t *lpp; /* print all but last -- deleting if requested */ - while ((rdp = TAILQ_FIRST(&rddelq))) { - TAILQ_REMOVE(&rddelq, rdp, rd_link); - fprintf(stderr, "\t%s\n", rdp->rd_name); - free_rec_del(rdp); + while ((lpp = TAILQ_FIRST(&lpdelq))) { + TAILQ_REMOVE(&lpdelq, lpp, lp_link); + fprintf(stderr, "\t%s\n", lpp->lp_name); + free_lpkg(lpp); } } @@ -636,18 +586,21 @@ pkg_do(char *pkg) } int -pkg_perform(char **pkgs) +pkg_perform(lpkg_head_t *pkgs) { - int i, err_cnt = 0; + int err_cnt = 0; int oldcwd; + lpkg_t *lpp; /* save cwd */ oldcwd=open(".", O_RDONLY, 0); if (oldcwd == -1) err(1, "cannot open \".\""); - for (i = 0; pkgs[i]; i++) { - err_cnt += pkg_do(pkgs[i]); + while ((lpp = TAILQ_FIRST(pkgs))) { + err_cnt += pkg_do(lpp->lp_name); + TAILQ_REMOVE(pkgs, lpp, lp_link); + free_lpkg(lpp); if (fchdir(oldcwd) == FAIL) err(1,"unable to change to previous directory"); } diff --git a/usr.sbin/pkg_install/delete/pkg_delete.1 b/usr.sbin/pkg_install/delete/pkg_delete.1 index 61a20b03760..109ee8c6790 100644 --- a/usr.sbin/pkg_install/delete/pkg_delete.1 +++ b/usr.sbin/pkg_install/delete/pkg_delete.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: pkg_delete.1,v 1.10 1999/03/08 00:20:21 hubertf Exp $ +.\" $NetBSD: pkg_delete.1,v 1.11 1999/03/22 05:02:40 hubertf Exp $ .\" .\" FreeBSD install - a package for the installation and maintainance .\" of non-core utilities. @@ -69,7 +69,9 @@ command to examine the installed package control files. The following command line options are supported: .Bl -tag -width indent .It Ar pkg-name ... -The named packages are deinstalled. If the +The named packages are deinstalled, wildcards can be used, see +.Xr pkg_info 1 . +If the .Fl F flag is given, one or more (absolute) filenames may be specified and the Package Database will be consulted for the package to which the @@ -200,6 +202,7 @@ or .Cm pkg_add . .Sh SEE ALSO .Xr pkg_add 1 , +.Xr pkg_admin 1 , .Xr pkg_create 1 , .Xr pkg_info 1 , .Xr mktemp 3 , diff --git a/usr.sbin/pkg_install/info/main.c b/usr.sbin/pkg_install/info/main.c index 3054121b640..702604451ad 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.15 1999/03/04 00:35:05 hubertf Exp $ */ +/* $NetBSD: main.c,v 1.16 1999/03/22 05:02:41 hubertf Exp $ */ #include <sys/cdefs.h> #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.15 1999/03/04 00:35:05 hubertf Exp $"); +__RCSID("$NetBSD: main.c,v 1.16 1999/03/22 05:02:41 hubertf Exp $"); #endif #endif @@ -49,6 +49,7 @@ char PlayPen[FILENAME_MAX]; size_t PlayPenSize = sizeof(PlayPen); char *CheckPkg = NULL; size_t termwidth = 0; +lpkg_head_t pkgs; static void usage(void) @@ -60,13 +61,23 @@ usage(void) exit(1); } +static int +find_fn(const char *pkg, char *data) +{ + lpkg_t *lpp; + + lpp=alloc_lpkg(pkg); + TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link); + + return 0; +} + int main(int argc, char **argv) { - int ch; - char **pkgs, **start; + int ch, rc; + lpkg_t *lpp; - pkgs = start = argv; while ((ch = getopt(argc, argv, Options)) != -1) switch(ch) { case 'a': @@ -192,28 +203,36 @@ main(int argc, char **argv) pkgdb_close(); } + TAILQ_INIT(&pkgs); + /* Get all the remaining package names, if any */ if (File2Pkg && !AllInstalled) if (pkgdb_open(1)==-1) { err(1, "cannot open pkgdb"); } while (*argv) { - /* pkgdb: if -F flag given, don't add pkgnames to *pkgs but - * rather resolve the given filenames to pkgnames using - * pkgdb_retrieve, then add them. + /* pkgdb: if -F flag given, don't add pkgnames to the "pkgs" + * queue but rather resolve the given filenames to pkgnames + * using pkgdb_retrieve, then add them. */ if (File2Pkg) { char *s; s = pkgdb_retrieve(*argv); - if (s) - *pkgs++ = s; - else - warnx("No matching pkg for %s.", *argv); - /* should we bomb out here instead? - HF */ + if (s) { + lpp=alloc_lpkg(s); + TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link); + } else + errx(1, "No matching pkg for %s.", *argv); } else { - *pkgs++ = *argv; + if (ispkgpattern(*argv)){ + if (findmatchingname(_pkgdb_getPKGDB_DIR(), *argv, find_fn, NULL) == 0) + errx(1, "No matching pkg for %s.", *argv); + } else { + lpp=alloc_lpkg(*argv); + TAILQ_INSERT_TAIL(&pkgs, lpp, lp_link); + } } argv++; } @@ -222,9 +241,8 @@ main(int argc, char **argv) pkgdb_close(); /* If no packages, yelp */ - if (pkgs == start && !AllInstalled && !CheckPkg) + if (TAILQ_FIRST(&pkgs)==NULL && !AllInstalled && !CheckPkg) warnx("missing package name(s)"), usage(); - *pkgs = NULL; if (isatty(STDOUT_FILENO)) { const char *p; @@ -237,6 +255,7 @@ main(int argc, char **argv) termwidth = win.ws_col; } - exit(pkg_perform(start)); + rc = pkg_perform(&pkgs); + exit(rc); /* NOTREACHED */ } diff --git a/usr.sbin/pkg_install/info/perform.c b/usr.sbin/pkg_install/info/perform.c index 072598a8a84..88e60807aed 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.21 1999/03/04 00:35:05 hubertf Exp $ */ +/* $NetBSD: perform.c,v 1.22 1999/03/22 05:02:41 hubertf Exp $ */ #include <sys/cdefs.h> #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.21 1999/03/04 00:35:05 hubertf Exp $"); +__RCSID("$NetBSD: perform.c,v 1.22 1999/03/22 05:02:41 hubertf Exp $"); #endif #endif @@ -237,12 +237,11 @@ cleanup(int sig) } int -pkg_perform(char **pkgs) +pkg_perform(lpkg_head_t *pkgs) { struct dirent *dp; char *tmp; DIR *dirp; - int i; int err_cnt = 0; signal(SIGINT, cleanup); @@ -291,9 +290,13 @@ pkg_perform(char **pkgs) } } } else { - for (i = 0; pkgs[i]; i++) { - err_cnt += pkg_do(pkgs[i]); - } + lpkg_t *lpp; + + while ((lpp = TAILQ_FIRST(pkgs))) { + TAILQ_REMOVE(pkgs, lpp, lp_link); + err_cnt += pkg_do(lpp->lp_name); + free_lpkg(lpp); + } } return err_cnt; } diff --git a/usr.sbin/pkg_install/info/pkg_info.1 b/usr.sbin/pkg_install/info/pkg_info.1 index 8dc0498765d..5afa4affa74 100644 --- a/usr.sbin/pkg_install/info/pkg_info.1 +++ b/usr.sbin/pkg_install/info/pkg_info.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: pkg_info.1,v 1.15 1999/03/07 11:58:28 mycroft Exp $ +.\" $NetBSD: pkg_info.1,v 1.16 1999/03/22 05:02:41 hubertf Exp $ .\" .\" FreeBSD install - a package for the installation and maintainance .\" of non-core utilities. @@ -47,8 +47,13 @@ command. .Pp The .Ar pkg-name -may be the name of an installed package, the pathname to a package -distribution file, a filename belonging to an installed package (if -F +may be the name of an installed package, a pattern matching several +installed packages (see the +.Fl e +switch for a description of possible patterns), the pathname to a +package distribution file, a filename belonging to an installed +package (if +.Fl F is also given), or a URL to an ftp-available package. .Pp The following command-line options are supported: @@ -203,6 +208,7 @@ of pkg_info .Fl aF . .Sh SEE ALSO .Xr pkg_add 1 , +.Xr pkg_admin 1 , .Xr pkg_create 1 , .Xr pkg_delete 1 , .Xr mktemp 3 , diff --git a/usr.sbin/pkg_install/lib/Makefile b/usr.sbin/pkg_install/lib/Makefile index 9a28ecc5002..e2f467b4393 100644 --- a/usr.sbin/pkg_install/lib/Makefile +++ b/usr.sbin/pkg_install/lib/Makefile @@ -1,8 +1,8 @@ -# $NetBSD: Makefile,v 1.11 1999/03/13 23:22:44 lukem Exp $ +# $NetBSD: Makefile,v 1.12 1999/03/22 05:02:41 hubertf Exp $ # Original from FreeBSD, no rcs id. LIB= install -SRCS= exec.c file.c global.c pen.c pkgdb.c plist.c str.c +SRCS= exec.c file.c global.c lpkg.c pen.c pkgdb.c plist.c str.c MKLINT= no MKMAN= no diff --git a/usr.sbin/pkg_install/lib/lib.h b/usr.sbin/pkg_install/lib/lib.h index f159111a9bd..9ba15b4ee24 100644 --- a/usr.sbin/pkg_install/lib/lib.h +++ b/usr.sbin/pkg_install/lib/lib.h @@ -1,4 +1,4 @@ -/* $NetBSD: lib.h,v 1.20 1999/03/09 11:10:40 agc Exp $ */ +/* $NetBSD: lib.h,v 1.21 1999/03/22 05:02:41 hubertf Exp $ */ /* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */ @@ -28,6 +28,7 @@ #include <sys/param.h> #include <sys/stat.h> #include <sys/file.h> +#include <sys/queue.h> #include <ctype.h> #include <dirent.h> @@ -88,6 +89,13 @@ /* The name of the "prefix" environment variable given to scripts */ #define PKG_PREFIX_VNAME "PKG_PREFIX" +/* This should only happen on 1.3 and 1.3.1, not 1.3.2 and up */ +#ifndef TAILQ_FIRST +#define TAILQ_FIRST(head) ((head)->tqh_first) +#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) +#endif + + /* enumerated constants for plist entry types */ typedef enum pl_ent_t { PLIST_SHOW_ALL = -1, @@ -137,6 +145,14 @@ enum { LegibleChecksumLen = 33 }; +/* List of packages */ +typedef struct _lpkg_t { + TAILQ_ENTRY(_lpkg_t) lp_link; + char *lp_name; +} lpkg_t; +TAILQ_HEAD(_lpkg_head_t, _lpkg_t); +typedef struct _lpkg_head_t lpkg_head_t; + /* type of function to be handed to findmatchingname; return value of this * is currently ignored */ typedef int (*matchfn)(const char *found, char *data); @@ -213,8 +229,13 @@ char* pkgdb_iter(void); char* _pkgdb_getPKGDB_FILE(void); char* _pkgdb_getPKGDB_DIR(void); +/* List of packages functions */ +lpkg_t *alloc_lpkg(const char *); +lpkg_t *find_on_queue(lpkg_head_t *, const char *); +void free_lpkg(lpkg_t *); + /* For all */ -int pkg_perform(char **); +int pkg_perform(lpkg_head_t *); /* Externs */ extern Boolean Verbose; diff --git a/usr.sbin/pkg_install/lib/lpkg.c b/usr.sbin/pkg_install/lib/lpkg.c new file mode 100644 index 00000000000..1c514a6a8c7 --- /dev/null +++ b/usr.sbin/pkg_install/lib/lpkg.c @@ -0,0 +1,64 @@ +/* $NetBSD: lpkg.c,v 1.1 1999/03/22 05:02:41 hubertf Exp $ */ + +/* + * Copyright (c) 1999 Christian E. Hopps + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Package-list auxiliary functions + */ + +#include <err.h> +#include "lib.h" + +/* add a package to the recursive delete list */ +lpkg_t * +alloc_lpkg(const char *pkgname) +{ + lpkg_t *lpp; + + if ((lpp = malloc(sizeof(*lpp))) == 0) + err(1, "cannot allocate recursion data"); + if ((lpp->lp_name = strdup(pkgname)) == 0) + err(1, "cannot allocate recursion data"); + return (lpp); +} + +void +free_lpkg(lpkg_t *lpp) +{ + free(lpp->lp_name); + free(lpp); +} + +lpkg_t * +find_on_queue(lpkg_head_t *qp, const char *name) +{ + lpkg_t *lpp; + + for (lpp = TAILQ_FIRST(qp); lpp; lpp = TAILQ_NEXT(lpp, lp_link)) + if (!strcmp(name, lpp->lp_name)) + return (lpp); + return (0); +} diff --git a/usr.sbin/pkg_install/lib/str.c b/usr.sbin/pkg_install/lib/str.c index 311ec5e7ac0..854a4ff1a96 100644 --- a/usr.sbin/pkg_install/lib/str.c +++ b/usr.sbin/pkg_install/lib/str.c @@ -1,11 +1,11 @@ -/* $NetBSD: str.c,v 1.13 1999/03/06 02:16:25 hubertf Exp $ */ +/* $NetBSD: str.c,v 1.14 1999/03/22 05:02:41 hubertf Exp $ */ #include <sys/cdefs.h> #ifndef lint #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.13 1999/03/06 02:16:25 hubertf Exp $"); +__RCSID("$NetBSD: str.c,v 1.14 1999/03/22 05:02:41 hubertf Exp $"); #endif #endif @@ -261,6 +261,7 @@ findmatchingname(const char *dir, const char *pattern, matchfn match, char *data if (pmatch(pattern, dp->d_name)) { if (match) { match(dp->d_name, data); + /* return value ignored for now */ } found = 1; } |
