diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2012-08-15 15:41:42 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2012-08-30 22:07:00 +0100 |
commit | b442994d56bf692b2f53af3a627a0ded7ca06e58 (patch) | |
tree | 1b450c93b53a824bf1a1bb8ac18c4457ba91a8d2 /src | |
parent | 7966e8f6323695130b70fcde493bda505575971c (diff) | |
download | libguestfs-b442994d56bf692b2f53af3a627a0ded7ca06e58.tar.gz libguestfs-b442994d56bf692b2f53af3a627a0ded7ca06e58.tar.xz libguestfs-b442994d56bf692b2f53af3a627a0ded7ca06e58.zip |
launch: Add utility function guestfs___lazy_make_tmpdir.
This lets us create g->tmpdir lazily earlier if needed.
This commit is just code motion.
(cherry picked from commit 4b8ac437295d5420d3186a913bc3740b69a8d342)
Diffstat (limited to 'src')
-rw-r--r-- | src/guestfs-internal.h | 1 | ||||
-rw-r--r-- | src/launch.c | 28 |
2 files changed, 21 insertions, 8 deletions
diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h index d76eac1a..832636c1 100644 --- a/src/guestfs-internal.h +++ b/src/guestfs-internal.h @@ -363,6 +363,7 @@ extern void guestfs___debug (guestfs_h *g, const char *fs, ...) extern void guestfs___trace (guestfs_h *g, const char *fs, ...) __attribute__((format (printf,2,3))); extern const char *guestfs___persistent_tmpdir (void); +extern int guestfs___lazy_make_tmpdir (guestfs_h *g); extern void guestfs___remove_tmpdir (const char *dir); 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/launch.c b/src/launch.c index a8b06ac4..3a3d4eb3 100644 --- a/src/launch.c +++ b/src/launch.c @@ -459,14 +459,8 @@ guestfs__launch (guestfs_h *g) TRACE0 (launch_start); /* Make the temporary directory. */ - if (!g->tmpdir) { - TMP_TEMPLATE_ON_STACK (dir_template); - g->tmpdir = safe_strdup (g, dir_template); - if (mkdtemp (g->tmpdir) == NULL) { - perrorf (g, _("%s: cannot create temporary directory"), dir_template); - return -1; - } - } + if (guestfs___lazy_make_tmpdir (g) == -1) + return -1; /* Allow anyone to read the temporary directory. The socket in this * directory won't be readable but anyone can see it exists if they @@ -1192,6 +1186,24 @@ guestfs___persistent_tmpdir (void) return tmpdir; } +/* The g->tmpdir (per-handle temporary directory) is not created when + * the handle is created. Instead we create it lazily before the + * first time it is used, or during launch. + */ +int +guestfs___lazy_make_tmpdir (guestfs_h *g) +{ + if (!g->tmpdir) { + TMP_TEMPLATE_ON_STACK (dir_template); + g->tmpdir = safe_strdup (g, dir_template); + if (mkdtemp (g->tmpdir) == NULL) { + perrorf (g, _("%s: cannot create temporary directory"), dir_template); + return -1; + } + } + return 0; +} + /* Recursively remove a temporary directory. If removal fails, just * return (it's a temporary directory so it'll eventually be cleaned * up by a temp cleaner). This is done using "rm -rf" because that's |