summaryrefslogtreecommitdiffstats
path: root/usr.sbin/pkg_install/lib/pen.c
diff options
context:
space:
mode:
authorjkh <jkh@FreeBSD.org>1998-02-16 17:16:51 +0000
committerjkh <jkh@FreeBSD.org>1998-02-16 17:16:51 +0000
commit7836fb80f5b1a2c27eeca9390f1b976a6886b12d (patch)
tree85a172286829ce0770e98088e0d74da47a2625af /usr.sbin/pkg_install/lib/pen.c
parent3513ffecbffcc3f1fd4e7b560ae701e59685d911 (diff)
downloadFreeBSD-src-7836fb80f5b1a2c27eeca9390f1b976a6886b12d.zip
FreeBSD-src-7836fb80f5b1a2c27eeca9390f1b976a6886b12d.tar.gz
Eliminate the idea of nested "playpens" entirely - it just obfuscated
the code and, in at least one case, made it more dangerous to no gain.
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 e34e628..0549f27 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);
}
OpenPOWER on IntegriCloud