diff options
Diffstat (limited to 'usr.sbin/pkg_install/delete')
-rw-r--r-- | usr.sbin/pkg_install/delete/main.c | 33 | ||||
-rw-r--r-- | usr.sbin/pkg_install/delete/perform.c | 64 | ||||
-rw-r--r-- | usr.sbin/pkg_install/delete/pkg_delete.1 | 20 |
3 files changed, 56 insertions, 61 deletions
diff --git a/usr.sbin/pkg_install/delete/main.c b/usr.sbin/pkg_install/delete/main.c index e31df41ae12..6c889f9e44e 100644 --- a/usr.sbin/pkg_install/delete/main.c +++ b/usr.sbin/pkg_install/delete/main.c @@ -1,7 +1,8 @@ -/* $OpenBSD: main.c,v 1.6 1998/04/07 04:17:51 deraadt Exp $ */ +/* $OpenBSD: main.c,v 1.7 1998/09/07 22:30:15 marc Exp $ */ +#include <sys/cdefs.h> #ifndef lint -static char *rcsid = "$OpenBSD: main.c,v 1.6 1998/04/07 04:17:51 deraadt Exp $"; +static char *rcsid = "$OpenBSD: main.c,v 1.7 1998/09/07 22:30:15 marc Exp $"; #endif /* @@ -25,6 +26,7 @@ static char *rcsid = "$OpenBSD: main.c,v 1.6 1998/04/07 04:17:51 deraadt Exp $"; * */ +#include <err.h> #include "lib.h" #include "delete.h" @@ -33,14 +35,14 @@ static char Options[] = "hvDdnfp:"; char *Prefix = NULL; Boolean NoDeInstall = FALSE; Boolean CleanDirs = FALSE; -Boolean Force = FALSE; + +static void usage __P((void)); int main(int argc, char **argv) { int ch, error; char **pkgs, **start; - char *prog_name = argv[0]; pkgs = start = argv; while ((ch = getopt(argc, argv, Options)) != -1) @@ -73,7 +75,7 @@ main(int argc, char **argv) case 'h': case '?': default: - usage(prog_name, NULL); + usage(); break; } @@ -87,31 +89,22 @@ main(int argc, char **argv) /* If no packages, yelp */ if (pkgs == start) - usage(prog_name, "Missing package name(s)"); + warnx("missing package name(s)"), usage(); *pkgs = NULL; if (!Fake && getuid() != 0) - errx(1, "You must be root to delete packages."); + errx(1, "you must be root to delete packages"); if ((error = pkg_perform(start)) != 0) { if (Verbose) - fprintf(stderr, "%d package deletion(s) failed.\n", error); + warnx("%d package deletion(s) failed", error); return error; } else return 0; } -void -usage(const char *name, const char *fmt, ...) +static void +usage() { - va_list args; - - va_start(args, fmt); - if (fmt) { - fprintf(stderr, "%s: ", name); - vfprintf(stderr, fmt, args); - fprintf(stderr, "\n"); - } - va_end(args); - fprintf(stderr, "usage: %s [-vDdnf] [-p prefix] pkg ...\n", name); + fprintf(stderr, "usage: pkg_delete [-vDdnf] [-p prefix] pkg-name ...\n"); exit(1); } diff --git a/usr.sbin/pkg_install/delete/perform.c b/usr.sbin/pkg_install/delete/perform.c index 0478d86b566..f973f57e90a 100644 --- a/usr.sbin/pkg_install/delete/perform.c +++ b/usr.sbin/pkg_install/delete/perform.c @@ -1,7 +1,7 @@ -/* $OpenBSD: perform.c,v 1.3 1997/06/17 08:38:03 deraadt Exp $ */ +/* $OpenBSD: perform.c,v 1.4 1998/09/07 22:30:15 marc Exp $ */ #ifndef lint -static const char *rcsid = "$OpenBSD: perform.c,v 1.3 1997/06/17 08:38:03 deraadt Exp $"; +static const char *rcsid = "$OpenBSD: perform.c,v 1.4 1998/09/07 22:30:15 marc Exp $"; #endif /* @@ -24,6 +24,7 @@ static const char *rcsid = "$OpenBSD: perform.c,v 1.3 1997/06/17 08:38:03 deraad * */ +#include <err.h> #include "lib.h" #include "delete.h" @@ -61,33 +62,34 @@ pkg_do(char *pkg) sprintf(LogDir, "%s/%s", (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR, pkg); if (!fexists(LogDir)) { - whinge("No such package '%s' installed.", pkg); + warnx("no such package '%s' installed", pkg); return 1; } if (!getcwd(home, FILENAME_MAX)) - barf("Unable to get current working directory!"); + cleanup(0), errx(2, "unable to get current working directory!"); if (chdir(LogDir) == FAIL) { - whinge("Unable to change directory to %s! Deinstall failed.", LogDir); + warnx("unable to change directory to %s! deinstall failed", LogDir); return 1; } if (!isemptyfile(REQUIRED_BY_FNAME)) { char buf[512]; - whinge("Package `%s' is required by these other packages", pkg); - whinge("and may not be deinstalled%s:", Force ? " (but I'll delete it anyway)" : "" ); + warnx("package `%s' is required by these other packages\n" + "and may not be deinstalled%s:", + pkg, Force ? " (but I'll delete it anyway)" : "" ); cfile = fopen(REQUIRED_BY_FNAME, "r"); if (cfile) { while (fgets(buf, sizeof(buf), cfile)) fprintf(stderr, "%s", buf); fclose(cfile); } else - whinge("cannot open requirements file `%s'", REQUIRED_BY_FNAME); + warnx("cannot open requirements file `%s'", REQUIRED_BY_FNAME); if (!Force) return 1; } sanity_check(LogDir); cfile = fopen(CONTENTS_FNAME, "r"); if (!cfile) { - whinge("Unable to open '%s' file.", CONTENTS_FNAME); + warnx("unable to open '%s' file", CONTENTS_FNAME); return 1; } /* If we have a prefix, add it now */ @@ -96,17 +98,18 @@ pkg_do(char *pkg) read_plist(&Plist, cfile); fclose(cfile); p = find_plist(&Plist, PLIST_CWD); - if (p) - setenv(PKG_PREFIX_VNAME, p->name, 1); - else - unsetenv(PKG_PREFIX_VNAME); + if (!p) { + warnx("package '%s' doesn't have a prefix", pkg); + return 1; + } + setenv(PKG_PREFIX_VNAME, p->name, 1); if (fexists(REQUIRE_FNAME)) { if (Verbose) printf("Executing 'require' script.\n"); vsystem("chmod +x %s", REQUIRE_FNAME); /* be sure */ if (vsystem("./%s %s DEINSTALL", REQUIRE_FNAME, pkg)) { - whinge("Package %s fails requirements %s", pkg, - Force ? "." : "- not deleted."); + warnx("package %s fails requirements %s", pkg, + Force ? "" : "- not deleted"); if (!Force) return 1; } @@ -117,22 +120,24 @@ pkg_do(char *pkg) else { vsystem("chmod +x %s", DEINSTALL_FNAME); /* make sure */ if (vsystem("./%s %s DEINSTALL", DEINSTALL_FNAME, pkg)) { - whinge("De-Install script returned error status."); + warnx("deinstall script returned error status"); if (!Force) return 1; } } } if (chdir(home) == FAIL) - barf("Toto! This doesn't look like Kansas anymore!"); + cleanup(0), errx(2, "Toto! This doesn't look like Kansas anymore!"); if (!Fake) { /* Some packages aren't packed right, so we need to just ignore delete_package()'s status. Ugh! :-( */ if (delete_package(FALSE, CleanDirs, &Plist) == FAIL) - warn("Couldn't entirely delete package (perhaps the packing list is\n" - "incorrectly specified?)\n"); + warnx( + "couldn't entirely delete package (perhaps the packing list is\n" + "incorrectly specified?)"); if (vsystem("%s -r %s", REMOVE_CMD, LogDir)) { - whinge("Couldn't remove log entry in %s, de-install failed.", LogDir); - return 1; + warnx("couldn't remove log entry in %s, deinstall failed", LogDir); + if (!Force) + return 1; } } for (p = Plist.head; p ; p = p->next) { @@ -151,13 +156,16 @@ static void sanity_check(char *pkg) { if (!fexists(CONTENTS_FNAME)) - barf("Installed package %s has no %s file!", pkg, CONTENTS_FNAME); + cleanup(0), errx(2, "installed package %s has no %s file!", + pkg, CONTENTS_FNAME); } void cleanup(int sig) { /* Nothing to do */ + if(sig) /* in case this is ever used as a signal handler */ + exit(1); } static void @@ -174,21 +182,21 @@ undepend(PackingList p, char *pkgname) p->name, REQUIRED_BY_FNAME); fp = fopen(fname, "r"); if (fp == NULL) { - whinge("Couldn't open dependency file `%s'", fname); + warnx("couldn't open dependency file `%s'", fname); return; } sprintf(ftmp, "%s.XXXXXXXXXX", fname); s = mkstemp(ftmp); if (s == -1) { fclose(fp); - whinge("Couldn't open temp file `%s'", ftmp); + warnx("couldn't open temp file `%s'", ftmp); return; } fpwr = fdopen(s, "w"); if (fpwr == NULL) { close(s); fclose(fp); - whinge("Couldn't fdopen temp file `%s'", ftmp); + warnx("couldn't fdopen temp file `%s'", ftmp); remove(ftmp); return; } @@ -200,18 +208,18 @@ undepend(PackingList p, char *pkgname) } (void) fclose(fp); if (fchmod(s, 0644) == FAIL) { - whinge("Error changing permission of temp file `%s'", ftmp); + warnx("error changing permission of temp file `%s'", ftmp); fclose(fpwr); remove(ftmp); return; } if (fclose(fpwr) == EOF) { - whinge("Error closing temp file `%s'", ftmp); + warnx("error closing temp file `%s'", ftmp); remove(ftmp); return; } if (rename(ftmp, fname) == -1) - warn("Error renaming `%s' to `%s'", ftmp, fname); + warn("error renaming `%s' to `%s'", ftmp, fname); remove(ftmp); /* just in case */ return; } diff --git a/usr.sbin/pkg_install/delete/pkg_delete.1 b/usr.sbin/pkg_install/delete/pkg_delete.1 index 2009bbf6714..44b20bf25af 100644 --- a/usr.sbin/pkg_install/delete/pkg_delete.1 +++ b/usr.sbin/pkg_install/delete/pkg_delete.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: pkg_delete.1,v 1.2 1996/10/08 01:21:02 michaels Exp $ +.\" $OpenBSD: pkg_delete.1,v 1.3 1998/09/07 22:30:15 marc Exp $ .\" .\" FreeBSD install - a package for the installation and maintainance .\" of non-core utilities. @@ -15,14 +15,14 @@ .\" Jordan K. Hubbard .\" .\" -.\" @(#)pkg_delete.1 +.\" from FreeBSD: @(#)pkg_delete.1 .\" .Dd November 25, 1994 .Dt pkg_delete 1 .Os .Sh NAME .Nm pkg_delete -.Nd a utility for deleting previously installed software package distributions. +.Nd a utility for deleting previously installed software package distributions .Sh SYNOPSIS .Nm .Op Fl vDdnf @@ -64,28 +64,24 @@ command to examine the installed package control files. .Ef .Sh OPTIONS -The following command line options are supported. +The following command line options are supported: .Bl -tag -width indent .It Ar pkg-name ... The named packages are deinstalled. .It Fl v -Turns on verbose output. -.Em "Optional." +Turn on verbose output. .It Fl D If a deinstallation script exists for a given package, do not execute it. -.Em "Optional." .It Fl n Don't actually deinstall a package, just report the steps that would be taken if it were. -.Em "Optional." .It Fl p Ar prefix -Sets +Set .Ar prefix as the directory in which to delete files from any installed packages which do not explicitly set theirs. For most packages, the prefix will be set automatically to the installed location by .Xr pkg_add 1 . -.Em "Optional." .It Fl d Remove empty directories created by file cleanup. By default, only files/directories explicitly listed in a package's contents (either as @@ -95,11 +91,9 @@ directive) will be removed at deinstallation time. This option tells .Nm to also remove any directories that were emptied as a result of removing the package. -.Em "Optional." .It Fl f Force removal of the package, even if a dependency is recorded or the deinstall or require script fails. -.Em "Optional." .El .Pp @@ -129,7 +123,7 @@ then this is executed first as (where .Ar pkg-name is the name of the package in question and -.I DEINSTALL +.Ar DEINSTALL is a keyword denoting that this is a deinstallation) to see whether or not deinstallation should continue. A non-zero exit status means no, unless the |