From dad2df585cf830423608e2027120a5a34082d64a Mon Sep 17 00:00:00 2001 From: jkh Date: Fri, 11 Sep 1998 07:26:58 +0000 Subject: correct usage of cleanup() everywhere - this became bogus when the warnx/errx stuff was added and nobody seems to have noticed. :) Noticed by: Josh MacDonald --- usr.sbin/pkg_install/lib/file.c | 59 ++++++++++++++++++++++++++-------------- usr.sbin/pkg_install/lib/msg.c | 6 ++-- usr.sbin/pkg_install/lib/pen.c | 14 ++++++---- usr.sbin/pkg_install/lib/plist.c | 10 ++++--- 4 files changed, 56 insertions(+), 33 deletions(-) (limited to 'usr.sbin/pkg_install/lib') diff --git a/usr.sbin/pkg_install/lib/file.c b/usr.sbin/pkg_install/lib/file.c index 1cf82cc..6d38321 100644 --- a/usr.sbin/pkg_install/lib/file.c +++ b/usr.sbin/pkg_install/lib/file.c @@ -1,6 +1,6 @@ #ifndef lint static const char rcsid[] = - "$Id: file.c,v 1.30 1997/10/18 05:54:17 jkh Exp $"; + "$Id: file.c,v 1.31 1998/09/08 10:42:26 jkh Exp $"; #endif /* @@ -327,16 +327,22 @@ fileGetContents(char *fname) struct stat sb; int fd; - if (stat(fname, &sb) == FAIL) - cleanup(0), errx(2, "can't stat '%s'", fname); + if (stat(fname, &sb) == FAIL) { + 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) - cleanup(0), errx(2, "unable to open '%s' for reading", fname); - if (read(fd, contents, sb.st_size) != sb.st_size) - cleanup(0), errx(2, "short read on '%s' - did not get %qd bytes", - fname, sb.st_size); + if (fd == FAIL) { + cleanup(0); + errx(2, "unable to open '%s' for reading", fname); + } + if (read(fd, contents, sb.st_size) != 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; @@ -384,14 +390,19 @@ write_file(char *name, char *str) int len; fp = fopen(name, "w"); - if (!fp) - cleanup(0), errx(2, "cannot fopen '%s' for writing", name); + if (!fp) { + cleanup(0); + errx(2, "cannot fopen '%s' for writing", name); + } len = strlen(str); - if (fwrite(str, 1, len, fp) != len) - cleanup(0), errx(2, "short fwrite on '%s', tried to write %d bytes", - name, len); - if (fclose(fp)) - cleanup(0), errx(2, "failure to fclose '%s'", name); + if (fwrite(str, 1, len, fp) != len) { + cleanup(0); + errx(2, "short fwrite on '%s', tried to write %d bytes", name, len); + } + if (fclose(fp)) { + cleanup(0); + errx(2, "failure to fclose '%s'", name); + } } void @@ -403,8 +414,10 @@ copy_file(char *dir, char *fname, char *to) snprintf(cmd, FILENAME_MAX, "cp -p -r %s %s", fname, to); else snprintf(cmd, FILENAME_MAX, "cp -p -r %s/%s %s", dir, fname, to); - if (vsystem(cmd)) - cleanup(0), errx(2, "could not perform '%s'", cmd); + if (vsystem(cmd)) { + cleanup(0); + errx(2, "could not perform '%s'", cmd); + } } void @@ -416,8 +429,10 @@ move_file(char *dir, char *fname, char *to) snprintf(cmd, FILENAME_MAX, "mv %s %s", fname, to); else snprintf(cmd, FILENAME_MAX, "mv %s/%s %s", dir, fname, to); - if (vsystem(cmd)) - cleanup(0), errx(2, "could not perform '%s'", cmd); + if (vsystem(cmd)) { + cleanup(0); + errx(2, "could not perform '%s'", cmd); + } } /* @@ -446,8 +461,10 @@ copy_hierarchy(char *dir, char *fname, Boolean to) #ifdef DEBUG printf("Using '%s' to copy trees.\n", cmd); #endif - if (system(cmd)) - cleanup(0), errx(2, "copy_file: could not perform '%s'", cmd); + if (system(cmd)) { + cleanup(0); + errx(2, "copy_file: could not perform '%s'", cmd); + } } /* Unpack a tar file */ diff --git a/usr.sbin/pkg_install/lib/msg.c b/usr.sbin/pkg_install/lib/msg.c index 3c2d199..a580d8a 100644 --- a/usr.sbin/pkg_install/lib/msg.c +++ b/usr.sbin/pkg_install/lib/msg.c @@ -1,6 +1,6 @@ #ifndef lint static const char rcsid[] = - "$Id: msg.c,v 1.9 1997/10/08 07:48:09 charnier Exp $"; + "$Id: msg.c,v 1.10 1997/10/13 15:03:55 jkh Exp $"; #endif /* @@ -31,8 +31,8 @@ static const char rcsid[] = void upchuck(const char *err) { - warn("fatal error during execution: %s", err); cleanup(0); + errx(1, "fatal error during execution: %s", err); } /* @@ -53,8 +53,8 @@ y_or_n(Boolean def, const char *msg, ...) */ tty = fopen("/dev/tty", "r"); if (!tty) { - warnx("can't open /dev/tty!"); cleanup(0); + errx(2, "can't open /dev/tty!"); } while (ch != 'Y' && ch != 'N') { vfprintf(stderr, msg, args); diff --git a/usr.sbin/pkg_install/lib/pen.c b/usr.sbin/pkg_install/lib/pen.c index d914833..714dbac 100644 --- a/usr.sbin/pkg_install/lib/pen.c +++ b/usr.sbin/pkg_install/lib/pen.c @@ -1,6 +1,6 @@ #ifndef lint static const char rcsid[] = - "$Id: pen.c,v 1.28 1998/04/12 16:01:10 jkh Exp $"; + "$Id: pen.c,v 1.29 1998/07/28 01:18:02 nectar Exp $"; #endif /* @@ -129,8 +129,10 @@ make_playpen(char *pen, size_t sz) return NULL; } - if (chdir(pen) == FAIL) - cleanup(0), errx(2, "can't chdir to '%s'", pen); + if (chdir(pen) == FAIL) { + cleanup(0); + errx(2, "can't chdir to '%s'", pen); + } if (PenLocation[0]) pushPen(PenLocation); @@ -148,8 +150,10 @@ leave_playpen() /* Don't interrupt while we're cleaning up */ oldsig = signal(SIGINT, SIG_IGN); if (Previous[0]) { - if (chdir(Previous) == FAIL) - cleanup(0), errx(2, "can't chdir back to '%s'", Previous); + if (chdir(Previous) == FAIL) { + cleanup(0); + errx(2, "can't chdir back to '%s'", Previous); + } Previous[0] = '\0'; } if (PenLocation[0]) { diff --git a/usr.sbin/pkg_install/lib/plist.c b/usr.sbin/pkg_install/lib/plist.c index 7bcd1c8..d18c543 100644 --- a/usr.sbin/pkg_install/lib/plist.c +++ b/usr.sbin/pkg_install/lib/plist.c @@ -1,6 +1,6 @@ #ifndef lint static const char rcsid[] = - "$Id: plist.c,v 1.25 1998/07/18 22:19:11 hoek Exp $"; + "$Id: plist.c,v 1.26 1998/09/01 06:58:11 jkh Exp $"; #endif /* @@ -250,8 +250,10 @@ read_plist(Package *pkg, FILE *fp) cp = pline; if (pline[0] == CMD_CHAR) { cmd = plist_cmd(pline + 1, &cp); - if (cmd == FAIL) - cleanup(0), errx(2, "bad command '%s'", pline); + if (cmd == FAIL) { + cleanup(0); + errx(2, "bad command '%s'", pline); + } if (*cp == '\0') cp = NULL; } @@ -388,7 +390,7 @@ delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg) case PLIST_FILE: last_file = p->name; sprintf(tmp, "%s/%s", Where, p->name); - if (isdir(tmp)) { + if (isdir(tmp) && fexists(tmp)) { warnx("cannot delete specified file `%s' - it is a directory!\n" "this packing list is incorrect - ignoring delete request", tmp); } -- cgit v1.1