extern char *guestfs_safe_strdup (guestfs_h *g, const char *str);
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 const char *guestfs___tmpdir (void);
extern void guestfs___free_inspect_info (guestfs_h *g);
extern int guestfs___set_busy (guestfs_h *g);
extern int guestfs___end_busy (guestfs_h *g);
int
guestfs__launch (guestfs_h *g)
{
- const char *tmpdir;
- char dir_template[PATH_MAX];
int r, pmore;
size_t len;
int wfd[2], rfd[2];
gettimeofday (&g->launch_t, NULL);
/* Make the temporary directory. */
-#ifdef P_tmpdir
- tmpdir = P_tmpdir;
-#else
- tmpdir = "/tmp";
-#endif
-
- tmpdir = getenv ("TMPDIR") ? : tmpdir;
- snprintf (dir_template, sizeof dir_template, "%s/libguestfsXXXXXX", tmpdir);
-
if (!g->tmpdir) {
+ const char *tmpdir = guestfs___tmpdir ();
+ char dir_template[strlen (tmpdir) + 32];
+ sprintf (dir_template, "%s/libguestfsXXXXXX", tmpdir);
+
g->tmpdir = safe_strdup (g, dir_template);
if (mkdtemp (g->tmpdir) == NULL) {
perrorf (g, _("%s: cannot create temporary directory"), dir_template);
return -1;
}
+const char *
+guestfs___tmpdir (void)
+{
+ const char *tmpdir;
+
+#ifdef P_tmpdir
+ tmpdir = P_tmpdir;
+#else
+ tmpdir = "/tmp";
+#endif
+
+ const char *t = getenv ("TMPDIR");
+ if (t) tmpdir = t;
+
+ return tmpdir;
+}
+
/* This function is used to print the qemu command line before it gets
* executed, when in verbose mode.
*/