From 1c390186cd64897d9b1b87cb01152be10cc44005 Mon Sep 17 00:00:00 2001 From: charnier Date: Wed, 8 Oct 1997 07:48:21 +0000 Subject: Use err(3). Cosmetics in usage string and man page. --- usr.sbin/pkg_install/delete/main.c | 39 ++++++++---------------- usr.sbin/pkg_install/delete/perform.c | 51 ++++++++++++++++++-------------- usr.sbin/pkg_install/delete/pkg_delete.1 | 16 ++++------ 3 files changed, 45 insertions(+), 61 deletions(-) (limited to 'usr.sbin/pkg_install/delete') diff --git a/usr.sbin/pkg_install/delete/main.c b/usr.sbin/pkg_install/delete/main.c index 4541646..863dc4a 100644 --- a/usr.sbin/pkg_install/delete/main.c +++ b/usr.sbin/pkg_install/delete/main.c @@ -1,5 +1,6 @@ #ifndef lint -static char *rcsid = "$Id: main.c,v 1.9 1997/03/31 05:10:48 imp Exp $"; +static const char rcsid[] = + "$Id: main.c,v 1.10 1997/09/18 14:08:40 phk Exp $"; #endif /* @@ -23,9 +24,9 @@ static char *rcsid = "$Id: main.c,v 1.9 1997/03/31 05:10:48 imp Exp $"; * */ +#include #include "lib.h" #include "delete.h" -#include static char Options[] = "hvDdnfp:"; @@ -33,12 +34,13 @@ char *Prefix = NULL; Boolean NoDeInstall = FALSE; Boolean CleanDirs = 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) @@ -71,7 +73,7 @@ main(int argc, char **argv) case 'h': case '?': default: - usage(prog_name, NULL); + usage(); break; } @@ -85,39 +87,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\n"); - } - va_end(args); - fprintf(stderr, "Usage: %s [args] pkg [ .. pkg ]\n", name); - fprintf(stderr, "Where args are one or more of:\n\n"); - fprintf(stderr, "-v verbose\n"); - fprintf(stderr, "-p arg override prefix with arg\n"); - fprintf(stderr, "-d delete empty directories when deinstalling\n"); - fprintf(stderr, "-f force delete even if dependencies exist\n"); - fprintf(stderr, " or deinstall/requirement checks fail\n"); - fprintf(stderr, "-D don't execute pkg de-install script, if any\n"); - fprintf(stderr, "-n don't actually de-install, just show steps\n"); + 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 4187a8c..1584b60 100644 --- a/usr.sbin/pkg_install/delete/perform.c +++ b/usr.sbin/pkg_install/delete/perform.c @@ -1,5 +1,6 @@ #ifndef lint -static const char *rcsid = "$Id: perform.c,v 1.12 1997/02/22 16:09:37 peter Exp $"; +static const char rcsid[] = + "$Id: perform.c,v 1.13 1997/03/06 10:21:57 jkh Exp $"; #endif /* @@ -22,6 +23,7 @@ static const char *rcsid = "$Id: perform.c,v 1.12 1997/02/22 16:09:37 peter Exp * */ +#include #include "lib.h" #include "delete.h" @@ -59,33 +61,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 */ @@ -95,7 +98,7 @@ pkg_do(char *pkg) fclose(cfile); p = find_plist(&Plist, PLIST_CWD); if (!p) { - whinge("Package '%s' doesn't have a prefix.", pkg); + warnx("package '%s' doesn't have a prefix", pkg); return 1; } setenv(PKG_PREFIX_VNAME, p->name, 1); @@ -104,8 +107,8 @@ pkg_do(char *pkg) 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; } @@ -116,21 +119,22 @@ 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) - whinge("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); + warnx("couldn't remove log entry in %s, deinstall failed", LogDir); if (!Force) return 1; } @@ -150,7 +154,8 @@ 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 @@ -173,21 +178,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.XXXXXX", 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; } @@ -199,18 +204,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) - whinge("Error renaming `%s' to `%s'", ftmp, fname); + warnx("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 ad9b0a5..9a85d5c 100644 --- a/usr.sbin/pkg_install/delete/pkg_delete.1 +++ b/usr.sbin/pkg_install/delete/pkg_delete.1 @@ -21,7 +21,7 @@ .Os FreeBSD 2.0 .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 @@ -63,28 +63,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 @@ -94,16 +90,14 @@ 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 .Sh TECHNICAL DETAILS -.Nm +.Nm Pkg_delete does pretty much what it says. It examines installed package records in .Pa /var/db/pkg/ , deletes the package contents, and finally removes the package records. -- cgit v1.1