diff options
author | joerg <joerg> | 2007-07-16 09:54:55 +0000 |
---|---|---|
committer | joerg <joerg> | 2007-07-16 09:54:55 +0000 |
commit | 2a03da4229e33c3aab9e2e0bb2814d6ada27f8aa (patch) | |
tree | a6bca23e7251594ebf4d955bcd47f7c63076ea44 | |
parent | 685ac7335fd1a966f13443739e00d14d54a5c0ab (diff) | |
download | pkgsrc-2a03da4229e33c3aab9e2e0bb2814d6ada27f8aa.tar.gz |
Merge r1.37 from NetBSD:
PR/36274: Jukka Salmi: pkg_add(8) -t option broken, template passed in
is treated as a directory. While there simplify and shorten the code...
-rw-r--r-- | pkgtools/pkg_install/files/lib/pen.c | 62 |
1 files changed, 36 insertions, 26 deletions
diff --git a/pkgtools/pkg_install/files/lib/pen.c b/pkgtools/pkg_install/files/lib/pen.c index 87853083702..52beaa9114e 100644 --- a/pkgtools/pkg_install/files/lib/pen.c +++ b/pkgtools/pkg_install/files/lib/pen.c @@ -1,4 +1,4 @@ -/* $NetBSD: pen.c,v 1.19 2006/04/04 06:34:25 wiz Exp $ */ +/* $NetBSD: pen.c,v 1.20 2007/07/16 09:54:55 joerg Exp $ */ #if HAVE_CONFIG_H #include "config.h" @@ -11,7 +11,7 @@ #if 0 static const char *rcsid = "from FreeBSD Id: pen.c,v 1.25 1997/10/08 07:48:12 charnier Exp"; #else -__RCSID("$NetBSD: pen.c,v 1.19 2006/04/04 06:34:25 wiz Exp $"); +__RCSID("$NetBSD: pen.c,v 1.20 2007/07/16 09:54:55 joerg Exp $"); #endif #endif @@ -100,38 +100,48 @@ where_playpen(void) static char * find_play_pen(char *pen, size_t pensize, size_t sz) { - char *cp; + const char **cp; struct stat sb; + char *r; + const char *tmpdir[] = { + "PKG_TMPDIR", + "TMPDIR", + "/var/tmp", + "/tmp", + "/usr/tmp", + NULL + }; if (pen == NULL) { cleanup(0); - errx(2, - "find_play_pen(): 'pen' variable is NULL\n" - "(this should not happen, please report!"); + errx(2, "find_play_pen(): 'pen' variable is NULL\n" + "(this should not happen, please report!)"); return NULL; } - if (pen[0] && stat(pen, &sb) != FAIL && (min_free(pen) >= sz)) + if (pen[0] && (r = strrchr(pen, '/')) != NULL) { + *r = '\0'; + if (stat(pen, &sb) != FAIL && (min_free(pen) >= sz)) { + *r = '/'; + return pen; + } + } + + for (cp = tmpdir; *cp; cp++) { + const char *d = (**cp == '/') ? *cp : getenv(*cp); + + if (d == NULL || stat(d, &sb) == FAIL || min_free(d) < sz) + continue; + + (void)snprintf(pen, pensize, "%s/instmp.XXXXXX", d); return pen; - else if ((cp = getenv("PKG_TMPDIR")) != NULL && stat(cp, &sb) != FAIL && (min_free(cp) >= sz)) - (void) snprintf(pen, pensize, "%s/instmp.XXXXXX", cp); - else if ((cp = getenv("TMPDIR")) != NULL && stat(cp, &sb) != FAIL && (min_free(cp) >= sz)) - (void) snprintf(pen, pensize, "%s/instmp.XXXXXX", cp); - else if (stat("/var/tmp", &sb) != FAIL && min_free("/var/tmp") >= sz) - strlcpy(pen, "/var/tmp/instmp.XXXXXX", pensize); - else if (stat("/tmp", &sb) != FAIL && min_free("/tmp") >= sz) - strlcpy(pen, "/tmp/instmp.XXXXXX", pensize); - else if (stat("/usr/tmp", &sb) != FAIL && min_free("/usr/tmp") >= sz) - strlcpy(pen, "/usr/tmp/instmp.XXXXXX", pensize); - else { - cleanup(0); - errx(2, - "can't find enough temporary space to extract the files, please set your\n" - "PKG_TMPDIR environment variable to a location with at least %lu bytes\n" - "free", (u_long) sz); - return NULL; } - return pen; + + cleanup(0); + errx(2, "Can't find enough temporary space to extract the files.\n" + "Please set your PKG_TMPDIR environment variable to a location " + "with at least %zu bytes free", sz); + return NULL; } /* @@ -211,7 +221,7 @@ leave_playpen(char *save) * operating systems. */ uint64_t -min_free(char *tmpdir) +min_free(const char *tmpdir) { struct statvfs buf; |