From 98430c35faa073c60d4c00542c090fe0407c5af7 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 21 Jul 2009 11:47:57 +0100 Subject: [PATCH] Allow TMPDIR to override directory used for temporary files (RHBZ#512905). --- guestfish.pod | 10 ++++++++++ guestfs.pod | 10 ++++++++++ src/guestfs.c | 12 +++++++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/guestfish.pod b/guestfish.pod index 32a3090..f2255f1 100644 --- a/guestfish.pod +++ b/guestfish.pod @@ -576,6 +576,16 @@ used. The C command uses C<$PAGER> as the pager. If not set, it uses C. +=item TMPDIR + +Location of temporary directory, defaults to C. + +If libguestfs was compiled to use the supermin appliance then each +handle will require rather a large amount of space in this directory +for short periods of time (~ 80 MB). You can use C<$TMPDIR> to +configure another directory to use in case C is not large +enough. + =back =head1 EXIT CODE diff --git a/guestfs.pod b/guestfs.pod index 2fd88ce..4235454 100644 --- a/guestfs.pod +++ b/guestfs.pod @@ -937,6 +937,16 @@ used. See also L above. +=item TMPDIR + +Location of temporary directory, defaults to C. + +If libguestfs was compiled to use the supermin appliance then each +handle will require rather a large amount of space in this directory +for short periods of time (~ 80 MB). You can use C<$TMPDIR> to +configure another directory to use in case C is not large +enough. + =back =head1 SEE ALSO diff --git a/src/guestfs.c b/src/guestfs.c index f445ada..386dee6 100644 --- a/src/guestfs.c +++ b/src/guestfs.c @@ -875,7 +875,8 @@ static const char *supermin_hostfiles_name = int guestfs_launch (guestfs_h *g) { - static const char *dir_template = "/tmp/libguestfsXXXXXX"; + const char *tmpdir; + char dir_template[PATH_MAX]; int r, i, pmore; size_t len; int wfd[2], rfd[2]; @@ -885,6 +886,15 @@ guestfs_launch (guestfs_h *g) char unixsock[256]; struct sockaddr_un addr; +#ifdef P_tmpdir + tmpdir = P_tmpdir; +#else + tmpdir = "/tmp"; +#endif + + tmpdir = getenv ("TMPDIR") ? : tmpdir; + snprintf (dir_template, sizeof dir_template, "%s/libguestfsXXXXXX", tmpdir); + /* Configured? */ if (!g->cmdline) { error (g, _("you must call guestfs_add_drive before guestfs_launch")); -- 1.8.3.1