From: Richard W.M. Jones Date: Wed, 19 Jan 2011 21:47:23 +0000 (+0000) Subject: Use /var/tmp for the cached appliance (for FHS compliance). X-Git-Tag: 1.9.6~2 X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=commitdiff_plain;h=78f1405de05ef1f2efebafd8245658d1707e59ef Use /var/tmp for the cached appliance (for FHS compliance). The FHS advises large files not to be stored in the root filesystem[1], and that /var/tmp is persistent across reboots[2] (whereas /tmp is possibly not[3]). Therefore we should store the large cached supermin appliance in /var/tmp instead of /tmp. /tmp is still used for all other temporary files and directories. In either case you can override this by setting $TMPDIR. [1] http://www.pathname.com/fhs/pub/fhs-2.3.html#THEROOTFILESYSTEM [2] http://www.pathname.com/fhs/pub/fhs-2.3.html#VARTMPTEMPORARYFILESPRESERVEDBETWEE [3] http://www.pathname.com/fhs/pub/fhs-2.3.html#TMPTEMPORARYFILES --- diff --git a/fish/guestfish.pod b/fish/guestfish.pod index 5ec6689..0f318f0 100644 --- a/fish/guestfish.pod +++ b/fish/guestfish.pod @@ -1052,12 +1052,13 @@ set, it uses C. =item TMPDIR -Location of temporary directory, defaults to C. +Location of temporary directory, defaults to C except for the +cached supermin appliance which defaults to C. If libguestfs was compiled to use the supermin appliance then the real appliance is cached in this directory, shared between all handles belonging to the same EUID. You can use C<$TMPDIR> to -configure another directory to use in case C is not large +configure another directory to use in case C is not large enough. =back diff --git a/src/appliance.c b/src/appliance.c index 1b6b505..ef724be 100644 --- a/src/appliance.c +++ b/src/appliance.c @@ -308,7 +308,7 @@ check_for_cached_appliance (guestfs_h *g, uid_t uid, char **kernel, char **initrd, char **appliance) { - const char *tmpdir = guestfs_tmpdir (); + const char *tmpdir = guestfs___persistent_tmpdir (); /* len must be longer than the length of any pathname we can * generate in this function. @@ -419,7 +419,7 @@ build_supermin_appliance (guestfs_h *g, if (g->verbose) guestfs___print_timestamped_message (g, "begin building supermin appliance"); - const char *tmpdir = guestfs_tmpdir (); + const char *tmpdir = guestfs___persistent_tmpdir (); /* len must be longer than the length of any pathname we can * generate in this function. diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h index 08b459b..194c892 100644 --- a/src/guestfs-internal.h +++ b/src/guestfs-internal.h @@ -257,6 +257,7 @@ extern char *guestfs_safe_strndup (guestfs_h *g, const char *str, size_t n); extern void *guestfs_safe_memdup (guestfs_h *g, void *ptr, size_t size); extern char *guestfs_safe_asprintf (guestfs_h *g, const char *fs, ...) __attribute__((format (printf,2,3))); +extern const char *guestfs___persistent_tmpdir (void); extern void guestfs___print_timestamped_argv (guestfs_h *g, const char *argv[]); extern void guestfs___print_timestamped_message (guestfs_h *g, const char *fs, ...); extern void guestfs___free_inspect_info (guestfs_h *g); diff --git a/src/guestfs.pod b/src/guestfs.pod index ab4e768..b8b8ca2 100644 --- a/src/guestfs.pod +++ b/src/guestfs.pod @@ -2501,12 +2501,13 @@ has the same effect as calling C. =item TMPDIR -Location of temporary directory, defaults to C. +Location of temporary directory, defaults to C except for the +cached supermin appliance which defaults to C. If libguestfs was compiled to use the supermin appliance then the real appliance is cached in this directory, shared between all handles belonging to the same EUID. You can use C<$TMPDIR> to -configure another directory to use in case C is not large +configure another directory to use in case C is not large enough. =back diff --git a/src/launch.c b/src/launch.c index e009aae..a7a86b9 100644 --- a/src/launch.c +++ b/src/launch.c @@ -770,6 +770,7 @@ guestfs__launch (guestfs_h *g) /* Return the location of the tmpdir (eg. "/tmp") and allow users * to override it at runtime using $TMPDIR. + * http://www.pathname.com/fhs/pub/fhs-2.3.html#TMPTEMPORARYFILES */ const char * guestfs_tmpdir (void) @@ -788,6 +789,23 @@ guestfs_tmpdir (void) return tmpdir; } +/* Return the location of the persistent tmpdir (eg. "/var/tmp") and + * allow users to override it at runtime using $TMPDIR. + * http://www.pathname.com/fhs/pub/fhs-2.3.html#VARTMPTEMPORARYFILESPRESERVEDBETWEE + */ +const char * +guestfs___persistent_tmpdir (void) +{ + const char *tmpdir; + + tmpdir = "/var/tmp"; + + const char *t = getenv ("TMPDIR"); + if (t) tmpdir = t; + + return tmpdir; +} + /* Compute Y - X and return the result in milliseconds. * Approximately the same as this code: * http://www.mpp.mpg.de/~huber/util/timevaldiff.c