summaryrefslogtreecommitdiffstats
path: root/src/guestfs-internal.h
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-11-08 11:36:35 +0000
committerRichard W.M. Jones <rjones@redhat.com>2012-11-09 13:11:53 +0000
commit1efed122c07792f4c66a4083159cfacfb1893212 (patch)
treec751f26ec9d3c152905fdf34d48a2b79a0af5216 /src/guestfs-internal.h
parente8d937bd739a70394ec72482a8cb1df3b0601dcc (diff)
downloadlibguestfs-1efed122c07792f4c66a4083159cfacfb1893212.tar.gz
libguestfs-1efed122c07792f4c66a4083159cfacfb1893212.tar.xz
libguestfs-1efed122c07792f4c66a4083159cfacfb1893212.zip
lib: Rework temporary and cache directory code.
New APIs: set-tmpdir, get-tmpdir, set-cachedir, get-cachedir. The current code has evolved over time and has a number of problems: (a) A single environment variable ($TMPDIR) controls the location of several directories. (b) It's hard for the library user to predict which directory libguestfs will use, unless the user simulates the same internal steps that libguestfs performs. This commit fixes these issues. (a) Now three environment variables control the location of all small temporary files, and the appliance cache: For temporary files: $LIBGUESTFS_TMPDIR or $TMPDIR or /tmp. For the appliance cache: $LIBGUESTFS_CACHEDIR or $TMPDIR or /var/tmp. The user can also set these directories explicitly through API calls (guestfs_set_tmpdir and guestfs_set_cachedir). (b) The user can also retrieve the actual directories that libguestfs will use, by calling guestfs_get_tmpdir and guestfs_get_cachedir. These functions are also used internally. This commit also: - reworks the internal tmpdir code - removes the internal (undocumented) guestfs_tmpdir call (replacing it with calls to the documented guestfs_get_tmpdir API instead) - changes the ./run script to set LIBGUESTFS_TMPDIR and LIBGUESTFS_CACHEDIR - adds a test - fixes a few places like libguestfs-make-fixed-appliance which depended on $TMPDIR
Diffstat (limited to 'src/guestfs-internal.h')
-rw-r--r--src/guestfs-internal.h27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h
index aed4182c..17903d30 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -71,10 +71,11 @@
#define TRACE4(name, arg1, arg2, arg3, arg4)
#endif
-#define TMP_TEMPLATE_ON_STACK(var) \
- const char *ttos_tmpdir = guestfs_tmpdir (); \
+#define TMP_TEMPLATE_ON_STACK(g,var) \
+ char *ttos_tmpdir = guestfs_get_tmpdir (g); \
char var[strlen (ttos_tmpdir) + 32]; \
- sprintf (var, "%s/libguestfsXXXXXX", ttos_tmpdir) \
+ sprintf (var, "%s/libguestfsXXXXXX", ttos_tmpdir); \
+ free (ttos_tmpdir)
#ifdef __APPLE__
#define UNIX_PATH_MAX 104
@@ -234,11 +235,19 @@ struct guestfs_h
const struct attach_ops *attach_ops;
/**** Runtime information. ****/
- char *tmpdir; /* Temporary directory containing socket. */
-
char *last_error; /* Last error on handle. */
int last_errnum; /* errno, or 0 if there was no errno */
+ /* Temporary and cache directories. */
+ /* The actual temporary directory - this is not created with the
+ * handle, you have to call guestfs___lazy_make_tmpdir.
+ */
+ char *tmpdir;
+ /* Environment variables that affect tmpdir/cachedir locations. */
+ char *env_tmpdir; /* $TMPDIR (NULL if not set) */
+ char *int_tmpdir; /* $LIBGUESTFS_TMPDIR or guestfs_set_tmpdir or NULL */
+ char *int_cachedir; /* $LIBGUESTFS_CACHEDIR or guestfs_set_cachedir or NULL */
+
/* Callbacks. */
guestfs_abort_cb abort_cb;
guestfs_error_handler_cb error_cb;
@@ -526,13 +535,15 @@ extern void guestfs___call_callbacks_void (guestfs_h *g, uint64_t event);
extern void guestfs___call_callbacks_message (guestfs_h *g, uint64_t event, const char *buf, size_t buf_len);
extern void guestfs___call_callbacks_array (guestfs_h *g, uint64_t event, const uint64_t *array, size_t array_len);
+/* tmpdirs.c */
+extern int guestfs___lazy_make_tmpdir (guestfs_h *g);
+extern void guestfs___remove_tmpdir (guestfs_h *g);
+extern void guestfs___recursive_remove_dir (guestfs_h *g, const char *dir);
+
/* appliance.c */
extern int guestfs___build_appliance (guestfs_h *g, char **kernel, char **initrd, char **appliance);
/* launch.c */
-extern const char *guestfs___persistent_tmpdir (void);
-extern int guestfs___lazy_make_tmpdir (guestfs_h *g);
-extern void guestfs___remove_tmpdir (guestfs_h *g, const char *dir);
extern int64_t guestfs___timeval_diff (const struct timeval *x, const struct timeval *y);
extern void guestfs___print_timestamped_message (guestfs_h *g, const char *fs, ...);
extern void guestfs___launch_send_progress (guestfs_h *g, int perdozen);