aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/pkg_install/lib
diff options
context:
space:
mode:
authorJordan K. Hubbard <jkh@FreeBSD.org>1995-08-17 00:36:06 +0000
committerJordan K. Hubbard <jkh@FreeBSD.org>1995-08-17 00:36:06 +0000
commit3122afe4bd5dff629e522e8901a23a140bc04d9c (patch)
treea2a17b322d58cfb605922fcd39bc609d21162676 /usr.sbin/pkg_install/lib
parenta16b708542875ee84fe25e333311c9ece27e9bf0 (diff)
Notes
Diffstat (limited to 'usr.sbin/pkg_install/lib')
-rw-r--r--usr.sbin/pkg_install/lib/pen.c46
1 files changed, 32 insertions, 14 deletions
diff --git a/usr.sbin/pkg_install/lib/pen.c b/usr.sbin/pkg_install/lib/pen.c
index 2786721673e7..febf2656ac4e 100644
--- a/usr.sbin/pkg_install/lib/pen.c
+++ b/usr.sbin/pkg_install/lib/pen.c
@@ -1,5 +1,5 @@
#ifndef lint
-static const char *rcsid = "$Id: pen.c,v 1.13 1995/04/26 07:43:35 jkh Exp $";
+static const char *rcsid = "$Id: pen.c,v 1.14 1995/08/06 03:21:04 jkh Exp $";
#endif
/*
@@ -32,6 +32,25 @@ static char Cwd[FILENAME_MAX];
static char Pen[FILENAME_MAX];
extern char *PlayPen;
+/* Find a good place to play. */
+static char *
+find_play_pen(size_t sz)
+{
+ char *cp;
+ struct stat sb;
+
+ if ((cp = getenv("PKG_TMPDIR")) != NULL && stat(cp, &sb) != FAIL && (min_free(cp) >= sz))
+ sprintf(Pen, "%s/instmp.XXXXXX", cp);
+ else if ((cp = getenv("TMPDIR")) != NULL && stat(cp, &sb) != FAIL && (min_free(cp) >= sz))
+ sprintf(Pen, "%s/instmp.XXXXXX", cp);
+ else if (stat("/var/tmp", &sb) != FAIL && min_free("/var/tmp") >= sz)
+ strcpy(Pen, "/var/tmp/instmp.XXXXXX");
+ else if (stat("/tmp", &sb) != FAIL && min_free("/tmp") >= sz)
+ strcpy(Pen, "/tmp/instmp.XXXXXX");
+ else barf("Can't find enough temporary space to extract the files, please set\nyour PKG_TMPDIR environment variable to a location with at least %d bytes\nfree.", sz);
+ return Pen;
+}
+
/*
* Make a temporary directory to play in and chdir() to it, returning
* pathname of previous working directory.
@@ -39,32 +58,31 @@ extern char *PlayPen;
char *
make_playpen(char *pen, size_t sz)
{
- if (!pen) {
- char *cp;
-
- if ((cp = getenv("PKG_TMPDIR")) != NULL)
- sprintf(Pen, "%s/instmp.XXXXXX", cp);
- else
- strcpy(Pen, "/var/tmp/instmp.XXXXXX");
+ if (!pen)
+ PlayPen = find_play_pen(sz);
+ else {
+ strcpy(Pen, pen);
PlayPen = Pen;
}
- else
- strcpy(Pen, pen);
if (!getcwd(Cwd, FILENAME_MAX))
upchuck("getcwd");
if (!mktemp(Pen))
barf("Can't mktemp '%s'.", Pen);
if (mkdir(Pen, 0755) == FAIL)
barf("Can't mkdir '%s'.", Pen);
- if (Verbose) {
+ if (Verbose)
+ {
if (!sz)
- fprintf(stderr, "Free temp space: %d bytes\n", min_free(Pen));
+ fprintf(stderr, "Free temp space: %d bytes in %s\n", min_free(Pen), Pen);
else
- fprintf(stderr, "Projected package size: %d bytes, free temp space: %d bytes\n", (int)sz, min_free(Pen));
+ fprintf(stderr, "Projected package size: %d bytes,
+free temp space: %d bytes in %s\n", (int)sz, min_free(Pen), Pen);
}
if (min_free(Pen) < sz) {
rmdir(Pen);
- barf("Not enough free space to create `%s'.\nPlease set your PKG_TMPDIR environment variable to a location with more space and\ntry the command again.", Pen);
+ barf("Not enough free space to create `%s'.\nPlease set your PKG_TMPDIR
+environment variable to a location with more space and\ntry the command
+again.", Pen);
PlayPen = NULL;
}
if (chdir(Pen) == FAIL)