summaryrefslogtreecommitdiffstats
path: root/usr.sbin/pkg_install/lib/pen.c
diff options
context:
space:
mode:
authorjkh <jkh@FreeBSD.org>1995-08-17 00:36:06 +0000
committerjkh <jkh@FreeBSD.org>1995-08-17 00:36:06 +0000
commitf9c6f6c7f4f081ee9748d9268ea672d0e7b0c98a (patch)
treea2a17b322d58cfb605922fcd39bc609d21162676 /usr.sbin/pkg_install/lib/pen.c
parent49de37c88791929bc81b67219fd52e735ac677fb (diff)
downloadFreeBSD-src-f9c6f6c7f4f081ee9748d9268ea672d0e7b0c98a.zip
FreeBSD-src-f9c6f6c7f4f081ee9748d9268ea672d0e7b0c98a.tar.gz
Some fixes to make this "TMPDIR agile".
Submitted by: jmacd + some of my own fixes.
Diffstat (limited to 'usr.sbin/pkg_install/lib/pen.c')
-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 2786721..febf265 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)
OpenPOWER on IntegriCloud