diff options
author | jkh <jkh@FreeBSD.org> | 1994-10-04 16:07:50 +0000 |
---|---|---|
committer | jkh <jkh@FreeBSD.org> | 1994-10-04 16:07:50 +0000 |
commit | 60db1604bf4f33d1e5384d1f523e02dc97604fcf (patch) | |
tree | 04e8f8795d8723da4cc214ddcd7655e4c877fbcb /usr.sbin/pkg_install/lib | |
parent | 04cc46fa4bb287b0511ad5c23cb4105bdba44606 (diff) | |
download | FreeBSD-src-60db1604bf4f33d1e5384d1f523e02dc97604fcf.zip FreeBSD-src-60db1604bf4f33d1e5384d1f523e02dc97604fcf.tar.gz |
Add the ability to verify that a package won't extract in the space
available. Thanks to Michael Elbel for pushing me in the right direction.
Diffstat (limited to 'usr.sbin/pkg_install/lib')
-rw-r--r-- | usr.sbin/pkg_install/lib/lib.h | 4 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/pen.c | 35 |
2 files changed, 32 insertions, 7 deletions
diff --git a/usr.sbin/pkg_install/lib/lib.h b/usr.sbin/pkg_install/lib/lib.h index 08de0be..31bd696 100644 --- a/usr.sbin/pkg_install/lib/lib.h +++ b/usr.sbin/pkg_install/lib/lib.h @@ -1,4 +1,4 @@ -/* $Id: lib.h,v 1.8 1994/08/28 14:15:29 jkh Exp $ */ +/* $Id: lib.h,v 1.9 1994/09/29 13:19:42 jkh Exp $ */ /* * FreeBSD install - a package for the installation and maintainance @@ -99,7 +99,7 @@ typedef struct _pack Package; /* Misc */ int vsystem(const char *, ...); void cleanup(int); -char *make_playpen(char *); +char *make_playpen(char *, size_t); void leave_playpen(void); char *where_playpen(void); diff --git a/usr.sbin/pkg_install/lib/pen.c b/usr.sbin/pkg_install/lib/pen.c index 1872d82..a3cfcdf 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.2 1993/09/04 05:06:51 jkh Exp $"; +static const char *rcsid = "$Id: pen.c,v 1.3 1993/09/05 04:54:23 jkh Exp $"; #endif /* @@ -23,28 +23,42 @@ static const char *rcsid = "$Id: pen.c,v 1.2 1993/09/04 05:06:51 jkh Exp $"; */ #include "lib.h" +#include <sys/param.h> +#include <sys/mount.h> /* For keeping track of where we are */ static char Cwd[FILENAME_MAX]; static char Pen[FILENAME_MAX]; +static long min_free(char *); /* * Make a temporary directory to play in and chdir() to it, returning * pathname of previous working directory. */ char * -make_playpen(char *pen) +make_playpen(char *pen, size_t sz) { - if (!pen) - pen = "/tmp/instmp.XXXXXX"; + if (!pen) { + char *cp; + + if ((cp = getenv("TMPDIR")) != NULL) + sprintf(Pen, "%s/instmp.XXXXXX", cp); + else + strcpy(Pen, "/tmp/instmp.XXXXXX"); + } + else + strcpy(Pen, pen); if (!getcwd(Cwd, FILENAME_MAX)) upchuck("getcwd"); - strcpy(Pen, pen); if (!mktemp(Pen)) barf("Can't mktemp '%s'.", Pen); if (mkdir(Pen, 0755) == FAIL) barf("Can't mkdir '%s'.", Pen); + if (min_free(Pen) < sz) { + rmdir(Pen); + barf("%s doesn't have enough free space. Please set your TMPDIR\nenvironment variable to a location with more space and\ntry the command again.", Pen); + } if (chdir(Pen) == FAIL) barf("Can't chdir to '%s'.", Pen); return Cwd; @@ -72,3 +86,14 @@ where_playpen(void) else return NULL; } + +static long min_free(char *tmpdir) +{ + struct statfs buf; + + if (statfs(tmpdir, &buf) != 0) { + perror("Error in statfs"); + return -1; + } + return buf.f_bavail * buf.f_bsize; +} |