aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/pkg_install/lib/pen.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/pkg_install/lib/pen.c')
-rw-r--r--usr.sbin/pkg_install/lib/pen.c30
1 files changed, 14 insertions, 16 deletions
diff --git a/usr.sbin/pkg_install/lib/pen.c b/usr.sbin/pkg_install/lib/pen.c
index e34e6286efbf..0549f27fe950 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.25 1997/10/08 07:48:12 charnier Exp $";
+ "$Id: pen.c,v 1.26 1998/01/09 14:52:18 jkh Exp $";
#endif
/*
@@ -30,13 +30,13 @@ static const char rcsid[] =
#include <sys/mount.h>
/* For keeping track of where we are */
-static char Current[FILENAME_MAX];
+static char PenLocation[FILENAME_MAX];
static char Previous[FILENAME_MAX];
char *
where_playpen(void)
{
- return Current;
+ return PenLocation;
}
/* Find a good place to play. */
@@ -76,6 +76,10 @@ find_play_pen(char *pen, size_t sz)
char *
make_playpen(char *pen, size_t sz)
{
+ if (PenLocation[0]) {
+ errx(2, "make_playpen() called before closing previous pen: %s", pen);
+ return NULL;
+ }
if (!find_play_pen(pen, sz))
return NULL;
@@ -98,21 +102,19 @@ make_playpen(char *pen, size_t sz)
"Please set your PKG_TMPDIR environment variable to a location\n"
"with more space and\ntry the command again", pen);
}
- if (Current[0])
- strcpy(Previous, Current);
- else if (!getcwd(Previous, FILENAME_MAX)) {
+ if (!getcwd(Previous, FILENAME_MAX)) {
upchuck("getcwd");
return NULL;
}
if (chdir(pen) == FAIL)
cleanup(0), errx(2, "can't chdir to '%s'", pen);
- strcpy(Current, pen);
+ strcpy(PenLocation, pen);
return Previous;
}
/* Convenience routine for getting out of playpen */
void
-leave_playpen(char *save)
+leave_playpen()
{
void (*oldsig)(int);
@@ -120,15 +122,11 @@ leave_playpen(char *save)
oldsig = signal(SIGINT, SIG_IGN);
if (Previous[0] && chdir(Previous) == FAIL)
cleanup(0), errx(2, "can't chdir back to '%s'", Previous);
- else if (Current[0] && strcmp(Current, Previous)) {
- if (Current[0] == '/' && vsystem("rm -rf %s", Current))
- warnx("couldn't remove temporary dir '%s'", Current);
- strcpy(Current, Previous);
+ else if (PenLocation[0]) {
+ if (PenLocation[0] == '/' && vsystem("rm -rf %s", PenLocation))
+ warnx("couldn't remove temporary dir '%s'", PenLocation);
}
- if (save)
- strcpy(Previous, save);
- else
- Previous[0] = '\0';
+ Previous[0] = PenLocation[0] = '\0';
signal(SIGINT, oldsig);
}