diff options
Diffstat (limited to 'usr.sbin/pkg_install/lib')
-rw-r--r-- | usr.sbin/pkg_install/lib/exec.c | 8 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/file.c | 32 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/global.c | 3 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/lib.h | 3 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/msg.c | 35 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/pen.c | 34 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/plist.c | 30 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/str.c | 3 |
8 files changed, 69 insertions, 79 deletions
diff --git a/usr.sbin/pkg_install/lib/exec.c b/usr.sbin/pkg_install/lib/exec.c index 87bcc10..0087c18 100644 --- a/usr.sbin/pkg_install/lib/exec.c +++ b/usr.sbin/pkg_install/lib/exec.c @@ -1,5 +1,6 @@ #ifndef lint -static const char *rcsid = "$Id$"; +static const char rcsid[] = + "$Id: exec.c,v 1.5 1997/02/22 16:09:46 peter Exp $"; #endif /* @@ -22,6 +23,7 @@ static const char *rcsid = "$Id$"; * */ +#include <err.h> #include "lib.h" /* @@ -40,13 +42,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 2748235..8bf27b6 100644 --- a/usr.sbin/pkg_install/lib/file.c +++ b/usr.sbin/pkg_install/lib/file.c @@ -1,5 +1,6 @@ #ifndef lint -static const char *rcsid = "$Id: file.c,v 1.27 1997/02/22 16:09:47 peter Exp $"; +static const char rcsid[] = + "$Id: file.c,v 1.28 1997/07/01 06:13:50 jkh Exp $"; #endif /* @@ -23,6 +24,7 @@ static const char *rcsid = "$Id: file.c,v 1.27 1997/02/22 16:09:47 peter Exp $"; */ #include "lib.h" +#include <err.h> #include <ftpio.h> #include <netdb.h> #include <pwd.h> @@ -220,13 +222,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; } @@ -236,7 +238,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 { @@ -325,14 +327,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; @@ -381,12 +384,13 @@ write_file(char *name, char *str) fp = fopen(name, "w"); if (!fp) - barf("Cannot 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 @@ -399,7 +403,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("Could not perform '%s'", cmd); + cleanup(0), errx(2, "could not perform '%s'", cmd); } void @@ -412,7 +416,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("Could not perform '%s'", cmd); + cleanup(0), errx(2, "could not perform '%s'", cmd); } /* @@ -442,7 +446,7 @@ copy_hierarchy(char *dir, char *fname, Boolean to) printf("Using '%s' to copy trees.\n", cmd); #endif if (system(cmd)) - barf("copy_file: Could not perform '%s'", cmd); + cleanup(0), errx(2, "copy_file: could not perform '%s'", cmd); } /* Unpack a tar file */ @@ -468,7 +472,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 3b00c81..75947b4 100644 --- a/usr.sbin/pkg_install/lib/global.c +++ b/usr.sbin/pkg_install/lib/global.c @@ -1,5 +1,6 @@ #ifndef lint -static const char *rcsid = "$Id$"; +static const char rcsid[] = + "$Id: global.c,v 1.5 1997/02/22 16:09:48 peter Exp $"; #endif /* diff --git a/usr.sbin/pkg_install/lib/lib.h b/usr.sbin/pkg_install/lib/lib.h index 5fda891..5d16f56 100644 --- a/usr.sbin/pkg_install/lib/lib.h +++ b/usr.sbin/pkg_install/lib/lib.h @@ -1,4 +1,4 @@ -/* $Id$ */ +/* $Id: lib.h,v 1.24 1997/02/22 16:09:49 peter Exp $ */ /* * FreeBSD install - a package for the installation and maintainance @@ -165,7 +165,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 e35aba8..032320b 100644 --- a/usr.sbin/pkg_install/lib/msg.c +++ b/usr.sbin/pkg_install/lib/msg.c @@ -1,5 +1,6 @@ #ifndef lint -static const char *rcsid = "$Id$"; +static const char rcsid[] = + "$Id: msg.c,v 1.8 1997/02/22 16:09:50 peter Exp $"; #endif /* @@ -23,44 +24,18 @@ static const char *rcsid = "$Id$"; * */ +#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); -} - /* * As a yes/no question, prompting from the varargs string and using * default if user just hits return. @@ -79,7 +54,7 @@ y_or_n(Boolean def, const char *msg, ...) */ tty = fopen("/dev/tty", "r"); if (!tty) - barf("Can't open /dev/tty!\n"); + cleanup(0), errx(2, "can't open /dev/tty!"); 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 4b636de..36ece65 100644 --- a/usr.sbin/pkg_install/lib/pen.c +++ b/usr.sbin/pkg_install/lib/pen.c @@ -1,5 +1,6 @@ #ifndef lint -static const char *rcsid = "$Id$"; +static const char rcsid[] = + "$Id: pen.c,v 1.24 1997/02/22 16:09:50 peter Exp $"; #endif /* @@ -22,6 +23,7 @@ static const char *rcsid = "$Id$"; * */ +#include <err.h> #include "lib.h" #include <sys/signal.h> #include <sys/param.h> @@ -57,9 +59,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; @@ -76,12 +80,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) @@ -89,10 +93,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); @@ -101,7 +105,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; } @@ -115,10 +119,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) @@ -134,7 +138,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 4db3ec4..2caf31a 100644 --- a/usr.sbin/pkg_install/lib/plist.c +++ b/usr.sbin/pkg_install/lib/plist.c @@ -1,5 +1,6 @@ #ifndef lint -static const char *rcsid = "$Id: plist.c,v 1.22 1997/07/01 06:13:51 jkh Exp $"; +static const char rcsid[] = + "$Id: plist.c,v 1.23 1997/09/02 08:48:47 jkh Exp $"; #endif /* @@ -23,7 +24,7 @@ static const char *rcsid = "$Id: plist.c,v 1.22 1997/07/01 06:13:51 jkh Exp $"; */ #include "lib.h" -#include <errno.h> +#include <err.h> #include <md5.h> /* Add an item to a packing list */ @@ -250,7 +251,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; } @@ -334,7 +335,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; @@ -378,7 +380,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; @@ -387,8 +389,8 @@ delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg) last_file = p->name; 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)) { @@ -418,7 +420,8 @@ delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg) if (make_preserve_name(tmp2, FILENAME_MAX, name, tmp)) { if (fexists(tmp2)) { if (rename(tmp2, tmp)) - whinge("preserve: Unable to restore %s as %s, errno = %d", tmp2, tmp, errno); + warn("preserve: unable to restore %s as %s", + tmp2, tmp); } } } @@ -429,14 +432,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; } } @@ -464,7 +467,8 @@ 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); + warnx("%s `%s' doesn't really exist", + isdir(dir) ? "directory" : "file", dir); return !ign_err; } else if (nukedirs) { @@ -489,7 +493,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 a9f1300..cb4fb41 100644 --- a/usr.sbin/pkg_install/lib/str.c +++ b/usr.sbin/pkg_install/lib/str.c @@ -1,5 +1,6 @@ #ifndef lint -static const char *rcsid = "$Id"; +static const char rcsid[] = + "$Id$"; #endif /* |