summaryrefslogtreecommitdiff
path: root/usr.sbin/pkg_install/lib
diff options
context:
space:
mode:
authorhubertf <hubertf@NetBSD.org>1997-10-16 00:31:32 +0000
committerhubertf <hubertf@NetBSD.org>1997-10-16 00:31:32 +0000
commitd0245e3952ee6e22ffeffe67e2c7dbf2ae7d93ed (patch)
tree287265b6040901fa5e180bad2048c0160cca569c /usr.sbin/pkg_install/lib
parentbc6479768b704b0477d2f52afcd91dc620e0a6a7 (diff)
First cut on importing pkg_install as of FreeBSD 971013:
- warn()/err() instead of whinge()/barf() - Update RCS Id strings - Update manpages (mostly)
Diffstat (limited to 'usr.sbin/pkg_install/lib')
-rw-r--r--usr.sbin/pkg_install/lib/exec.c11
-rw-r--r--usr.sbin/pkg_install/lib/file.c35
-rw-r--r--usr.sbin/pkg_install/lib/global.c6
-rw-r--r--usr.sbin/pkg_install/lib/lib.h5
-rw-r--r--usr.sbin/pkg_install/lib/msg.c43
-rw-r--r--usr.sbin/pkg_install/lib/pen.c37
-rw-r--r--usr.sbin/pkg_install/lib/plist.c41
-rw-r--r--usr.sbin/pkg_install/lib/str.c6
8 files changed, 86 insertions, 98 deletions
diff --git a/usr.sbin/pkg_install/lib/exec.c b/usr.sbin/pkg_install/lib/exec.c
index a0c17da16ba..40974c59b20 100644
--- a/usr.sbin/pkg_install/lib/exec.c
+++ b/usr.sbin/pkg_install/lib/exec.c
@@ -1,10 +1,10 @@
-/* $NetBSD: exec.c,v 1.2 1997/06/05 12:59:44 agc Exp $ */
+/* $NetBSD: exec.c,v 1.3 1997/10/16 00:32:17 hubertf Exp $ */
#ifndef lint
#if 0
-static const char *rcsid = "from FreeBSD Id: exec.c,v 1.5 1997/02/22 16:09:46 peter Exp";
+static const char *rcsid = "from FreeBSD Id: exec.c,v 1.6 1997/10/08 07:47:50 charnier Exp";
#else
-static const char *rcsid = "$NetBSD: exec.c,v 1.2 1997/06/05 12:59:44 agc Exp $";
+static const char *rcsid = "$NetBSD: exec.c,v 1.3 1997/10/16 00:32:17 hubertf Exp $";
#endif
#endif
@@ -28,6 +28,7 @@ static const char *rcsid = "$NetBSD: exec.c,v 1.2 1997/06/05 12:59:44 agc Exp $"
*
*/
+#include <err.h>
#include "lib.h"
/*
@@ -46,13 +47,13 @@ vsystem(const char *fmt, ...)
maxargs -= 32; /* some slop for the sh -c */
cmd = malloc(maxargs);
if (!cmd) {
- whinge("vsystem can't alloc arg space");
+ warnx("vsystem can't alloc arg space");
return 1;
}
va_start(args, fmt);
if (vsnprintf(cmd, maxargs, fmt, args) > maxargs) {
- whinge("vsystem args are too long");
+ warnx("vsystem args are too long");
return 1;
}
#ifdef DEBUG
diff --git a/usr.sbin/pkg_install/lib/file.c b/usr.sbin/pkg_install/lib/file.c
index f27c3d74c06..a901b41796f 100644
--- a/usr.sbin/pkg_install/lib/file.c
+++ b/usr.sbin/pkg_install/lib/file.c
@@ -1,10 +1,10 @@
-/* $NetBSD: file.c,v 1.2 1997/06/05 12:59:45 agc Exp $ */
+/* $NetBSD: file.c,v 1.3 1997/10/16 00:32:19 hubertf Exp $ */
#ifndef lint
#if 0
-static const char *rcsid = "from FreeBSD Id: file.c,v 1.27 1997/02/22 16:09:47 peter Exp";
+static const char *rcsid = "from FreeBSD Id: file.c,v 1.29 1997/10/08 07:47:54 charnier Exp";
#else
-static const char *rcsid = "$NetBSD: file.c,v 1.2 1997/06/05 12:59:45 agc Exp $";
+static const char *rcsid = "$NetBSD: file.c,v 1.3 1997/10/16 00:32:19 hubertf Exp $";
#endif
#endif
@@ -29,6 +29,7 @@ static const char *rcsid = "$NetBSD: file.c,v 1.2 1997/06/05 12:59:45 agc Exp $"
*/
#include "lib.h"
+#include <err.h>
#include <ftpio.h>
#include <netdb.h>
#include <pwd.h>
@@ -226,13 +227,13 @@ fileGetURL(char *base, char *spec)
strcpy(fname, spec);
cp = fileURLHost(fname, host, HOSTNAME_MAX);
if (!*cp) {
- whinge("URL `%s' has bad host part!", fname);
+ warnx("URL `%s' has bad host part!", fname);
return NULL;
}
cp = fileURLFilename(fname, file, FILENAME_MAX);
if (!*cp) {
- whinge("URL `%s' has bad filename part!", fname);
+ warnx("URL `%s' has bad filename part!", fname);
return NULL;
}
@@ -242,7 +243,7 @@ fileGetURL(char *base, char *spec)
/* Make up a convincing "password" */
pw = getpwuid(getuid());
if (!pw) {
- whinge("Can't get user name for ID %d\n.", getuid());
+ warnx("can't get user name for ID %d", getuid());
strcpy(pword, "joe@");
}
else {
@@ -331,14 +332,15 @@ fileGetContents(char *fname)
int fd;
if (stat(fname, &sb) == FAIL)
- barf("Can't stat '%s'.", fname);
+ cleanup(0), errx(2, "can't stat '%s'", fname);
contents = (char *)malloc(sb.st_size + 1);
fd = open(fname, O_RDONLY, 0);
if (fd == FAIL)
- barf("Unable to open '%s' for reading.", fname);
+ cleanup(0), errx(2, "unable to open '%s' for reading", fname);
if (read(fd, contents, sb.st_size) != sb.st_size)
- barf("Short read on '%s' - did not get %qd bytes.", fname, sb.st_size);
+ cleanup(0), errx(2, "short read on '%s' - did not get %qd bytes",
+ fname, sb.st_size);
close(fd);
contents[sb.st_size] = '\0';
return contents;
@@ -353,12 +355,13 @@ write_file(char *name, char *str)
fp = fopen(name, "w");
if (!fp)
- barf("Can't fopen '%s' for writing.", name);
+ cleanup(0), errx(2, "cannot fopen '%s' for writing", name);
len = strlen(str);
if (fwrite(str, 1, len, fp) != len)
- barf("Short fwrite on '%s', tried to write %d bytes.", name, len);
+ cleanup(0), errx(2, "short fwrite on '%s', tried to write %d bytes",
+ name, len);
if (fclose(fp))
- barf("failure to fclose '%s'.", name);
+ cleanup(0), errx(2, "failure to fclose '%s'", name);
}
void
@@ -371,7 +374,7 @@ copy_file(char *dir, char *fname, char *to)
else
snprintf(cmd, FILENAME_MAX, "cp -p -r %s/%s %s", dir, fname, to);
if (vsystem(cmd))
- barf("Couldn't perform '%s'", cmd);
+ cleanup(0), errx(2, "could not perform '%s'", cmd);
}
void
@@ -384,7 +387,7 @@ move_file(char *dir, char *fname, char *to)
else
snprintf(cmd, FILENAME_MAX, "mv %s/%s %s", dir, fname, to);
if (vsystem(cmd))
- barf("Couldn't perform '%s'", cmd);
+ cleanup(0), errx(2, "could not perform '%s'", cmd);
}
/*
@@ -414,7 +417,7 @@ copy_hierarchy(char *dir, char *fname, Boolean to)
printf("Using '%s' to copy trees.\n", cmd);
#endif
if (system(cmd))
- barf("copy_file: Couldn't perform '%s'", cmd);
+ cleanup(0), errx(2, "copy_file: could not perform '%s'", cmd);
}
/* Unpack a tar file */
@@ -440,7 +443,7 @@ unpack(char *pkg, char *flist)
strcpy(args, "z");
strcat(args, "xpf");
if (vsystem("tar %s %s %s", args, pkg, flist ? flist : "")) {
- whinge("Tar extract of %s failed!", pkg);
+ warnx("tar extract of %s failed!", pkg);
return 1;
}
return 0;
diff --git a/usr.sbin/pkg_install/lib/global.c b/usr.sbin/pkg_install/lib/global.c
index 2e17cd58267..ea3f4c28a3c 100644
--- a/usr.sbin/pkg_install/lib/global.c
+++ b/usr.sbin/pkg_install/lib/global.c
@@ -1,10 +1,10 @@
-/* $NetBSD: global.c,v 1.2 1997/06/05 12:59:49 agc Exp $ */
+/* $NetBSD: global.c,v 1.3 1997/10/16 00:32:20 hubertf Exp $ */
#ifndef lint
#if 0
-static const char *rcsid = "from FreeBSD Id: global.c,v 1.5 1997/02/22 16:09:48 peter Exp";
+static const char *rcsid = "from FreeBSD Id: global.c,v 1.6 1997/10/08 07:47:58 charnier Exp";
#else
-static const char *rcsid = "$NetBSD: global.c,v 1.2 1997/06/05 12:59:49 agc Exp $";
+static const char *rcsid = "$NetBSD: global.c,v 1.3 1997/10/16 00:32:20 hubertf Exp $";
#endif
#endif
diff --git a/usr.sbin/pkg_install/lib/lib.h b/usr.sbin/pkg_install/lib/lib.h
index c990da557e3..9d0cf395ee6 100644
--- a/usr.sbin/pkg_install/lib/lib.h
+++ b/usr.sbin/pkg_install/lib/lib.h
@@ -1,6 +1,6 @@
-/* $NetBSD: lib.h,v 1.2 1997/06/05 12:59:50 agc Exp $ */
+/* $NetBSD: lib.h,v 1.3 1997/10/16 00:32:22 hubertf Exp $ */
-/* from FreeBSD Id: lib.h,v 1.24 1997/02/22 16:09:49 peter Exp */
+/* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */
/*
* FreeBSD install - a package for the installation and maintainance
@@ -167,7 +167,6 @@ int plist_cmd(char *, char **);
int delete_package(Boolean, Boolean, Package *);
/* For all */
-void usage(const char *, const char *, ...);
int pkg_perform(char **);
/* Externs */
diff --git a/usr.sbin/pkg_install/lib/msg.c b/usr.sbin/pkg_install/lib/msg.c
index a68fe9aa330..e47ca7a74cb 100644
--- a/usr.sbin/pkg_install/lib/msg.c
+++ b/usr.sbin/pkg_install/lib/msg.c
@@ -1,10 +1,10 @@
-/* $NetBSD: msg.c,v 1.2 1997/06/05 12:59:52 agc Exp $ */
+/* $NetBSD: msg.c,v 1.3 1997/10/16 00:32:24 hubertf Exp $ */
#ifndef lint
#if 0
-static const char *rcsid = "from FreeBSD Id: msg.c,v 1.8 1997/02/22 16:09:50 peter Exp";
+static const char *rcsid = "from FreeBSD Id: msg.c,v 1.10 1997/10/13 15:03:55 jkh Exp";
#else
-static const char *rcsid = "$NetBSD: msg.c,v 1.2 1997/06/05 12:59:52 agc Exp $";
+static const char *rcsid = "$NetBSD: msg.c,v 1.3 1997/10/16 00:32:24 hubertf Exp $";
#endif
#endif
@@ -29,42 +29,15 @@ static const char *rcsid = "$NetBSD: msg.c,v 1.2 1997/06/05 12:59:52 agc Exp $";
*
*/
+#include <err.h>
#include "lib.h"
/* Die a relatively simple death */
void
upchuck(const char *err)
{
- fprintf(stderr, "Fatal error during execution: ");
- perror(err);
+ warn("fatal error during execution: %s", err);
cleanup(0);
- exit(1);
-}
-
-/* Die a more complex death */
-void
-barf(const char *err, ...)
-{
- va_list args;
-
- va_start(args, err);
- vfprintf(stderr, err, args);
- fputc('\n', stderr);
- va_end(args);
- cleanup(0);
- exit(2);
-}
-
-/* Get annoyed about something but don't go to pieces over it */
-void
-whinge(const char *err, ...)
-{
- va_list args;
-
- va_start(args, err);
- vfprintf(stderr, err, args);
- fputc('\n', stderr);
- va_end(args);
}
/*
@@ -84,8 +57,10 @@ y_or_n(Boolean def, const char *msg, ...)
* collected on stdin
*/
tty = fopen("/dev/tty", "r");
- if (!tty)
- barf("Can't open /dev/tty!\n");
+ if (!tty) {
+ warnx("can't open /dev/tty!");
+ cleanup(0);
+ }
while (ch != 'Y' && ch != 'N') {
vfprintf(stderr, msg, args);
if (def)
diff --git a/usr.sbin/pkg_install/lib/pen.c b/usr.sbin/pkg_install/lib/pen.c
index 369998cd215..6a53d4e0e07 100644
--- a/usr.sbin/pkg_install/lib/pen.c
+++ b/usr.sbin/pkg_install/lib/pen.c
@@ -1,10 +1,10 @@
-/* $NetBSD: pen.c,v 1.2 1997/06/05 12:59:52 agc Exp $ */
+/* $NetBSD: pen.c,v 1.3 1997/10/16 00:32:26 hubertf Exp $ */
#ifndef lint
#if 0
-static const char *rcsid = "from FreeBSD Id: pen.c,v 1.24 1997/02/22 16:09:50 peter Exp";
+static const char *rcsid = "from FreeBSD Id: pen.c,v 1.25 1997/10/08 07:48:12 charnier Exp";
#else
-static const char *rcsid = "$NetBSD: pen.c,v 1.2 1997/06/05 12:59:52 agc Exp $";
+static const char *rcsid = "$NetBSD: pen.c,v 1.3 1997/10/16 00:32:26 hubertf Exp $";
#endif
#endif
@@ -28,6 +28,7 @@ static const char *rcsid = "$NetBSD: pen.c,v 1.2 1997/06/05 12:59:52 agc Exp $";
*
*/
+#include <err.h>
#include "lib.h"
#include <sys/signal.h>
#include <sys/param.h>
@@ -63,9 +64,11 @@ find_play_pen(char *pen, size_t sz)
else if ((stat("/usr/tmp", &sb) == SUCCESS || mkdir("/usr/tmp", 01777) == SUCCESS) && min_free("/usr/tmp") >= sz)
strcpy(pen, "/usr/tmp/instmp.XXXXXX");
else {
- barf("Can't find enough temporary space to extract the files, please set\n"
- "your PKG_TMPDIR environment variable to a location with at least %d bytes\n"
- "free.", sz);
+ cleanup(0);
+ errx(2,
+"can't find enough temporary space to extract the files, please set your\n"
+"PKG_TMPDIR environment variable to a location with at least %d bytes\n"
+"free", sz);
return NULL;
}
return pen;
@@ -82,12 +85,12 @@ make_playpen(char *pen, size_t sz)
return NULL;
if (!mktemp(pen)) {
- barf("Can't mktemp '%s'.", pen);
- return NULL;
+ cleanup(0);
+ errx(2, "can't mktemp '%s'", pen);
}
if (mkdir(pen, 0755) == FAIL) {
- barf("Can't mkdir '%s'.", pen);
- return NULL;
+ cleanup(0);
+ errx(2, "can't mkdir '%s'", pen);
}
if (Verbose) {
if (sz)
@@ -95,10 +98,10 @@ make_playpen(char *pen, size_t sz)
}
if (min_free(pen) < sz) {
rmdir(pen);
- barf("Not enough free space to create: `%s'\n"
+ cleanup(0);
+ errx(2, "not enough free space to create '%s'.\n"
"Please set your PKG_TMPDIR environment variable to a location\n"
- "with more space and\ntry the command again.", pen);
- return NULL;
+ "with more space and\ntry the command again", pen);
}
if (Current[0])
strcpy(Previous, Current);
@@ -107,7 +110,7 @@ make_playpen(char *pen, size_t sz)
return NULL;
}
if (chdir(pen) == FAIL)
- barf("Can't chdir to '%s'.", pen);
+ cleanup(0), errx(2, "can't chdir to '%s'", pen);
strcpy(Current, pen);
return Previous;
}
@@ -121,10 +124,10 @@ leave_playpen(char *save)
/* Don't interrupt while we're cleaning up */
oldsig = signal(SIGINT, SIG_IGN);
if (Previous[0] && chdir(Previous) == FAIL)
- barf("Can't chdir back to '%s'.", Previous);
+ cleanup(0), errx(2, "can't chdir back to '%s'", Previous);
else if (Current[0] && strcmp(Current, Previous)) {
if (vsystem("rm -rf %s", Current))
- whinge("Couldn't remove temporary dir '%s'", Current);
+ warnx("couldn't remove temporary dir '%s'", Current);
strcpy(Current, Previous);
}
if (save)
@@ -140,7 +143,7 @@ min_free(char *tmpdir)
struct statfs buf;
if (statfs(tmpdir, &buf) != 0) {
- perror("Error in statfs");
+ warn("statfs");
return -1;
}
return (off_t)buf.f_bavail * (off_t)buf.f_bsize;
diff --git a/usr.sbin/pkg_install/lib/plist.c b/usr.sbin/pkg_install/lib/plist.c
index 7899eb37c3b..ef2a6a9503f 100644
--- a/usr.sbin/pkg_install/lib/plist.c
+++ b/usr.sbin/pkg_install/lib/plist.c
@@ -1,10 +1,10 @@
-/* $NetBSD: plist.c,v 1.2 1997/06/05 12:59:53 agc Exp $ */
+/* $NetBSD: plist.c,v 1.3 1997/10/16 00:32:28 hubertf Exp $ */
#ifndef lint
#if 0
-static const char *rcsid = "from FreeBSD Id: plist.c,v 1.19 1997/02/22 16:09:51 peter Exp";
+static const char *rcsid = "from FreeBSD Id: plist.c,v 1.24 1997/10/08 07:48:15 charnier Exp";
#else
-static const char *rcsid = "$NetBSD: plist.c,v 1.2 1997/06/05 12:59:53 agc Exp $";
+static const char *rcsid = "$NetBSD: plist.c,v 1.3 1997/10/16 00:32:28 hubertf Exp $";
#endif
#endif
@@ -29,6 +29,7 @@ static const char *rcsid = "$NetBSD: plist.c,v 1.2 1997/06/05 12:59:53 agc Exp $
*/
#include "lib.h"
+#include <err.h>
#include <md5.h>
/* Add an item to a packing list */
@@ -255,7 +256,7 @@ read_plist(Package *pkg, FILE *fp)
if (pline[0] == CMD_CHAR) {
cmd = plist_cmd(pline + 1, &cp);
if (cmd == FAIL)
- barf("Bad command '%s'", pline);
+ cleanup(0), errx(2, "bad command '%s'", pline);
if (*cp == '\0')
cp = NULL;
}
@@ -339,7 +340,8 @@ write_plist(Package *pkg, FILE *fp)
break;
default:
- barf("Unknown command type %d (%s)\n", plist->type, plist->name);
+ cleanup(0);
+ errx(2, "unknown command type %d (%s)", plist->type, plist->name);
break;
}
plist = plist->next;
@@ -377,7 +379,7 @@ delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg)
if (Verbose)
printf("Execute `%s'\n", tmp);
if (!Fake && system(tmp)) {
- whinge("unexec command for `%s' failed.", tmp);
+ warnx("unexec command for `%s' failed", tmp);
fail = FAIL;
}
break;
@@ -385,8 +387,8 @@ delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg)
case PLIST_FILE:
sprintf(tmp, "%s/%s", Where, p->name);
if (isdir(tmp)) {
- whinge("Attempting to delete directory `%s' as a file\n"
- "This packing list is incorrect - ignoring delete request.\n", tmp);
+ warnx("attempting to delete directory `%s' as a file\n"
+ "this packing list is incorrect - ignoring delete request", tmp);
}
else {
if (p->next && p->next->type == PLIST_COMMENT && !strncmp(p->next->name, "MD5:", 4)) {
@@ -409,7 +411,7 @@ delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg)
printf("Delete file %s\n", tmp);
if (!Fake && delete_hierarchy(tmp, ign_err, nukedirs)) {
- whinge("Unable to completely remove file '%s'", tmp);
+ warn("preserve: unable to completely remove file '%s'", tmp);
fail = FAIL;
}
}
@@ -419,14 +421,14 @@ delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg)
case PLIST_DIR_RM:
sprintf(tmp, "%s/%s", Where, p->name);
if (!isdir(tmp)) {
- whinge("Attempting to delete file `%s' as a directory\n"
- "This packing list is incorrect - ignoring delete request.\n", tmp);
+ warnx("attempting to delete file `%s' as a directory\n"
+ "this packing list is incorrect - ignoring delete request", tmp);
}
else {
if (Verbose)
printf("Delete directory %s\n", tmp);
if (!Fake && delete_hierarchy(tmp, ign_err, FALSE)) {
- whinge("Unable to completely remove directory '%s'", tmp);
+ warnx("unable to completely remove directory '%s'", tmp);
fail = FAIL;
}
}
@@ -454,14 +456,19 @@ delete_hierarchy(char *dir, Boolean ign_err, Boolean nukedirs)
cp1 = cp2 = dir;
if (!fexists(dir)) {
if (!ign_err)
- whinge("%s `%s' doesn't really exist.", isdir(dir) ? "Directory" : "File", dir);
- } else if (nukedirs) {
+ warnx("%s `%s' doesn't really exist",
+ isdir(dir) ? "directory" : "file", dir);
+ return !ign_err;
+ }
+ else if (nukedirs) {
if (vsystem("%s -r%s %s", REMOVE_CMD, (ign_err ? "f" : ""), dir))
return 1;
- } else if (isdir(dir)) {
+ }
+ else if (isdir(dir)) {
if (RMDIR(dir) && !ign_err)
return 1;
- } else {
+ }
+ else {
if (REMOVE(dir, ign_err))
return 1;
}
@@ -475,7 +482,7 @@ delete_hierarchy(char *dir, Boolean ign_err, Boolean nukedirs)
return 0;
if (RMDIR(dir) && !ign_err)
if (!fexists(dir))
- whinge("Directory `%s' doesn't really exist.", dir);
+ warnx("directory `%s' doesn't really exist", dir);
else
return 1;
/* back up the pathname one component */
diff --git a/usr.sbin/pkg_install/lib/str.c b/usr.sbin/pkg_install/lib/str.c
index d902a236e01..25551c0a726 100644
--- a/usr.sbin/pkg_install/lib/str.c
+++ b/usr.sbin/pkg_install/lib/str.c
@@ -1,10 +1,10 @@
-/* $NetBSD: str.c,v 1.2 1997/06/05 12:59:54 agc Exp $ */
+/* $NetBSD: str.c,v 1.3 1997/10/16 00:32:30 hubertf Exp $ */
#ifndef lint
#if 0
-static const char *rcsid = "FreeBSD - Id";
+static const char *rcsid = "Id: str.c,v 1.5 1997/10/08 07:48:21 charnier Exp";
#else
-static const char *rcsid = "$NetBSD: str.c,v 1.2 1997/06/05 12:59:54 agc Exp $";
+static const char *rcsid = "$NetBSD: str.c,v 1.3 1997/10/16 00:32:30 hubertf Exp $";
#endif
#endif