diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2001-04-08 16:45:49 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2001-04-08 16:45:49 +0000 |
commit | 5a14ac2a8fbdc64a6e5a1d31d891a4f0eee033d6 (patch) | |
tree | e31007d42dcc89fb9503a1c900c02a5f4ddcb019 /usr.sbin/pkg_install/lib | |
parent | 40d86c85d5851915c47abba5df4f515c693af109 (diff) |
Better error messages: pwarnx function, which works like pwarn, except
it shows a current package name along with the program name, e.g.,
pkg_add(foo-3.0): some error occurred.
A few messages now bear redundant pkgnames, which is much better than
doing pkg_add * and being informed that something went slightly wrong
somewhere...
Diffstat (limited to 'usr.sbin/pkg_install/lib')
-rw-r--r-- | usr.sbin/pkg_install/lib/Makefile | 4 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/exec.c | 8 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/file.c | 10 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/lib.h | 6 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/pen.c | 6 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/plist.c | 24 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/pwarnx.c | 79 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/str.c | 8 |
8 files changed, 114 insertions, 31 deletions
diff --git a/usr.sbin/pkg_install/lib/Makefile b/usr.sbin/pkg_install/lib/Makefile index 632aba902a6..e1f0b4efbfa 100644 --- a/usr.sbin/pkg_install/lib/Makefile +++ b/usr.sbin/pkg_install/lib/Makefile @@ -1,6 +1,6 @@ -# $OpenBSD: Makefile,v 1.4 1999/10/05 22:34:45 espie Exp $ +# $OpenBSD: Makefile,v 1.5 2001/04/08 16:45:47 espie Exp $ LIB= install -SRCS= file.c plist.c str.c exec.c global.c pen.c +SRCS= file.c plist.c str.c exec.c global.c pen.c pwarnx.c CFLAGS+= ${DEBUG} NOPROFILE= yes NOPIC= yes diff --git a/usr.sbin/pkg_install/lib/exec.c b/usr.sbin/pkg_install/lib/exec.c index aa0a68c9602..25fa5caf7c4 100644 --- a/usr.sbin/pkg_install/lib/exec.c +++ b/usr.sbin/pkg_install/lib/exec.c @@ -1,7 +1,7 @@ -/* $OpenBSD: exec.c,v 1.5 1998/10/13 23:09:52 marc Exp $ */ +/* $OpenBSD: exec.c,v 1.6 2001/04/08 16:45:47 espie Exp $ */ #ifndef lint -static const char *rcsid = "$OpenBSD: exec.c,v 1.5 1998/10/13 23:09:52 marc Exp $"; +static const char *rcsid = "$OpenBSD: exec.c,v 1.6 2001/04/08 16:45:47 espie Exp $"; #endif /* @@ -43,13 +43,13 @@ vsystem(const char *fmt, ...) maxargs = (size_t) sysconf(_SC_ARG_MAX); maxargs -= 32; /* some slop for the sh -c */ if ((cmd = (char *) malloc(maxargs)) == (char *) NULL) { - warnx("vsystem can't alloc arg space"); + pwarnx("vsystem can't alloc arg space"); return 1; } va_start(args, fmt); if (vsnprintf(cmd, maxargs, fmt, args) > maxargs) { - warnx("vsystem args are too long"); + pwarnx("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 fc22e9dbbf6..cf4f754236a 100644 --- a/usr.sbin/pkg_install/lib/file.c +++ b/usr.sbin/pkg_install/lib/file.c @@ -1,7 +1,7 @@ -/* $OpenBSD: file.c,v 1.13 2001/03/11 13:22:31 wilfried Exp $ */ +/* $OpenBSD: file.c,v 1.14 2001/04/08 16:45:47 espie Exp $ */ #ifndef lint -static const char *rcsid = "$OpenBSD: file.c,v 1.13 2001/03/11 13:22:31 wilfried Exp $"; +static const char *rcsid = "$OpenBSD: file.c,v 1.14 2001/04/08 16:45:47 espie Exp $"; #endif /* @@ -320,13 +320,13 @@ fileGetURL(char *base, char *spec) strlcpy(fname, spec, sizeof fname); cp = fileURLHost(fname, host, MAXHOSTNAMELEN); if (!*cp) { - warnx("URL `%s' has bad host part!", fname); + pwarnx("URL `%s' has bad host part!", fname); return NULL; } cp = fileURLFilename(fname, file, FILENAME_MAX); if (!*cp) { - warnx("URL `%s' has bad filename part!", fname); + pwarnx("URL `%s' has bad filename part!", fname); return NULL; } @@ -610,7 +610,7 @@ unpack(char *pkg, char *flist) strcpy(args, "z"); strcat(args, "xpf"); if (vsystem("tar %s %s %s", args, pkg, flist ? flist : "")) { - warnx("tar extract of %s failed!", pkg); + pwarnx("tar extract of %s failed!", pkg); return 1; } return 0; diff --git a/usr.sbin/pkg_install/lib/lib.h b/usr.sbin/pkg_install/lib/lib.h index 7a349d18b69..1b66ad12da4 100644 --- a/usr.sbin/pkg_install/lib/lib.h +++ b/usr.sbin/pkg_install/lib/lib.h @@ -1,4 +1,4 @@ -/* $OpenBSD: lib.h,v 1.7 2001/04/02 10:13:40 espie Exp $ */ +/* $OpenBSD: lib.h,v 1.8 2001/04/08 16:45:47 espie Exp $ */ /* * FreeBSD install - a package for the installation and maintainance @@ -205,6 +205,10 @@ int delete_package(Boolean, Boolean, package_t *); /* For all */ int pkg_perform(char **); + +void set_pkg(const char *); +void pwarnx(const char *, ...); + /* Externs */ extern Boolean Verbose; extern Boolean Fake; diff --git a/usr.sbin/pkg_install/lib/pen.c b/usr.sbin/pkg_install/lib/pen.c index 7f1f2e8d38f..55160413ddb 100644 --- a/usr.sbin/pkg_install/lib/pen.c +++ b/usr.sbin/pkg_install/lib/pen.c @@ -1,7 +1,7 @@ -/* $OpenBSD: pen.c,v 1.8 1998/10/13 23:09:54 marc Exp $ */ +/* $OpenBSD: pen.c,v 1.9 2001/04/08 16:45:48 espie Exp $ */ #ifndef lint -static const char *rcsid = "$OpenBSD: pen.c,v 1.8 1998/10/13 23:09:54 marc Exp $"; +static const char *rcsid = "$OpenBSD: pen.c,v 1.9 2001/04/08 16:45:48 espie Exp $"; #endif /* @@ -152,7 +152,7 @@ leave_playpen(char *save) abort(); } if (vsystem("rm -rf %s", Current)) - warnx("couldn't remove temporary dir '%s'", Current); + pwarnx("couldn't remove temporary dir '%s'", Current); strcpy(Current, Previous); } if (save) diff --git a/usr.sbin/pkg_install/lib/plist.c b/usr.sbin/pkg_install/lib/plist.c index 99b382b5fd1..9277fe55897 100644 --- a/usr.sbin/pkg_install/lib/plist.c +++ b/usr.sbin/pkg_install/lib/plist.c @@ -1,6 +1,6 @@ -/* $OpenBSD: plist.c,v 1.10 2001/04/02 10:13:40 espie Exp $ */ +/* $OpenBSD: plist.c,v 1.11 2001/04/08 16:45:48 espie Exp $ */ #ifndef lint -static const char *rcsid = "$OpenBSD: plist.c,v 1.10 2001/04/02 10:13:40 espie Exp $"; +static const char *rcsid = "$OpenBSD: plist.c,v 1.11 2001/04/08 16:45:48 espie Exp $"; #endif /* @@ -245,7 +245,7 @@ read_plist(package_t *pkg, FILE *fp) if (pline[0] == CMD_CHAR) { cmd = plist_cmd(pline + 1, &cp); if (cmd == FAIL) { - warnx("Unrecognised PLIST command `%s'", pline); + pwarnx("Unrecognised PLIST command `%s'", pline); continue; } if (*cp == '\0') @@ -273,7 +273,7 @@ write_plist(package_t *pkg, FILE *fp) for (cmdp = cmdv ; cmdp->c_type != FAIL && cmdp->c_type != p->type ; cmdp++) { } if (cmdp->c_type == FAIL) { - warnx("Unknown PLIST command type %d (%s)", p->type, p->name); + pwarnx("Unknown PLIST command type %d (%s)", p->type, p->name); } else if (cmdp->c_argc == 0) { (void) fprintf(fp, "%c%s\n", CMD_CHAR, cmdp->c_s); } else { @@ -315,13 +315,13 @@ delete_package(Boolean ign_err, Boolean nukedirs, package_t *pkg) case PLIST_UNEXEC: if (!format_cmd(tmp, sizeof(tmp), p->name, Where, last_file)) { - warnx("unexec command `%s' could not expand", p->name); + pwarnx("unexec command `%s' could not expand", p->name); fail = FAIL; } else { if (Verbose) printf("Execute `%s'\n", tmp); if (!Fake && system(tmp)) { - warnx("unexec command for `%s' failed", tmp); + pwarnx("unexec command for `%s' failed", tmp); fail = FAIL; } } @@ -331,7 +331,7 @@ delete_package(Boolean ign_err, Boolean nukedirs, package_t *pkg) last_file = p->name; (void) snprintf(tmp, sizeof(tmp), "%s/%s", Where, p->name); if (isdir(tmp)) { - warnx("attempting to delete directory `%s' as a file\n" + pwarnx("attempting to delete directory `%s' as a file\n" "this packing list is incorrect - ignoring delete request", tmp); } else { @@ -363,10 +363,10 @@ delete_package(Boolean ign_err, Boolean nukedirs, package_t *pkg) (void) snprintf(tmp, sizeof(tmp), "%s/%s", Where, p->name); if (!isdir(tmp)) { if (fexists(tmp)) { - warnx("attempting to delete file `%s' as a directory\n" + pwarnx("attempting to delete file `%s' as a directory\n" "this packing list is incorrect - ignoring delete request", tmp); } else { - warnx("attempting to delete non-existent directory `%s'\n" + pwarnx("attempting to delete non-existent directory `%s'\n" "this packing list is incorrect - ignoring delete request", tmp); } } @@ -374,7 +374,7 @@ delete_package(Boolean ign_err, Boolean nukedirs, package_t *pkg) if (Verbose) printf("Delete directory %s\n", tmp); if (!Fake && delete_hierarchy(tmp, ign_err, FALSE)) { - warnx("unable to completely remove directory '%s'", tmp); + pwarnx("unable to completely remove directory '%s'", tmp); fail = FAIL; } } @@ -404,7 +404,7 @@ delete_hierarchy(char *dir, Boolean ign_err, Boolean nukedirs) cp1 = cp2 = dir; if (!fexists(dir)) { if (!ign_err) - warnx("%s `%s' doesn't really exist", + pwarnx("%s `%s' doesn't really exist", isdir(dir) ? "directory" : "file", dir); return !ign_err; } @@ -430,7 +430,7 @@ delete_hierarchy(char *dir, Boolean ign_err, Boolean nukedirs) return 0; if (RMDIR(dir) && !ign_err) { if (!fexists(dir)) - warnx("directory `%s' doesn't really exist", dir); + pwarnx("directory `%s' doesn't really exist", dir); else return 1; } diff --git a/usr.sbin/pkg_install/lib/pwarnx.c b/usr.sbin/pkg_install/lib/pwarnx.c new file mode 100644 index 00000000000..982cf27aa4f --- /dev/null +++ b/usr.sbin/pkg_install/lib/pwarnx.c @@ -0,0 +1,79 @@ +/* $OpenBSD: pwarnx.c,v 1.1 2001/04/08 16:45:48 espie Exp $ */ + +/*- + * Copyright (c) 1993 + * The Regents of the University of California. 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. + */ + +#include <stdarg.h> +#include <stdio.h> +#include <string.h> +#include "lib.h" + +static char pkgname[60]; + +void +set_pkg(name) + const char *name; +{ + + char *name2; + + if (name != NULL) { + name2 = strrchr(name, '/'); + if (name2 != NULL) + name = name2+1; + strlcpy(pkgname, name, sizeof pkgname); + name2 = strstr(pkgname, ".tgz"); + if (name2 != NULL && name2[4] == '\0') + *name2 = '\0'; + } else + pkgname[0] = '\0'; +} + + +extern char *__progname; + +void +pwarnx(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + + if (pkgname[0] == '\0') + (void)fprintf(stderr, "%s: ", __progname); + else + (void)fprintf(stderr, "%s(%s): ", __progname, pkgname); + if (fmt != NULL) + (void)vfprintf(stderr, fmt, ap); + (void)fprintf(stderr, "\n"); + va_end(ap); +} diff --git a/usr.sbin/pkg_install/lib/str.c b/usr.sbin/pkg_install/lib/str.c index 572add98089..ef12746d43a 100644 --- a/usr.sbin/pkg_install/lib/str.c +++ b/usr.sbin/pkg_install/lib/str.c @@ -1,7 +1,7 @@ -/* $OpenBSD: str.c,v 1.4 1998/10/13 23:09:54 marc Exp $ */ +/* $OpenBSD: str.c,v 1.5 2001/04/08 16:45:48 espie Exp $ */ #ifndef lint -static const char *rcsid = "$OpenBSD: str.c,v 1.4 1998/10/13 23:09:54 marc Exp $"; +static const char *rcsid = "$OpenBSD: str.c,v 1.5 2001/04/08 16:45:48 espie Exp $"; #endif /* @@ -204,7 +204,7 @@ alternate_match(const char *pattern, const char *pkg) } } if (cnt != 0) { - warnx("Malformed alternate `%s'", pattern); + pwarnx("Malformed alternate `%s'", pattern); return 1; } for (found = 0, cp = sep + 1; *sep != '}'; cp = sep + 1) { @@ -308,7 +308,7 @@ findmatchingname(const char *dir, const char *pattern, matchfn f, char *data) found = 0; if ((dirp = opendir(dir)) == NULL) { - /* warnx("can't opendir dir '%s'", dir); */ + /* pwarnx("can't opendir dir '%s'", dir); */ return -1; } while ((dp = readdir(dirp)) != NULL) { |