diff options
Diffstat (limited to 'src/launch.c')
-rw-r--r-- | src/launch.c | 28 |
1 files changed, 20 insertions, 8 deletions
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 |