mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
lib: Use guestfs_int_make_temp_path in a few more places.
There were various places in the library where we open coded making temporary filenames. This uses the utility function instead.
This commit is contained in:
@@ -74,7 +74,9 @@ guestfs_int_get_uefi (guestfs_h *g, char **code, char **vars, int *flags)
|
||||
* into the address space read-only as that triggers a different
|
||||
* path inside UEFI.
|
||||
*/
|
||||
varst = safe_asprintf (g, "%s/vars.fd.%d", g->tmpdir, ++g->unique);
|
||||
varst = guestfs_int_make_temp_path (g, "vars", "fd");
|
||||
if (!varst)
|
||||
return -1;
|
||||
guestfs_int_cmd_add_arg (copycmd, "cp");
|
||||
guestfs_int_cmd_add_arg (copycmd, varsfile);
|
||||
guestfs_int_cmd_add_arg (copycmd, varst);
|
||||
|
||||
@@ -812,11 +812,9 @@ guestfs_int_cmd_pipe_run (struct command *cmd, const char *mode)
|
||||
* we write them into a temporary file and provide a separate
|
||||
* function for the caller to read the error messages.
|
||||
*/
|
||||
if (guestfs_int_lazy_make_tmpdir (cmd->g) == -1)
|
||||
cmd->error_file = guestfs_int_make_temp_path (cmd->g, "cmderr", "txt");
|
||||
if (!cmd->error_file)
|
||||
goto error;
|
||||
|
||||
cmd->error_file =
|
||||
safe_asprintf (cmd->g, "%s/cmderr.%d", cmd->g->tmpdir, ++cmd->g->unique);
|
||||
errfd = open (cmd->error_file,
|
||||
O_WRONLY|O_CREAT|O_NOCTTY|O_TRUNC|O_CLOEXEC, 0600);
|
||||
if (errfd == -1) {
|
||||
|
||||
@@ -987,9 +987,9 @@ guestfs_impl_add_drive_scratch (guestfs_h *g, int64_t size,
|
||||
* because everything in g->tmpdir is 'rm -rf'd when the handle is
|
||||
* closed.
|
||||
*/
|
||||
if (guestfs_int_lazy_make_tmpdir (g) == -1)
|
||||
filename = guestfs_int_make_temp_path (g, "scratch", "img");
|
||||
if (!filename)
|
||||
return -1;
|
||||
filename = safe_asprintf (g, "%s/scratch.%d", g->tmpdir, ++g->unique);
|
||||
|
||||
/* Create a raw format temporary disk. */
|
||||
if (guestfs_disk_create (g, filename, "raw", size, -1) == -1)
|
||||
|
||||
@@ -390,7 +390,9 @@ icon_cirros (guestfs_h *g, size_t *size_r)
|
||||
return NOT_FOUND;
|
||||
|
||||
/* Use pbmtext to render it. */
|
||||
pngfile = safe_asprintf (g, "%s/cirros.png", g->tmpdir);
|
||||
pngfile = guestfs_int_make_temp_path (g, "cirros", "png");
|
||||
if (!pngfile)
|
||||
return NOT_FOUND;
|
||||
|
||||
guestfs_int_cmd_add_string_unquoted (cmd, PBMTEXT " < ");
|
||||
guestfs_int_cmd_add_string_quoted (cmd, local);
|
||||
@@ -474,7 +476,9 @@ icon_windows_xp (guestfs_h *g, const char *systemroot, size_t *size_r)
|
||||
if (filename_downloaded == NULL)
|
||||
return NOT_FOUND;
|
||||
|
||||
pngfile = safe_asprintf (g, "%s/windows-xp-icon.png", g->tmpdir);
|
||||
pngfile = guestfs_int_make_temp_path (g, "windows-xp-icon", "png");
|
||||
if (!pngfile)
|
||||
return NOT_FOUND;
|
||||
|
||||
guestfs_int_cmd_add_string_unquoted (cmd, WRESTOOL " -x --type=2 --name=143 ");
|
||||
guestfs_int_cmd_add_string_quoted (cmd, filename_downloaded);
|
||||
@@ -542,7 +546,9 @@ icon_windows_7 (guestfs_h *g, const char *systemroot, size_t *size_r)
|
||||
if (filename_downloaded == NULL)
|
||||
return NOT_FOUND;
|
||||
|
||||
pngfile = safe_asprintf (g, "%s/windows-7-icon.png", g->tmpdir);
|
||||
pngfile = guestfs_int_make_temp_path (g, "windows-7-icon", "png");
|
||||
if (!pngfile)
|
||||
return NOT_FOUND;
|
||||
|
||||
guestfs_int_cmd_add_string_unquoted (cmd,
|
||||
WRESTOOL " -x --type=2 --name=6801 ");
|
||||
|
||||
@@ -86,11 +86,10 @@ create_cow_overlay_direct (guestfs_h *g, void *datav, struct drive *drv)
|
||||
if (!backing_drive)
|
||||
return NULL;
|
||||
|
||||
if (guestfs_int_lazy_make_tmpdir (g) == -1)
|
||||
overlay = guestfs_int_make_temp_path (g, "overlay", "qcow2");
|
||||
if (!overlay)
|
||||
return NULL;
|
||||
|
||||
overlay = safe_asprintf (g, "%s/overlay%d", g->tmpdir, ++g->unique);
|
||||
|
||||
optargs.bitmask = GUESTFS_DISK_CREATE_BACKINGFILE_BITMASK;
|
||||
optargs.backingfile = backing_drive;
|
||||
if (drv->src.format) {
|
||||
|
||||
@@ -224,11 +224,10 @@ make_qcow2_overlay (guestfs_h *g, const char *backing_drive,
|
||||
char *overlay;
|
||||
struct guestfs_disk_create_argv optargs;
|
||||
|
||||
if (guestfs_int_lazy_make_tmpdir (g) == -1)
|
||||
overlay = guestfs_int_make_temp_path (g, "overlay", "qcow2");
|
||||
if (!overlay)
|
||||
return NULL;
|
||||
|
||||
overlay = safe_asprintf (g, "%s/overlay%d", g->tmpdir, ++g->unique);
|
||||
|
||||
optargs.bitmask = GUESTFS_DISK_CREATE_BACKINGFILE_BITMASK;
|
||||
optargs.backingfile = backing_drive;
|
||||
if (format) {
|
||||
|
||||
@@ -54,11 +54,10 @@ make_cow_overlay (guestfs_h *g, const char *original)
|
||||
char *overlay;
|
||||
int r;
|
||||
|
||||
if (guestfs_int_lazy_make_tmpdir (g) == -1)
|
||||
overlay = guestfs_int_make_temp_path (g, "overlay", "qcow2");
|
||||
if (!overlay)
|
||||
return NULL;
|
||||
|
||||
overlay = safe_asprintf (g, "%s/overlay%d", g->tmpdir, g->unique++);
|
||||
|
||||
guestfs_int_cmd_add_arg (cmd, "uml_mkcow");
|
||||
guestfs_int_cmd_add_arg (cmd, overlay);
|
||||
guestfs_int_cmd_add_arg (cmd, original);
|
||||
|
||||
Reference in New Issue
Block a user